Detected bodyless Methods declared within interfaces/have abstract modifiers

This commit is contained in:
bigguy345 committed 2025-12-31 14:09:17 +02:00
1 parent 6c0a2caa7e
commit 4ff47456b7
2 files changed
+29 -4

No files matched your search

@@ -18,7 +18,6 @@ import noppes.npcs.client.gui.util.script.interpreter.type.ScriptTypeInfo;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeChecker;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeResolver;
import scala.annotation.meta.param;
import java.util.*;
import java.util.regex.Matcher;
@@ -596,7 +595,7 @@ public class ScriptDocument {
private void parseMethodDeclarations() {
Pattern methodWithBody = Pattern.compile(
"\\b([a-zA-Z_][a-zA-Z0-9_<>\\[\\]]*)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\(([^)]*)\\)\\s*\\{");
"\\b([a-zA-Z_][a-zA-Z0-9_<>\\[\\]]*)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\(([^)]*)\\)\\s*(\\{|;)");
Matcher m = methodWithBody.matcher(text);
while (m.find()) {
@@ -604,14 +603,22 @@ public class ScriptDocument {
continue;
String returnType = m.group(1);
if (returnType.equals("class") || returnType.equals("interface") || returnType.equals("enum") ||returnType.equals("new")) {
continue;
}
String methodName = m.group(2);
String paramList = m.group(3);
String delimiter = m.group(4);
boolean bodyless = delimiter.equals(";");
int bodyStart = text.indexOf('{', m.end() - 1);
int bodyEnd = findMatchingBrace(bodyStart);
int bodyStart = bodyless ? m.end() : text.indexOf('{', m.end() - 1);
int bodyEnd = bodyless ? m.end() : findMatchingBrace(bodyStart);
if (bodyEnd < 0)
bodyEnd = text.length();
// Extract documentation before this method
String documentation = extractDocumentationBefore(m.start());
@@ -638,6 +645,17 @@ public class ScriptDocument {
modifiers,
documentation
);
for (ScriptTypeInfo scriptType : scriptTypes.values()) {
if (scriptType.containsPosition(bodyStart)) {
// scriptType.addMethod(methodInfo);
if (scriptType.getKind() == TypeInfo.Kind.INTERFACE)
methodInfo.setBodyless(bodyless);
break;
}
}
// Validate the method (return statements, parameters) with type resolution
String methodBodyText = bodyEnd > bodyStart + 1 ? text.substring(bodyStart + 1, bodyEnd) : "";
@@ -56,6 +56,7 @@ public final class MethodInfo {
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
private boolean bodyless;
// Error tracking for method declarations
private ErrorType errorType = ErrorType.NONE;
private String errorMessage;
@@ -193,6 +194,8 @@ public final class MethodInfo {
public boolean isPrivate() { return Modifier.isPrivate(modifiers); }
public boolean isProtected() { return Modifier.isProtected(modifiers); }
public String getDocumentation() { return documentation; }
public boolean isBodyless() { return bodyless; }
public void setBodyless(boolean bodyless) { this.bodyless = bodyless; }
/**
* Check if a position is inside this method's body.
@@ -427,6 +430,10 @@ public final class MethodInfo {
// Validate parameters
validateParameters();
//No need to check for return types/statements
if(bodyless)
return;
// Validate return statement types FIRST if we have a type resolver
// This ensures type errors are shown even if there's also a missing return
if (typeResolver != null) {