From ac8ab9b0f0d8d089442c73937b40c1b326876e5c Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Fri, 6 Mar 2026 18:38:40 +0200 Subject: [PATCH] Properly parsed statics and finals for JS types in Autocomplete --- .../autocomplete/JSAutocompleteProvider.java | 60 ++++++++++++++----- .../script/interpreter/type/TypeResolver.java | 2 +- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java index fb06144cf..d45f08549 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java @@ -62,21 +62,28 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { super.addMemberSuggestions(context, items); return; } - + + boolean isStaticContext = isStaticAccess(receiverExpr, getMemberAccessResolvePosition(context)); + // Add synthetic members (e.g., array built-ins: length, clone) - for (FieldInfo field : receiverType.syntheticFields) - if (!context.methodsOnly) + for (FieldInfo field : receiverType.syntheticFields) { + if (!context.methodsOnly) { + if (isStaticContext && !field.isStatic()) continue; items.add(AutocompleteItem.fromField(field)); - for (MethodInfo method : receiverType.syntheticMethods) + } + } + for (MethodInfo method : receiverType.syntheticMethods) { + if (isStaticContext && !method.isStatic()) continue; items.add(AutocompleteItem.fromMethod(method, context.methodsOnly)); + } // For pure JS types, check JSTypeRegistry JSTypeInfo jsTypeInfo = receiverType.getJSTypeInfo(); if (jsTypeInfo != null) { // Pass both: jsTypeInfo (current type in hierarchy) and receiverType (context for type params) - addMethodsFromType(jsTypeInfo, receiverType, items, new HashSet<>(), context.methodsOnly); + addMethodsFromType(jsTypeInfo, receiverType, items, new HashSet<>(), context.methodsOnly, isStaticContext); if (!context.methodsOnly && ConfigScript.ShowImplementationFieldsInAutocomplete) { - addFieldsFromType(jsTypeInfo, receiverType, items, new HashSet<>()); + addFieldsFromType(jsTypeInfo, receiverType, items, new HashSet<>(), isStaticContext); } } } @@ -109,7 +116,7 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { * @param contextType The original TypeInfo context for resolving type parameters (stays constant) */ protected void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added) { - addMethodsFromType(type, contextType, items, added, 0, false); + addMethodsFromType(type, contextType, items, added, 0, false, false); } /** @@ -118,9 +125,20 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { * @param contextType The original TypeInfo context for resolving type parameters (stays constant) * @param forMethodReference If true, insert text will NOT include parentheses */ - protected void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, boolean forMethodReference) { - addMethodsFromType(type, contextType, items, added, 0, forMethodReference); - } + protected void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, boolean forMethodReference) { + addMethodsFromType(type, contextType, items, added, 0, forMethodReference, false); + } + + /** + * Recursively add methods from a type and its parents. + * @param type The current JS type to get methods from (changes as we walk up inheritance) + * @param contextType The original TypeInfo context for resolving type parameters (stays constant) + * @param forMethodReference If true, insert text will NOT include parentheses + * @param isStaticContext If true, only add static methods + */ + protected void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, boolean forMethodReference, boolean isStaticContext) { + addMethodsFromType(type, contextType, items, added, 0, forMethodReference, isStaticContext); + } /** * Recursively add methods from a type and its parents with inheritance depth tracking. @@ -129,7 +147,7 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { * @param contextType The original TypeInfo context for resolving type parameters (e.g., IPlayer with T → EntityPlayerMP) */ private void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth) { - addMethodsFromType(type, contextType, items, added, depth, false); + addMethodsFromType(type, contextType, items, added, depth, false, false); } /** @@ -140,6 +158,10 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { * @param forMethodReference If true, insert text will NOT include parentheses */ private void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth, boolean forMethodReference) { + addMethodsFromType(type, contextType, items, added, depth, forMethodReference, false); + } + + private void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth, boolean forMethodReference, boolean isStaticContext) { // Collect base method names (without $N suffix) that we haven't processed yet Set baseNames = new HashSet<>(); for (String key : type.getMethods().keySet()) { @@ -164,13 +186,14 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { } // Add one autocomplete item per overload for (JSMethodInfo method : overloads) { + if (isStaticContext && !method.isStatic()) continue; items.add(AutocompleteItem.fromJSMethod(method, contextType, depth, forMethodReference)); } } // Add from parent type with incremented depth - keep same contextType if (type.getResolvedParent() != null) { - addMethodsFromType(type.getResolvedParent(), contextType, items, added, depth + 1, forMethodReference); + addMethodsFromType(type.getResolvedParent(), contextType, items, added, depth + 1, forMethodReference, isStaticContext); } } @@ -180,7 +203,11 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { * @param contextType The original TypeInfo context for resolving type parameters (stays constant) */ protected void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added) { - addFieldsFromType(type, contextType, items, added, 0); + addFieldsFromType(type, contextType, items, added, 0, false); + } + + protected void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, boolean isStaticContext) { + addFieldsFromType(type, contextType, items, added, 0, isStaticContext); } /** @@ -189,8 +216,13 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { * @param contextType The original TypeInfo context for resolving type parameters */ private void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth) { + addFieldsFromType(type, contextType, items, added, depth, false); + } + + private void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth, boolean isStaticContext) { for (JSFieldInfo field : type.getFields().values()) { if (!added.contains(field.getName())) { + if (isStaticContext && !field.isStatic()) continue; added.add(field.getName()); // Pass contextType (original receiver) for type parameter resolution, not current type items.add(AutocompleteItem.fromJSField(field, contextType, depth)); @@ -199,7 +231,7 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { // Add from parent type with incremented depth - keep same contextType if (type.getResolvedParent() != null) { - addFieldsFromType(type.getResolvedParent(), contextType, items, added, depth + 1); + addFieldsFromType(type.getResolvedParent(), contextType, items, added, depth + 1, isStaticContext); } } diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeResolver.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeResolver.java index 4c0e845e9..c340984b9 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeResolver.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeResolver.java @@ -935,7 +935,7 @@ public class TypeResolver { // Not a variable - check if it's a type name by trying to resolve as type TypeInfo typeCheck = document.resolveType(identifier); - boolean isType = typeCheck != null && typeCheck.isResolved() && !typeCheck.isJSType(); // JS types aren't static access in this context + boolean isType = typeCheck != null && typeCheck.isResolved(); return isStaticAccess(typeCheck, isType); }