From 04d041a7dcb4f57c5b5bf460cf78cddfaba4853b Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 9 Nov 2010 20:32:47 +0100 Subject: Delegate annotation --- src/core/lombok/Delegate.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/core/lombok/Delegate.java (limited to 'src') diff --git a/src/core/lombok/Delegate.java b/src/core/lombok/Delegate.java new file mode 100644 index 00000000..0bbaed0d --- /dev/null +++ b/src/core/lombok/Delegate.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. + * + * 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; + +public @interface Delegate { + Class value() default java.lang.Object.class; +} -- cgit From 0951ea38fe11189cdc4c2778fdad9e9e3ad6a6ae Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 9 Nov 2010 20:35:34 +0100 Subject: Experiment to try and make java 'self referential' by deleting the Enter and MemberEnter state. So far it doesn't work yet. --- src/core/lombok/eclipse/handlers/HandleVal.java | 2 +- src/core/lombok/javac/HandlerLibrary.java | 39 +++++++++++----------- src/core/lombok/javac/JavacAnnotationHandler.java | 5 +++ src/core/lombok/javac/JavacResolution.java | 1 + src/core/lombok/javac/JavacTransformer.java | 34 ++++++++++++++++--- src/core/lombok/javac/apt/Processor.java | 3 +- src/core/lombok/javac/handlers/HandleCleanup.java | 6 +++- .../lombok/javac/handlers/HandleConstructor.java | 12 +++++++ src/core/lombok/javac/handlers/HandleData.java | 4 +++ .../javac/handlers/HandleEqualsAndHashCode.java | 4 +++ src/core/lombok/javac/handlers/HandleGetter.java | 4 +++ src/core/lombok/javac/handlers/HandleLog.java | 18 +++++++++- src/core/lombok/javac/handlers/HandlePrintAST.java | 4 +++ src/core/lombok/javac/handlers/HandleSetter.java | 4 +++ .../lombok/javac/handlers/HandleSneakyThrows.java | 4 +++ .../lombok/javac/handlers/HandleSynchronized.java | 4 +++ src/core/lombok/javac/handlers/HandleToString.java | 4 +++ src/core/lombok/javac/handlers/HandleVal.java | 4 ++- src/delombok/lombok/delombok/Delombok.java | 3 +- .../lombok/netbeans/agent/NetbeansEntryPoint.java | 2 +- 20 files changed, 130 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java index b3cfa879..7f4f36fb 100644 --- a/src/core/lombok/eclipse/handlers/HandleVal.java +++ b/src/core/lombok/eclipse/handlers/HandleVal.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. + * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java index 5b792874..8eb7be9f 100644 --- a/src/core/lombok/javac/HandlerLibrary.java +++ b/src/core/lombok/javac/HandlerLibrary.java @@ -51,7 +51,7 @@ public class HandlerLibrary { private final Map> annotationHandlers = new HashMap>(); private final Collection visitorHandlers = new ArrayList(); private final Messager messager; - private boolean skipPrintAST = true; + private int phase = 0; /** * Creates a new HandlerLibrary that will report any problems or errors to the provided messager. @@ -70,6 +70,10 @@ public class HandlerLibrary { this.annotationClass = annotationClass; } + public boolean isResolutionBased() { + return handler.isResolutionBased(); + } + public boolean handle(final JavacNode node) { return handler.handle(Javac.createAnnotation(annotationClass, node), (JCAnnotation)node.get(), node); } @@ -160,12 +164,14 @@ public class HandlerLibrary { boolean handled = false; for (String fqn : resolver.findTypeMatches(node, rawType)) { boolean isPrintAST = fqn.equals(PrintAST.class.getName()); - if (isPrintAST == skipPrintAST) continue; + if (isPrintAST && phase != 2) continue; + if (!isPrintAST && phase == 2) continue; AnnotationHandlerContainer container = annotationHandlers.get(fqn); if (container == null) continue; try { - handled |= container.handle(node); + if (container.isResolutionBased() && phase == 1) handled |= container.handle(node); + if (!container.isResolutionBased() && phase == 0) handled |= container.handle(node); } catch (AnnotationValueDecodeFail fail) { fail.owner.setError(fail.getMessage(), fail.idx); } catch (Throwable t) { @@ -183,13 +189,8 @@ public class HandlerLibrary { */ public void callASTVisitors(JavacAST ast) { for (JavacASTVisitor visitor : visitorHandlers) try { - if (!visitor.isResolutionBased()) ast.traverse(visitor); - } catch (Throwable t) { - javacError(String.format("Lombok visitor handler %s failed", visitor.getClass()), t); - } - - for (JavacASTVisitor visitor : visitorHandlers) try { - if (visitor.isResolutionBased()) ast.traverse(visitor); + if (!visitor.isResolutionBased() && phase == 0) ast.traverse(visitor); + if (visitor.isResolutionBased() && phase == 1) ast.traverse(visitor); } catch (Throwable t) { javacError(String.format("Lombok visitor handler %s failed", visitor.getClass()), t); } @@ -197,17 +198,17 @@ 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} annotation, - * which is almost always intended to run last. Hence, this hack, which lets it in fact run last. - * - * @see #skipAllButPrintAST() + * random right now. As a temporary hack we've identified 3 important phases. */ - public void skipPrintAST() { - skipPrintAST = true; + public void setPreResolutionPhase() { + phase = 0; + } + + public void setPostResolutionPhase() { + phase = 1; } - /** @see #skipPrintAST() */ - public void skipAllButPrintAST() { - skipPrintAST = false; + public void setPrintASTPhase() { + phase = 2; } } diff --git a/src/core/lombok/javac/JavacAnnotationHandler.java b/src/core/lombok/javac/JavacAnnotationHandler.java index 5b6fe4ce..ee330ecb 100644 --- a/src/core/lombok/javac/JavacAnnotationHandler.java +++ b/src/core/lombok/javac/JavacAnnotationHandler.java @@ -55,4 +55,9 @@ public interface JavacAnnotationHandler { * compile session (you've handled it), or {@code false} to indicate you aren't done yet. */ boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode); + + /** + * Return true if this handler requires resolution. + */ + boolean isResolutionBased(); } diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index e0eb436d..26ff34d0 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -11,6 +11,7 @@ import javax.lang.model.type.TypeKind; import javax.tools.DiagnosticListener; import com.sun.tools.javac.code.BoundKind; +import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type.ArrayType; diff --git a/src/core/lombok/javac/JavacTransformer.java b/src/core/lombok/javac/JavacTransformer.java index 5f145460..c703b1c7 100644 --- a/src/core/lombok/javac/JavacTransformer.java +++ b/src/core/lombok/javac/JavacTransformer.java @@ -22,16 +22,18 @@ package lombok.javac; import java.util.ArrayList; -import java.util.List; import javax.annotation.processing.Messager; +import com.sun.tools.javac.comp.Enter; +import com.sun.tools.javac.comp.MemberEnter; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.List; public class JavacTransformer { private final HandlerLibrary handlers; @@ -42,18 +44,39 @@ public class JavacTransformer { this.handlers = HandlerLibrary.load(messager); } - public boolean transform(Context context, Iterable compilationUnits) { - List asts = new ArrayList(); + public boolean transform(Context context, java.util.List compilationUnitsRaw) { + List compilationUnits; + if (compilationUnitsRaw instanceof List) { + compilationUnits = (List)compilationUnitsRaw; + } else { + compilationUnits = List.nil(); + for (int i = compilationUnitsRaw.size() -1; i >= 0; i--) { + compilationUnits = compilationUnits.prepend(compilationUnitsRaw.get(i)); + } + } + + java.util.List asts = new ArrayList(); for (JCCompilationUnit unit : compilationUnits) asts.add(new JavacAST(messager, context, unit)); - handlers.skipPrintAST(); + handlers.setPreResolutionPhase(); + for (JavacAST ast : asts) { + ast.traverse(new AnnotationVisitor()); + handlers.callASTVisitors(ast); + } + + context.put(Enter.class, (Enter) null); + context.put(MemberEnter.class, (MemberEnter) null); + Enter.instance(context).main(compilationUnits); + + handlers.setPostResolutionPhase(); for (JavacAST ast : asts) { ast.traverse(new AnnotationVisitor()); handlers.callASTVisitors(ast); } - handlers.skipAllButPrintAST(); + + handlers.setPrintASTPhase(); for (JavacAST ast : asts) { ast.traverse(new AnnotationVisitor()); } @@ -61,6 +84,7 @@ public class JavacTransformer { for (JavacAST ast : asts) { if (ast.isChanged()) return true; } + return false; } diff --git a/src/core/lombok/javac/apt/Processor.java b/src/core/lombok/javac/apt/Processor.java index 037f5ba5..58631c66 100644 --- a/src/core/lombok/javac/apt/Processor.java +++ b/src/core/lombok/javac/apt/Processor.java @@ -26,6 +26,7 @@ import java.io.InputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; import java.util.IdentityHashMap; import java.util.Map; @@ -172,7 +173,7 @@ public class Processor extends AbstractProcessor { if (unit != null) units.put(unit, null); } - transformer.transform(processingEnv.getContext(), units.keySet()); + transformer.transform(processingEnv.getContext(), new ArrayList(units.keySet())); return false; } diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java index 779dd3ea..7210c5e7 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2010 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 @@ -154,4 +154,8 @@ public class HandleCleanup implements JavacAnnotationHandler { } } } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index c2332974..d56c976f 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -69,6 +69,10 @@ public class HandleConstructor { new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, false, false); return true; } + + @Override public boolean isResolutionBased() { + return false; + } } @ProviderFor(JavacAnnotationHandler.class) @@ -86,6 +90,10 @@ public class HandleConstructor { new HandleConstructor().generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, false, suppressConstructorProperties); return true; } + + @Override public boolean isResolutionBased() { + return false; + } } private static List findRequiredFields(JavacNode typeNode) { @@ -131,6 +139,10 @@ public class HandleConstructor { new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, false, suppressConstructorProperties); return true; } + + @Override public boolean isResolutionBased() { + return false; + } } public void generateRequiredArgsConstructor(JavacNode typeNode, AccessLevel level, String staticName, boolean skipIfConstructorExists) { diff --git a/src/core/lombok/javac/handlers/HandleData.java b/src/core/lombok/javac/handlers/HandleData.java index 2087c133..682b7fe4 100644 --- a/src/core/lombok/javac/handlers/HandleData.java +++ b/src/core/lombok/javac/handlers/HandleData.java @@ -63,4 +63,8 @@ public class HandleData implements JavacAnnotationHandler { return true; } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index c5475fb1..376823cf 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -479,4 +479,8 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler { return treeMaker.MethodDef(treeMaker.Modifiers(access, nonNulls.appendList(nullables)), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue); } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java index 03e40d7f..c72892cc 100644 --- a/src/core/lombok/javac/handlers/HandleLog.java +++ b/src/core/lombok/javac/handlers/HandleLog.java @@ -121,6 +121,10 @@ public class HandleLog { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { return processAnnotation(LoggingFramework.COMMONS, annotation, annotationNode); } + + @Override public boolean isResolutionBased() { + return false; + } } /** @@ -131,7 +135,11 @@ public class HandleLog { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { return processAnnotation(LoggingFramework.JUL, annotation, annotationNode); } - } + + @Override public boolean isResolutionBased() { + return false; + } + } /** * Handles the {@link lombok.extern.log4j.Log} annotation for javac. @@ -141,6 +149,10 @@ public class HandleLog { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { return processAnnotation(LoggingFramework.LOG4J, annotation, annotationNode); } + + @Override public boolean isResolutionBased() { + return false; + } } /** @@ -151,6 +163,10 @@ public class HandleLog { @Override public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { return processAnnotation(LoggingFramework.SLF4J, annotation, annotationNode); } + + @Override public boolean isResolutionBased() { + return false; + } } enum LoggingFramework { diff --git a/src/core/lombok/javac/handlers/HandlePrintAST.java b/src/core/lombok/javac/handlers/HandlePrintAST.java index 4c25694b..61b877d6 100644 --- a/src/core/lombok/javac/handlers/HandlePrintAST.java +++ b/src/core/lombok/javac/handlers/HandlePrintAST.java @@ -54,4 +54,8 @@ public class HandlePrintAST implements JavacAnnotationHandler { return true; } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 98b68e4a..9c7a233a 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -238,4 +238,8 @@ public class HandleSetter implements JavacAnnotationHandler { return v.visitNoType(this, p); } } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleSneakyThrows.java b/src/core/lombok/javac/handlers/HandleSneakyThrows.java index b2337f67..0f37a80e 100644 --- a/src/core/lombok/javac/handlers/HandleSneakyThrows.java +++ b/src/core/lombok/javac/handlers/HandleSneakyThrows.java @@ -110,4 +110,8 @@ public class HandleSneakyThrows implements JavacAnnotationHandler return maker.Try(tryBlock, List.of(maker.Catch(catchParam, catchBody)), null); } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java index a095aaf1..b1394b02 100644 --- a/src/core/lombok/javac/handlers/HandleSynchronized.java +++ b/src/core/lombok/javac/handlers/HandleSynchronized.java @@ -107,4 +107,8 @@ public class HandleSynchronized implements JavacAnnotationHandler return true; } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java index e3cb0294..f52602c3 100644 --- a/src/core/lombok/javac/handlers/HandleToString.java +++ b/src/core/lombok/javac/handlers/HandleToString.java @@ -247,4 +247,8 @@ public class HandleToString implements JavacAnnotationHandler { } return typeName; } + + @Override public boolean isResolutionBased() { + return false; + } } diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java index 5da6fec0..983f2d86 100644 --- a/src/core/lombok/javac/handlers/HandleVal.java +++ b/src/core/lombok/javac/handlers/HandleVal.java @@ -1,5 +1,5 @@ /* - * Copyright © 2010 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,8 +31,10 @@ import org.mangosdk.spi.ProviderFor; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop; import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCNewArray; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 6866d97f..846b448f 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -383,7 +383,8 @@ public class Delombok { compiler.enterTrees(toJavacList(roots)); for (JCCompilationUnit unit : roots) { - boolean changed = new JavacTransformer(messager).transform(context, Collections.singleton(unit)); + // Run one single massive transform instead of a lot of singleton calls, as this causes a heck of a lot of refilling of the enter cache. + boolean changed = new JavacTransformer(messager).transform(context, Collections.singletonList(unit)); DelombokResult result = new DelombokResult(commentsMap.get(unit).comments, unit, force || changed); if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged"); Writer rawWriter; diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java index 963b70b5..f1f02d2c 100644 --- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java +++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java @@ -69,7 +69,7 @@ public class NetbeansEntryPoint implements TaskListener { if (TaskEvent.Kind.PARSE == event.getKind()) { JavacTransformer transformer = new JavacTransformer(new DummyMessager()); //TODO hook into netbeans error reporting! JCCompilationUnit compilationUnit = (JCCompilationUnit) event.getCompilationUnit(); - transformer.transform(context, Collections.singleton(compilationUnit)); + transformer.transform(context, Collections.singletonList(compilationUnit)); } } } -- cgit From 186b16c28cf461f88a3b5eecd2fa4523af2949d9 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 9 Nov 2010 23:52:54 +0100 Subject: EqualsAndHashCode no longer worked right when working on a class with 0 fileds. Fixed. Thanks to Philipp Eichhorn for spotting this problem! --- .../eclipse/handlers/HandleEqualsAndHashCode.java | 2 +- .../javac/handlers/HandleEqualsAndHashCode.java | 36 ++++++++++++---------- 2 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 23d24fb0..2b830241 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -505,7 +505,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler other = (MyType) o; */ { - if (!fields.isEmpty()) { + if (!fields.isEmpty() || needsCanEqual) { LocalDeclaration other = new LocalDeclaration(otherName, pS, pE); other.modifiers |= ClassFileConstants.AccFinal; Eclipse.setGeneratedBy(other, source); diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index f824986c..8d524964 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -356,24 +356,26 @@ public class HandleEqualsAndHashCode implements JavacAnnotationHandler other = (MyType) o; */ { - final JCExpression selfType1, selfType2; - List wildcards1 = List.nil(); - List wildcards2 = List.nil(); - for (int i = 0 ; i < type.typarams.length() ; i++) { - wildcards1 = wildcards1.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); - wildcards2 = wildcards2.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); - } - - if (type.typarams.isEmpty()) { - selfType1 = maker.Ident(type.name); - selfType2 = maker.Ident(type.name); - } else { - selfType1 = maker.TypeApply(maker.Ident(type.name), wildcards1); - selfType2 = maker.TypeApply(maker.Ident(type.name), wildcards2); + if (!fields.isEmpty() || needsCanEqual) { + final JCExpression selfType1, selfType2; + List wildcards1 = List.nil(); + List wildcards2 = List.nil(); + for (int i = 0 ; i < type.typarams.length() ; i++) { + wildcards1 = wildcards1.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + wildcards2 = wildcards2.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + } + + if (type.typarams.isEmpty()) { + selfType1 = maker.Ident(type.name); + selfType2 = maker.Ident(type.name); + } else { + selfType1 = maker.TypeApply(maker.Ident(type.name), wildcards1); + selfType2 = maker.TypeApply(maker.Ident(type.name), wildcards2); + } + + statements = statements.append( + maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, selfType1, maker.TypeCast(selfType2, maker.Ident(oName)))); } - - statements = statements.append( - maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, selfType1, maker.TypeCast(selfType2, maker.Ident(oName)))); } /* if (!other.canEqual(this)) return false; */ { -- cgit From 63519f9ae601e00430c5fd542bedf79beb688db3 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 10 Nov 2010 00:24:10 +0100 Subject: Undone something that'll never work anyway --- src/core/lombok/javac/JavacResolution.java | 1 - src/core/lombok/javac/JavacTransformer.java | 6 ------ 2 files changed, 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index 26ff34d0..e0eb436d 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -11,7 +11,6 @@ import javax.lang.model.type.TypeKind; import javax.tools.DiagnosticListener; import com.sun.tools.javac.code.BoundKind; -import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type.ArrayType; diff --git a/src/core/lombok/javac/JavacTransformer.java b/src/core/lombok/javac/JavacTransformer.java index c703b1c7..5d1e79af 100644 --- a/src/core/lombok/javac/JavacTransformer.java +++ b/src/core/lombok/javac/JavacTransformer.java @@ -25,8 +25,6 @@ import java.util.ArrayList; import javax.annotation.processing.Messager; -import com.sun.tools.javac.comp.Enter; -import com.sun.tools.javac.comp.MemberEnter; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -65,10 +63,6 @@ public class JavacTransformer { handlers.callASTVisitors(ast); } - context.put(Enter.class, (Enter) null); - context.put(MemberEnter.class, (MemberEnter) null); - Enter.instance(context).main(compilationUnits); - handlers.setPostResolutionPhase(); for (JavacAST ast : asts) { ast.traverse(new AnnotationVisitor()); -- cgit From d02a0f823fb5922ddc2e29e62cc0359be3fce0a8 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 10 Nov 2010 00:32:56 +0100 Subject: deleted netbeans agent. With the new resolution features it'll never work, and netbeans has supported lombok as a plain annotation processor for quite a while now. --- .../lombok/installer/netbeans/NetbeansFinder.java | 206 ----------- .../installer/netbeans/NetbeansLocation.java | 410 --------------------- .../netbeans/NetbeansLocationProvider.java | 125 ------- .../lombok/installer/netbeans/netbeans.png | Bin 1705 -> 0 bytes .../lombok/netbeans/agent/NetbeansEntryPoint.java | 75 ---- .../lombok/netbeans/agent/NetbeansPatcher.java | 134 ------- .../lombok/netbeans/agent/PatchFixes.java | 183 --------- .../lombok/netbeans/agent/package-info.java | 26 -- 8 files changed, 1159 deletions(-) delete mode 100644 src/installer/lombok/installer/netbeans/NetbeansFinder.java delete mode 100644 src/installer/lombok/installer/netbeans/NetbeansLocation.java delete mode 100644 src/installer/lombok/installer/netbeans/NetbeansLocationProvider.java delete mode 100644 src/installer/lombok/installer/netbeans/netbeans.png delete mode 100644 src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java delete mode 100644 src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java delete mode 100644 src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java delete mode 100644 src/netbeansAgent/lombok/netbeans/agent/package-info.java (limited to 'src') diff --git a/src/installer/lombok/installer/netbeans/NetbeansFinder.java b/src/installer/lombok/installer/netbeans/NetbeansFinder.java deleted file mode 100644 index 28cdffac..00000000 --- a/src/installer/lombok/installer/netbeans/NetbeansFinder.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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.installer.netbeans; - -import static java.util.Arrays.asList; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import lombok.installer.CorruptedIdeLocationException; -import lombok.installer.IdeFinder; -import lombok.installer.IdeLocation; - -import org.mangosdk.spi.ProviderFor; - -/** Utility class for doing various OS-specific operations related to finding Netbeans installations. */ -@ProviderFor(IdeFinder.class) -public class NetbeansFinder extends IdeFinder { - /** - * Returns a list of paths of Netbeans installations. - * - * Netbeans installations are found by checking for the existence of 'netbeans.exe' in the following locations: - *
    - *
  • X:\*Program Files*\*NetBeans*
  • - *
  • X:\*NetBeans*
  • - *
- * - * Where 'X' is tried for all local disk drives, unless there's a problem calling fsutil, in which case only - * C: is tried. - */ - private void findNetbeansOnWindows(List locations, List problems) { - List driveLetters = asList("C"); - try { - driveLetters = getDrivesOnWindows(); - } catch (Throwable ignore) { - ignore.printStackTrace(); - } - - //Various try/catch/ignore statements are in this for loop. Weird conditions on the disk can cause exceptions, - //such as an unformatted drive causing a NullPointerException on listFiles. Best action is almost invariably to just - //continue onwards. - for (String letter : driveLetters) { - try { - File f = new File(letter + ":\\"); - for (File dir : f.listFiles()) { - if (!dir.isDirectory()) continue; - try { - if (dir.getName().toLowerCase().contains("netbeans")) { - String netbeansLocation = findNetbeansOnWindows1(dir); - if (netbeansLocation != null) { - try { - IdeLocation newLocation = NetbeansLocationProvider.create0(netbeansLocation); - if (newLocation != null) locations.add(newLocation); - } catch (CorruptedIdeLocationException e) { - problems.add(e); - } - } - } - } catch (Exception ignore) {} - - try { - if (dir.getName().toLowerCase().contains("program files")) { - for (File dir2 : dir.listFiles()) { - if (!dir2.isDirectory()) continue; - if (dir2.getName().toLowerCase().contains("netbeans")) { - String netbeansLocation = findNetbeansOnWindows1(dir2); - if (netbeansLocation != null) { - try { - IdeLocation newLocation = NetbeansLocationProvider.create0(netbeansLocation); - if (newLocation != null) locations.add(newLocation); - } catch (CorruptedIdeLocationException e) { - problems.add(e); - } - } - } - } - } - } catch (Exception ignore) {} - } - } catch (Exception ignore) {} - } - } - - /** Checks if the provided directory contains 'netbeans.exe', and if so, returns the directory, otherwise null. */ - private String findNetbeansOnWindows1(File dir) { - if (new File(dir, "bin/netbeans.exe").isFile()) return dir.getAbsolutePath(); - return null; - } - - /** - * Calls the OS-dependent 'find Netbeans' routine. If the local OS doesn't have a routine written for it, - * null is returned. - * - * @param locations - * List of valid netbeans locations - provide an empty list; this - * method will fill it. - * @param problems - * List of netbeans locations that seem to contain half-baked - * netbeanses that can't be installed. Provide an empty list; this - * method will fill it. - */ - @Override - public void findIdes(List locations, List problems) { - switch (getOS()) { - case WINDOWS: - findNetbeansOnWindows(locations, problems); - break; - case MAC_OS_X: - findNetbeansOnMac(locations, problems); - break; - default: - case UNIX: - findNetbeansOnUnix(locations, problems); - break; - } - } - - /** Scans a couple of likely locations on linux. */ - private void findNetbeansOnUnix(List locations, List problems) { - List guesses = new ArrayList(); - - File d; - - d = new File("/usr/bin/netbeans"); - if (d.exists()) guesses.add(d.getPath()); - d = new File("/usr/local/bin/netbeans"); - if (d.exists()) guesses.add(d.getPath()); - d = new File(System.getProperty("user.home", "."), "bin/netbeans"); - if (d.exists()) guesses.add(d.getPath()); - - findNetbeansInSubDir("/usr/local/share", guesses); - findNetbeansInSubDir("/usr/local", guesses); - findNetbeansInSubDir("/usr/share", guesses); - findNetbeansInSubDir(System.getProperty("user.home", "."), guesses); - - for (String guess : guesses) { - try { - IdeLocation newLocation = NetbeansLocationProvider.create0(guess); - if (newLocation != null) locations.add(newLocation); - } catch (CorruptedIdeLocationException e) { - problems.add(e); - } - } - } - - private static void findNetbeansInSubDir(String dir, List guesses) { - File d = new File(dir); - if (!d.isDirectory()) return; - for (File f : d.listFiles()) { - if (f.isDirectory() && f.getName().toLowerCase().contains("netbeans")) { - File possible = new File(f, "bin/netbeans"); - if (possible.exists()) guesses.add(possible.getAbsolutePath()); - } - } - } - - /** - * Scans /Applications for any folder named 'Eclipse' - */ - private static void findNetbeansOnMac(List locations, List problems) { - for (File dir : new File("/Applications").listFiles()) { - if (!dir.isDirectory()) continue; - if (dir.getName().toLowerCase().startsWith("netbeans") && dir.getName().toLowerCase().endsWith(".app")) { - try { - IdeLocation newLocation = NetbeansLocationProvider.create0(dir.getAbsolutePath()); - if (newLocation != null) locations.add(newLocation); - } catch (CorruptedIdeLocationException e) { - problems.add(e); - } - } - if (dir.getName().toLowerCase().contains("netbeans")) { - for (File dir2 : dir.listFiles()) { - if (!dir2.isDirectory()) continue; - if (dir2.getName().toLowerCase().startsWith("netbeans") && dir2.getName().toLowerCase().endsWith(".app")) { - try { - IdeLocation newLocation = NetbeansLocationProvider.create0(dir2.getAbsolutePath()); - if (newLocation != null) locations.add(newLocation); - } catch (CorruptedIdeLocationException e) { - problems.add(e); - } - } - } - } - } - } -} diff --git a/src/installer/lombok/installer/netbeans/NetbeansLocation.java b/src/installer/lombok/installer/netbeans/NetbeansLocation.java deleted file mode 100644 index 6db57207..00000000 --- a/src/installer/lombok/installer/netbeans/NetbeansLocation.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright © 2009-2010 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.installer.netbeans; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import lombok.installer.CorruptedIdeLocationException; -import lombok.installer.IdeFinder; -import lombok.installer.IdeLocation; -import lombok.installer.InstallException; -import lombok.installer.Installer; -import lombok.installer.UninstallException; - -public class NetbeansLocation extends IdeLocation { - private final String name; - private final File netbeansConfPath; - private final String version; - private final int versionFirst, versionSecond; - private final boolean hasLombok; - - private static final String OS_NEWLINE = IdeFinder.getOS().getLineEnding(); - - NetbeansLocation(String nameOfLocation, File pathToNetbeansConf) throws CorruptedIdeLocationException { - this.name = nameOfLocation; - this.netbeansConfPath = pathToNetbeansConf; - try { - this.hasLombok = checkForLombok(netbeansConfPath); - } catch (IOException e) { - throw new CorruptedIdeLocationException( - "I can't read the configuration file of the Netbeans installed at " + name + "\n" + - "You may need to run this installer with root privileges if you want to modify that Netbeans.", "netbeans", e); - } - this.version = findNetbeansVersion(netbeansConfPath); - int first, second; - String[] vs = version.split("\\."); - try { - first = Integer.parseInt(vs[0]); - } catch (Exception e) { - first = 0; - } - try { - second = Integer.parseInt(vs[1]); - } catch (Exception e) { - second = 0; - } - this.versionFirst = first; - this.versionSecond = second; - } - - public boolean versionIsPre68() { - return versionFirst < 6 || (versionFirst == 6 && versionSecond < 8); - } - - public boolean versionIs68() { - return versionFirst == 6 && versionSecond == 8; - } - - public boolean versionIsPost68() { - return versionFirst > 6 || (versionFirst == 6 && versionSecond > 8); - } - - @Override public int hashCode() { - return netbeansConfPath.hashCode(); - } - - @Override public boolean equals(Object o) { - if (!(o instanceof NetbeansLocation)) return false; - return ((NetbeansLocation)o).netbeansConfPath.equals(netbeansConfPath); - } - - /** - * Returns the name of this location; generally the path to the netbeans executable. - */ - @Override - public String getName() { - return name; - } - - /** - * @return true if the Netbeans installation has been instrumented with lombok. - */ - @Override - public boolean hasLombok() { - return hasLombok; - } - - private final String ID_CHARS = "(?:\\\\.|[^\"\\\\])*"; - private final Pattern JAVA_AGENT_LINE_MATCHER = Pattern.compile( - "^\\s*netbeans_default_options\\s*=\\s*\"\\s*" + ID_CHARS + "(?<=[ \"])(-J-javaagent:\\\\\".*lombok.*\\.jar\\\\\")(?=[ \"])" + ID_CHARS +"\\s*\"\\s*(?:#.*)?$", Pattern.CASE_INSENSITIVE); - - private final Pattern OPTIONS_LINE_MATCHER = Pattern.compile( - "^\\s*netbeans_default_options\\s*=\\s*\"\\s*" + ID_CHARS + "\\s*(\")\\s*(?:#.*)?$", Pattern.CASE_INSENSITIVE); - - private String findNetbeansVersion(File iniFile) { - String forcedVersion = System.getProperty("force.netbeans.version", null); - if (forcedVersion != null) return forcedVersion; - - try { - for (File child : iniFile.getParentFile().getParentFile().listFiles()) { - if (!child.isDirectory()) continue; - String name = child.getName(); - if (name == null || !name.startsWith("nb")) continue; - String version = name.substring(2); - File versionFile = new File(child, "VERSION.txt"); - if (versionFile.exists() && versionFile.canRead() && !versionFile.isDirectory()) { - try { - version = readVersionFile(versionFile); - } catch (IOException e) { - // Intentional Fallthrough - } - } - if (version != null && version.length() > 0) { - return version; - } - } - } catch (NullPointerException e) { - // Intentional Fallthrough - } - - return "UNKNOWN"; - } - - private static String readVersionFile(File file) throws IOException { - FileInputStream fis = new FileInputStream(file); - StringBuilder version = new StringBuilder(); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8")); - for (String line = br.readLine(); line != null; line = br.readLine()) { - if (line.startsWith("#")) continue; - if (version.length() > 0) version.append(" "); - version.append(line); - } - return version.toString(); - } finally { - fis.close(); - } - } - - private boolean checkForLombok(File iniFile) throws IOException { - if (!iniFile.exists()) return false; - FileInputStream fis = new FileInputStream(iniFile); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(fis)); - String line; - while ((line = br.readLine()) != null) { - if (JAVA_AGENT_LINE_MATCHER.matcher(line.trim()).matches()) return true; - } - - return false; - } finally { - fis.close(); - } - } - - /** - * Uninstalls lombok from this location. - * It's a no-op if lombok wasn't there in the first place, - * and it will remove a half-succeeded lombok installation as well. - * - * @throws UninstallException - * If there's an obvious I/O problem that is preventing - * installation. bugs in the uninstall code will probably throw - * other exceptions; this is intentional. - */ - @Override - public void uninstall() throws UninstallException { - final List lombokJarsForWhichCantDeleteSelf = new ArrayList(); - File dir = netbeansConfPath.getParentFile(); - - StringBuilder newContents = new StringBuilder(); - if (netbeansConfPath.exists()) { - try { - FileInputStream fis = new FileInputStream(netbeansConfPath); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(fis)); - String line; - while ((line = br.readLine()) != null) { - Matcher m = JAVA_AGENT_LINE_MATCHER.matcher(line); - if (m.matches()) { - newContents.append(line.substring(0, m.start(1)) + line.substring(m.end(1))); - } else { - newContents.append(line); - } - newContents.append(OS_NEWLINE); - } - } finally { - fis.close(); - } - - FileOutputStream fos = new FileOutputStream(netbeansConfPath); - try { - fos.write(newContents.toString().getBytes()); - } finally { - fos.close(); - } - } catch (IOException e) { - throw new UninstallException("Cannot uninstall lombok from " + name + generateWriteErrorMessage(), e); - } - } - - File lombokJar = new File(dir, "lombok.jar"); - if (lombokJar.exists()) { - if (!lombokJar.delete()) { - if (IdeFinder.getOS() == IdeFinder.OS.WINDOWS && Installer.isSelf(lombokJar.getAbsolutePath())) { - lombokJarsForWhichCantDeleteSelf.add(lombokJar); - } else { - throw new UninstallException( - "Can't delete " + lombokJar.getAbsolutePath() + generateWriteErrorMessage(), null); - } - } - } - - if (!lombokJarsForWhichCantDeleteSelf.isEmpty()) { - throw new UninstallException(true, - "lombok.jar cannot delete itself on windows.\nHowever, lombok has been uncoupled from your netbeans.\n" + - "You can safely delete this jar file. You can find it at:\n" + - lombokJarsForWhichCantDeleteSelf.get(0).getAbsolutePath(), null); - } - } - - private static String generateWriteErrorMessage() { - String osSpecificError; - - switch (IdeFinder.getOS()) { - default: - case MAC_OS_X: - case UNIX: - osSpecificError = ":\nStart terminal, go to the directory with lombok.jar, and run: sudo java -jar lombok.jar"; - break; - case WINDOWS: - osSpecificError = ":\nStart a new cmd (dos box) with admin privileges, go to the directory with lombok.jar, and run: java -jar lombok.jar"; - break; - } - - return ", probably because this installer does not have the access rights.\n" + - "Try re-running the installer with administrative privileges" + osSpecificError; - } - - /** - * Install lombok into the Netbeans at this location. - * If lombok is already there, it is overwritten neatly (upgrade mode). - * - * @throws InstallException - * If there's an obvious I/O problem that is preventing - * installation. bugs in the install code will probably throw - * other exceptions; this is intentional. - */ - @Override - public String install() throws InstallException { - if ("UNKNOWN".equals(version)) { - throw new InstallException(String.format( - "Can't determine version of Netbeans installed at:\n%s\n\n" + - "Your Netbeans version determines what this installer does:\n" + - "Pre 6.8: Lombok is not compatible with netbeans pre 6.8, and thus won't install.\n" + - "6.8: Lombok will install itself into Netbeans.\n" + - "6.9 and later: NetBeans supports lombok natively. This installer will explain how to enable it.\n\n" + - "If you know your netbeans version, you can force this by starting the installer with:\n" + - "java -Dforce.netbeans.version=6.8 -jar lombok.jar", this.getName()), null); - } - - if (versionIsPre68()) { - throw new InstallException(String.format( - "Lombok is not compatible with Netbeans versions prior to 6.8.\n" + - "Therefore, lombok will not be installed at:\n%s\nbecause it is version: %s", - this.getName(), version), null); - } - if (versionIsPost68()) { - try { - uninstall(); - } catch (Exception e) { - // Well, we tried. Lombok on 6.9 doesn't do anything, so we'll leave it then. - } - - throw new InstallException(true, String.format( - "Starting with NetBeans 6.9, lombok is natively supported and does not need to be installed at:\n%s\n\n" + - "To use lombok.jar in your netbeans project:\n" + - "1. Add lombok.jar to your project (Go to Project Properties, 'Libraries' page, and add lombok.jar in the 'Compile' tab).\n" + - "2. Enable Annotation Processors (Go to Project Properties, 'Build/Compiling' page, and check 'Enable Annotation Processing in Editor').\n" + - "\n" + - "NB: In the first release of NetBeans 6.9, due to a netbeans bug, maven-based projects don't run annotation processors. This \n" + - "issue should be fixed by the great folks at NetBeans soon.", this.getName()), null); - } - - boolean installSucceeded = false; - StringBuilder newContents = new StringBuilder(); - - File lombokJar = new File(netbeansConfPath.getParentFile(), "lombok.jar"); - - /* No need to copy lombok.jar to itself, obviously. On windows this would generate an error so we check for this. */ - if (!Installer.isSelf(lombokJar.getAbsolutePath())) { - File ourJar = findOurJar(); - byte[] b = new byte[524288]; - boolean readSucceeded = true; - try { - FileOutputStream out = new FileOutputStream(lombokJar); - try { - readSucceeded = false; - InputStream in = new FileInputStream(ourJar); - try { - while (true) { - int r = in.read(b); - if (r == -1) break; - if (r > 0) readSucceeded = true; - out.write(b, 0, r); - } - } finally { - in.close(); - } - } finally { - out.close(); - } - } catch (IOException e) { - try { - lombokJar.delete(); - } catch (Throwable ignore) { /* Nothing we can do about that. */ } - if (!readSucceeded) throw new InstallException( - "I can't read my own jar file. I think you've found a bug in this installer!\nI suggest you restart it " + - "and use the 'what do I do' link, to manually install lombok. Also, tell us about this at:\n" + - "http://groups.google.com/group/project-lombok - Thanks!", e); - throw new InstallException("I can't write to your Netbeans directory at " + name + generateWriteErrorMessage(), e); - } - } - - try { - FileInputStream fis = new FileInputStream(netbeansConfPath); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(fis)); - String line; - while ((line = br.readLine()) != null) { - Matcher m = JAVA_AGENT_LINE_MATCHER.matcher(line); - if (m.matches()) { - newContents.append(line.substring(0, m.start(1))); - newContents.append("-J-javaagent:\\\"" + canonical(lombokJar) + "\\\""); - newContents.append(line.substring(m.end(1))); - newContents.append(OS_NEWLINE); - continue; - } - - m = OPTIONS_LINE_MATCHER.matcher(line); - if (m.matches()) { - newContents.append(line.substring(0, m.start(1))); - newContents.append(" ").append("-J-javaagent:\\\"" + canonical(lombokJar) +"\\\"\""); - newContents.append(line.substring(m.end(1))).append(OS_NEWLINE); - continue; - } - - newContents.append(line).append(OS_NEWLINE); - } - } finally { - fis.close(); - } - - FileOutputStream fos = new FileOutputStream(netbeansConfPath); - try { - fos.write(newContents.toString().getBytes()); - } finally { - fos.close(); - } - installSucceeded = true; - } catch (IOException e) { - throw new InstallException("Cannot install lombok at " + name + generateWriteErrorMessage(), e); - } finally { - if (!installSucceeded) try { - lombokJar.delete(); - } catch (Throwable ignore) {} - } - - if (!installSucceeded) { - throw new InstallException("I can't find the netbeans.conf file. Is this a real Netbeans installation?", null); - } - - return "If you start netbeans with custom parameters, you'll need to add:
" + - "-J-javaagent:\\\"" + canonical(lombokJar) + "\\\"
" + - "as parameter as well."; - } - - @Override public URL getIdeIcon() { - return NetbeansLocation.class.getResource("netbeans.png"); - } -} diff --git a/src/installer/lombok/installer/netbeans/NetbeansLocationProvider.java b/src/installer/lombok/installer/netbeans/NetbeansLocationProvider.java deleted file mode 100644 index 68a00756..00000000 --- a/src/installer/lombok/installer/netbeans/NetbeansLocationProvider.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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.installer.netbeans; - -import static lombok.installer.IdeLocation.canonical; - -import java.io.File; -import java.io.IOException; -import java.util.regex.Pattern; - -import lombok.installer.CorruptedIdeLocationException; -import lombok.installer.IdeLocation; -import lombok.installer.IdeLocationProvider; -import lombok.installer.IdeFinder.OS; - -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) -public class NetbeansLocationProvider implements IdeLocationProvider { - - @Override public IdeLocation create(String path) throws CorruptedIdeLocationException { - return create0(path); - } - - /** - * Create a new NetbeansLocation by pointing at either the directory containing the executable, or the executable itself, - * or a netbeans.conf file. - * - * @throws NotAnIdeLocationException - * If this isn't an Eclipse executable or a directory with an - * Eclipse executable. - */ - static NetbeansLocation create0(String path) throws CorruptedIdeLocationException { - if (path == null) throw new NullPointerException("path"); - File p = new File(path); - - if (!p.exists()) return null; - if (p.isDirectory()) { - String name = p.getName().toLowerCase(); - if (name.endsWith(".app") && name.startsWith("netbeans")) { - File conf = new File(p, "Contents/Resources/NetBeans/etc/netbeans.conf"); - if (conf.exists()) return new NetbeansLocation(path, conf); - } - - File f = new File(p, "bin/netbeans"); - if (f.isFile()) return findNetbeansConfFromExe(f, 0); - f = new File(p, "bin/netbeans.exe"); - if (f.isFile()) return findNetbeansConfFromExe(f, 0); - f = new File(p, "etc/netbeans.conf"); - if (f.isFile()) return new NetbeansLocation(canonical(f.getParentFile().getParentFile()), f); - } - - if (p.isFile()) { - if (p.getName().equalsIgnoreCase("netbeans.conf")) { - return new NetbeansLocation(canonical(p.getParentFile().getParentFile()), p); - } - - if (p.getName().equalsIgnoreCase("netbeans") || p.getName().equalsIgnoreCase("netbeans.exe")) { - return findNetbeansConfFromExe(p, 0); - } - } - - return null; - } - - private static NetbeansLocation findNetbeansConfFromExe(File exePath, int loopCounter) throws CorruptedIdeLocationException { - /* Try looking for netbeans.conf as etc/netbeans.conf */ { - File conf = new File(exePath.getParentFile(), "etc/netbeans.conf"); - if (conf.isFile()) return new NetbeansLocation(canonical(exePath), conf); - } - - /* Try looking for netbeans.conf as ../etc/netbeans.conf */ { - File conf = new File(exePath.getParentFile().getParentFile(), "etc/netbeans.conf"); - if (conf.isFile()) return new NetbeansLocation(canonical(exePath), conf); - } - - /* If executable is a soft link, follow it and retry. */ { - if (loopCounter < 50) { - try { - String oPath = exePath.getAbsolutePath(); - String nPath = exePath.getCanonicalPath(); - if (!oPath.equals(nPath)) try { - return findNetbeansConfFromExe(new File(nPath), loopCounter + 1); - } catch (CorruptedIdeLocationException ignore) { - // Unlinking didn't help find a netbeans, so continue. - } - } catch (IOException ignore) { /* okay, that didn't work, assume it isn't a soft link then. */ } - } - } - - /* If we get this far, we lose. */ - return null; - } - - @Override public Pattern getLocationSelectors(OS os) { - switch (os) { - case MAC_OS_X: - return Pattern.compile("^(netbeans|netbeans\\.conf|NetBeans.*\\.app)$", Pattern.CASE_INSENSITIVE); - case WINDOWS: - return Pattern.compile("^(netbeans\\.exe|netbeans\\.conf)$", Pattern.CASE_INSENSITIVE); - default: - case UNIX: - return Pattern.compile("^(netbeans|netbeans\\.conf)$", Pattern.CASE_INSENSITIVE); - } - } -} diff --git a/src/installer/lombok/installer/netbeans/netbeans.png b/src/installer/lombok/installer/netbeans/netbeans.png deleted file mode 100644 index 43fe63cc..00000000 Binary files a/src/installer/lombok/installer/netbeans/netbeans.png and /dev/null differ diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java deleted file mode 100644 index f1f02d2c..00000000 --- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.netbeans.agent; - -import java.util.Collections; - -import javax.annotation.processing.Messager; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.Element; -import javax.tools.Diagnostic.Kind; - -import lombok.javac.JavacTransformer; - -import com.sun.source.util.TaskEvent; -import com.sun.source.util.TaskListener; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; -import com.sun.tools.javac.util.Context; - -public class NetbeansEntryPoint implements TaskListener { - public class DummyMessager implements Messager { - @Override public void printMessage(Kind kind, CharSequence msg) { - System.err.printf("%s: %s\n", kind, msg); - } - - @Override public void printMessage(Kind kind, CharSequence msg, Element e) { - printMessage(kind, msg); - } - - @Override public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a) { - printMessage(kind, msg); - } - - @Override public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { - printMessage(kind, msg); - } - } - - private final Context context; - - public NetbeansEntryPoint(Context context) { - this.context = context; - } - - @Override public void started(TaskEvent event) { - //we run at the end, so all the action is in #finished. - } - - @Override public void finished(TaskEvent event) { - if (TaskEvent.Kind.PARSE == event.getKind()) { - JavacTransformer transformer = new JavacTransformer(new DummyMessager()); //TODO hook into netbeans error reporting! - JCCompilationUnit compilationUnit = (JCCompilationUnit) event.getCompilationUnit(); - transformer.transform(context, Collections.singletonList(compilationUnit)); - } - } -} diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java deleted file mode 100644 index ffe491ae..00000000 --- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.netbeans.agent; - -import java.lang.instrument.Instrumentation; - -import lombok.core.Agent; -import lombok.patcher.Hook; -import lombok.patcher.MethodTarget; -import lombok.patcher.ScriptManager; -import lombok.patcher.StackRequest; -import lombok.patcher.scripts.ScriptBuilder; - -/** - * This is a java-agent that patches some of netbeans's classes so that lombok is initialized as Javac TaskListener, - * allowing us to change AST nodes anytime netbeans parses source code. It also fixes some of the places in netbeans that - * can't deal with generated code. - * - * The hard work on figuring out where to patch has been done by Jan Lahoda (jlahoda@netbeans.org) - */ -public class NetbeansPatcher extends Agent { - @Override - public void runAgent(String agentArgs, Instrumentation instrumentation, boolean injected) throws Exception { - registerPatchScripts(instrumentation, injected); - } - - private static void registerPatchScripts(Instrumentation instrumentation, boolean reloadExistingClasses) { - ScriptManager sm = new ScriptManager(); - sm.registerTransformer(instrumentation); - - patchNetbeansClassLoader(sm); - patchNetbeansJavac(sm); - patchNetbeansMissingPositionAwareness(sm); - - if (reloadExistingClasses) sm.reloadClasses(instrumentation); - } - - private static void patchNetbeansClassLoader(ScriptManager sm) { - sm.addScript(ScriptBuilder.exitEarly() - .transplant().request(StackRequest.PARAM1, StackRequest.P