mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 14:16:11 +00:00
'val' with an array on the initializer didn't work in eclipse.
This commit is contained in:
1 parent
3855a2171b
commit
46feeaab85
2 files changed
+51
-29
No files matched your search
@@ -311,30 +311,52 @@ public class Eclipse {
|
||||
}
|
||||
|
||||
public static TypeReference makeType(TypeBinding binding, ASTNode pos, boolean allowCompound) {
|
||||
int dims = binding.dimensions();
|
||||
binding = binding.leafComponentType();
|
||||
|
||||
// Primitives
|
||||
|
||||
char[] base = null;
|
||||
|
||||
switch (binding.id) {
|
||||
case TypeIds.T_int:
|
||||
return new SingleTypeReference(TypeConstants.INT, pos(pos));
|
||||
base = TypeConstants.INT;
|
||||
break;
|
||||
case TypeIds.T_long:
|
||||
return new SingleTypeReference(TypeConstants.LONG, pos(pos));
|
||||
base = TypeConstants.LONG;
|
||||
break;
|
||||
case TypeIds.T_short:
|
||||
return new SingleTypeReference(TypeConstants.SHORT, pos(pos));
|
||||
base = TypeConstants.SHORT;
|
||||
break;
|
||||
case TypeIds.T_byte:
|
||||
return new SingleTypeReference(TypeConstants.BYTE, pos(pos));
|
||||
base = TypeConstants.BYTE;
|
||||
break;
|
||||
case TypeIds.T_double:
|
||||
return new SingleTypeReference(TypeConstants.DOUBLE, pos(pos));
|
||||
base = TypeConstants.DOUBLE;
|
||||
break;
|
||||
case TypeIds.T_float:
|
||||
return new SingleTypeReference(TypeConstants.FLOAT, pos(pos));
|
||||
base = TypeConstants.FLOAT;
|
||||
break;
|
||||
case TypeIds.T_boolean:
|
||||
return new SingleTypeReference(TypeConstants.BOOLEAN, pos(pos));
|
||||
case TypeIds.T_void:
|
||||
return new SingleTypeReference(TypeConstants.VOID, pos(pos));
|
||||
base = TypeConstants.BOOLEAN;
|
||||
break;
|
||||
case TypeIds.T_char:
|
||||
return new SingleTypeReference(TypeConstants.CHAR, pos(pos));
|
||||
base = TypeConstants.CHAR;
|
||||
break;
|
||||
case TypeIds.T_void:
|
||||
base = TypeConstants.VOID;
|
||||
break;
|
||||
case TypeIds.T_null:
|
||||
return null;
|
||||
}
|
||||
|
||||
if (base != null) {
|
||||
if (dims > 0) {
|
||||
return new ArrayTypeReference(base, dims, pos(pos));
|
||||
}
|
||||
return new SingleTypeReference(base, pos(pos));
|
||||
}
|
||||
|
||||
if (binding.isAnonymousType()) {
|
||||
ReferenceBinding ref = (ReferenceBinding)binding;
|
||||
ReferenceBinding[] supers = ref.superInterfaces();
|
||||
@@ -406,8 +428,6 @@ public class Eclipse {
|
||||
}
|
||||
}
|
||||
|
||||
int dims = binding.dimensions();
|
||||
|
||||
if (params.length > 0) {
|
||||
if (parts.length > 1) {
|
||||
TypeReference[][] typeArguments = new TypeReference[parts.length][];
|
||||
|
||||
@@ -69,7 +69,7 @@ public class EclipsePatcher extends Agent {
|
||||
patchPostCompileHookEcj(sm);
|
||||
}
|
||||
|
||||
patchEcjTransformers(sm);
|
||||
patchEcjTransformers(sm, ecjOnly);
|
||||
|
||||
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
|
||||
}
|
||||
@@ -256,8 +256,8 @@ public class EclipsePatcher extends Agent {
|
||||
.request(StackRequest.THIS, StackRequest.RETURN_VALUE).build());
|
||||
}
|
||||
|
||||
private static void patchEcjTransformers(ScriptManager sm) {
|
||||
patchHandleVal(sm);
|
||||
private static void patchEcjTransformers(ScriptManager sm, boolean ecj) {
|
||||
patchHandleVal(sm, ecj);
|
||||
}
|
||||
|
||||
// Creates a copy of the 'initialization' field on a LocalDeclaration if the type of the LocalDeclaration is 'val', because the completion parser will null this out,
|
||||
@@ -265,7 +265,7 @@ public class EclipsePatcher extends Agent {
|
||||
// Also patches local declaration to not call .resolveType() on the initializer expression if we've already done so (calling it twice causes weird errors),
|
||||
// and patches .resolve() on LocalDeclaration itself to just-in-time replace the 'val' vartype with the right one.
|
||||
|
||||
private static void patchHandleVal(ScriptManager sm) {
|
||||
private static void patchHandleVal(ScriptManager sm, boolean ecj) {
|
||||
final String LOCALDECLARATION_SIG = "org.eclipse.jdt.internal.compiler.ast.LocalDeclaration";
|
||||
final String EXPRESSION_SIG = "org.eclipse.jdt.internal.compiler.ast.Expression";
|
||||
final String BLOCKSCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.BlockScope";
|
||||
@@ -278,19 +278,21 @@ public class EclipsePatcher extends Agent {
|
||||
.decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "handleValForLocalDeclaration", "boolean", LOCALDECLARATION_SIG, BLOCKSCOPE_SIG))
|
||||
.build());
|
||||
|
||||
sm.addScript(ScriptBuilder.addField()
|
||||
.fieldName("$initCopy")
|
||||
.fieldType("Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;")
|
||||
.setPublic()
|
||||
.setTransient()
|
||||
.targetClass("org.eclipse.jdt.internal.compiler.ast.LocalDeclaration")
|
||||
.build());
|
||||
|
||||
sm.addScript(ScriptBuilder.wrapReturnValue()
|
||||
.target(new MethodTarget(PARSER_SIG, "consumeExitVariableWithInitialization", "void"))
|
||||
.request(StackRequest.THIS)
|
||||
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "copyInitializationOfLocalDeclarationForVal", "void", PARSER_SIG))
|
||||
.build());
|
||||
if (!ecj) {
|
||||
sm.addScript(ScriptBuilder.addField()
|
||||
.fieldName("$initCopy")
|
||||
.fieldType("Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;")
|
||||
.setPublic()
|
||||
.setTransient()
|
||||
.targetClass("org.eclipse.jdt.internal.compiler.ast.LocalDeclaration")
|
||||
.build());
|
||||
|
||||
sm.addScript(ScriptBuilder.wrapReturnValue()
|
||||
.target(new MethodTarget(PARSER_SIG, "consumeExitVariableWithInitialization", "void"))
|
||||
.request(StackRequest.THIS)
|
||||
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "copyInitializationOfLocalDeclarationForVal", "void", PARSER_SIG))
|
||||
.build());
|
||||
}
|
||||
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG))
|
||||
|
||||
Reference in new issue
Block a user