Can IntelliJ IDEA automatically fill the method call with variables? - java

Can IntelliJ IDEA automatically fill the method call with variables?
Possibly using the names which are based on the names of the parameters of the method which is called and even also with possibility to extract those variables as parameters of the current method?
See the screenshots below for reference.
Before: IntelliJ knows what are the names of the parameters of the method which is being called.
After: IntelliJ created properly named variables for us.
With automatic extracting of all parameters: IntellJ can automatically extract these variables to be parameters of the current method.

It should work if there are the local variables with the same name exist in context:
See also IDEABKL-6690, IDEABKL-5496 requests.
You can also try Smart Completion: https://www.jetbrains.com/help/idea/auto-completing-code.html#smart_completion.
There is a custom plugin that seems to do the thing - https://plugins.jetbrains.com/plugin/8638-auto-filling-java-call-arguments. You can give it a try

Related

Add local variable to JShell evaluation context

I'm using jdk.jshell.JShell to evaluate Java code programmatically and I'd like to add a local variable to the active evaluation context, so the value is useable in the shell.
I'm instantiating the JShell with a DirectExecutionControl, so it runs on the same JVM as the main code. I've spent quite a lot of time stepping through the source code of the JDK trying to see where I could plug myself, but it's quite opaque; simply getting an Object result out of eval(...) instead of a String required a number of hacks (Oracle, why?).
The answer here seems to suggest that this is not possible, without justification, but I'm too deep into this to accept that.
Ideas I have thought about:
- creating a class dynamically, with a field corresponding to the variable I want to add, and `import static`ing that class into the JShell (but I don't know how to dynamically add an import either)
- trying to find one of the internal auto-generated classes JShell is using to store the variables, and replacing them using arcane reflection magic

Is it possible to make a static reference to an excel sheet in AnyLogic?

I want to call an Excel with a static java function within an AnyLogic Model as shown in the picture. The function "readExcelFile" has to be static, because I want to call it from another class within my AnyLogic Project.
However, when I call the function, an error occurs: "Cannot make a static reference to the non-static field produktionssystem".
Is there a solution for this problem?
The error is because the Excel element produktionssystem can only ever be a (non-static) element in whatever agent type your function is also in (Main from the screenshot). By definition a static function cannot see any elements (Java fields) inside agent instances.
But you should never need a static function unless you need to share it across runs (which can have dangerous side effects if you're not careful). Your agents that need to call it just need a reference to an agent instance that does have the function.
If the calling agent is a 'child' of the function-declaring agent, you've already got the "Link to upper level agent" main provided by AnyLogic (and this will always exist if the calling agent is anywhere in the model's hierarchy of agents). Otherwise your calling agent will need something like a parameter of type Main which is set by whoever creates it.
It's tough to understand what is causing the error here, because I can't see inside your function.
There is no inherent issue with read/write to Excel files from within another class (i.e. within another agent, custom class, etc...).
Here is a link to a public model on the AnyLogic cloud that I found very helpful when I first started working with Excel files within AnyLogic:
https://cloud.anylogic.com/model/99d9f196-17e7-47c3-9b28-63a6f23b0dad?mode=SETTINGS

Java variable names out of strings

Have a problem with undocumented libraries, where I am trying to replace some classes in the .jar without any source code provided. One class is implemented from an existing one (no java file for it) so i have all the methods and method signatures but the no way to make any sens out of parameters because they are all named arg0, arg1..., because there are a lot of methods and some contain up to 43 parameters trying to loop through the parameters in order to see what is coming in. Is there any way to use String and dynamically get to that variable?
edit:
---more info---
Everything is compiled in the jar file, which I was able to repackage without one class that I want to change. So, the class that I want to change extended another class which is compiled. So, when extended the compiled class my IDE auto-generated all the methods and their signatures whre the parameters are named sequentially and I would like to place a for-loop in every function to see what is coming in instead of go one-by-one and print it to the console. I think I was a little vague in the original question.
Thank you
No, if those symbols have been removed from the compiled class file, you cannot recover them.
You can't get access to the parameter names unless the class was compiled in debug mode. But if you just want to iterate and print the values of each parameter passed in, mockito might be able to help you there if you mock the method. Or you can just step with a graphical debugger.

Whats up with the URL's fragment for generic methods?

I'm using IntelliJ IDEA and have it set up to open the JavaDoc for any type or member in my browser. Now it seems that IntelliJ IDEA can't guess the full URL for methods that have a generic type as parameter, when I try to to open the documentation for the method java.lang.Object.isAssignableFrom(Class<?>) it asks which of these two URLs should be opened:
file:///[...]/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class<?>)
file:///[...]/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class)
Are these two competing standards for encoding the type of a method with generic parameters? Can I assume that only one will be used in the future (presumably the first)?
For an added bonus: Is there a way to set up IntelliJ IDEA to automatically chose one of these forms by defaults?

How can I pass arguments to an extension point constructor?

Eclipse calls the default (zero-argument) constructor when instantiating an extension point. I want to provide some arguments. I found a recommendation to use IExecutableExtension#setInitializationData but that appears to require specifying the argument values statically in XML. I need them to be dynamic. Another recommendation was to implement IExecutableExtensionFactory but that seems heavy handed. (The interface also seems pointless, as all it contains is a create() method.) I could add a method to set the values after creation but my class won't work correctly without them and they shouldn't be changed after creation, so forcing them to be provided at object creation time is preferable. This can't be a unique situation. What's the standard way of handling this?
If the arguments need to be "dynamic," where would they come from? How would Eclipse know what values to use? Extension point objects are created when the plugin is activated, so there is not much context available at that point.
I think the best option for you is to use IExecutableExtensionFactory after all. Your factory can implement IExecutableExtension to receive the XML configuration data and then be coded to create the objects based on that and any other context you can make available to it.
Depending on your needs, you could use Dynamic String Substitution Variables to insert certain context into your factory. See also Externalizing strings in plugin.xml for Eclipse plugin

Categories

Resources