mbien commented on code in PR #9210:
URL: https://github.com/apache/netbeans/pull/9210#discussion_r2825399502


##########
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:
   added regression test and updated the logic so that it breaks out of both 
loops instead of just the inner loop.



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

Reply via email to