From 21095bbb972b590cd4fc61ea911aca60ec30cedf Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 6 Mar 2014 23:21:55 +0100 Subject: pre-release version bump --- src/core/lombok/core/Version.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java index 6e68f035..3c5afbae 100644 --- a/src/core/lombok/core/Version.java +++ b/src/core/lombok/core/Version.java @@ -28,9 +28,9 @@ public class Version { // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. // Official builds always end in an even number. (Since 0.10.2). - private static final String VERSION = "1.12.5"; - private static final String RELEASE_NAME = "Edgy Guinea Pig"; -// private static final String RELEASE_NAME = "Angry Butterfly"; + private static final String VERSION = "1.12.6"; +// private static final String RELEASE_NAME = "Edgy Guinea Pig"; + private static final String RELEASE_NAME = "Angry Butterfly"; private Version() { //Prevent instantiation -- cgit From aeae9023424ba39d47fe42b03772988dc0c18a07 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 7 Mar 2014 00:01:58 +0100 Subject: post release version bump --- doc/changelog.markdown | 2 ++ src/core/lombok/core/Version.java | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/doc/changelog.markdown b/doc/changelog.markdown index e32361a2..24a69a41 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -1,6 +1,8 @@ Lombok Changelog ---------------- +### v1.12.7 "Edgy Guinea Pig" + ### v1.12.6 (March 6th, 2014) * GOOSECHASE: We're trying to fix a deadlock/race condition in the EquinoxClassLoader when Eclipse works with SVN or Gradle. (v2) * PLATFORM: Added support for Eclipse Luna. [Issue #609](https://code.google.com/p/projectlombok/issues/detail?id=609) diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java index 3c5afbae..2bd07d5a 100644 --- a/src/core/lombok/core/Version.java +++ b/src/core/lombok/core/Version.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2014 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,9 +28,9 @@ public class Version { // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. // Official builds always end in an even number. (Since 0.10.2). - private static final String VERSION = "1.12.6"; -// private static final String RELEASE_NAME = "Edgy Guinea Pig"; - private static final String RELEASE_NAME = "Angry Butterfly"; + private static final String VERSION = "1.12.7"; + private static final String RELEASE_NAME = "Edgy Guinea Pig"; +// private static final String RELEASE_NAME = "Angry Butterfly"; private Version() { //Prevent instantiation -- cgit From 17972d59fa7e2eec6b73ba5da8234f5fa7ac2536 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 17 Mar 2014 21:56:49 +0100 Subject: [#590][refactor] Fix for deadlock in WeakHashMap. Refactored all code that used a WeakHashMap to fake a field. --- doc/changelog.markdown | 3 +- src/core/lombok/core/AnnotationProcessor.java | 10 +- src/core/lombok/core/debug/DebugSnapshotStore.java | 3 +- src/core/lombok/eclipse/HandlerLibrary.java | 15 +- .../eclipse/handlers/EclipseHandlerUtil.java | 42 +--- src/core/lombok/javac/HandlerLibrary.java | 13 +- .../lombok/javac/handlers/JavacHandlerUtil.java | 16 +- .../lombok/eclipse/agent/PatchDelegate.java | 14 +- .../lombok/eclipse/agent/PatchExtensionMethod.java | 17 +- src/utils/lombok/core/BooleanFieldAugment.java | 185 +++++++++++++++++ src/utils/lombok/core/ReferenceFieldAugment.java | 218 +++++++++++++++++++++ src/utils/lombok/javac/CommentCatcher.java | 28 +-- .../javac/java6/CommentCollectingParser.java | 13 +- .../java6/CommentCollectingParserFactory.java | 16 +- .../javac/java7/CommentCollectingParser.java | 12 +- .../java7/CommentCollectingParserFactory.java | 16 +- .../javac/java8/CommentCollectingParser.java | 12 +- .../java8/CommentCollectingParserFactory.java | 16 +- 18 files changed, 504 insertions(+), 145 deletions(-) create mode 100644 src/utils/lombok/core/BooleanFieldAugment.java create mode 100644 src/utils/lombok/core/ReferenceFieldAugment.java (limited to 'src') diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 8fbc87b0..cf2d286b 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,9 +2,10 @@ Lombok Changelog ---------------- ### v1.12.7 "Edgy Guinea Pig" +* BUGFIX: Deadlocks would occasionally occur in eclipse when using lazy getters [Issue #590](https://code.google.com/p/projectlombok/issues/detail?id=590) ### v1.12.6 (March 6th, 2014) -* BUGFIX: deadlocks would occasionally occur in eclipse during project builds, especially if using the gradle plugin. [Issue #645](https://code.google.com/p/projectlombok/issues/detail?id=645) +* BUGFIX: Deadlocks would occasionally occur in eclipse during project builds, especially if using the gradle plugin. [Issue #645](https://code.google.com/p/projectlombok/issues/detail?id=645) * PLATFORM: Added support for Eclipse Luna. [Issue #609](https://code.google.com/p/projectlombok/issues/detail?id=609) * PLATFORM: Initial JDK8 support for eclipse's alpha support in kepler. [Issue #597](https://code.google.com/p/projectlombok/issues/detail?id=597) * FEATURE: The various `@Log` annotations now support the `topic` parameter, which sets the logger's name. The default remains the fully qualified type name of the class itself. [Issue #632](https://code.google.com/p/projectlombok/issues/detail?id=632). diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java index 734150cd..ecce1849 100644 --- a/src/core/lombok/core/AnnotationProcessor.java +++ b/src/core/lombok/core/AnnotationProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2014 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 @@ -29,9 +29,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; @@ -63,8 +61,8 @@ public class AnnotationProcessor extends AbstractProcessor { private final List active = new ArrayList(); private final List delayedWarnings = new ArrayList(); - private static final Map lombokAlreadyAddedTo = new WeakHashMap(); - + private static final BooleanFieldAugment lombokAlreadyAddedTo = BooleanFieldAugment.augment(ClassLoader.class, "lombok$alreadyAddedTo"); + static class JavacDescriptor extends ProcessorDescriptor { private Processor processor; @@ -100,7 +98,7 @@ public class AnnotationProcessor extends AbstractProcessor { private ClassLoader findAndPatchClassLoader(ProcessingEnvironment procEnv) throws Exception { ClassLoader environmentClassLoader = procEnv.getClass().getClassLoader(); if (environmentClassLoader != null && environmentClassLoader.getClass().getCanonicalName().equals("org.codehaus.plexus.compiler.javac.IsolatedClassLoader")) { - if (lombokAlreadyAddedTo.put(environmentClassLoader, true) == null) { + if (!lombokAlreadyAddedTo.set(environmentClassLoader)) { Method m = environmentClassLoader.getClass().getDeclaredMethod("addURL", URL.class); URL selfUrl = new File(ClassRootFinder.findClassRootOfClass(AnnotationProcessor.class)).toURI().toURL(); m.invoke(environmentClassLoader, selfUrl); diff --git a/src/core/lombok/core/debug/DebugSnapshotStore.java b/src/core/lombok/core/debug/DebugSnapshotStore.java index 19f4d5b1..daaf9509 100644 --- a/src/core/lombok/core/debug/DebugSnapshotStore.java +++ b/src/core/lombok/core/debug/DebugSnapshotStore.java @@ -35,8 +35,9 @@ import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; public class DebugSnapshotStore { public static final DebugSnapshotStore INSTANCE = new DebugSnapshotStore(); - public static boolean GLOBAL_DSS_DISABLE_SWITCH = true; + public static final boolean GLOBAL_DSS_DISABLE_SWITCH = true; + // All access should synchronize on the map private final Map> map = new WeakHashMap>(); diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java index 242e923c..15a98b85 100644 --- a/src/core/lombok/eclipse/HandlerLibrary.java +++ b/src/core/lombok/eclipse/HandlerLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2014 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 @@ -33,11 +33,11 @@ import java.util.HashMap; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; -import java.util.WeakHashMap; import lombok.Lombok; import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValueDecodeFail; +import lombok.core.BooleanFieldAugment; import lombok.core.HandlerPriority; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; @@ -185,19 +185,14 @@ public class HandlerLibrary { } } - private static final Map handledMap = new WeakHashMap(); - private static final Object MARKER = new Object(); + private static final BooleanFieldAugment handled = BooleanFieldAugment.augment(ASTNode.class, "lombok$handled"); private boolean checkAndSetHandled(ASTNode node) { - synchronized (handledMap) { - return handledMap.put(node, MARKER) != MARKER; - } + return !handled.set(node); } private boolean needsHandling(ASTNode node) { - synchronized (handledMap) { - return handledMap.get(node) != MARKER; - } + return !handled.get(node); } /** diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index fbad53d4..c4115652 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -25,7 +25,6 @@ import static lombok.eclipse.Eclipse.*; import static lombok.core.TransformationsUtil.*; import java.lang.reflect.Constructor; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -35,7 +34,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.WeakHashMap; import lombok.AccessLevel; import lombok.Data; @@ -44,6 +42,8 @@ import lombok.Lombok; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValue; +import lombok.core.BooleanFieldAugment; +import lombok.core.ReferenceFieldAugment; import lombok.core.TransformationsUtil; import lombok.core.TypeResolver; import lombok.eclipse.EclipseAST; @@ -207,27 +207,10 @@ public class EclipseHandlerUtil { } } - private static Field generatedByField; - - static { - try { - generatedByField = ASTNode.class.getDeclaredField("$generatedBy"); - } catch (Throwable t) { - //ignore - no $generatedBy exists when running in ecj. - } - } - - private static Map generatedNodes = new WeakHashMap(); + private static ReferenceFieldAugment generatedNodes = ReferenceFieldAugment.augment(ASTNode.class, ASTNode.class, "$generatedBy"); public static ASTNode getGeneratedBy(ASTNode node) { - if (generatedByField != null) { - try { - return (ASTNode) generatedByField.get(node); - } catch (Exception e) {} - } - synchronized (generatedNodes) { - return generatedNodes.get(node); - } + return generatedNodes.get(node); } public static boolean isGenerated(ASTNode node) { @@ -235,15 +218,7 @@ public class EclipseHandlerUtil { } public static ASTNode setGeneratedBy(ASTNode node, ASTNode source) { - if (generatedByField != null) { - try { - generatedByField.set(node, source); - return node; - } catch (Exception e) {} - } - synchronized (generatedNodes) { - generatedNodes.put(node, source); - } + generatedNodes.set(node, source); return node; } @@ -865,12 +840,11 @@ public class EclipseHandlerUtil { } } - private static final Map generatedLazyGettersWithPrimitiveBoolean = new WeakHashMap(); - private static final Object MARKER = new Object(); + private static final BooleanFieldAugment generatedLazyGettersWithPrimitiveBoolean = BooleanFieldAugment.augment(FieldDeclaration.class, "lombok$booleanLazyGetter"); static void registerCreatedLazyGetter(FieldDeclaration field, char[] methodName, TypeReference returnType) { if (isBoolean(returnType)) { - generatedLazyGettersWithPrimitiveBoolean.put(field, MARKER); + generatedLazyGettersWithPrimitiveBoolean.set(field); } } @@ -880,7 +854,7 @@ public class EclipseHandlerUtil { private static GetterMethod findGetter(EclipseNode field) { FieldDeclaration fieldDeclaration = (FieldDeclaration) field.get(); - boolean forceBool = generatedLazyGettersWithPrimitiveBoolean.containsKey(fieldDeclaration); + boolean forceBool = generatedLazyGettersWithPrimitiveBoolean.get(fieldDeclaration); TypeReference fieldType = fieldDeclaration.type; boolean isBoolean = forceBool || isBoolean(fieldType); diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java index 4306b5f2..0cab56f9 100644 --- a/src/core/lombok/javac/HandlerLibrary.java +++ b/src/core/lombok/javac/HandlerLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2014 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,16 +30,16 @@ import java.util.HashMap; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; -import java.util.WeakHashMap; import javax.annotation.processing.Messager; import javax.tools.Diagnostic; +import lombok.core.AnnotationValues.AnnotationValueDecodeFail; +import lombok.core.BooleanFieldAugment; import lombok.core.HandlerPriority; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; import lombok.core.TypeResolver; -import lombok.core.AnnotationValues.AnnotationValueDecodeFail; import lombok.javac.handlers.JavacHandlerUtil; import com.sun.tools.javac.tree.JCTree; @@ -204,13 +204,10 @@ public class HandlerLibrary { if (t != null) t.printStackTrace(); } - private static final Map handledMap = new WeakHashMap(); - private static final Object MARKER = new Object(); + private static final BooleanFieldAugment handled = BooleanFieldAugment.augment(JCTree.class, "lombok$handled"); private boolean checkAndSetHandled(JCTree node) { - synchronized (handledMap) { - return handledMap.put(node, MARKER) != MARKER; - } + return !handled.set(node); } /** diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index bc4dda8e..de73b3be 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -25,13 +25,11 @@ import static lombok.core.TransformationsUtil.INVALID_ON_BUILDERS; import static lombok.javac.Javac.*; import java.lang.annotation.Annotation; -import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.WeakHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,6 +39,7 @@ import lombok.Getter; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValue; +import lombok.core.ReferenceFieldAugment; import lombok.core.TransformationsUtil; import lombok.core.TypeResolver; import lombok.delombok.LombokOptionsFactory; @@ -109,7 +108,7 @@ public class JavacHandlerUtil { } } - private static Map> generatedNodes = new WeakHashMap>(); + private static ReferenceFieldAugment generatedNodes = ReferenceFieldAugment.augmentWeakField(JCTree.class, JCTree.class, "lombok$generatedNodes"); /** * Contributed by Jan Lahoda; many lombok transformations should not be run (or a lite version should be run) when the netbeans editor @@ -126,10 +125,7 @@ public class JavacHandlerUtil { } public static JCTree getGeneratedBy(JCTree node) { - synchronized (generatedNodes) { - WeakReference ref = generatedNodes.get(node); - return ref == null ? null : ref.get(); - } + return generatedNodes.get(node); } public static boolean isGenerated(JCTree node) { @@ -145,10 +141,8 @@ public class JavacHandlerUtil { public static T setGeneratedBy(T node, JCTree source, Context context) { if (node == null) return null; - synchronized (generatedNodes) { - if (source == null) generatedNodes.remove(node); - else generatedNodes.put(node, new WeakReference(source)); - } + if (source == null) generatedNodes.clear(node); + else generatedNodes.set(node, source); if (source != null && (!inNetbeansEditor(context) || (node instanceof JCVariableDecl && (((JCVariableDecl) node).mods.flags & Flags.PARAMETER) != 0))) node.pos = source.pos; return node; } diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java index 6fdcfa63..6a0c25e7 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 The Project Lombok Authors. + * Copyright (C) 2010-2014 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,11 +30,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; import lombok.core.AST.Kind; +import lombok.core.BooleanFieldAugment; import lombok.eclipse.EclipseAST; import lombok.eclipse.EclipseNode; import lombok.eclipse.TransformEclipseAST; @@ -182,11 +181,10 @@ public class PatchDelegate { return null; } - private static Map alreadyApplied = new WeakHashMap(); - private static final Object MARKER = new Object(); + private static BooleanFieldAugment applied = BooleanFieldAugment.augment(Annotation.class, "lombok$applied"); public static void markHandled(Annotation annotation) { - alreadyApplied.put(annotation, MARKER); + applied.set(annotation); } private static void fillMethodBindingsForFields(CompilationUnitDeclaration cud, ClassScope scope, List methodsToDelegate) { @@ -197,7 +195,7 @@ public class PatchDelegate { if (field.annotations == null) continue; for (Annotation ann : field.annotations) { if (!isDelegate(ann, decl)) continue; - if (alreadyApplied.put(ann, MARKER) == MARKER) continue; + if (applied.set(ann)) continue; if ((field.modifiers & ClassFileConstants.AccStatic) != 0) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); @@ -250,7 +248,7 @@ public class PatchDelegate { if (methodDecl.annotations == null) continue; for (Annotation ann : methodDecl.annotations) { if (!isDelegate(ann, decl)) continue; - if (alreadyApplied.put(ann, MARKER) == MARKER) continue; + if (applied.set(ann)) continue; if (!(methodDecl instanceof MethodDeclaration)) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java index a3d77055..9b3ec5df 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 The Project Lombok Authors. + * Copyright (C) 2012-2014 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 @@ -27,12 +27,11 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValueDecodeFail; +import lombok.core.ReferenceFieldAugment; import lombok.eclipse.EclipseAST; import lombok.eclipse.EclipseNode; import lombok.eclipse.TransformEclipseAST; @@ -179,14 +178,14 @@ public class PatchExtensionMethod { return extensionMethods; } - private static final Map ERRORS = new WeakHashMap(); + private static final ReferenceFieldAugment postponedErrors = ReferenceFieldAugment.augment(MessageSend.class, PostponedError.class, "lombok$postponedErrors"); public static void errorNoMethodFor(ProblemReporter problemReporter, MessageSend messageSend, TypeBinding recType, TypeBinding[] params) { - ERRORS.put(messageSend, new PostponedNoMethodError(problemReporter, messageSend, recType, params)); + postponedErrors.set(messageSend, new PostponedNoMethodError(problemReporter, messageSend, recType, params)); } public static void invalidMethod(ProblemReporter problemReporter, MessageSend messageSend, MethodBinding method) { - ERRORS.put(messageSend, new PostponedInvalidMethodError(problemReporter, messageSend, method)); + postponedErrors.set(messageSend, new PostponedInvalidMethodError(problemReporter, messageSend, method)); } public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend methodCall, BlockScope scope) { @@ -216,7 +215,7 @@ public class PatchExtensionMethod { if (!extension.suppressBaseMethods && !(methodCall.binding instanceof ProblemMethodBinding)) continue; for (MethodBinding extensionMethod : extension.extensionMethods) { if (!Arrays.equals(methodCall.selector, extensionMethod.selector)) continue; - ERRORS.remove(methodCall); + postponedErrors.clear(methodCall); if (methodCall.receiver instanceof ThisReference) { methodCall.receiver.bits &= ~ASTNode.IsImplicitThis; } @@ -258,10 +257,10 @@ public class PatchExtensionMethod { } } - PostponedError error = ERRORS.get(methodCall); + PostponedError error = postponedErrors.get(methodCall); if (error != null) error.fire(); - ERRORS.remove(methodCall); + postponedErrors.clear(methodCall); return resolvedType; } diff --git a/src/utils/lombok/core/BooleanFieldAugment.java b/src/utils/lombok/core/BooleanFieldAugment.java new file mode 100644 index 00000000..d843e9df --- /dev/null +++ b/src/utils/lombok/core/BooleanFieldAugment.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2014 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.core; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * Augments a instance of a type with a boolean field. + *

+ * If the type already declares a boolean field, that field is used. Otherwise the field will be augmented. + * + * @param the type to augment. + */ +public abstract class BooleanFieldAugment { + + /** + * Augments a instance of a type with a boolean field. + *

+ * If the type already declares a boolean instance field, that field might be used. Otherwise the field will be augmented. + *

+ * This code assumes that for any combination of {@code type} and {@code name} this method is only called once. + * Otherwise, whether state is shared is undefined. + * + * @param type to augment + * @param name of the field + * @throws NullPointerException if {@code type} or {@code name} is {@code null} + */ + public static BooleanFieldAugment augment(Class type, String name) { + checkNotNull(type, "type"); + checkNotNull(name, "name"); + Field booleanField = getBooleanField(type, name); + if (booleanField == null) { + return new MapFieldAugment(); + } + return new ExistingFieldAugment(booleanField); + } + + private BooleanFieldAugment() { + // prevent external instantiation + } + + private static Field getBooleanField(Class type, String name) { + try { + Field result = type.getDeclaredField(name); + if (Modifier.isStatic(result.getModifiers()) || result.getType() != boolean.class) { + return null; + } + result.setAccessible(true); + return result; + } catch (Throwable t) { + return null; + } + } + + /** + * Sets the field to {@code true}. + * @returns the previous value + * @throws NullPointerException if {@code object} is {@code null} + */ + public abstract boolean set(T object); + + /** + * Sets the field to {@code false}. + * @returns the previous value + * @throws NullPointerException if {@code object} is {@code null} + */ + public abstract boolean clear(T object); + + /** + * @eturn {code true} if the field is set, otherwise {@code false}. + * @throws NullPointerException if {@code object} is {@code null} + */ + public abstract boolean get(T object); + + private static class MapFieldAugment extends BooleanFieldAugment { + private static final Object MARKER = new Object(); + + private final Map values = new WeakHashMap(); + + public boolean set(T object) { + checkNotNull(object, "object"); + synchronized (values) { + return values.put(object, MARKER) != null; + } + } + + public boolean clear(T object) { + checkNotNull(object, "object"); + synchronized (values) { + return values.remove(object) != null; + } + } + + public boolean get(T object) { + checkNotNull(object, "object"); + synchronized (values) { + return values.get(object) != null; + } + } + } + + private static class ExistingFieldAugment extends BooleanFieldAugment { + private final Object lock = new Object(); + private final Field booleanField; + + private ExistingFieldAugment(Field booleanField) { + this.booleanField = booleanField; + } + + @Override public boolean set(T object) { + checkNotNull(object, "object"); + try { + synchronized (lock) { + boolean result = booleanField.getBoolean(object); + booleanField.setBoolean(object, true); + return result; + } + } catch (IllegalAccessException e) { + throw sneakyThrow(e); + } + } + + @Override public boolean clear(T object) { + checkNotNull(object, "object"); + try { + synchronized (lock) { + boolean result = booleanField.getBoolean(object); + booleanField.setBoolean(object, false); + return result; + } + } catch (IllegalAccessException e) { + throw sneakyThrow(e); + } + } + + @Override public boolean get(T object) { + checkNotNull(object, "object"); + try { + synchronized (lock) { + return booleanField.getBoolean(object); + } + } catch (IllegalAccessException e) { + throw sneakyThrow(e); + } + } + } + + private static T checkNotNull(T object, String name) { + if (object == null) throw new NullPointerException(name); + return object; + } + + private static RuntimeException sneakyThrow(Throwable t) { + if (t == null) throw new NullPointerException("t"); + BooleanFieldAugment.sneakyThrow0(t); + return null; + } + + @SuppressWarnings("unchecked") + private static void sneakyThrow0(Throwable t) throws T { + throw (T)t; + } +} \ No newline at end of file diff --git a/src/utils/lombok/core/ReferenceFieldAugment.java b/src/utils/lombok/core/ReferenceFieldAugment.java new file mode 100644 index 00000000..214817a7 --- /dev/null +++ b/src/utils/lombok/core/ReferenceFieldAugment.java @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2014 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.core; + +import java.lang.ref.WeakReference; +import java.util.Map; +import java.util.WeakHashMap; + +public abstract class ReferenceFieldAugment { + + /** + * Augments a instance of a type with a reference field. + *

+ * If the type already declares an instance field with the given name and field type, that field might be used. Otherwise the field will be augmented. + *

+ * This code assumes that for any combination of {@code type} and {@code name} this method is only called once. + * Otherwise, whether state is shared is undefined. + * + * @param type to augment + * @param fieldType type of the field + * @param name of the field + * @throws NullPointerException if {@code type}, {@code fieldType} or {@code name} is {@code null} + */ + public static ReferenceFieldAugment augment(Class type, Class fieldType, String name) { + return new MapFieldAugment(); + } + + /** + * Augments a instance of a type with a weak reference field. + *

+ * If the type already declares an instance field with the given name and field type, that field might be used. Otherwise the field will be augmented. + *

+ * This code assumes that for any combination of {@code type} and {@code name} this method is only called once. + * Otherwise, whether state is shared is undefined. + * + * @param type to augment + * @param fieldType type of the field + * @param name of the field + * @throws NullPointerException if {@code type}, {@code fieldType} or {@code name} is {@code null} + */ + public static ReferenceFieldAugment augmentWeakField(Class type, Class fieldType, String name) { + return new MapWeakFieldAugment(); + } + + private ReferenceFieldAugment() { + // prevent external instantiation + } + + /** + * @throws NullPointerException if {@code object} is {@code null} + */ + public abstract F get(T object); + + /** + * @throws NullPointerException if {@code object} or {@code expected} is {@code null} + */ + public final void set(T object, F value) { + getAndSet(object, value); + } + + /** + * @return the value of the field before the operation. + * @throws NullPointerException if {@code object} or {@code expected} is {@code null} + */ + public abstract F getAndSet(T object, F value); + + /** + * @return the value of the field before the operation. + * @throws NullPointerException if {@code object} is {@code null} + */ + public abstract F clear(T object); + + /** + * @return the value of the field after the operation. If the value was equal to {@code expected} or already cleared {@code null}, otherwise the current value. + * @throws NullPointerException if {@code object} or {@code expected} is {@code null} + */ + public abstract F compareAndClear(T object, F expected); + + /** + * @return the value of the field after the operation. + * @throws NullPointerException if {@code object} or {@code value} is {@code null} + */ + public abstract F setIfAbsent(T object, F value); + + /** + * @return the value of the field after the operation. + * @throws NullPointerException if {@code object}, {@code expected} or {@code value} is {@code null} + */ + public abstract F compareAndSet(T object, F expected, F value); + + private static class MapFieldAugment extends ReferenceFieldAugment { + final Map values = new WeakHashMap(); + + @Override + public F get(T object) { + checkNotNull(object, "object"); + synchronized (values) { + return read(object); + } + } + + @Override + public F getAndSet(T object, F value) { + checkNotNull(object, "object"); + checkNotNull(value, "value"); + synchronized (values) { + F result = read(object); + write(object, value); + return result; + } + } + + @Override + public F clear(T object) { + checkNotNull(object, "object"); + synchronized (values) { + F result = read(object); + values.remove(object); + return result; + } + } + + @Override + public F compareAndClear(T object, F expected) { + checkNotNull(object, "object"); + checkNotNull(expected, "expected"); + synchronized (values) { + F result = read(object); + if (result == null) { + return null; + } + if (!expected.equals(result)) { + return result; + } + values.remove(object); + return null; + } + } + + @Override + public F setIfAbsent(T object, F value) { + checkNotNull(object, "object"); + checkNotNull(value, "value"); + synchronized (values) { + F result = read(object); + if (result != null) { + return result; + } + write(object, value); + return value; + } + } + + @Override + public F compareAndSet(T object, F expected, F value) { + checkNotNull(object, "object"); + checkNotNull(expected, "expected"); + checkNotNull(value, "value"); + synchronized (values) { + F result = read(object); + if (!expected.equals(result)) { + return result; + } + write(object, value); + return value; + } + } + + @SuppressWarnings("unchecked") + F read(T object) { + return (F)values.get(object); + } + + void write(T object, F value) { + values.put(object, value); + } + } + + static class MapWeakFieldAugment extends MapFieldAugment { + + @SuppressWarnings("unchecked") + F read(T object) { + WeakReference read = (WeakReference)values.get(object); + if (read == null) return null; + F result = read.get(); + if (result == null) values.remove(object); + return result; + } + + void write(T object, F value) { + values.put(object, new WeakReference(value)); + } + } + + private static T checkNotNull(T object, String name) { + if (object == null) throw new NullPointerException(name); + return object; + } +} diff --git a/src/utils/lombok/javac/CommentCatcher.java b/src/utils/lombok/javac/CommentCatcher.java index 36d90e30..ff6be7a2 100644 --- a/src/utils/lombok/javac/CommentCatcher.java +++ b/src/utils/lombok/javac/CommentCatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013 The Project Lombok Authors. + * Copyright (C) 2011-2014 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 @@ -24,8 +24,8 @@ package lombok.javac; import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; + +import lombok.core.ReferenceFieldAugment; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -33,24 +33,24 @@ import com.sun.tools.javac.util.Context; public class CommentCatcher { private final JavaCompiler compiler; - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; public static CommentCatcher create(Context context) { registerCommentsCollectingScannerFactory(context); JavaCompiler compiler = new JavaCompiler(context); - Map> commentsMap = new WeakHashMap>(); - setInCompiler(compiler, context, commentsMap); + ReferenceFieldAugment> comments = ReferenceFieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments"); + setInCompiler(compiler, context, comments); compiler.keepComments = true; compiler.genEndPos = true; - return new CommentCatcher(compiler, commentsMap); + return new CommentCatcher(compiler, comments); } - private CommentCatcher(JavaCompiler compiler, Map> commentsMap) { + private CommentCatcher(JavaCompiler compiler, ReferenceFieldAugment> commentsField) { this.compiler = compiler; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JavaCompiler getCompiler() { @@ -59,14 +59,14 @@ public class CommentCatcher { public void setComments(JCCompilationUnit ast, List comments) { if (comments != null) { - commentsMap.put(ast, comments); + commentsField.set(ast, comments); } else { - commentsMap.remove(ast); + commentsField.clear(ast); } } public List getComments(JCCompilationUnit ast) { - List list = commentsMap.get(ast); + List list = commentsField.get(ast); return list == null ? Collections.emptyList() : list; } @@ -89,7 +89,7 @@ public class CommentCatcher { } } - private static void setInCompiler(JavaCompiler compiler, Context context, Map> commentsMap) { + private static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment> commentsField) { try { Class parserFactory; int javaCompilerVersion = Javac.getJavaCompilerVersion(); @@ -100,7 +100,7 @@ public class CommentCatcher { } else { parserFactory = Class.forName("lombok.javac.java8.CommentCollectingParserFactory"); } - parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class, Map.class).invoke(null, compiler, context, commentsMap); + parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class, ReferenceFieldAugment.class).invoke(null, compiler, context, commentsField); } catch (InvocationTargetException e) { throw Javac.sneakyThrow(e.getCause()); } catch (Exception e) { diff --git a/src/utils/lombok/javac/java6/CommentCollectingParser.java b/src/utils/lombok/javac/java6/CommentCollectingParser.java index 30192b06..215bf5b6 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 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,7 @@ */ package lombok.javac.java6; -import java.util.Map; - +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -33,20 +32,20 @@ import com.sun.tools.javac.util.List; class CommentCollectingParser extends EndPosParser { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; private final Lexer lexer; - protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, Map> commentsMap) { + protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, ReferenceFieldAugment> commentsField) { super(fac, S, keepDocComments); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } @Override public JCCompilationUnit compilationUnit() { JCCompilationUnit result = super.compilationUnit(); if (lexer instanceof CommentCollectingScanner) { List comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java index b250b898..124a05f7 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 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 @@ -22,8 +22,8 @@ package lombok.javac.java6; import java.lang.reflect.Field; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -34,32 +34,32 @@ import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; public class CommentCollectingParserFactory extends Parser.Factory { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; static Context.Key key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment> commentsField) { super(context); - this.commentsMap = commentsMap; + this.commentsField = commentsField; } @Override public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) { - Object x = new CommentCollectingParser(this, S, true, commentsMap); + Object x = new CommentCollectingParser(this, S, true, commentsField); return (Parser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac7's EndPosParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, Map> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment> commentsField) { context.put(CommentCollectingParserFactory.key(), (Parser.Factory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } diff --git a/src/utils/lombok/javac/java7/CommentCollectingParser.java b/src/utils/lombok/javac/java7/CommentCollectingParser.java index 0e8a4ef6..27d731ba 100644 --- a/src/utils/lombok/javac/java7/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java7/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 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 @@ -22,8 +22,8 @@ package lombok.javac.java7; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -32,21 +32,21 @@ import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; class CommentCollectingParser extends EndPosParser { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; private final Lexer lexer; protected CommentCollectingParser(ParserFactory fac, Lexer S, - boolean keepDocComments, boolean keepLineMap, Map> commentsMap) { + boolean keepDocComments, boolean keepLineMap, ReferenceFieldAugment> commentsField) { super(fac, S, keepDocComments, keepLineMap); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JCCompilationUnit parseCompilationUnit() { JCCompilationUnit result = super.parseCompilationUnit(); if (lexer instanceof CommentCollectingScanner) { List comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java index ed8279df..dba5a0fa 100644 --- a/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 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 @@ -23,8 +23,8 @@ package lombok.javac.java7; import java.lang.reflect.Field; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -36,36 +36,36 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; public class CommentCollectingParserFactory extends ParserFactory { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; private final Context context; static Context.Key key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment> commentsField) { super(context); this.context = context; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public Parser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { ScannerFactory scannerFactory = ScannerFactory.instance(context); Lexer lexer = scannerFactory.newScanner(input, true); - Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, commentsMap); + Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, commentsField); return (Parser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac7's EndPosParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, Map> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment> commentsField) { context.put(CommentCollectingParserFactory.key(), (ParserFactory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } diff --git a/src/utils/lombok/javac/java8/CommentCollectingParser.java b/src/utils/lombok/javac/java8/CommentCollectingParser.java index e305e44f..9a05267c 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java8/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 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 @@ -22,8 +22,8 @@ package lombok.javac.java8; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.JavacParser; @@ -32,21 +32,21 @@ import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; class CommentCollectingParser extends JavacParser { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; private final Lexer lexer; protected CommentCollectingParser(ParserFactory fac, Lexer S, - boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions, Map> commentsMap) { + boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions, ReferenceFieldAugment> commentsField) { super(fac, S, keepDocComments, keepLineMap, keepEndPositions); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JCCompilationUnit parseCompilationUnit() { JCCompilationUnit result = super.parseCompilationUnit(); if (lexer instanceof CommentCollectingScanner) { List comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java index 6b5f9198..5bed46fc 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 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 @@ -23,8 +23,8 @@ package lombok.javac.java8; import java.lang.reflect.Field; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -36,36 +36,36 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; public class CommentCollectingParserFactory extends ParserFactory { - private final Map> commentsMap; + private final ReferenceFieldAugment> commentsField; private final Context context; static Context.Key key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment> commentsField) { super(context); this.context = context; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { ScannerFactory scannerFactory = ScannerFactory.instance(context); Lexer lexer = scannerFactory.newScanner(input, true); - Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, keepEndPos, commentsMap); + Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, keepEndPos, commentsField); return (JavacParser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac8's JavacParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, Map> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment> commentsField) { context.put(CommentCollectingParserFactory.key(), (ParserFactory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } -- cgit