aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2014-05-27 20:29:54 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2014-05-27 20:29:54 +0200
commit713822db9894cf99184aff57b3387f99846aa870 (patch)
tree7b5ee62283336897fda2b4b84f5c1472358b6dce /src/core/lombok/eclipse
parent4b878f9ba996f852ce555c3024512ae34e34774e (diff)
downloadlombok-713822db9894cf99184aff57b3387f99846aa870.tar.gz
lombok-713822db9894cf99184aff57b3387f99846aa870.tar.bz2
lombok-713822db9894cf99184aff57b3387f99846aa870.zip
Changed the lombok.nonNull.exceptionType configkey to be an enum, partly to enforce only sensible exceptions and partly to make it possible to have the message be ‘x is null’ when throwing IAEs.
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 022cad91..874efb4e 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -46,6 +46,7 @@ import lombok.core.AnnotationValues.AnnotationValue;
import lombok.core.BooleanFieldAugment;
import lombok.core.ReferenceFieldAugment;
import lombok.core.TypeResolver;
+import lombok.core.configuration.NullCheckExceptionType;
import lombok.core.handlers.HandlerUtil;
import lombok.eclipse.EclipseAST;
import lombok.eclipse.EclipseNode;
@@ -1402,15 +1403,8 @@ public class EclipseHandlerUtil {
* @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
*/
public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) {
- String exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
- if (exceptionType == null) {
- exceptionType = HandlerUtil.DEFAULT_EXCEPTION_FOR_NON_NULL;
- } else {
- if (!HandlerUtil.isLegalBasicClassReference(exceptionType)) {
- sourceNode.addWarning("Configuration key contains invalid java type reference '" + exceptionType + "'; use something like 'java.lang.NullPointerException' as value for this key.");
- exceptionType = HandlerUtil.DEFAULT_EXCEPTION_FOR_NON_NULL;
- }
- }
+ NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
+ if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;
ASTNode source = sourceNode.get();
@@ -1421,12 +1415,15 @@ public class EclipseHandlerUtil {
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
int partCount = 0;
- for (int i = 0; i < exceptionType.length(); i++) if (exceptionType.charAt(i) == '.') partCount++;
+ String exceptionTypeStr = exceptionType.getExceptionType();
+ for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++;
long[] ps = new long[partCount];
Arrays.fill(ps, 0L);
- exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionType), ps);
+ exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps);
setGeneratedBy(exception.type, source);
- exception.arguments = new Expression[] { new StringLiteral(variable.name, pS, pE, 0)};
+ exception.arguments = new Expression[] {
+ new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0)
+ };
setGeneratedBy(exception.arguments[0], source);
ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
setGeneratedBy(throwStatement, source);