mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 21:17:32 +00:00
Fixed modifiers breaking global field declaration type
This commit is contained in:
1 parent
d9d89a2f23
commit
026a3dc8d3
2 files changed
+35
-1
No files matched your search
@@ -764,10 +764,13 @@ public class ScriptDocument {
|
||||
if (isExcluded(m.start()))
|
||||
continue;
|
||||
|
||||
String typeName = m.group(1);
|
||||
String typeNameRaw = m.group(1);
|
||||
String fieldName = m.group(2);
|
||||
int position = m.start(2);
|
||||
|
||||
// Strip modifiers (public, private, protected, static, final, etc.) from type name
|
||||
String typeName = stripModifiers(typeNameRaw);
|
||||
|
||||
// Check if inside a method - if so, it's a local, not global
|
||||
boolean insideMethod = false;
|
||||
for (MethodInfo method : methods) {
|
||||
@@ -785,6 +788,27 @@ public class ScriptDocument {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip Java modifiers from a type name string.
|
||||
* e.g., "public static String" -> "String"
|
||||
*/
|
||||
private String stripModifiers(String typeName) {
|
||||
if (typeName == null) return null;
|
||||
|
||||
String[] parts = typeName.trim().split("\\s+");
|
||||
// Filter out known modifiers
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String part : parts) {
|
||||
if (!TypeResolver.isModifier(part)) {
|
||||
if (result.length() > 0) result.append(" ");
|
||||
result.append(part);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private TypeInfo resolveType(String typeName) {
|
||||
return resolveTypeAndTrackUsage(typeName);
|
||||
}
|
||||
|
||||
@@ -379,6 +379,16 @@ public class TypeResolver {
|
||||
typeName.equals("short") || typeName.equals("int") || typeName.equals("long") ||
|
||||
typeName.equals("float") || typeName.equals("double") || typeName.equals("void");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a word is a Java modifier keyword.
|
||||
*/
|
||||
public static boolean isModifier(String word) {
|
||||
return word.equals("public") || word.equals("private") || word.equals("protected") ||
|
||||
word.equals("static") || word.equals("final") || word.equals("abstract") ||
|
||||
word.equals("synchronized") || word.equals("volatile") || word.equals("transient") ||
|
||||
word.equals("native") || word.equals("strictfp");
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a type occurrence within generic content.
|
||||
|
||||
Reference in new issue
Block a user