lahodaj commented on code in PR #9210:
URL: https://github.com/apache/netbeans/pull/9210#discussion_r2824369336
##########
java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java:
##########
@@ -478,30 +476,16 @@ public static Context resolveContext(CompilationInfo
controller, Document doc, i
}
}
if (el != null && el.getKind() == ElementKind.METHOD) {
- for (Element peer :
el.getEnclosingElement().getEnclosedElements()) {
- if
(peer.getKind().name().contains("RECORD_COMPONENT")) {
- try {
- Class<?> recordComponent =
Class.forName("javax.lang.model.element.RecordComponentElement", true,
VariableTree.class.getClassLoader());
- Method getAccessor =
recordComponent.getDeclaredMethod("getAccessor");
- Method getRecordComponents =
TypeElement.class.getDeclaredMethod("getRecordComponents");
- for (Element component :
(Iterable<Element>) getRecordComponents.invoke(peer.getEnclosingElement())) {
- if (Objects.equals(el,
getAccessor.invoke(component))) {
+ Element enclosing = el.getEnclosingElement();
+ if (enclosing.getKind() == ElementKind.RECORD) {
+ for (Element peer :
enclosing.getEnclosedElements()) {
+ if (peer.getKind() ==
ElementKind.RECORD_COMPONENT) {
+ for (RecordComponentElement component :
((TypeElement)peer.getEnclosingElement()).getRecordComponents()) {
Review Comment:
I think it mostly is OK. And it basically weakly suggests that
`peer.getEnclosingElement() == enclosing`, which should be always true. (I
probably would just do `enclosing.getEnclosingElement()`, though.)
I wonder if it is possible to write a test for this - I can try at some
point if needed.
Otherwise - great cleanup, thanks for doing this!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists