diff options
author | Bulgakov Alexander <abulgakov@at-consulting.ru> | 2016-11-12 23:04:48 +0300 |
---|---|---|
committer | Bulgakov Alexander <abulgakov@at-consulting.ru> | 2016-11-12 23:04:48 +0300 |
commit | 69eeb9edc767bb3ceb0320bb5a0ea60dfabe827c (patch) | |
tree | e579423fe8ae7b5a961b0e643703a45dd167e36b /src/core/lombok/javac | |
parent | 67371e5841e1dd8ed5d663f1c907da0952976b8f (diff) | |
download | lombok-69eeb9edc767bb3ceb0320bb5a0ea60dfabe827c.tar.gz lombok-69eeb9edc767bb3ceb0320bb5a0ea60dfabe827c.tar.bz2 lombok-69eeb9edc767bb3ceb0320bb5a0ea60dfabe827c.zip |
a initialization of variable like "var o = null;" will throw the compile time error "variable initializer is 'null'"
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleVal.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java index 47965573..2ff3bf38 100644 --- a/src/core/lombok/javac/handlers/HandleVal.java +++ b/src/core/lombok/javac/handlers/HandleVal.java @@ -22,7 +22,10 @@ package lombok.javac.handlers; import static lombok.core.handlers.HandlerUtil.*; +import static lombok.eclipse.handlers.HandleVal.addVarNullInitMessage; import static lombok.javac.handlers.JavacHandlerUtil.*; + +import com.sun.tools.javac.tree.JCTree.JCLiteral; import lombok.ConfigurationKeys; import lombok.experimental.var; import lombok.val; @@ -51,7 +54,9 @@ import com.sun.tools.javac.util.List; @HandlerPriority(65536) // 2^16; resolution needs to work, so if the RHS expression is i.e. a call to a generated getter, we have to run after that getter has been generated. @ResolutionResetNeeded public class HandleVal extends JavacASTAdapter { - + + public static final String VARIABLE_INITIALIZER_IS_NULL = "variable initializer is 'null'"; + private static boolean eq(String typeTreeToString, String key) { return (typeTreeToString.equals(key) || typeTreeToString.equals("lombok." + key)); } @@ -118,6 +123,9 @@ public class HandleVal extends JavacASTAdapter { try { if (rhsOfEnhancedForLoop == null) { if (local.init.type == null) { + if (isVar && local.init instanceof JCLiteral && ((JCLiteral) local.init).value == null) { + addVarNullInitMessage(localNode); + } JavacResolution resolver = new JavacResolution(localNode.getContext()); try { type = ((JCExpression) resolver.resolveMethodMember(localNode).get(local.init)).type; |