aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-12-28 16:50:19 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-12-28 16:51:02 +0100
commit52582dc10ea1b5ea4a1dbb71831a442056354990 (patch)
treeafd0794b7360e5c174a79a54c54a50aacfe31efc /src/core/lombok/javac
parentd80139fa8f21b1e6c7fad0a0607986d7b246a06f (diff)
downloadlombok-52582dc10ea1b5ea4a1dbb71831a442056354990.tar.gz
lombok-52582dc10ea1b5ea4a1dbb71831a442056354990.tar.bz2
lombok-52582dc10ea1b5ea4a1dbb71831a442056354990.zip
@ToString, @Getter, and @XArgsConstructor now work on, and are legal on, enums. Docs have been updated.
Behaviour of @XArgsConstructor when its placement makes no sense (i.e. when annotating an interface with them) is no longer 'throw weird errors', but has been brought in line with the others: A nice error message is generated. Fixes issue #175
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java17
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java4
-rw-r--r--src/core/lombok/javac/handlers/HandleToString.java4
3 files changed, 21 insertions, 4 deletions
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index 7f0c2ba6..3cb36c30 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -62,6 +62,7 @@ public class HandleConstructor {
markAnnotationAsProcessed(annotationNode, NoArgsConstructor.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode typeNode = annotationNode.up();
+ if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return true;
NoArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
String staticName = ann.staticName();
@@ -82,6 +83,7 @@ public class HandleConstructor {
markAnnotationAsProcessed(annotationNode, RequiredArgsConstructor.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode typeNode = annotationNode.up();
+ if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return true;
RequiredArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
String staticName = ann.staticName();
@@ -120,6 +122,7 @@ public class HandleConstructor {
markAnnotationAsProcessed(annotationNode, AllArgsConstructor.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode typeNode = annotationNode.up();
+ if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return true;
AllArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
String staticName = ann.staticName();
@@ -148,6 +151,20 @@ public class HandleConstructor {
}
}
+ static boolean checkLegality(JavacNode typeNode, JavacNode errorNode, String name) {
+ JCClassDecl typeDecl = null;
+ if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
+ long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
+ boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION)) != 0;
+
+ if (typeDecl == null || notAClass) {
+ errorNode.addError(name + " is only supported on a class or an enum.");
+ return false;
+ }
+
+ return true;
+ }
+
public void generateRequiredArgsConstructor(JavacNode typeNode, AccessLevel level, String staticName, boolean skipIfConstructorExists) {
generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, skipIfConstructorExists, false);
}
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index cfe5c98a..8a1f7eed 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -85,10 +85,10 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
JCClassDecl typeDecl = null;
if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
- boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0;
+ boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION)) != 0;
if (typeDecl == null || notAClass) {
- errorNode.addError("@Getter is only supported on a class or a field.");
+ errorNode.addError("@Getter is only supported on a class, an enum, or a field.");
return false;
}
diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java
index 6f7465f3..8bc8036f 100644
--- a/src/core/lombok/javac/handlers/HandleToString.java
+++ b/src/core/lombok/javac/handlers/HandleToString.java
@@ -117,7 +117,7 @@ public class HandleToString implements JavacAnnotationHandler<ToString> {
boolean notAClass = true;
if (typeNode.get() instanceof JCClassDecl) {
long flags = ((JCClassDecl)typeNode.get()).mods.flags;
- notAClass = (flags & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0;
+ notAClass = (flags & (Flags.INTERFACE | Flags.ANNOTATION)) != 0;
}
if (callSuper == null) {
@@ -127,7 +127,7 @@ public class HandleToString implements JavacAnnotationHandler<ToString> {
}
if (notAClass) {
- errorNode.addError("@ToString is only supported on a class.");
+ errorNode.addError("@ToString is only supported on a class or enum.");
return false;
}