IDEA shows method as in use, when it is not - java

Why does IDEA show this SimpleClass.start method as in use:
Even when it is not. Changing the name of the method to something else then greys it out as not in use:
Seems to not only happen with start but also init and stop for ones I've tried. Am using version 13.1.4 on Windows.

This is a performance optimisation.
Basically IntelliJ IDEA first checks its index for occurrences of the name of the method.
Then it checks in the file of every occurrence to see if it's really a usage of that method.
If the name of the method is used in many places, many files will have to be parsed and checked. To avoid taking too much time and cpu for that, the check is skipped if there are more than a certain amount of occurrences in the index and it assumes that the method is used (Since the probability is very high).
Running the unused declaration inspection in batch mode (Analyze > Run Inspection by Name...) will still report the method as unused.

Related

AnyLogic method exceeding the byte limit error: how these methods are actually defined?

This is a follow-up question on this; regarding the error message as below:
Description: The code of method _createPersistentElementsBP5_xjal() is exceeding the 65535 bytes limit.
It basically says that the size of the code for the method _createPersistentElementsBP5_xjal() has exceeded the maximum limit. By inspecting the Java code of the model, I see that my main agent is divided into six parts: _createPersistentElementsBP1_xjal(), _createPersistentElementsBP2_xjal(),..., _createPersistentElementsBP6_xjal().
And the one with number 5 has issues. However, I cannot find any defined logic on how these methods are separated (e.g., what elements to include in which method).
If you look at the top part of the screenshot, you will see that paths 5,6,7 belong to ...BP4_xjal(). And then starts ...BP5_xjal() (the problematic one) with intersections and a node called reversePoint4. In fact, reversePoint4 and path5/6/7 all belong to the same network.
The question is: what is the basis for such method definitions in AnyLogic (e.g., which elements will belong to which method)? Is it done arbitrarily?
You can probably only know an answer to this by asking AnyLogic support since this is the internals of its code generation. My guess would be that it just splits the initialisation of space markup elements into 'chunks' of a given number (perhaps --- and this would be rather ironic --- to try to avoid method/signature size issues).
(I'm assuming that the BP1-5 splits don't correspond to any 'functional' splits in your model; e.g., different space markup networks or similar. You seem to be implying that in your question.)
Java has an in-built limit on the amount of text that can be used to define a single method (more explanation here). In this case, this error is caused by the actual text of the method is generated by AnyLogic.
To solve this I would try to restructure the model to reduce the amount of text. This can be done by defining functions that create elements instead of defining elements directly or moving elements inside other agents that are then included in Main agent.

Drools Decision Table Action Execution Order

I have a Drools decision table (see below) whereby Rule 2 has a condition that checks whether a nutrient score is between a certain threshold and executes an action based on this condition. There is an initial rule (RULE 1) that performs a check and performs its action, which updates the overall scores that i want Rule2 to use when executing its conditions.
What i expect/need:
Rule 1 to run, if the condition is met then update the overall score on $model (by executing its action) and then rule 2 run and for it's conditions to use the updated score value that was updated by Rule 1's action running.
What's actually happening
Rule 1 runs it's condition, Rule 2 runs its condition, Rule 1's action is run, Rule 2's action is run. Rule 2 is running it's condition before Rule 1's action has run, and therefore uses an outdated score.
I've proven (i think) by changing the priority/salience value that i can change the order in which the rules run their conditions, but it seems that all rule conditions are running before actions. I expected Rule 1's action to run before the next rule.
Have i fundamentally mis-understood the concept? An obvious mistake? Or if anyone has a suggested workaround that would be great.
To clarify this is a stateless ki session.
Thanks in advance, this is driving me mad!
Drools works by taking all of the rules up front and evaluating whether their conditions are satisfied. Each of these rules is called a "match". When you fire the rules, Drools collects all of the matches, orders them (either naturally or by salience), and then iterates through and executes them one by one.
As the rules are executed, they might change working memory like your example does. Unless you explicitly tell Drools that you're doing so, however, it won't re-evaluate the matches. The match phase has already been completed by the time the rules are executed.
It is possible to tell Drools that you are modifying working memory and that you need it to re-evaluate its rules based on the new data. To do this, you need to use one of the built-in methods:
Method
Explanation
insert
Put a new fact into working memory.
delete or retract
Removes some information (object/s) from working memory.
update
Update/replace a fact in working memory.
modify
Change fields inside of a fact in working memory.
Which one you choose depends on what you're trying to do. Note that calling 'update' will call all matches to be re-evaluated ... it's the equivalent of calling "fire rules" a second time with the new data (so the same rule might hit multiple times, which may or may not be intentional). In comparison, insert will only evaluate subsequent rules to determine if they now match or don't based on the new conditions.
So if your intention is to cause other rules to fire or not by changing the data in working memory, you'll need to use one of these built-in methods to tell Drools that you're making a change that it should re-evaluate its matches for.
I discuss this concept in more detail in this answer specifically about DRL. The same concepts apply to decision tables.

Detecting termination in CP-SAT

I was exploring the CP-SAT APIs for fetching all solution for given set of constraints.
As per the API documentation, onSolutionCallback() function is called for every solution found. However if I need to find all solutions for a given model, is there a way to detect the last solution or the feasibility of no more solutions through onSolutionCallback() function or other means?
I found that searchAllSolutions() API can be used and we can set termination conditions based on time or number of solutions. Assuming I can wait unlimited amount of time, how do I detect that there are no more solutions feasible?
https://developers.google.com/optimization/cp/cp_tasks
Another related question:
Is there any remote chance for a CP SAT solver to run into a non-deterministic state or run into infinite loops (or such) even when there is a feasible solution possible for given set of constraints?
I plan to use the CPSAT for a production usecase and hence would like to know its determinism and upper bounds for execution.
Edit: Added the second question.

IntelliJ debugging - Watch for any variable containing a specific value

Is it possible to put out a global watch or breakpoint, on no specific variable or line of code, with the aim of identifying the first instance of a value?
I'm debugging on an old java6 web app that does a million calculations between multiple databases and dozens of classes with thousands of lines of code each. I'm not exactly sure which of these dozens of classes are being called within this project containing hundreds of classes.
Let's say I'm looking for where "the dog runs" appears in the flow of a calculation: Is it possible to listen for the first appearance of that string with the intention of finding what variable will contain the value?
I do not think that is possible to monitor where a value comes into existence as i think you have asked.
However, you can set "field watchpoints" which are basically expressions like break when x = "the dog runs". When i have used these before the program will run very very slowly.
Refer here for details of how to set it: Intellij breakpoints.
Another technique is to start near the top of where you think a value is being set to what you want. Step over each method until you see where the value set to what you are looking for. Then repeat the process inside the method that you saw it change (i.e. this time step into the method where the value changed).
Within this "second level method", you will probably see another call that sets the value you are looking for. So repeat the process again until you find a system call that sets the value (e.g. a read from a database or a regex match etc).
It sounds tedious, but it is a "divide and conquer" method of the form that eliminates a huge chunk of code that doesn't set the value you are looking for into the one method call that does. Then you divide and conquer the inner workings of that method. In practice, it doesn't take long before you narrow it down.

What do these numbers `10k`, `6k`, `1k`, `210` in java eclipse code completion mean?

What do 10k, 6k, 1k and 210 mean in this eclipse Luna code completion popup. It appeared when I was trying to override a method from a custom class in a custom class.
That is a certain plugin at work, either Code Recommenders or something similar.
Basically, it's (crowd sourced) information that tells you how often or likely a certain method is called or overridden.
AFAIK, The greater the number to the right of a method, the greater the probability that you'll use that method in that context, as calculated by some weird algorithm.
These numbers come from our Codetrails Connect Hippie Completion.
It shows how often developers call or override methods and suggests them in order of frequency. In this case, Object.equals() was overridden about 10.000 times, while Object.hashCode() was overridden about 6.000 times.
The data comes from users of Codetrails Connect who decided to share their code completion events with us. We then aggregate those events and provide the resulting information back to our users.
You can adjust the way these numbers are shown at Preferences > Codetrails Connect > Hippie - Relevance Indicator Settings. Instead of the default "Heatmap", you can elect to show absolute, unrounded numbers with "Simple (m/n)" or show the relative "Percentage" for proposals.

Categories

Resources