Skip to content
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

Merged
merged 1 commit into from
Oct 8, 2020

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Oct 7, 2020

Fixes #1548
Requires redhat-developer/vscode-java#1646

Signed-off-by: Snjezana Peco snjezana.peco@redhat.com

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
Copy link
Contributor

@rgrunber rgrunber left a 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.

Comment on lines +73 to +74
int offset = JsonRpcHelpers.toOffset(typeRoot.getBuffer(), param.getPosition().getLine(), param.getPosition().getCharacter());
elementToSearch = typeRoot.getElementAt(offset);
Copy link
Contributor

@rgrunber rgrunber Oct 7, 2020

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 ?

Copy link
Contributor Author

@snjeza snjeza Oct 7, 2020

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.

Copy link
Contributor

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.

Comment on lines +110 to +113
IAnnotation annotation = declaringType.getAnnotation("Builder");
if (annotation == null || !annotation.exists()) {
annotation = declaringType.getAnnotation("lombok.Builder");
}
Copy link
Contributor

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.

@snjeza snjeza merged commit ece3235 into eclipse-jdtls:master Oct 8, 2020
Copy link
Contributor

@fbricon fbricon left a 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";
Copy link
Contributor

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";

howel52 pushed a commit to howel52/eclipse.jdt.ls that referenced this pull request Apr 13, 2021
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find references to fields via getters/setters
3 participants