mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 04:09:57 +00:00
1 parent
7d6bacb824
commit
2311634817
3 files changed
+11
-71
No files matched your search
+8
-20
@@ -101,19 +101,13 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider {
|
||||
* Recursively add methods from a type and its parents.
|
||||
*/
|
||||
protected void addMethodsFromType(JSTypeInfo type, List<AutocompleteItem> items, Set<String> added) {
|
||||
addMethodsFromType(type, items, added, 0, new HashSet<>());
|
||||
addMethodsFromType(type, items, added, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively add methods from a type and its parents with inheritance depth tracking and cycle detection.
|
||||
* Recursively add methods from a type and its parents with inheritance depth tracking.
|
||||
*/
|
||||
private void addMethodsFromType(JSTypeInfo type, List<AutocompleteItem> items, Set<String> added, int depth, Set<String> visited) {
|
||||
// Prevent infinite recursion from circular inheritance
|
||||
if (visited.contains(type.getFullName())) {
|
||||
return;
|
||||
}
|
||||
visited.add(type.getFullName());
|
||||
|
||||
private void addMethodsFromType(JSTypeInfo type, List<AutocompleteItem> items, Set<String> added, int depth) {
|
||||
for (JSMethodInfo method : type.getMethods().values()) {
|
||||
String name = method.getName();
|
||||
// Skip overload markers (name$1, name$2, etc.)
|
||||
@@ -128,7 +122,7 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider {
|
||||
|
||||
// Add from parent type with incremented depth
|
||||
if (type.getResolvedParent() != null) {
|
||||
addMethodsFromType(type.getResolvedParent(), items, added, depth + 1, visited);
|
||||
addMethodsFromType(type.getResolvedParent(), items, added, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,19 +130,13 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider {
|
||||
* Recursively add fields from a type and its parents.
|
||||
*/
|
||||
protected void addFieldsFromType(JSTypeInfo type, List<AutocompleteItem> items, Set<String> added) {
|
||||
addFieldsFromType(type, items, added, 0, new HashSet<>());
|
||||
addFieldsFromType(type, items, added, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively add fields from a type and its parents with inheritance depth tracking and cycle detection.
|
||||
* Recursively add fields from a type and its parents with inheritance depth tracking.
|
||||
*/
|
||||
private void addFieldsFromType(JSTypeInfo type, List<AutocompleteItem> items, Set<String> added, int depth, Set<String> visited) {
|
||||
// Prevent infinite recursion from circular inheritance
|
||||
if (visited.contains(type.getFullName())) {
|
||||
return;
|
||||
}
|
||||
visited.add(type.getFullName());
|
||||
|
||||
private void addFieldsFromType(JSTypeInfo type, List<AutocompleteItem> items, Set<String> added, int depth) {
|
||||
for (JSFieldInfo field : type.getFields().values()) {
|
||||
if (!added.contains(field.getName())) {
|
||||
added.add(field.getName());
|
||||
@@ -158,7 +146,7 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider {
|
||||
|
||||
// Add from parent type with incremented depth
|
||||
if (type.getResolvedParent() != null) {
|
||||
addFieldsFromType(type.getResolvedParent(), items, added, depth + 1, visited);
|
||||
addFieldsFromType(type.getResolvedParent(), items, added, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-42
@@ -89,25 +89,12 @@ public class JSTypeInfo {
|
||||
* Get a method by name, including inherited methods.
|
||||
*/
|
||||
public JSMethodInfo getMethod(String name) {
|
||||
return getMethod(name, new HashSet<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to get method with cycle detection.
|
||||
*/
|
||||
private JSMethodInfo getMethod(String name, Set<String> visited) {
|
||||
// Prevent infinite recursion from circular inheritance
|
||||
if (visited.contains(this.fullName)) {
|
||||
return null;
|
||||
}
|
||||
visited.add(this.fullName);
|
||||
|
||||
JSMethodInfo method = methods.get(name);
|
||||
if (method != null) return method;
|
||||
|
||||
// Check parent
|
||||
if (resolvedParent != null) {
|
||||
return resolvedParent.getMethod(name, visited);
|
||||
return resolvedParent.getMethod(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -116,21 +103,8 @@ public class JSTypeInfo {
|
||||
* Get all methods with a given name (for overloads).
|
||||
*/
|
||||
public List<JSMethodInfo> getMethodOverloads(String name) {
|
||||
return getMethodOverloads(name, new HashSet<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to get method overloads with cycle detection.
|
||||
*/
|
||||
private List<JSMethodInfo> getMethodOverloads(String name, Set<String> visited) {
|
||||
List<JSMethodInfo> overloads = new ArrayList<>();
|
||||
|
||||
// Prevent infinite recursion from circular inheritance
|
||||
if (visited.contains(this.fullName)) {
|
||||
return overloads;
|
||||
}
|
||||
visited.add(this.fullName);
|
||||
|
||||
// Get from this type
|
||||
if (methods.containsKey(name)) {
|
||||
overloads.add(methods.get(name));
|
||||
@@ -144,7 +118,7 @@ public class JSTypeInfo {
|
||||
|
||||
// Get from parent
|
||||
if (resolvedParent != null) {
|
||||
overloads.addAll(resolvedParent.getMethodOverloads(name, visited));
|
||||
overloads.addAll(resolvedParent.getMethodOverloads(name));
|
||||
}
|
||||
|
||||
return overloads;
|
||||
@@ -161,25 +135,12 @@ public class JSTypeInfo {
|
||||
* Get a field by name, including inherited fields.
|
||||
*/
|
||||
public JSFieldInfo getField(String name) {
|
||||
return getField(name, new HashSet<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to get field with cycle detection.
|
||||
*/
|
||||
private JSFieldInfo getField(String name, Set<String> visited) {
|
||||
// Prevent infinite recursion from circular inheritance
|
||||
if (visited.contains(this.fullName)) {
|
||||
return null;
|
||||
}
|
||||
visited.add(this.fullName);
|
||||
|
||||
JSFieldInfo field = fields.get(name);
|
||||
if (field != null) return field;
|
||||
|
||||
// Check parent
|
||||
if (resolvedParent != null) {
|
||||
return resolvedParent.getField(name, visited);
|
||||
return resolvedParent.getField(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
-9
@@ -368,16 +368,7 @@ public class JSTypeRegistry {
|
||||
public void resolveInheritance() {
|
||||
for (JSTypeInfo type : types.values()) {
|
||||
JSTypeInfo child = type;
|
||||
Set<String> visited = new HashSet<>();
|
||||
while (child != null && child.getExtendsType() != null && child.getResolvedParent() == null) {
|
||||
// Prevent circular inheritance
|
||||
if (visited.contains(child.getFullName())) {
|
||||
System.out.println("WARNING: Circular inheritance detected: " + child.getFullName() +
|
||||
" extends " + child.getExtendsType());
|
||||
break;
|
||||
}
|
||||
visited.add(child.getFullName());
|
||||
|
||||
JSTypeInfo parent = getType(child.getExtendsType());
|
||||
if (parent != null) {
|
||||
child.setResolvedParent(parent);
|
||||
|
||||
Reference in new issue
Block a user