From c900526ebf620dcf4f92e7d6c8f7d529900ee666 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 2 Apr 2012 22:56:47 +0200 Subject: Philipp Eichhorn's patch to use marker annotations instead of boolean-returning interface methods for eclipse's postdiet and javac's isResolutionBased. --- src/core/lombok/eclipse/DeferUntilPostDiet.java | 37 ++++++++++++++++++++++ src/core/lombok/eclipse/EclipseASTVisitor.java | 9 +----- .../lombok/eclipse/EclipseAnnotationHandler.java | 11 +------ src/core/lombok/eclipse/EclipseNode.java | 4 +-- src/core/lombok/eclipse/HandlerLibrary.java | 4 +-- src/core/lombok/eclipse/TransformEclipseAST.java | 6 +--- .../lombok/eclipse/handlers/HandlePrintAST.java | 8 ++--- .../eclipse/handlers/HandleSneakyThrows.java | 8 ++--- .../eclipse/handlers/HandleSynchronized.java | 8 ++--- src/core/lombok/eclipse/handlers/HandleVal.java | 6 ++-- 10 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 src/core/lombok/eclipse/DeferUntilPostDiet.java (limited to 'src/core/lombok/eclipse') diff --git a/src/core/lombok/eclipse/DeferUntilPostDiet.java b/src/core/lombok/eclipse/DeferUntilPostDiet.java new file mode 100644 index 00000000..e275affa --- /dev/null +++ b/src/core/lombok/eclipse/DeferUntilPostDiet.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2012 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 + * 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.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark a handler class with this annotation to indicate that this handler should not be run in the diet parse phase. + * 'diet parse' is where method bodies aren't filled in yet. If you have a method-level annotation that modifies the contents of that method, + * you need to put this annotation on your handler. Otherwise, do not put this annotation on your handler. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface DeferUntilPostDiet { +} diff --git a/src/core/lombok/eclipse/EclipseASTVisitor.java b/src/core/lombok/eclipse/EclipseASTVisitor.java index e09602e8..c51a2e87 100644 --- a/src/core/lombok/eclipse/EclipseASTVisitor.java +++ b/src/core/lombok/eclipse/EclipseASTVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -44,13 +44,6 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference; * calling the appropriate visit and endVisit methods. */ public interface EclipseASTVisitor { - /** - * Return true if this handler should not be run in the diet parse phase. - * 'diet parse' is where method bodies aren't filled in yet. If you have a method-level annotation that modifies the contents of that method, - * return {@code true} here. Otherwise, return {@code false} here. - */ - boolean deferUntilPostDiet(); - /** * Called at the very beginning and end. */ diff --git a/src/core/lombok/eclipse/EclipseAnnotationHandler.java b/src/core/lombok/eclipse/EclipseAnnotationHandler.java index 55175cef..ca9cac83 100644 --- a/src/core/lombok/eclipse/EclipseAnnotationHandler.java +++ b/src/core/lombok/eclipse/EclipseAnnotationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -59,13 +59,4 @@ public abstract class EclipseAnnotationHandler annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseNode annotationNode) { } - - /** - * Return true if this handler should not be run in the diet parse phase. - * 'diet parse' is where method bodies aren't filled in yet. If you have a method-level annotation that modifies the contents of that method, - * return {@code true} here. Otherwise, return {@code false} here. - */ - public boolean deferUntilPostDiet() { - return false; - } } diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java index 835020c5..2c970db2 100644 --- a/src/core/lombok/eclipse/EclipseNode.java +++ b/src/core/lombok/eclipse/EclipseNode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -50,7 +50,7 @@ public class EclipseNode extends lombok.core.LombokNode { - @Override public boolean deferUntilPostDiet() { - return true; - } - public void handle(AnnotationValues annotation, Annotation ast, EclipseNode annotationNode) { PrintStream stream = System.out; String fileName = annotation.getInstance().outfile(); diff --git a/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java b/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java index b0e8ca01..b7c8a5d8 100644 --- a/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java +++ b/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -30,6 +30,7 @@ import java.util.List; import lombok.SneakyThrows; import lombok.core.AnnotationValues; +import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; @@ -56,6 +57,7 @@ import org.mangosdk.spi.ProviderFor; * Handles the {@code lombok.HandleSneakyThrows} annotation for eclipse. */ @ProviderFor(EclipseAnnotationHandler.class) +@DeferUntilPostDiet public class HandleSneakyThrows extends EclipseAnnotationHandler { private static class DeclaredException { @@ -68,10 +70,6 @@ public class HandleSneakyThrows extends EclipseAnnotationHandler { } } - @Override public boolean deferUntilPostDiet() { - return true; - } - @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { List exceptionNames = annotation.getRawExpressions("value"); List exceptions = new ArrayList(); diff --git a/src/core/lombok/eclipse/handlers/HandleSynchronized.java b/src/core/lombok/eclipse/handlers/HandleSynchronized.java index cf9a05e0..e4c58eab 100644 --- a/src/core/lombok/eclipse/handlers/HandleSynchronized.java +++ b/src/core/lombok/eclipse/handlers/HandleSynchronized.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -28,6 +28,7 @@ import java.lang.reflect.Modifier; import lombok.Synchronized; import lombok.core.AnnotationValues; import lombok.core.AST.Kind; +import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; @@ -50,14 +51,11 @@ import org.mangosdk.spi.ProviderFor; * Handles the {@code lombok.Synchronized} annotation for eclipse. */ @ProviderFor(EclipseAnnotationHandler.class) +@DeferUntilPostDiet public class HandleSynchronized extends EclipseAnnotationHandler { private static final char[] INSTANCE_LOCK_NAME = "$lock".toCharArray(); private static final char[] STATIC_LOCK_NAME = "$LOCK".toCharArray(); - @Override public boolean deferUntilPostDiet() { - return true; - } - @Override public void preHandle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { EclipseNode methodNode = annotationNode.up(); if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration)) return; diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java index a5cf29b2..56b3effd 100644 --- a/src/core/lombok/eclipse/handlers/HandleVal.java +++ b/src/core/lombok/eclipse/handlers/HandleVal.java @@ -22,6 +22,7 @@ package lombok.eclipse.handlers; import lombok.val; +import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseASTAdapter; import lombok.eclipse.EclipseASTVisitor; import lombok.eclipse.EclipseNode; @@ -36,11 +37,8 @@ import org.mangosdk.spi.ProviderFor; * This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}. */ @ProviderFor(EclipseASTVisitor.class) +@DeferUntilPostDiet public class HandleVal extends EclipseASTAdapter { - @Override public boolean deferUntilPostDiet() { - return false; - } - @Override public void visitLocal(EclipseNode localNode, LocalDeclaration local) { if (!EclipseHandlerUtil.typeMatches(val.class, localNode, local.type)) return; boolean variableOfForEach = false; -- cgit