mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
Added FieldInfo initStart/initEnd for enum constants
This commit is contained in:
1 parent
96c243f6bf
commit
75c5637aa7
2 files changed
+40
-31
No files matched your search
+36
-29
@@ -89,42 +89,49 @@ public class EnumConstantInfo {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine init range (the constructor arguments)
|
||||
int initStart = -1;
|
||||
int initEnd = -1;
|
||||
|
||||
// Create MethodCallInfo for constructor validation if args present
|
||||
MethodCallInfo constructorCall = null;
|
||||
if (argsClause != null && !argsClause.isEmpty()) {
|
||||
initStart = bodyOffset + m.start(2); // Position of '('
|
||||
initEnd = bodyOffset + m.end(2) - 1; // Position after ')'
|
||||
|
||||
constructorCall = createConstructorCall(
|
||||
enumType,
|
||||
constantName,
|
||||
absPos,
|
||||
initStart,
|
||||
initEnd
|
||||
);
|
||||
} else if (enumType.hasConstructors()) {
|
||||
// No args provided, but enum has constructors - validate against no-arg constructor
|
||||
initStart = absPos + constantName.length();
|
||||
initEnd = initStart;
|
||||
|
||||
constructorCall = createConstructorCall(
|
||||
enumType,
|
||||
constantName,
|
||||
absPos,
|
||||
initStart,
|
||||
initEnd
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Create FieldInfo for the enum constant
|
||||
FieldInfo fieldInfo = FieldInfo.enumConstant(
|
||||
constantName,
|
||||
enumType,
|
||||
absPos,
|
||||
args,
|
||||
enumType
|
||||
enumType,
|
||||
initStart,
|
||||
initEnd
|
||||
);
|
||||
|
||||
// Create MethodCallInfo for constructor validation if args present
|
||||
MethodCallInfo constructorCall = null;
|
||||
if (argsClause != null && !argsClause.isEmpty()) {
|
||||
int openParenPos = bodyOffset + m.start(2);
|
||||
int closeParenPos = bodyOffset + m.end(2) - 1;
|
||||
|
||||
constructorCall = createConstructorCall(
|
||||
enumType,
|
||||
constantName,
|
||||
absPos,
|
||||
openParenPos,
|
||||
closeParenPos
|
||||
);
|
||||
} else if (enumType.hasConstructors()) {
|
||||
// No args provided, but enum has constructors - validate against no-arg constructor
|
||||
int openParenPos = absPos + constantName.length();
|
||||
int closeParenPos = openParenPos;
|
||||
|
||||
constructorCall = createConstructorCall(
|
||||
enumType,
|
||||
constantName,
|
||||
absPos,
|
||||
openParenPos,
|
||||
closeParenPos
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
EnumConstantInfo constantInfo = new EnumConstantInfo(fieldInfo, constructorCall, enumType);
|
||||
constants.add(constantInfo);
|
||||
|
||||
|
||||
@@ -155,11 +155,13 @@ public final class FieldInfo {
|
||||
* @param declOffset The declaration position
|
||||
* @param args The constructor arguments (or null if no args)
|
||||
* @param containingEnum The enum type this constant belongs to
|
||||
* @param initStart The position of '(' if args present, else -1
|
||||
* @param initEnd The position after ')' if args present, else -1
|
||||
*/
|
||||
public static FieldInfo enumConstant(String name, TypeInfo type, int declOffset, String args, TypeInfo containingEnum) {
|
||||
public static FieldInfo enumConstant(String name, TypeInfo type, int declOffset, String args, TypeInfo containingEnum, int initStart, int initEnd) {
|
||||
// Enum constants are implicitly public static final
|
||||
int modifiers = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
|
||||
return new FieldInfo(name, Scope.ENUM_CONSTANT, type, declOffset, true, null, null, -1, -1,
|
||||
return new FieldInfo(name, Scope.ENUM_CONSTANT, type, declOffset, true, null, null, initStart, initEnd,
|
||||
modifiers, null, args, containingEnum);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user