aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleGetter.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-02-11 22:34:48 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-02-11 22:34:48 +0100
commitaafd83079a3000d3deb6e40a182849da2509fbfb (patch)
treecf87951eee9bb098bb96ecc3c02c6f1ab34c405d /src/core/lombok/javac/handlers/HandleGetter.java
parentef8769d3180b2c6de91a64f69dfa23a2e6e449b9 (diff)
downloadlombok-aafd83079a3000d3deb6e40a182849da2509fbfb.tar.gz
lombok-aafd83079a3000d3deb6e40a182849da2509fbfb.tar.bz2
lombok-aafd83079a3000d3deb6e40a182849da2509fbfb.zip
BIG commit:
* re-introduction of onMethod/onConstructor/onParam * tests checking error/warnings rewritten to be more heuristic, in order to accomodate difference in messaging between java6 and java 7 * Ability to eliminate java's own output of erroneous error messages (heh); i.e. those messages that are invalidated by lombok's actions. This mechanism is used for onMethod/onConstructor/onParam * First steps to unifying a billion setGeneratedBy calls into a single visitor traversal for eclipse' HandleGetter/Setter/Constructor/Wither * To simplify 'zooming in' the tests on just a few files, added an 'accept' mechanism. * Updated copyright headers of website to 2013.
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleGetter.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 65947c72..bc68d5ad 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2012 The Project Lombok Authors.
+ * Copyright (C) 2009-2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,8 +21,8 @@
*/
package lombok.javac.handlers;
-import static lombok.javac.handlers.JavacHandlerUtil.*;
import static lombok.javac.Javac.*;
+import static lombok.javac.handlers.JavacHandlerUtil.*;
import java.util.Collection;
import java.util.Collections;
@@ -32,9 +32,9 @@ import java.util.Map;
import lombok.AccessLevel;
import lombok.Delegate;
import lombok.Getter;
+import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
import lombok.core.TransformationsUtil;
-import lombok.core.AST.Kind;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
import lombok.javac.handlers.JavacHandlerUtil.FieldAccess;
@@ -43,7 +43,6 @@ import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBinary;
import com.sun.tools.javac.tree.JCTree.JCBlock;
@@ -60,10 +59,11 @@ import com.sun.tools.javac.tree.JCTree.JCSynchronized;
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
-import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
/**
* Handles the {@code lombok.Getter} annotation for javac.
@@ -123,8 +123,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
//The annotation will make it happen, so we can skip it.
return;
}
-
- createGetterForField(level, fieldNode, fieldNode, false, lazy);
+ createGetterForField(level, fieldNode, fieldNode, false, lazy, List.<JCAnnotation>nil());
}
@Override public void handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacNode annotationNode) {
@@ -144,25 +143,30 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
if (node == null) return;
+ List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Getter(onMethod=", annotationNode);
+
switch (node.getKind()) {
case FIELD:
- createGetterForFields(level, fields, annotationNode, true, lazy);
+ createGetterForFields(level, fields, annotationNode, true, lazy, onMethod);
break;
case TYPE:
+ if (!onMethod.isEmpty()) {
+ annotationNode.addError("'onMethod' is not supported for @Getter on a type.");
+ }
if (lazy) annotationNode.addError("'lazy' is not supported for @Getter on a type.");
generateGetterForType(node, annotationNode, level, false);
break;
}
}
- private void createGetterForFields(AccessLevel level, Collection<JavacNode> fieldNodes, JavacNode errorNode, boolean whineIfExists, boolean lazy) {
+ private void createGetterForFields(AccessLevel level, Collection<JavacNode> fieldNodes, JavacNode errorNode, boolean whineIfExists, boolean lazy, List<JCAnnotation> onMethod) {
for (JavacNode fieldNode : fieldNodes) {
- createGetterForField(level, fieldNode, errorNode, whineIfExists, lazy);
+ createGetterForField(level, fieldNode, errorNode, whineIfExists, lazy, onMethod);
}
}
private void createGetterForField(AccessLevel level,
- JavacNode fieldNode, JavacNode source, boolean whineIfExists, boolean lazy) {
+ JavacNode fieldNode, JavacNode source, boolean whineIfExists, boolean lazy, List<JCAnnotation> onMethod) {
if (fieldNode.getKind() != Kind.FIELD) {
source.addError("@Getter is only supported on a class or a field.");
return;
@@ -208,10 +212,10 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
long access = toJavacModifier(level) | (fieldDecl.mods.flags & Flags.STATIC);
- injectMethod(fieldNode.up(), createGetter(access, fieldNode, fieldNode.getTreeMaker(), lazy, source.get()));
+ injectMethod(fieldNode.up(), createGetter(access, fieldNode, fieldNode.getTreeMaker(), source.get(), lazy, onMethod));
}
- private JCMethodDecl createGetter(long access, JavacNode field, TreeMaker treeMaker, boolean lazy, JCTree source) {
+ private JCMethodDecl createGetter(long access, JavacNode field, TreeMaker treeMaker, JCTree source, boolean lazy, List<JCAnnotation> onMethod) {
JCVariableDecl fieldNode = (JCVariableDecl) field.get();
// Remember the type; lazy will change it
@@ -240,7 +244,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
- List<JCAnnotation> annsOnMethod = nonNulls.appendList(nullables);
+ List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables);
if (isFieldDeprecated(field)) {
annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil()));
}