-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find references to fields via getters/setters #1561
Conversation
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the change works for me with "java.references.includeGetterSetter": true in settings.json. Just had a question about some added logic.
int offset = JsonRpcHelpers.toOffset(typeRoot.getBuffer(), param.getPosition().getLine(), param.getPosition().getCharacter()); | ||
elementToSearch = typeRoot.getElementAt(offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular case you encountered that this addresses, or is this just a precaution ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an Eclipse upstream issue.
You can reproduce it using the following steps:
- git clone git@github.com:Frederick888/java-dummy.git
- cd java-dummy
- mvn clean verify # download lombok-1.18.10.jar
- start Eclipse with the following VM arguments:
-javaagent:~/.m2/repository/org/projectlombok/lombok/1.18.10/lombok-1.18.10.jar -Dlog.level=ALL -XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx3G
- open the java-dummy project in Eclipse
- open Apple.java
- right click the id field (line 20), select References>Workspace
You will get the "Operation is unavailable on the current selection. Please select a valid Java element type" message dialog.
If you start Eclipse without the "-javaagent:/home/snpe/.m2/repository/org/projectlombok/lombok/1.18.10/lombok-1.18.10.jar" VM arguments, it works fine.
This code solves such issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, definitely looks like a JDT-lombok issue when lombok handles the generated bytecode. getElementAt(..) seems to work around the limitations of codeSelect(..). We could probably file this upstream eventually although it seems like such issues have happened in the past, and we would probably need to do a thorough investigation proving it really is needed (See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442070 )
Also, if we have to support any additional builder generation libraries in the future, we should probably clean up getBuilderName(..) and the block below its invocation.
Change looks good though, so feel free to merge.
IAnnotation annotation = declaringType.getAnnotation("Builder"); | ||
if (annotation == null || !annotation.exists()) { | ||
annotation = declaringType.getAnnotation("lombok.Builder"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may eventually have to evolve to support other builders (eg. https://immutables.github.io/ ) but I think it should be fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename preference to java.references.includeAccessors and set default value to true
* Preference key used to include getter, setter and builder/constructor when | ||
* finding references. | ||
*/ | ||
public static final String JAVA_REFERENCES_INCLUDE_GETTERSETTER = "java.references.includeGetterSetter"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JAVA_REFERENCES_INCLUDE_ACCESSORS = "java.references.includeAccessors";
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
Show resolved
Hide resolved
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
Fixes #1548
Requires redhat-developer/vscode-java#1646
Signed-off-by: Snjezana Peco snjezana.peco@redhat.com