aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok/eclipse')
-rw-r--r--src/lombok/eclipse/Eclipse.java65
-rw-r--r--src/lombok/eclipse/EclipseAST.java97
-rw-r--r--src/lombok/eclipse/EclipseASTAdapter.java66
-rw-r--r--src/lombok/eclipse/EclipseASTVisitor.java46
-rw-r--r--src/lombok/eclipse/EclipseAnnotationHandler.java47
-rw-r--r--src/lombok/eclipse/HandlerLibrary.java68
-rw-r--r--src/lombok/eclipse/TransformEclipseAST.java25
-rw-r--r--src/lombok/eclipse/handlers/HandleCleanup.java24
-rw-r--r--src/lombok/eclipse/handlers/HandleData.java24
-rw-r--r--src/lombok/eclipse/handlers/HandleGetter.java36
-rw-r--r--src/lombok/eclipse/handlers/HandlePrintAST.java24
-rw-r--r--src/lombok/eclipse/handlers/HandleSetter.java36
-rw-r--r--src/lombok/eclipse/handlers/HandleSneakyThrows.java24
-rw-r--r--src/lombok/eclipse/handlers/HandleSynchronized.java34
-rw-r--r--src/lombok/eclipse/handlers/PKG.java21
15 files changed, 619 insertions, 18 deletions
diff --git a/src/lombok/eclipse/Eclipse.java b/src/lombok/eclipse/Eclipse.java
index 549de3c0..84a65da1 100644
--- a/src/lombok/eclipse/Eclipse.java
+++ b/src/lombok/eclipse/Eclipse.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
import java.lang.reflect.Method;
@@ -42,25 +63,43 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.osgi.framework.Bundle;
public class Eclipse {
+ /**
+ * Eclipse's Parser class is instrumented to not attempt to fill in the body of any method or initializer
+ * or field initialization if this flag is set. Set it on the flag field of
+ * any method, field, or initializer you create!
+ */
public static final int ECLIPSE_DO_NOT_TOUCH_FLAG = ASTNode.Bit24;
+
private Eclipse() {
//Prevent instantiation
}
private static final String DEFAULT_BUNDLE = "org.eclipse.jdt.core";
+ /**
+ * Generates an error in the eclipse error log. Note that most people never look at it!
+ */
public static void error(CompilationUnitDeclaration cud, String message) {
error(cud, message, DEFAULT_BUNDLE, null);
}
+ /**
+ * Generates an error in the eclipse error log. Note that most people never look at it!
+ */
public static void error(CompilationUnitDeclaration cud, String message, Throwable error) {
error(cud, message, DEFAULT_BUNDLE, error);
}
+ /**
+ * Generates an error in the eclipse error log. Note that most people never look at it!
+ */
public static void error(CompilationUnitDeclaration cud, String message, String bundleName) {
error(cud, message, bundleName, null);
}
+ /**
+ * Generates an error in the eclipse error log. Note that most people never look at it!
+ */
public static void error(CompilationUnitDeclaration cud, String message, String bundleName, Throwable error) {
Bundle bundle = Platform.getBundle(bundleName);
if ( bundle == null ) {
@@ -74,6 +113,10 @@ public class Eclipse {
if ( cud != null ) EclipseAST.addProblemToCompilationResult(cud, false, message + " - See error log.", 0, 0);
}
+ /**
+ * For 'speed' reasons, eclipse works a lot with char arrays. I have my doubts this was a fruitful exercise,
+ * but we need to deal with it. This turns [[java][lang][String]] into "java.lang.String".
+ */
static String toQualifiedName(char[][] typeName) {
StringBuilder sb = new StringBuilder();
boolean first = true;
@@ -84,6 +127,11 @@ public class Eclipse {
return sb.toString();
}
+ /**
+ * You can't share TypeParameter objects or bad things happen; for example, one 'T' resolves differently
+ * from another 'T', even for the same T in a single class file. Unfortunately the TypeParameter type hierarchy
+ * is complicated and there's no clone method on TypeParameter itself. This method can clone them.
+ */
public static TypeParameter[] copyTypeParams(TypeParameter[] params) {
if ( params == null ) return null;
TypeParameter[] out = new TypeParameter[params.length];
@@ -106,6 +154,10 @@ public class Eclipse {
return out;
}
+ /**
+ * Convenience method that creates a new array and copies each TypeReference in the source array via
+ * {@link #copyType(TypeReference)}.
+ */
public static TypeReference[] copyTypes(TypeReference[] refs) {
if ( refs == null ) return null;
TypeReference[] outs = new TypeReference[refs.length];
@@ -116,6 +168,11 @@ public class Eclipse {
return outs;
}
+ /**
+ * You can't share TypeReference objects or subtle errors start happening.
+ * Unfortunately the TypeReference type hierarchy is complicated and there's no clone
+ * method on TypeReference itself. This method can clone them.
+ */
public static TypeReference copyType(TypeReference ref) {
if ( ref instanceof ParameterizedQualifiedTypeReference ) {
ParameterizedQualifiedTypeReference iRef = (ParameterizedQualifiedTypeReference) ref;
@@ -179,6 +236,11 @@ public class Eclipse {
return ref;
}
+ /**
+ * Checks if the provided annotation type is likely to be the intended type for the given annotation node.
+ *
+ * This is a guess, but a decent one.
+ */
public static boolean annotationTypeMatches(Class<? extends java.lang.annotation.Annotation> type, Node node) {
if ( node.getKind() != Kind.ANNOTATION ) return false;
TypeReference typeRef = ((Annotation)node.get()).type;
@@ -197,6 +259,9 @@ public class Eclipse {
return false;
}
+ /**
+ * Provides AnnotationValues with the data it needs to do its thing.
+ */
public static <A extends java.lang.annotation.Annotation> AnnotationValues<A>
createAnnotation(Class<A> type, final Node annotationNode) {
final Annotation annotation = (Annotation) annotationNode.get();
diff --git a/src/lombok/eclipse/EclipseAST.java b/src/lombok/eclipse/EclipseAST.java
index 5018f484..cb530f0e 100644
--- a/src/lombok/eclipse/EclipseAST.java
+++ b/src/lombok/eclipse/EclipseAST.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
import java.util.ArrayList;
@@ -25,13 +46,31 @@ import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
import org.eclipse.jdt.internal.compiler.util.Util;
+/**
+ * Wraps around eclipse's internal AST view to add useful features as well as the ability to visit parents from children,
+ * something eclipse's own AST system does not offer.
+ */
public class EclipseAST extends AST<ASTNode> {
+ /**
+ * Creates a new EclipseAST of the provided Compilation Unit.
+ *
+ * @param ast The compilation unit, which serves as the top level node in the tree to be built.
+ */
+ public EclipseAST(CompilationUnitDeclaration ast) {
+ super(toFileName(ast));
+ this.compilationUnitDeclaration = ast;
+ setTop(buildCompilationUnit(ast));
+ this.completeParse = isComplete(ast);
+ }
+
+ /** {@inheritDoc} */
@Override public String getPackageDeclaration() {
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) top().get();
ImportReference pkg = cud.currentPackage;
return pkg == null ? null : Eclipse.toQualifiedName(pkg.getImportName());
}
+ /** {@inheritDoc} */
@Override public Collection<String> getImportStatements() {
List<String> imports = new ArrayList<String>();
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) top().get();
@@ -44,25 +83,38 @@ public class EclipseAST extends AST<ASTNode> {
return imports;
}
+ /**
+ * Runs through the entire AST, starting at the compilation unit, calling the provided visitor's visit methods
+ * for each node, depth first.
+ */
public void traverse(EclipseASTVisitor visitor) {
top().traverse(visitor);
}
- void traverseChildren(EclipseASTVisitor visitor, Node node) {
+ private void traverseChildren(EclipseASTVisitor visitor, Node node) {
for ( Node child : node.down() ) {
child.traverse(visitor);
}
}
+ /**
+ * Eclipse starts off with a 'diet' parse which leaves method bodies blank, amongst other shortcuts.
+ *
+ * For such diet parses, this method returns false, otherwise it returns true. Any lombok processor
+ * that needs the contents of methods should just do nothing (and return false so it gets another shot later!)
+ * when this is false.
+ */
public boolean isCompleteParse() {
return completeParse;
}
+ /** {@inheritDoc} */
@Override public Node top() {
return (Node) super.top();
}
- public Node get(ASTNode node) {
+ /** {@inheritDoc} */
+ @Override public Node get(ASTNode node) {
return (Node) super.get(node);
}
@@ -72,7 +124,7 @@ public class EclipseAST extends AST<ASTNode> {
final int sourceStart;
final int sourceEnd;
- public ParseProblem(boolean isWarning, String message, int sourceStart, int sourceEnd) {
+ ParseProblem(boolean isWarning, String message, int sourceStart, int sourceEnd) {
this.isWarning = isWarning;
this.message = message;
this.sourceStart = sourceStart;
@@ -100,6 +152,10 @@ public class EclipseAST extends AST<ASTNode> {
propagateProblems();
}
+ /**
+ * Adds a problem to the provided CompilationResult object so that it will show up
+ * in the Problems/Warnings view.
+ */
static void addProblemToCompilationResult(CompilationUnitDeclaration ast,
boolean isWarning, String message, int sourceStart, int sourceEnd) {
if ( ast.compilationResult == null ) return;
@@ -141,11 +197,20 @@ public class EclipseAST extends AST<ASTNode> {
}
}
+ /**
+ * Eclipse specific version of the AST.Node class.
+ */
public final class Node extends AST<ASTNode>.Node {
+ /**
+ * See the {@link AST.Node} constructor for information.
+ */
Node(ASTNode node, List<Node> children, Kind kind) {
super(node, children, kind);
}
+ /**
+ * Visits this node and all child nodes depth-first, calling the provided visitor's visit methods.
+ */
public void traverse(EclipseASTVisitor visitor) {
switch ( getKind() ) {
case COMPILATION_UNIT:
@@ -219,6 +284,7 @@ public class EclipseAST extends AST<ASTNode> {
}
}
+ /** {@inheritDoc} */
@Override public String getName() {
final char[] n;
if ( node instanceof TypeDeclaration ) n = ((TypeDeclaration)node).name;
@@ -230,18 +296,22 @@ public class EclipseAST extends AST<ASTNode> {
return n == null ? null : new String(n);
}
+ /** {@inheritDoc} */
@Override public void addError(String message) {
this.addError(message, this.get().sourceStart, this.get().sourceEnd);
}
+ /** Generate a compiler error that shows the wavy underline from-to the stated character positions. */
public void addError(String message, int sourceStart, int sourceEnd) {
addProblem(new ParseProblem(false, message, sourceStart, sourceEnd));
}
+ /** {@inheritDoc} */
@Override public void addWarning(String message) {
this.addWarning(message, this.get().sourceStart, this.get().sourceEnd);
}
+ /** Generate a compiler warning that shows the wavy underline from-to the stated character positions. */
public void addWarning(String message, int sourceStart, int sourceEnd) {
addProblem(new ParseProblem(true, message, sourceStart, sourceEnd));
}
@@ -251,6 +321,7 @@ public class EclipseAST extends AST<ASTNode> {
return (Node) super.up();
}
+ /** {@inheritDoc} */
@Override protected boolean calculateIsStructurallySignificant() {
if ( node instanceof TypeDeclaration ) return true;
if ( node instanceof AbstractMethodDeclaration ) return true;
@@ -281,6 +352,11 @@ public class EclipseAST extends AST<ASTNode> {
return (Node) super.top();
}
+ /**
+ * Convenient shortcut to the owning EclipseAST object's isCompleteParse method.
+ *
+ * @see JavacAST#isCompleteParse()
+ */
public boolean isCompleteParse() {
return completeParse;
}
@@ -289,17 +365,15 @@ public class EclipseAST extends AST<ASTNode> {
private final CompilationUnitDeclaration compilationUnitDeclaration;
private boolean completeParse;
- public EclipseAST(CompilationUnitDeclaration ast) {
- super(toFileName(ast));
- this.compilationUnitDeclaration = ast;
- setTop(buildCompilationUnit(ast));
- this.completeParse = isComplete(ast);
- }
-
private static String toFileName(CompilationUnitDeclaration ast) {
return ast.compilationResult.fileName == null ? null : new String(ast.compilationResult.fileName);
}
+ /**
+ * Call to move an EclipseAST generated for a diet parse to rebuild itself for the full parse -
+ * with filled in method bodies and such. Also propagates problems and errors, which in diet parse
+ * mode can't be reliably added to the problems/warnings view.
+ */
public void reparse() {
propagateProblems();
if ( completeParse ) return;
@@ -315,6 +389,7 @@ public class EclipseAST extends AST<ASTNode> {
return (unit.bits & ASTNode.HasAllMethodBodies) != 0;
}
+ /** {@inheritDoc} */
@Override protected Node buildTree(ASTNode node, Kind kind) {
switch ( kind ) {
case COMPILATION_UNIT:
@@ -459,6 +534,8 @@ public class EclipseAST extends AST<ASTNode> {
return putInMap(new Node(statement, childNodes, Kind.STATEMENT));
}
+ /** For eclipse, only Statement counts, as Expression is a subclass of it, eventhough this isn't
+ * entirely correct according to the JLS spec (only some expressions can be used as statements, not all of them). */
@Override protected Collection<Class<? extends ASTNode>> getStatementTypes() {
return Collections.<Class<? extends ASTNode>>singleton(Statement.class);
}
diff --git a/src/lombok/eclipse/EclipseASTAdapter.java b/src/lombok/eclipse/EclipseASTAdapter.java
index da040037..bb185670 100644
--- a/src/lombok/eclipse/EclipseASTAdapter.java
+++ b/src/lombok/eclipse/EclipseASTAdapter.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
import lombok.eclipse.EclipseAST.Node;
@@ -12,26 +33,71 @@ import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+/**
+ * Standard adapter for the {@link EclipseASTVisitor} interface. Every method on that interface
+ * has been implemented with an empty body. Override whichever methods you need.
+ */
public abstract class EclipseASTAdapter implements EclipseASTVisitor {
+ /** {@inheritDoc} */
public void visitCompilationUnit(Node top, CompilationUnitDeclaration unit) {}
+
+ /** {@inheritDoc} */
public void endVisitCompilationUnit(Node top, CompilationUnitDeclaration unit) {}
+
+ /** {@inheritDoc} */
public void visitType(Node typeNode, TypeDeclaration type) {}
+
+ /** {@inheritDoc} */
public void visitAnnotationOnType(TypeDeclaration type, Node annotationNode, Annotation annotation) {}
+
+ /** {@inheritDoc} */
public void endVisitType(Node typeNode, TypeDeclaration type) {}
+
+ /** {@inheritDoc} */
public void visitInitializer(Node initializerNode, Initializer initializer) {}
+
+ /** {@inheritDoc} */
public void endVisitInitializer(Node initializerNode, Initializer initializer) {}
+
+ /** {@inheritDoc} */
public void visitField(Node fieldNode, FieldDeclaration field) {}
+
+ /** {@inheritDoc} */
public void visitAnnotationOnField(FieldDeclaration field, Node annotationNode, Annotation annotation) {}
+
+ /** {@inheritDoc} */
public void endVisitField(Node fieldNode, FieldDeclaration field) {}
+
+ /** {@inheritDoc} */
public void visitMethod(Node methodNode, AbstractMethodDeclaration method) {}
+
+ /** {@inheritDoc} */
public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {}
+
+ /** {@inheritDoc} */
public void endVisitMethod(Node methodNode, AbstractMethodDeclaration method) {}
+
+ /** {@inheritDoc} */
public void visitMethodArgument(Node argNode, Argument arg, AbstractMethodDeclaration method) {}
+
+ /** {@inheritDoc} */
public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {}
+
+ /** {@inheritDoc} */
public void endVisitMethodArgument(Node argNode, Argument arg, AbstractMethodDeclaration method) {}
+
+ /** {@inheritDoc} */
public void visitLocal(Node localNode, LocalDeclaration local) {}
+
+ /** {@inheritDoc} */
public void visitAnnotationOnLocal(LocalDeclaration local, Node annotationNode, Annotation annotation) {}
+
+ /** {@inheritDoc} */
public void endVisitLocal(Node localNode, LocalDeclaration local) {}
+
+ /** {@inheritDoc} */
public void visitStatement(Node statementNode, Statement statement) {}
+
+ /** {@inheritDoc} */
public void endVisitStatement(Node statementNode, Statement statement) {}
}
diff --git a/src/lombok/eclipse/EclipseASTVisitor.java b/src/lombok/eclipse/EclipseASTVisitor.java
index 49a8696b..ac4ed238 100644
--- a/src/lombok/eclipse/EclipseASTVisitor.java
+++ b/src/lombok/eclipse/EclipseASTVisitor.java
@@ -1,7 +1,26 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
-import java.io.File;
-import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.lang.reflect.Modifier;
@@ -20,7 +39,10 @@ import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
-//TODO expand javadoc
+/**
+ * Implement so you can ask any JavacAST.Node to traverse depth-first through all children,
+ * calling the appropriate visit and endVisit methods.
+ */
public interface EclipseASTVisitor {
/**
* Called at the very beginning and end.
@@ -82,20 +104,30 @@ public interface EclipseASTVisitor {
void visitStatement(Node statementNode, Statement statement);
void endVisitStatement(Node statementNode, Statement statement);
+ /**
+ * Prints the structure of an AST.
+ */
public static class Printer implements EclipseASTVisitor {
private final PrintStream out;
private final boolean printContent;
private int disablePrinting = 0;
private int indent = 0;
+ /**
+ * @param printContent if true, method and initializer bodies are printed directly, as java code,
+ * instead of a tree listing of every AST node inside it.
+ */
public Printer(boolean printContent) {
this(printContent, System.out);
}
- public Printer(boolean printContent, File file) throws FileNotFoundException {
- this(printContent, new PrintStream(file));
- }
-
+ /**
+ * @param printContent if true, method and initializer bodies are printed directly, as java code,
+ * instead of a tree listing of every AST node inside it.
+ * @param PrintStream write output to this stream. You must close it yourself. flush() is called after every line.
+ *
+ * @see java.io.PrintStream#flush()
+ */
public Printer(boolean printContent, PrintStream out) {
this.printContent = printContent;
this.out = out;
diff --git a/src/lombok/eclipse/EclipseAnnotationHandler.java b/src/lombok/eclipse/EclipseAnnotationHandler.java
index e94607f6..39e4d3df 100644
--- a/src/lombok/eclipse/EclipseAnnotationHandler.java
+++ b/src/lombok/eclipse/EclipseAnnotationHandler.java
@@ -1,7 +1,54 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
import lombok.core.AnnotationValues;
+/**
+ * Implement this interface if you want to be triggered for a specific annotation.
+ *
+ * You MUST replace 'T' with a specific annotation type, such as:
+ *
+ * <code>public class HandleGetter implements EclipseAnnotationHandler&lt;<b>Getter</b>&gt;</code>
+ *
+ * Because this generics parameter is inspected to figure out which class you're interested in.
+ *
+ * You also need to register yourself via SPI discovery as being an implementation of <code>EclipseAnnotationHandler</code>.
+ */
public interface EclipseAnnotationHandler<T extends java.lang.annotation.Annotation> {
+ /**
+ * Called when an annotation is found that is likely to match the annotation you're interested in.
+ *
+ * Be aware that you'll be called for ANY annotation node in the source that looks like a match. There is,
+ * for example, no guarantee that the annotation node belongs to a method, even if you set your
+ * TargetType in the annotation to methods only.
+ *
+ * @param annotation The actual annotation - use this object to retrieve the annotation parameters.
+ * @param ast The eclipse AST node representing the annotation.
+ * @param annotationNode The Lombok AST wrapper around the 'ast' parameter. You can use this object
+ * to travel back up the chain (something javac AST can't do) to the parent of the annotation, as well
+ * as access useful methods such as generating warnings or errors focused on the annotation.
+ * @return <code>true</code> if you don't want to be called again about this annotation during this
+ * compile session (you've handled it), or <code>false</code> to indicate you aren't done yet.
+ */
boolean handle(AnnotationValues<T> annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseAST.Node annotationNode);
}
diff --git a/src/lombok/eclipse/HandlerLibrary.java b/src/lombok/eclipse/HandlerLibrary.java
index 6ee2baaa..b319f580 100644
--- a/src/lombok/eclipse/HandlerLibrary.java
+++ b/src/lombok/eclipse/HandlerLibrary.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
import static lombok.eclipse.Eclipse.toQualifiedName;
@@ -21,7 +42,19 @@ import lombok.eclipse.EclipseAST.Node;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+/**
+ * This class tracks 'handlers' and knows how to invoke them for any given AST node.
+ *
+ * This class can find the handlers (via SPI discovery) and will set up the given AST node, such as
+ * building an AnnotationValues instance.
+ */
public class HandlerLibrary {
+ /**
+ * Creates a new HandlerLibrary. Errors will be reported to the eclipse Error log.
+ * You probably want to use {@link #load()} instead.
+ */
+ public HandlerLibrary() {}
+
private TypeLibrary typeLibrary = new TypeLibrary();
private static class AnnotationHandlerContainer<T extends Annotation> {
@@ -47,6 +80,11 @@ public class HandlerLibrary {
private boolean skipPrintAST;
+ /**
+ * Creates a new HandlerLibrary. Errors will be reported to the eclipse Error log.
+ * then uses SPI discovery to load all annotation and visitor based handlers so that future calls
+ * to the handle methods will defer to these handlers.
+ */
public static HandlerLibrary load() {
HandlerLibrary lib = new HandlerLibrary();
@@ -56,6 +94,7 @@ public class HandlerLibrary {
return lib;
}
+ /** Uses SPI Discovery to find implementations of {@link EclipseAnnotationHandler}. */
@SuppressWarnings("unchecked") private static void loadAnnotationHandlers(HandlerLibrary lib) {
Iterator<EclipseAnnotationHandler> it;
try {
@@ -80,6 +119,7 @@ public class HandlerLibrary {
}
}
+ /** Uses SPI Discovery to find implementations of {@link EclipseASTVisitor}. */
private static void loadVisitorHandlers(HandlerLibrary lib) {
Iterator<EclipseASTVisitor> it;
try {
@@ -96,6 +136,23 @@ public class HandlerLibrary {
}
}
+ /**
+ * Handles the provided annotation node by first finding a qualifying instance of
+ * {@link EclipseAnnotationHandler} and if one exists, calling it with a freshly cooked up
+ * instance of {@link AnnotationValues}.
+ *
+ * Note that depending on the printASTOnly flag, the {@link lombok.core.PrintAST} annotation
+ * will either be silently skipped, or everything that isn't <code>PrintAST</code> will be skipped.
+ *
+ * The HandlerLibrary will attempt to guess if the given annotation node represents a lombok annotation.
+ * For example, if <code>lombok.*</code> is in the import list, then this method will guess that
+ * <code>Getter</code> refers to <code>lombok.Getter</code>, presuming that {@link lombok.javac.handlers.HandleGetter}
+ * has been loaded.
+ *
+ * @param unit The Compilation Unit that contains the Annotation AST Node.
+ * @param node The Lombok AST Node representing the Annotation AST Node.
+ * @param annotation 'node.get()' - convenience parameter.
+ */
public boolean handle(CompilationUnitDeclaration ast, EclipseAST.Node annotationNode,
org.eclipse.jdt.internal.compiler.ast.Annotation annotation) {
String pkgName = annotationNode.getPackageDeclaration();
@@ -124,6 +181,9 @@ public class HandlerLibrary {
return handled;
}
+ /**
+ * Will call all registered {@link EclipseASTVisitor} instances.
+ */
public void callASTVisitors(EclipseAST ast) {
for ( EclipseASTVisitor visitor : visitorHandlers ) try {
ast.traverse(visitor);
@@ -133,10 +193,18 @@ public class HandlerLibrary {
}
}
+ /**
+ * Lombok does not currently support triggering annotations in a specified order; the order is essentially
+ * random right now. This lack of order is particularly annoying for the <code>PrintAST</code> annotation,
+ * which is almost always intended to run last. Hence, this hack, which lets it in fact run last.
+ *
+ * {@see #skipAllButPrintAST}
+ */
public void skipPrintAST() {
skipPrintAST = true;
}
+ /** {@see #skipPrintAST} */
public void skipAllButPrintAST() {
skipPrintAST = false;
}
diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java
index 66d663f4..f7a4c715 100644
--- a/src/lombok/eclipse/TransformEclipseAST.java
+++ b/src/lombok/eclipse/TransformEclipseAST.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse;
import java.lang.reflect.Field;
@@ -102,6 +123,10 @@ public class TransformEclipseAST {
this.ast = ast;
}
+ /**
+ * First handles all lombok annotations except PrintAST, then calls all non-annotation based handlers.
+ * then handles any PrintASTs.
+ */
public void go() {
handlers.skipPrintAST();
ast.traverse(new AnnotationVisitor());
diff --git a/src/lombok/eclipse/handlers/HandleCleanup.java b/src/lombok/eclipse/handlers/HandleCleanup.java
index b5251e8a..29f1ec7c 100644
--- a/src/lombok/eclipse/handlers/HandleCleanup.java
+++ b/src/lombok/eclipse/handlers/HandleCleanup.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import java.util.Arrays;
@@ -24,6 +45,9 @@ import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
import org.eclipse.jdt.internal.compiler.ast.TryStatement;
import org.mangosdk.spi.ProviderFor;
+/**
+ * Handles the <code>lombok.Cleanup</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
public boolean handle(AnnotationValues<Cleanup> annotation, Annotation ast, Node annotationNode) {
diff --git a/src/lombok/eclipse/handlers/HandleData.java b/src/lombok/eclipse/handlers/HandleData.java
index 84db0df1..c7f053e6 100644
--- a/src/lombok/eclipse/handlers/HandleData.java
+++ b/src/lombok/eclipse/handlers/HandleData.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import static lombok.eclipse.Eclipse.*;
@@ -67,6 +88,9 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.mangosdk.spi.ProviderFor;
+/**
+ * Handles the <code>lombok.Data</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleData implements EclipseAnnotationHandler<Data> {
public boolean handle(AnnotationValues<Data> annotation, Annotation ast, Node annotationNode) {
diff --git a/src/lombok/eclipse/handlers/HandleGetter.java b/src/lombok/eclipse/handlers/HandleGetter.java
index 159b49fd..78b399c5 100644
--- a/src/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/lombok/eclipse/handlers/HandleGetter.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import static lombok.eclipse.handlers.PKG.*;
@@ -23,8 +44,23 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.mangosdk.spi.ProviderFor;
+/**
+ * Handles the <code>lombok.Getter</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleGetter implements EclipseAnnotationHandler<Getter> {
+ /**
+ * Generates a getter on the stated field.
+ *
+ * Used by {@link HandleData}.
+ *
+ * The difference between this call and the handle method is as follows:
+ *
+ * If there is a <code>lombok.Getter</code> annotation on the field, it is used and the
+ * same rules apply (e.g. warning if the method already exists, stated access level applies).
+ * If not, the getter is still generated if it isn't already there, though there will not
+ * be a warning if its already there. The default access level is used.
+ */
public void generateGetterForField(Node fieldNode, ASTNode pos) {
AccessLevel level = AccessLevel.PUBLIC;
Node errorNode = fieldNode;
diff --git a/src/lombok/eclipse/handlers/HandlePrintAST.java b/src/lombok/eclipse/handlers/HandlePrintAST.java
index a2ccad77..2b06fbe4 100644
--- a/src/lombok/eclipse/handlers/HandlePrintAST.java
+++ b/src/lombok/eclipse/handlers/HandlePrintAST.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import java.io.File;
@@ -14,6 +35,9 @@ import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseAST.Node;
+/**
+ * Handles the <code>lombok.core.PrintAST</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandlePrintAST implements EclipseAnnotationHandler<PrintAST> {
public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) {
diff --git a/src/lombok/eclipse/handlers/HandleSetter.java b/src/lombok/eclipse/handlers/HandleSetter.java
index 57dabc03..70eb855e 100644
--- a/src/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/lombok/eclipse/handlers/HandleSetter.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import static lombok.eclipse.handlers.PKG.*;
@@ -27,8 +48,23 @@ import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.mangosdk.spi.ProviderFor;
+/**
+ * Handles the <code>lombok.Setter</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleSetter implements EclipseAnnotationHandler<Setter> {
+ /**
+ * Generates a setter on the stated field.
+ *
+ * Used by {@link HandleData}.
+ *
+ * The difference between this call and the handle method is as follows:
+ *
+ * If there is a <code>lombok.Setter</code> annotation on the field, it is used and the
+ * same rules apply (e.g. warning if the method already exists, stated access level applies).
+ * If not, the setter is still generated if it isn't already there, though there will not
+ * be a warning if its already there. The default access level is used.
+ */
public void generateSetterForField(Node fieldNode, ASTNode pos) {
AccessLevel level = AccessLevel.PUBLIC;
Node errorNode = fieldNode;
diff --git a/src/lombok/eclipse/handlers/HandleSneakyThrows.java b/src/lombok/eclipse/handlers/HandleSneakyThrows.java
index 01b00efb..8126944d 100644
--- a/src/lombok/eclipse/handlers/HandleSneakyThrows.java
+++ b/src/lombok/eclipse/handlers/HandleSneakyThrows.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import java.util.ArrayList;
@@ -27,6 +48,9 @@ import org.eclipse.jdt.internal.compiler.ast.TryStatement;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.mangosdk.spi.ProviderFor;
+/**
+ * Handles the <code>lombok.HandleSneakyThrows</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows> {
private static class DeclaredException {
diff --git a/src/lombok/eclipse/handlers/HandleSynchronized.java b/src/lombok/eclipse/handlers/HandleSynchronized.java
index e1d4ed6a..9290990b 100644
--- a/src/lombok/eclipse/handlers/HandleSynchronized.java
+++ b/src/lombok/eclipse/handlers/HandleSynchronized.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import static lombok.eclipse.handlers.PKG.*;
@@ -27,6 +48,9 @@ import org.eclipse.jdt.internal.compiler.ast.ThisReference;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.mangosdk.spi.ProviderFor;
+/**
+ * Handles the <code>lombok.Synchronized</code> annotation for javac.
+ */
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleSynchronized implements EclipseAnnotationHandler<Synchronized> {
private static final char[] INSTANCE_LOCK_NAME = "$lock".toCharArray();
@@ -49,9 +73,17 @@ public class HandleSynchronized implements EclipseAnnotationHandler<Synchronized
}
char[] lockName = annotation.getInstance().value().toCharArray();
- if ( lockName.length == 0 ) lockName = method.isStatic() ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
+ boolean autoMake = false;
+ if ( lockName.length == 0 ) {
+ autoMake = true;
+ lockName = method.isStatic() ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
+ }
if ( fieldExists(new String(lockName), methodNode) == MemberExistsResult.NOT_EXISTS ) {
+ if ( !autoMake ) {
+ annotationNode.addError("The field " + new String(lockName) + " does not exist.");
+ return true;
+ }
FieldDeclaration fieldDecl = new FieldDeclaration(lockName, 0, -1);
fieldDecl.declarationSourceEnd = -1;
diff --git a/src/lombok/eclipse/handlers/PKG.java b/src/lombok/eclipse/handlers/PKG.java
index 697514a7..7fdf7afd 100644
--- a/src/lombok/eclipse/handlers/PKG.java
+++ b/src/lombok/eclipse/handlers/PKG.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok.eclipse.handlers;
import java.lang.reflect.Modifier;