I am writing a java program with an open source library using Eclipse and I am observing my IDE suggestions as follows. I added the library to my project by importing jar from IDE.
As you can see in the image, it shows me parameter names as srg0, arg1,..
However, in the source code of the library in github, it uses different variable names such as P, N, r.
I have observed in some cases IDE shows the same name that is used in the source.
I am curious on how IDE shows parameter name in such cases. How does the IDE pick parameter names to show here?
Either the references class would have had to be compiled using the -parameter compiler flag (see https://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html)
Or you need to attach the source of the library to the library jar
Related
Also whenever I try to see the methods of a DS using the "." the IDE won't show me the methods of the map. It's like if I'm programming in a word document, no help of the IDE. Also you can see the weird colors of the variables in the photo. I don't know what's happening.
I'm not sure about the syntax coloring, but when working with Java, at minimum you need some context: the relevant "classpath". Eclipse provides that by having you create a Java Project and setting up the project's Java Build Path. The error message is telling you that it can't do what you're trying to do because you lack all of that. Without that information, there's no way to tell if you're referring to types, methods, and fields that actually exist, and definitely nothing against which to create completion proposals.
So create a project using the New Java Project wizard. Put your source file into the Source Folder, in the correct place according to its package statement, and then proceed with whatever it is you were trying to do.
I have implemented an AnnotationProcessor that picks up class annotations that take a string argument. The string argument is an expression in a domain-specific language, which the annotation processor will use to compile a class file.
I create a small test project to try this out. The behaviour I see is this:
I can successfully build the project using maven
I can successfully run the project from within intellij
Despite the project RUNNING in intellij, the generated class is not recognised in the editor ("Cannot resolve class '...'"), and intelli-sense does not work, either.
I've tried to find the issue and found:
the class file that is being generated is being created in target/classes/package/name/KlassName.class (this is the location that the Filer::createClassFile method picks, I'd have expected this to go to some separate directory though).
if I'd create a java source file during annotation processing (using Filer::createSourceFile), intellij would have no problem. However, I can't do that, since the compiler is a library that really must create classes directly.
I have two guesses about what a solution might look like:
This problem might stem from intellij not looking inside target/classes when type checking in the editor window.
The class files should be generated in a separate directory instead. If so, what is the setting to fix that?
I have reproduced this issue using intellij IDEA 2016.2.1 and intellij IDEA 2017.2 EAP.
My goal is to add some source code to existing class using annotations.
First, I create an annotation and then I implemented a AbstractProcessor Class.
After that I create the javax.annotation.processing.Processor file and I generate the JAR file using the export eclipse option.
When I use my jar in other project I have the following error:
Internal compiler error: java.lang.NoClassDefFoundError: com/sun/source/util/Trees at org.xxx.preprocessor.ActionProcessor.init(ActionProcessor.java:44)
And the mentioned line is like the joined picture:
I want to use tree in order to get the compilation unit and add some code to my annotated function.
So in the first time I don't know how to fix this problem, or another way to do this.
You wrote an AP tool which is based on Sun internal code but run it inside of the Eclipse IDE. Eclipse comes with it's own Java compiler, so you don't have access to internal Java classes anymore.
I suggest to look at Project Lombok which has the exact same problem and look at their solution. The source hides behind the "Contribute" link: https://github.com/rzwitserloot/lombok
In the src/ folder is a folder eclipseAgent/ which should get you started.
Sometimes I find that Eclipse can't find certain class source files when I ctrl-click a classname in source code, even while finding it via ctrl-shift-T (typing the class name) works fine.
Is there a way to set ctrl-click to use the same search path as ctrl-shift-T?
Eclipse Version: Neon Milestone 1 (4.6.0M1)
Build id: 20150820-1211
[EDIT: to clarify, I'm aware I can probably resolve my issue by attaching source, etc. But the point is I don't want to have two separate search paths here -- since ctrl-shift-T already works fully and takes me to the correct source code, this means that Eclipse DOES at some level already know where the source code is. Therefore I want to latch onto that rather than manually configuring it a second time]
You need to tell eclipse where the source for that class is located. When you go to the definition currently, you are accessing it through the jar dependency. When you use ctrl+shift+t you are looking up the actual source file in a different location. You need to connect the two. When you open the decompiled class, there should be a button that says "attach source..." Click the button and navigate to where the source for the class is.
I have been searching for a long time on how to step through imported code classes in netbeans with no solution.
When debugging or stepping into the code, netbeans does not highlight and stop at the imported code classes being used. This is extremely inconvenient since the code I am working on is complex and stepping through is the only way to fully understand it.
I created a new project with existing sources. I have made sure that under window>debugging>sources I have added my working folders.
I also made sure the sources were added in the "runtime" classpath.
The compile classpath appears to be empty, I'm not sure whether that has something to do with it.
MORE INFO: In the debugging window while the program is paused, the main method profile from my imported class says it is reading from "Hidden source calls", but it is really just the normal imported code.
Why is this happening? Can anyone please help?
Folks,
One of the reasons you can get Hidden Source calls is adding in existing packages and java source code at the wrong directory level. You MUST add in the parent directory of the package not the child directory that represent the package name,
example if you have /home/torsi/java/src/torsipackage/com/main.java, you need to add in src, not torsipackage, you will now you made this mistake if you see listed in the top-level package name for your package.
Tom
Well I've not heard the term "Hidden source calls" before but I wonder if you're trying to step into third party code? If you want to step into compiled code it must have source associated I believe. I think it's possible to step into native code because they include the source somehow in the distribution for that exact reason. If you want to step into a library that's been developed by some other private entity you will likely not be afforded that luxury unless it's open source, and even then you may have to retrieve the source first.
Ultimately my point is that there is a difference between a .java file and a .class file. I believe it's possible to reverse engineer .class files but haven't done research on the topic.
If you want to step into code you didn't write odds are you'll need to change your code to work with the imported library or alternatively file a bug report with the developer.