Copilot commented on code in PR #3999:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3999#discussion_r4002673589


##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLCompletionHelper.java:
##########
@@ -313,11 +313,13 @@ private static List<CompletionItem> 
memberItemsForChain(String[] chain, String t
         String head = chain[0];
         String rootType;
         int firstFieldSegment = 1;
+        boolean typeReference = false;
         if (head.startsWith("$")) {
             rootType = LhsBindingResolver.resolveAt(text, 
DRLHoverHelper.positionToOffset(text, caret), typeIndex)
                     .get(head.substring(1));
         } else if (!head.isEmpty() && Character.isUpperCase(head.charAt(0))) {
             rootType = head;
+            typeReference = true;

Review Comment:
   Fully qualified type references still do not reach this branch. For 
`org.drools.completion.fixtures.Rounding.`, `head` is `org`, so it is treated 
as a lower-case field of the enclosing pattern and the walk returns no static 
items. Consume the longest class-indexed qualified prefix as a type reference 
(as `DRLHoverHelper.fqcnPrefixEnd` already does) before applying the static 
first hop.



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLHoverHelper.java:
##########
@@ -309,10 +311,10 @@ private static Hover hoverChain(Chain chain, String text, 
Position position,
                             segment, segment, parsed.compilationUnit, 
classIndex);
                     if (fqcn != null) {
                         if (hovered) {
-                            return markdown(renderJavaType(segment, fqcn, 
memberIndex.membersOf(fqcn),
-                                    memberIndex.constructorsOf(fqcn)));
+                            return markdown(renderJavaType(segment, fqcn, 
memberIndex));
                         }
                         runningType = fqcn;
+                        fromTypeRef = true;

Review Comment:
   Only classpath types set `fromTypeRef`, so `Person.field` for a non-enum DRL 
declaration still falls through to `findField` and renders an instance field as 
valid type-qualified access. Declared enums need their existing constant 
handling, but other declared type references should stop the chain instead.



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/JavaSourceTypeParser.java:
##########
@@ -172,22 +178,26 @@ private static JavaSourceType 
fromInterface(JavaParser.InterfaceDeclarationConte
         List<String> interfaces = (id.EXTENDS() != null && 
!id.typeList().isEmpty())
                 ? simplifyAll(id.typeList(0)) : List.of();
 
-        List<Field> fields = new ArrayList<>();
+        // An interface field is implicitly public static final, so
+        // collectInterfaceMember's field list is the constant list: it becomes
+        // the static view, not the member view, matching what reflection
+        // reports once the interface is compiled.
+        List<Field> constants = new ArrayList<>();
         List<Field> getters = new ArrayList<>();
         if (id.interfaceBody() != null) {
             for (JavaParser.InterfaceBodyDeclarationContext ibd : 
id.interfaceBody().interfaceBodyDeclaration()) {
                 try {
-                    collectInterfaceMember(ibd, fields, getters);
+                    collectInterfaceMember(ibd, constants, getters);
                 } catch (Exception e) {
                     logger.fine(() -> "Skipping interface member in " + 
simpleName + ": " + e.getMessage());
                 }
             }
         }
         Map<String, Field> members = new LinkedHashMap<>();
-        mergeGettersThenFields(members, getters, fields);
+        mergeGettersThenFields(members, getters, List.of());
 
         return new JavaSourceType(fqcn(pkg, simpleName), simpleName, false, 
null, interfaces,
-                new ArrayList<>(members.values()), List.of(), List.of(),
+                new ArrayList<>(members.values()), List.of(), constants, 
List.of(),

Review Comment:
   Interface static methods are never captured: this constructor hard-codes an 
empty `staticMethods` list, although interfaces may declare public static 
methods and reflection returns them after compilation. Extend interface-member 
collection to emit signatures for static interface methods so source fallback 
remains consistent.
   
   This issue also appears on line 226 of the same file.



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/JavaSourceTypeParser.java:
##########
@@ -255,40 +265,33 @@ private static void 
collectBodyMembers(List<JavaParser.ClassBodyDeclarationConte
                     boolean isStatic = hasStaticModifier(cbd.modifier());
                     for (JavaParser.VariableDeclaratorContext vd : 
fd.variableDeclarators().variableDeclarator()) {
                         String name = 
vd.variableDeclaratorId().identifier().getText();
-                        if (isStatic) {
-                            // Kept by name only: reachable as Type.NAME, but 
not a
-                            // property of a fact, so out of the member list.
-                            staticFieldsOut.add(name);
-                        } else {
-                            fieldsOut.add(new Field(name, type, null, 
Field.Origin.FIELD));
-                        }
+                        // A static is reachable as Type.NAME but is not a 
property
+                        // of a fact, so the two views stay disjoint.
+                        (isStatic ? staticFieldsOut : fieldsOut)
+                                .add(new Field(name, type, null, 
Field.Origin.FIELD));

Review Comment:
   Static field types are stored after `simplify` has stripped array brackets. 
A source declaration such as `public static String[] NAMES` is exposed as 
`String`, whereas reflection exposes `String[]`; hover details and the 
second-hop member walk therefore change after a build. Preserve array 
dimensions for the static field view.
   
   This issue also appears on line 276 of the same file.



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLCompletionHelper.java:
##########
@@ -329,6 +331,28 @@ private static List<CompletionItem> 
memberItemsForChain(String[] chain, String t
             return null;
         }
 
+        // After a type name Java permits only statics — the one set the 
instance
+        // view cannot legally offer. A DRL declare is exempt: it has no 
statics,
+        // and its enum constants are already members, which the walk below
+        // offers. Only the first hop is static; past it, instance members
+        // resume, because a constant is an ordinary value of its own type.
+        if (typeReference && typeIndex.get(simpleNameOf(rootType)) == null) {

Review Comment:
   This exemption covers every DRL-declared type, not just declared enums. 
Consequently `Person.` still offers `Person`'s instance fields even though they 
cannot be accessed through the type name. Preserve the enum-constant special 
case, but return no members for a non-enum declared type reference.



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

Reply via email to