aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/handlers/PKG.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-08-28 00:02:15 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-08-28 00:02:15 +0200
commite1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496 (patch)
tree5f014017561f6a9cff56e8ad35f2c6e3cf7b882e /src/lombok/eclipse/handlers/PKG.java
parentd16775032b638789f998f3f362b7ed7d4f5098ae (diff)
downloadlombok-e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496.tar.gz
lombok-e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496.tar.bz2
lombok-e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496.zip
null checks are no longer generated if you put @NonNull on primitives.
Diffstat (limited to 'src/lombok/eclipse/handlers/PKG.java')
-rw-r--r--src/lombok/eclipse/handlers/PKG.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lombok/eclipse/handlers/PKG.java b/src/lombok/eclipse/handlers/PKG.java
index 17096b70..87ccd736 100644
--- a/src/lombok/eclipse/handlers/PKG.java
+++ b/src/lombok/eclipse/handlers/PKG.java
@@ -29,7 +29,9 @@ import java.util.List;
import java.util.regex.Pattern;
import lombok.AccessLevel;
+import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAST;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
@@ -55,6 +57,11 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference;
class PKG {
private PKG() {}
+ static boolean isPrimitive(TypeReference ref) {
+ if (ref.dimensions() > 0) return false;
+ return TransformationsUtil.PRIMITIVE_TYPE_NAME_PATTERN.matcher(Eclipse.toQualifiedName(ref.getTypeName())).matches();
+ }
+
static int toModifier(AccessLevel value) {
switch ( value ) {
case MODULE:
@@ -232,9 +239,6 @@ class PKG {
type.add(method, Kind.METHOD).recursiveSetHandled();
}
- static final Pattern NON_NULL_PATTERN = Pattern.compile("^no[tn]null$", Pattern.CASE_INSENSITIVE);
- static final Pattern NULLABLE_PATTERN = Pattern.compile("^nullable$", Pattern.CASE_INSENSITIVE);
-
static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) {
List<Annotation> result = new ArrayList<Annotation>();
for (Annotation annotation : field.annotations) {
@@ -251,6 +255,7 @@ class PKG {
}
static Statement generateNullCheck(AbstractVariableDeclaration variable) {
+ if (isPrimitive(variable.type)) return null;
AllocationExpression exception = new AllocationExpression();
exception.type = new QualifiedTypeReference(fromQualifiedName("java.lang.NullPointerException"), new long[]{0, 0, 0});
exception.arguments = new Expression[] { new StringLiteral(variable.name, 0, variable.name.length - 1, 0)};