mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 03:07:34 +00:00
MethodInfo now stores it's java Method
This commit is contained in:
1 parent
790cfae476
commit
96d12c360d
2 files changed
+16
-31
No files matched your search
+4
-22
@@ -533,15 +533,10 @@ public class TokenHoverInfo {
|
||||
}
|
||||
|
||||
// Try to get actual Java method for more details
|
||||
if (containingType != null && containingType.getJavaClass() != null && methodInfo != null) {
|
||||
Class<?> clazz = containingType.getJavaClass();
|
||||
Method javaMethod = findJavaMethod(clazz, methodInfo.getName(), methodInfo.getParameterCount());
|
||||
|
||||
if (javaMethod != null) {
|
||||
buildMethodDeclaration(javaMethod, containingType);
|
||||
extractJavadoc(javaMethod);
|
||||
return;
|
||||
}
|
||||
if (methodInfo != null && methodInfo.getJavaMethod() != null) {
|
||||
buildMethodDeclaration(methodInfo.getJavaMethod(), containingType);
|
||||
extractJavadoc(methodInfo.getJavaMethod());
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback to basic method info
|
||||
@@ -748,19 +743,6 @@ public class TokenHoverInfo {
|
||||
declaration.add(new TextSegment(text, color));
|
||||
}
|
||||
|
||||
private Method findJavaMethod(Class<?> clazz, String name, int paramCount) {
|
||||
try {
|
||||
for (Method m : clazz.getMethods()) {
|
||||
if (m.getName().equals(name) && m.getParameterCount() == paramCount) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void buildMethodDeclaration(Method method, TypeInfo containingType) {
|
||||
int mods = method.getModifiers();
|
||||
|
||||
|
||||
+12
-9
@@ -54,6 +54,7 @@ public final class MethodInfo {
|
||||
private final boolean isDeclaration; // true if this is a declaration, false if it's a call
|
||||
private final int modifiers; // Java Modifier flags (e.g., Modifier.PUBLIC | Modifier.STATIC)
|
||||
private final String documentation; // Javadoc/comment documentation for this method
|
||||
private final java.lang.reflect.Method javaMethod; // The Java reflection Method, if this was created from reflection
|
||||
|
||||
// Error tracking for method declarations
|
||||
private ErrorType errorType = ErrorType.NONE;
|
||||
@@ -64,7 +65,7 @@ public final class MethodInfo {
|
||||
private MethodInfo(String name, TypeInfo returnType, TypeInfo containingType,
|
||||
List<FieldInfo> parameters, int fullDeclarationOffset, int typeOffset, int nameOffset,
|
||||
int bodyStart, int bodyEnd, boolean resolved, boolean isDeclaration,
|
||||
int modifiers, String documentation) {
|
||||
int modifiers, String documentation, java.lang.reflect.Method javaMethod) {
|
||||
this.name = name;
|
||||
this.returnType = returnType;
|
||||
this.containingType = containingType;
|
||||
@@ -78,33 +79,34 @@ public final class MethodInfo {
|
||||
this.isDeclaration = isDeclaration;
|
||||
this.modifiers = modifiers;
|
||||
this.documentation = documentation;
|
||||
this.javaMethod = javaMethod;
|
||||
}
|
||||
|
||||
// Factory methods
|
||||
public static MethodInfo declaration(String name, TypeInfo returnType, List<FieldInfo> params,
|
||||
int fullDeclOffset, int typeOffset, int nameOffset,
|
||||
int bodyStart, int bodyEnd) {
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, 0, null);
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, 0, null, null);
|
||||
}
|
||||
|
||||
public static MethodInfo declaration(String name, TypeInfo returnType, List<FieldInfo> params,
|
||||
int fullDeclOffset, int typeOffset, int nameOffset,
|
||||
int bodyStart, int bodyEnd, boolean isStatic) {
|
||||
int modifiers = isStatic ? Modifier.STATIC : 0;
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, modifiers, null);
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, modifiers, null, null);
|
||||
}
|
||||
|
||||
public static MethodInfo declaration(String name, TypeInfo returnType, List<FieldInfo> params,
|
||||
int fullDeclOffset, int typeOffset, int nameOffset,
|
||||
int bodyStart, int bodyEnd, boolean isStatic, String documentation) {
|
||||
int modifiers = isStatic ? Modifier.STATIC : 0;
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, modifiers, documentation);
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, modifiers, documentation, null);
|
||||
}
|
||||
|
||||
public static MethodInfo declaration(String name, TypeInfo returnType, List<FieldInfo> params,
|
||||
int fullDeclOffset, int typeOffset, int nameOffset,
|
||||
int bodyStart, int bodyEnd, int modifiers, String documentation) {
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, modifiers, documentation);
|
||||
return new MethodInfo(name, returnType, null, params, fullDeclOffset, typeOffset, nameOffset, bodyStart, bodyEnd, true, true, modifiers, documentation, null);
|
||||
}
|
||||
|
||||
public static MethodInfo call(String name, TypeInfo containingType, int paramCount) {
|
||||
@@ -114,7 +116,7 @@ public final class MethodInfo {
|
||||
for (int i = 0; i < paramCount; i++) {
|
||||
params.add(FieldInfo.unresolved("arg" + i, FieldInfo.Scope.PARAMETER));
|
||||
}
|
||||
return new MethodInfo(name, null, containingType, params, -1, -1, -1, -1, -1, resolved, false, 0, null);
|
||||
return new MethodInfo(name, null, containingType, params, -1, -1, -1, -1, -1, resolved, false, 0, null, null);
|
||||
}
|
||||
|
||||
public static MethodInfo unresolvedCall(String name, int paramCount) {
|
||||
@@ -122,7 +124,7 @@ public final class MethodInfo {
|
||||
for (int i = 0; i < paramCount; i++) {
|
||||
params.add(FieldInfo.unresolved("arg" + i, FieldInfo.Scope.PARAMETER));
|
||||
}
|
||||
return new MethodInfo(name, null, null, params, -1, -1, -1, -1, -1, false, false, 0, null);
|
||||
return new MethodInfo(name, null, null, params, -1, -1, -1, -1, -1, false, false, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +143,7 @@ public final class MethodInfo {
|
||||
params.add(FieldInfo.reflectionParam("arg" + i, paramType));
|
||||
}
|
||||
|
||||
return new MethodInfo(name, returnType, containingType, params, -1, -1, -1, -1, -1, true, false, modifiers, null);
|
||||
return new MethodInfo(name, returnType, containingType, params, -1, -1, -1, -1, -1, true, false, modifiers, null, method);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +162,7 @@ public final class MethodInfo {
|
||||
params.add(FieldInfo.reflectionParam("arg" + i, paramType));
|
||||
}
|
||||
|
||||
return new MethodInfo(name, returnType, containingType, params, -1, -1, -1, -1, -1, true, true, modifiers, null);
|
||||
return new MethodInfo(name, returnType, containingType, params, -1, -1, -1, -1, -1, true, true, modifiers, null, null);
|
||||
}
|
||||
|
||||
// Getters
|
||||
@@ -169,6 +171,7 @@ public final class MethodInfo {
|
||||
public TypeInfo getContainingType() { return containingType; }
|
||||
public List<FieldInfo> getParameters() { return Collections.unmodifiableList(parameters); }
|
||||
public int getParameterCount() { return parameters.size(); }
|
||||
public Method getJavaMethod() { return javaMethod; }
|
||||
/** @deprecated Use getTypeOffset() or getNameOffset() instead */
|
||||
@Deprecated
|
||||
public int getDeclarationOffset() { return typeOffset; }
|
||||
|
||||
Reference in new issue
Block a user