Removed redundant JS type resolution code and improved logic

This commit is contained in:
bigguy345 committed 2026-01-05 05:43:30 +02:00
1 parent 5720b3a081
commit 3929888f60
3 files changed
+39 -63

No files matched your search

@@ -1655,24 +1655,16 @@ public class ScriptDocument {
}
public TypeInfo resolveType(String typeName) {
// Use language-appropriate resolution
if (isJavaScript()) {
return resolveJSTypeUnified(typeName);
}
/**
* Resolve a JS type name to unified TypeInfo.
* Handles JS primitives, .d.ts defined types, and falls back to Java types.
*/
if (isJavaScript())
return typeResolver.resolveJSType(typeName);
return resolveTypeAndTrackUsage(typeName);
}
/**
* Resolve a JS type name to unified TypeInfo.
* Handles JS primitives, .d.ts defined types, and falls back to Java types.
*/
private TypeInfo resolveJSTypeUnified(String typeName) {
if (typeName == null || typeName.isEmpty()) {
return TypeInfo.fromPrimitive("void");
}
return typeResolver.resolveJSType(typeName);
}
/**
* Resolve a type and track the import usage for unused import detection.
* Checks script-defined types first, then falls back to imported types.
@@ -2455,45 +2447,6 @@ public class ScriptDocument {
marks.add(new ScriptLine.Mark(start, end, TokenType.COMMENT, null));
}
}
/**
* Resolve a type name from JSDoc to a TypeInfo.
*/
private TypeInfo resolveJSDocType(String typeName) {
if (typeName == null || typeName.isEmpty()) {
return null;
}
// Handle union types - use first type
if (typeName.contains("|")) {
typeName = typeName.split("\\|")[0].trim();
}
// Handle nullable
typeName = typeName.replace("?", "").trim();
// Map JSDoc types to Java types
switch (typeName.toLowerCase()) {
case "string":
return TypeInfo.fromClass(String.class);
case "number":
case "int":
case "integer":
return isJavaScript() ? TypeInfo.fromClass(double.class) : TypeInfo.fromClass(int.class);
case "boolean":
case "bool":
return TypeInfo.fromClass(boolean.class);
case "void":
return TypeInfo.fromPrimitive("void");
case "any":
case "object":
case "*":
return TypeInfo.ANY;
}
// Try through the type resolver
return resolveType(typeName);
}
private void markMethodDeclarations(List<ScriptLine.Mark> marks) {
Matcher m = METHOD_DECL_PATTERN.matcher(text);
@@ -37,13 +37,19 @@ public class TypeInfo {
*/
public static final TypeInfo VOID = fromPrimitive("void");
public static final TypeInfo BOOLEAN = fromPrimitive("boolean");
public static final TypeInfo STRING = TypeInfo.fromClass(String.class);
/**
* Singleton constant for the "any" type (used in JavaScript/TypeScript).
* The "any" type is universally compatible - it can be assigned to anything
* and anything can be assigned to it.
*/
public static final TypeInfo ANY = new TypeInfo("any", "any", "", Kind.CLASS, null, true, null);
public static final TypeInfo NUMBER = new TypeInfo("number", "number", "", Kind.CLASS, double.class, true, null);
private final String simpleName; // e.g., "List", "ColorType"
private final String fullName; // e.g., "java.util.List", "kamkeel...IOverlay$ColorType"
private final String packageName; // e.g., "java.util", "kamkeel.npcdbc.api.client.overlay"
@@ -136,18 +136,35 @@ public class TypeResolver {
if (jsTypeName == null || jsTypeName.isEmpty()) {
return TypeInfo.fromPrimitive("void");
}
// Handle union types - use first type
if (jsTypeName.contains("|")) {
jsTypeName = jsTypeName.split("\\|")[0].trim();
}
// Handle nullable
jsTypeName = jsTypeName.replace("?", "").trim();
// Strip array brackets for base type resolution
boolean isArray = jsTypeName.endsWith("[]");
String baseName = isArray ? jsTypeName.substring(0, jsTypeName.length() - 2) : jsTypeName;
// Check JS primitives first
if (JS_PRIMITIVE_TO_JAVA.containsKey(baseName)) {
String javaType = JS_PRIMITIVE_TO_JAVA.get(baseName);
TypeInfo baseType = TypeResolver.isPrimitiveType(javaType)
? TypeInfo.fromPrimitive(javaType)
: resolveFullName("java.lang." + javaType);
return isArray ? TypeInfo.arrayOf(baseType) : baseType;
switch (baseName.toLowerCase()) {
case "string":
return TypeInfo.STRING;
case "number":
case "int":
case "integer":
return TypeInfo.NUMBER;
case "boolean":
case "bool":
return TypeInfo.BOOLEAN;
case "void":
return TypeInfo.VOID;
case "any":
case "object":
case "*":
return TypeInfo.ANY;
}
// Check JS type registry