diff options
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleVal.java')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleVal.java | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java index 0a136d0b..e8b1deb4 100644 --- a/src/core/lombok/eclipse/handlers/HandleVal.java +++ b/src/core/lombok/eclipse/handlers/HandleVal.java @@ -21,18 +21,14 @@ */ package lombok.eclipse.handlers; -import static lombok.core.handlers.HandlerUtil.*; -import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches; - import lombok.ConfigurationKeys; -import lombok.val; import lombok.core.HandlerPriority; import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseASTAdapter; import lombok.eclipse.EclipseASTVisitor; import lombok.eclipse.EclipseNode; - import lombok.experimental.var; +import lombok.val; import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer; import org.eclipse.jdt.internal.compiler.ast.ForStatement; import org.eclipse.jdt.internal.compiler.ast.ForeachStatement; @@ -40,6 +36,9 @@ import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.mangosdk.spi.ProviderFor; +import static lombok.core.handlers.HandlerUtil.handleFlagUsage; +import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches; + /* * This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}. */ @@ -51,34 +50,34 @@ public class HandleVal extends EclipseASTAdapter { TypeReference type = local.type; boolean isVal = typeMatches(val.class, localNode, type); boolean isVar = typeMatches(var.class, localNode, type); - if (!(isVal ||isVar)) return; - + if (!(isVal || isVar)) return; + if (isVal) handleFlagUsage(localNode, ConfigurationKeys.VAL_FLAG_USAGE, "val"); if (isVar) handleFlagUsage(localNode, ConfigurationKeys.VAR_FLAG_USAGE, "var"); - + boolean variableOfForEach = false; - + if (localNode.directUp().get() instanceof ForeachStatement) { ForeachStatement fs = (ForeachStatement) localNode.directUp().get(); variableOfForEach = fs.elementVariable == local; } - + String annotation = isVal ? "val" : "var"; if (local.initialization == null && !variableOfForEach) { localNode.addError("'" + annotation + "' on a local variable requires an initializer expression"); return; } - + if (local.initialization instanceof ArrayInitializer) { localNode.addError("'" + annotation + "' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })"); return; } - + if (isVal && localNode.directUp().get() instanceof ForStatement) { localNode.addError("'val' is not allowed in old-style for loops"); return; } - + if (local.initialization != null && local.initialization.getClass().getName().equals("org.eclipse.jdt.internal.compiler.ast.LambdaExpression")) { localNode.addError("'" + annotation + "' is not allowed with lambda expressions."); } |