From 9630fc96e8382d68505a4cb8ab2ae08aec48e776 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Tue, 26 Mar 2013 02:42:14 +0100 Subject: Massive performance improvements, and a few potentially breaking changes for other lombok plugin developers. --- src/core/lombok/eclipse/EclipseAST.java | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/core/lombok/eclipse/EclipseAST.java') diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index 8ab42140..d1f4ff06 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 The Project Lombok Authors. + * Copyright (C) 2009-2013 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ import java.util.List; import lombok.Lombok; import lombok.core.AST; +import lombok.core.ImmutableList; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -55,7 +56,7 @@ public class EclipseAST extends AST { * @param ast The compilation unit, which serves as the top level node in the tree to be built. */ public EclipseAST(CompilationUnitDeclaration ast) { - super(toFileName(ast), packageDeclaration(ast), imports(ast)); + super(toFileName(ast), packageDeclaration(ast), new EclipseImportList(ast)); this.compilationUnitDeclaration = ast; setTop(buildCompilationUnit(ast)); this.completeParse = isComplete(ast); @@ -67,18 +68,6 @@ public class EclipseAST extends AST { return pkg == null ? null : Eclipse.toQualifiedName(pkg.getImportName()); } - private static Collection imports(CompilationUnitDeclaration cud) { - List imports = new ArrayList(); - if (cud.imports == null) return imports; - for (ImportReference imp : cud.imports) { - if (imp == null) continue; - String qualifiedName = Eclipse.toQualifiedName(imp.getImportName()); - if ((imp.bits & ASTNode.OnDemand) != 0) qualifiedName += ".*"; - imports.add(qualifiedName); - } - return imports; - } - /** * Runs through the entire AST, starting at the compilation unit, calling the provided visitor's visit methods * for each node, depth first. @@ -88,8 +77,10 @@ public class EclipseAST extends AST { } void traverseChildren(EclipseASTVisitor visitor, EclipseNode node) { - for (EclipseNode child : node.down()) { - child.traverse(visitor); + ImmutableList children = node.down(); + int len = children.size(); + for (int i = 0; i < len; i++) { + children.get(i).traverse(visitor); } } -- cgit From 9c1e29842e65bf20895db9e19336b2ca948236ad Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 23 May 2013 22:58:34 +0200 Subject: Added methods to obtain JLS support-level version information from AST/LombokNode. Tests updates to honour these with //version X at the top of any test file (now also in eclipse, which until now always said it was v6) --- src/core/lombok/core/AST.java | 10 ++++++++++ src/core/lombok/core/LombokNode.java | 9 +++++++++ src/core/lombok/eclipse/EclipseAST.java | 14 ++++++++++++++ src/core/lombok/javac/JavacAST.java | 10 ++++++++++ src/utils/lombok/eclipse/Eclipse.java | 19 +++++++++++++++++++ test/core/src/lombok/DirectoryRunner.java | 3 ++- 6 files changed, 64 insertions(+), 1 deletion(-) (limited to 'src/core/lombok/eclipse/EclipseAST.java') diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index a2279efe..30297418 100644 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -146,9 +146,19 @@ public abstract class AST, L extends LombokNode, return nodeMap.get(node); } + /** + * Returns the JLS spec version that the compiler uses to parse and compile this AST. + * For example, if -source 1.6 is on the command line, this will return {@code 6}. + */ + public int getSourceVersion() { + return 6; + } + /** * Returns the latest version of the java language specification supported by the host compiler. * For example, if compiling with javac v1.7, this returns {@code 7}. + * + * NB: Even if -source (lower than maximum) is specified, this method still returns the maximum supported number. */ public int getLatestJavaSpecSupported() { return 6; diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java index aa161a8d..30bacc56 100644 --- a/src/core/lombok/core/LombokNode.java +++ b/src/core/lombok/core/LombokNode.java @@ -189,6 +189,15 @@ public abstract class LombokNode, L extends LombokNode { return pkg == null ? null : Eclipse.toQualifiedName(pkg.getImportName()); } + @Override public int getSourceVersion() { + long sl = compilationUnitDeclaration.problemReporter.options.sourceLevel; + long cl = compilationUnitDeclaration.problemReporter.options.complianceLevel; + sl >>= 16; + cl >>= 16; + if (sl == 0) sl = cl; + if (cl == 0) cl = sl; + return Math.min((int)(sl - 44), (int)(cl - 44)); + } + + @Override public int getLatestJavaSpecSupported() { + return Eclipse.getEcjCompilerVersion(); + } + /** * Runs through the entire AST, starting at the compilation unit, calling the provided visitor's visit methods * for each node, depth first. diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java index 9e15516e..8197dae6 100644 --- a/src/core/lombok/javac/JavacAST.java +++ b/src/core/lombok/javac/JavacAST.java @@ -34,6 +34,7 @@ import javax.tools.JavaFileObject; import lombok.core.AST; import com.sun.tools.javac.code.Symtab; +import com.sun.tools.javac.code.Source; import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.model.JavacTypes; import com.sun.tools.javac.tree.JCTree; @@ -113,6 +114,15 @@ public class JavacAST extends AST { for (JavacNode child : node.down()) child.traverse(visitor); } + @Override public int getSourceVersion() { + try { + String nm = Source.instance(context).name(); + int underscoreIdx = nm.indexOf('_'); + if (underscoreIdx > -1) return Integer.parseInt(nm.substring(underscoreIdx + 1)); + } catch (Exception ignore) {} + return 6; + } + @Override public int getLatestJavaSpecSupported() { return Javac.getJavaCompilerVersion(); } diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index 150f3a96..edfe1536 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -21,6 +21,7 @@ */ package lombok.eclipse; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -38,6 +39,7 @@ import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; public class Eclipse { @@ -177,4 +179,21 @@ public class Eclipse { return null; } + + private static int ecjCompilerVersionCached = -1; + + public static int getEcjCompilerVersion() { + if (ecjCompilerVersionCached >= 0) return ecjCompilerVersionCached; + + for (Field f : CompilerOptions.class.getDeclaredFields()) { + try { + if (f.getName().startsWith("VERSION_1_")) { + ecjCompilerVersionCached = Math.max(ecjCompilerVersionCached, Integer.parseInt(f.getName().substring("VERSION_1_".length()))); + } + } catch (Exception ignore) {} + } + + if (ecjCompilerVersionCached < 5) ecjCompilerVersionCached = 5; + return ecjCompilerVersionCached; + } } diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index 855db023..5325c1e3 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -32,6 +32,7 @@ import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.eclipse.Eclipse; import lombok.javac.Javac; import org.junit.runner.Description; @@ -53,7 +54,7 @@ public class DirectoryRunner extends Runner { }, ECJ { @Override public int getVersion() { - return 6; + return Eclipse.getEcjCompilerVersion(); } }; -- cgit From 7bbb7cf3ca25cb8727a6ec226de1ed1fc5bf47e9 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 28 May 2013 13:03:54 +0200 Subject: Fixes for issue 470: VerifyErrors when using @SneakyThrows. --- doc/changelog.markdown | 1 + .../bytecode/PreventNullAnalysisRemover.java | 2 +- src/core/lombok/bytecode/SneakyThrowsRemover.java | 115 ++++++++++++++++++++- src/core/lombok/core/PostCompiler.java | 4 +- src/core/lombok/eclipse/EclipseAST.java | 15 +-- src/core/lombok/eclipse/EclipseAstProblemView.java | 9 +- src/core/lombok/eclipse/TransformEclipseAST.java | 2 +- .../eclipse/handlers/EclipseHandlerUtil.java | 2 +- .../lombok/eclipse/agent/EclipsePatcher.java | 2 +- .../lombok/eclipse/agent/PatchFixes.java | 7 +- 10 files changed, 131 insertions(+), 28 deletions(-) (limited to 'src/core/lombok/eclipse/EclipseAST.java') diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 3eb8b5f5..e2e3d6b5 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,6 +2,7 @@ Lombok Changelog ---------------- ### v0.11.9 (Edgy Guinea Pig) +* BUGFIX: Usage of `Lombok.sneakyThrow()` or `@SneakyThrows` would sometimes result in invalid classes (classes which fail with `VerifyError`). [Issue #470](https://code.google.com/p/projectlombok/issues/detail?id=470) * BUGFIX: Using `val` in try-with-resources did not work for javac. [Issue #520](https://code.google.com/p/projectlombok/issues/detail?id=520) * BUGFIX: When using `@Data`, warnings are not generated if certain aspects are not generated because you wrote explicit versions of them. However, this gets confusing with `equals` / `hashCode` / `canEqual`, as nothing is generated if any one of those methods is present. Now, if one of `equals` or `hashCode` is present but not the other one (or `canEqual` is present but `equals` and/or `hashCode` is missing), a warning is emitted to explain that lombok will not generate any of the equals / hashCode methods, and that you should either write them all yourself or remove them all. [Issue #513](https://code.google.com/p/projectlombok/issues/detail?id=513) diff --git a/src/core/lombok/bytecode/PreventNullAnalysisRemover.java b/src/core/lombok/bytecode/PreventNullAnalysisRemover.java index 3342eacb..751e691f 100644 --- a/src/core/lombok/bytecode/PreventNullAnalysisRemover.java +++ b/src/core/lombok/bytecode/PreventNullAnalysisRemover.java @@ -44,7 +44,7 @@ public class PreventNullAnalysisRemover implements PostCompilerTransformation { byte[] fixedByteCode = fixJSRInlining(original); ClassReader reader = new ClassReader(fixedByteCode); - ClassWriter writer = new FixedClassWriter(reader, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); + ClassWriter writer = new FixedClassWriter(reader, 0); final AtomicBoolean changesMade = new AtomicBoolean(); diff --git a/src/core/lombok/bytecode/SneakyThrowsRemover.java b/src/core/lombok/bytecode/SneakyThrowsRemover.java index c54495d4..914c313a 100644 --- a/src/core/lombok/bytecode/SneakyThrowsRemover.java +++ b/src/core/lombok/bytecode/SneakyThrowsRemover.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 The Project Lombok Authors. + * Copyright (C) 2010-2013 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,19 +32,21 @@ import org.mangosdk.spi.ProviderFor; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Handle; +import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @ProviderFor(PostCompilerTransformation.class) public class SneakyThrowsRemover implements PostCompilerTransformation { - @Override public byte[] applyTransformations(byte[] original, String fileName, DiagnosticsReceiver diagnostics) { + @Override public byte[] applyTransformations(byte[] original, String fileName, final DiagnosticsReceiver diagnostics) { if (!new ClassFileMetaData(original).usesMethod("lombok/Lombok", "sneakyThrow")) return null; byte[] fixedByteCode = fixJSRInlining(original); ClassReader reader = new ClassReader(fixedByteCode); - ClassWriter writer = new FixedClassWriter(reader, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); + ClassWriter writer = new ClassWriter(reader, 0); final AtomicBoolean changesMade = new AtomicBoolean(); @@ -53,6 +55,8 @@ public class SneakyThrowsRemover implements PostCompilerTransformation { super(Opcodes.ASM4, mv); } + private boolean methodInsnQueued = false; + @Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { if ( opcode == Opcodes.INVOKESTATIC && @@ -60,16 +64,117 @@ public class SneakyThrowsRemover implements PostCompilerTransformation { "lombok/Lombok".equals(owner) && "(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;".equals(desc)) { - changesMade.set(true); if (System.getProperty("lombok.debugAsmOnly", null) != null) { super.visitMethodInsn(opcode, owner, name, desc); // DEBUG for issue 470! } else { - super.visitInsn(Opcodes.ATHROW); + methodInsnQueued = true; } } else { super.visitMethodInsn(opcode, owner, name, desc); } } + + private void handleQueue() { + if (!methodInsnQueued) return; + super.visitMethodInsn(Opcodes.INVOKESTATIC, "lombok/Lombok", "sneakyThrow", "(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;"); + methodInsnQueued = false; + diagnostics.addWarning("Proper usage is: throw lombok.Lombok.sneakyThrow(someException);. You did not 'throw' it. Because of this, the call to sneakyThrow " + + "remains in your classfile and you will need lombok.jar on the classpath at runtime."); + } + + @Override public void visitInsn(int arg0) { + if (methodInsnQueued && arg0 == Opcodes.ATHROW) { + changesMade.set(true); + // As expected, the required ATHROW. We can now safely 'eat' the previous call. + methodInsnQueued = false; + } + handleQueue(); + super.visitInsn(arg0); + } + @Override public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3, Object[] arg4) { + handleQueue(); + super.visitFrame(arg0, arg1, arg2, arg3, arg4); + } + + @Override public void visitIincInsn(int arg0, int arg1) { + handleQueue(); + super.visitIincInsn(arg0, arg1); + } + + @Override public void visitFieldInsn(int arg0, String arg1, String arg2, String arg3) { + handleQueue(); + super.visitFieldInsn(arg0, arg1, arg2, arg3); + } + + @Override public void visitIntInsn(int arg0, int arg1) { + handleQueue(); + super.visitIntInsn(arg0, arg1); + } + + @Override public void visitEnd() { + handleQueue(); + super.visitEnd(); + } + + @Override public void visitInvokeDynamicInsn(String arg0, String arg1, Handle arg2, Object... arg3) { + handleQueue(); + super.visitInvokeDynamicInsn(arg0, arg1, arg2, arg3); + } + + @Override public void visitLabel(Label arg0) { + handleQueue(); + super.visitLabel(arg0); + } + + @Override public void visitJumpInsn(int arg0, Label arg1) { + handleQueue(); + super.visitJumpInsn(arg0, arg1); + } + + @Override public void visitLdcInsn(Object arg0) { + handleQueue(); + super.visitLdcInsn(arg0); + } + + @Override public void visitLocalVariable(String arg0, String arg1, String arg2, Label arg3, Label arg4, int arg5) { + handleQueue(); + super.visitLocalVariable(arg0, arg1, arg2, arg3, arg4, arg5); + } + + @Override public void visitMaxs(int arg0, int arg1) { + handleQueue(); + super.visitMaxs(arg0, arg1); + } + + @Override public void visitLookupSwitchInsn(Label arg0, int[] arg1, Label[] arg2) { + handleQueue(); + super.visitLookupSwitchInsn(arg0, arg1, arg2); + } + + @Override public void visitMultiANewArrayInsn(String arg0, int arg1) { + handleQueue(); + super.visitMultiANewArrayInsn(arg0, arg1); + } + + @Override public void visitVarInsn(int arg0, int arg1) { + handleQueue(); + super.visitVarInsn(arg0, arg1); + } + + @Override public void visitTryCatchBlock(Label arg0, Label arg1, Label arg2, String arg3) { + handleQueue(); + super.visitTryCatchBlock(arg0, arg1, arg2, arg3); + } + + @Override public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label... arg3) { + handleQueue(); + super.visitTableSwitchInsn(arg0, arg1, arg2, arg3); + } + + @Override public void visitTypeInsn(int arg0, String arg1) { + handleQueue(); + super.visitTypeInsn(arg0, arg1); + } } reader.accept(new ClassVisitor(Opcodes.ASM4, writer) { diff --git a/src/core/lombok/core/PostCompiler.java b/src/core/lombok/core/PostCompiler.java index 1e40cca2..4a099862 100644 --- a/src/core/lombok/core/PostCompiler.java +++ b/src/core/lombok/core/PostCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Project Lombok Authors. + * Copyright (C) 2010-2013 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,7 @@ public final class PostCompiler { private static List transformations; public static byte[] applyTransformations(byte[] original, String fileName, DiagnosticsReceiver diagnostics) { + if (System.getProperty("lombok.disablePostCompiler", null) != null) return original; init(diagnostics); byte[] previous = original; for (PostCompilerTransformation transformation : transformations) { @@ -59,6 +60,7 @@ public final class PostCompiler { } public static OutputStream wrapOutputStream(final OutputStream originalStream, final String fileName, final DiagnosticsReceiver diagnostics) throws IOException { + if (System.getProperty("lombok.disablePostCompiler", null) != null) return originalStream; return new ByteArrayOutputStream() { @Override public void close() throws IOException { // no need to call super diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index 612dcff7..eed3c0b6 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -24,6 +24,7 @@ package lombok.eclipse; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import org.eclipse.jdt.internal.compiler.CompilationResult; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -123,7 +124,8 @@ public class EclipseAST extends AST { } void addToCompilationResult() { - addProblemToCompilationResult((CompilationUnitDeclaration) top().get(), + CompilationUnitDeclaration cud = (CompilationUnitDeclaration) top().get(); + addProblemToCompilationResult(cud.getFileName(), cud.compilationResult, isWarning, message, sourceStart, sourceEnd); } } @@ -147,11 +149,10 @@ public class EclipseAST extends AST { * Adds a problem to the provided CompilationResult object so that it will show up * in the Problems/Warnings view. */ - public static void addProblemToCompilationResult(CompilationUnitDeclaration ast, + public static void addProblemToCompilationResult(char[] fileNameArray, CompilationResult result, boolean isWarning, String message, int sourceStart, int sourceEnd) { - if (ast.compilationResult == null) return; try { - EcjReflectionCheck.addProblemToCompilationResult.invoke(null, ast, isWarning, message, sourceStart, sourceEnd); + EcjReflectionCheck.addProblemToCompilationResult.invoke(null, fileNameArray, result, isWarning, message, sourceStart, sourceEnd); } catch (NoClassDefFoundError e) { //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly //do anything useful here. @@ -168,7 +169,7 @@ public class EclipseAST extends AST { //do anything useful here. } } - + private final CompilationUnitDeclaration compilationUnitDeclaration; private boolean completeParse; @@ -358,7 +359,7 @@ public class EclipseAST extends AST { } private static class EcjReflectionCheck { - private static final String CUD_TYPE = "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"; + private static final String COMPILATIONRESULT_TYPE = "org.eclipse.jdt.internal.compiler.CompilationResult"; public static Method addProblemToCompilationResult; public static final Throwable problem; @@ -367,7 +368,7 @@ public class EclipseAST extends AST { Throwable problem_ = null; Method m = null; try { - m = EclipseAstProblemView.class.getMethod("addProblemToCompilationResult", Class.forName(CUD_TYPE), boolean.class, String.class, int.class, int.class); + m = EclipseAstProblemView.class.getMethod("addProblemToCompilationResult", char[].class, Class.forName(COMPILATIONRESULT_TYPE), boolean.class, String.class, int.class, int.class); } catch (Throwable t) { // That's problematic, but as long as no local classes are used we don't actually need it. // Better fail on local classes than crash altogether. diff --git a/src/core/lombok/eclipse/EclipseAstProblemView.java b/src/core/lombok/eclipse/EclipseAstProblemView.java index a2d5b833..c1179666 100644 --- a/src/core/lombok/eclipse/EclipseAstProblemView.java +++ b/src/core/lombok/eclipse/EclipseAstProblemView.java @@ -3,7 +3,6 @@ package lombok.eclipse; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.internal.compiler.CompilationResult; -import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; import org.eclipse.jdt.internal.compiler.util.Util; @@ -13,14 +12,12 @@ public class EclipseAstProblemView { * Adds a problem to the provided CompilationResult object so that it will show up * in the Problems/Warnings view. */ - public static void addProblemToCompilationResult(CompilationUnitDeclaration ast, + public static void addProblemToCompilationResult(char[] fileNameArray, CompilationResult result, boolean isWarning, String message, int sourceStart, int sourceEnd) { - if (ast.compilationResult == null) return; - char[] fileNameArray = ast.getFileName(); + if (result == null) return; if (fileNameArray == null) fileNameArray = "(unknown).java".toCharArray(); int lineNumber = 0; int columnNumber = 1; - CompilationResult result = ast.compilationResult; int[] lineEnds = null; lineNumber = sourceStart >= 0 ? Util.getLineNumber(sourceStart, lineEnds = result.getLineSeparatorPositions(), 0, lineEnds.length-1) @@ -33,7 +30,7 @@ public class EclipseAstProblemView { fileNameArray, message, 0, new String[0], isWarning ? ProblemSeverities.Warning : ProblemSeverities.Error, sourceStart, sourceEnd, lineNumber, columnNumber); - ast.compilationResult.record(ecProblem, null); + result.record(ecProblem, null); } private static class LombokProblem extends DefaultProblem { diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java index 47e620f6..11caf5c2 100644 --- a/src/core/lombok/eclipse/TransformEclipseAST.java +++ b/src/core/lombok/eclipse/TransformEclipseAST.java @@ -144,7 +144,7 @@ public class TransformEclipseAST { try { String message = "Lombok can't parse this source: " + t.toString(); - EclipseAST.addProblemToCompilationResult(ast, false, message, 0, 0); + EclipseAST.addProblemToCompilationResult(ast.getFileName(), ast.compilationResult, false, message, 0, 0); t.printStackTrace(); } catch (Throwable t2) { try { diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index d47b6715..7703336f 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -142,7 +142,7 @@ public class EclipseHandlerUtil { } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends. new TerminalLogger().error(message, bundleName, error); } - if (cud != null) EclipseAST.addProblemToCompilationResult(cud, false, message + " - See error log.", 0, 0); + if (cud != null) EclipseAST.addProblemToCompilationResult(cud.getFileName(), cud.compilationResult, false, message + " - See error log.", 0, 0); } /** diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index f9b53e68..8c6011bc 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -267,7 +267,7 @@ public class EclipsePatcher extends Agent { .build()); } - + private static void patchPostCompileHookEclipse(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder", "writeClassFileContents")) diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java index cb3ee817..0002e26e 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 The Project Lombok Authors. + * Copyright (C) 2010-2013 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -329,19 +329,16 @@ public class PatchFixes { return newSimpleNames; } - public static byte[] runPostCompiler(byte[] bytes, String fileName) { - if (System.getProperty("lombok.disablePostCompiler", null) != null) return bytes; + public static byte[] runPostCompiler(byte[] bytes, String fileName) { byte[] transformed = PostCompiler.applyTransformations(bytes, fileName, DiagnosticsReceiver.CONSOLE); return transformed == null ? bytes : transformed; } public static OutputStream runPostCompiler(OutputStream out) throws IOException { - if (System.getProperty("lombok.disablePostCompiler", null) != null) return out; return PostCompiler.wrapOutputStream(out, "TEST", DiagnosticsReceiver.CONSOLE); } public static BufferedOutputStream runPostCompiler(BufferedOutputStream out, String path, String name) throws IOException { - if (System.getProperty("lombok.disablePostCompiler", null) != null) return out; String fileName = path + "/" + name; return new BufferedOutputStream(PostCompiler.wrapOutputStream(out, fileName, DiagnosticsReceiver.CONSOLE)); } -- cgit From ec0cc4348cf71d872b796d0733fb64fc576ef5df Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 16 Jul 2013 00:45:09 +0200 Subject: Renamed ImmutableList to LombokImmutableList, to reduce our ImmutableList coming up in autocomplete dialogs when guava's was intended. --- src/core/lombok/core/AST.java | 2 +- src/core/lombok/core/LombokNode.java | 8 +- src/core/lombok/eclipse/EclipseAST.java | 4 +- src/utils/lombok/core/ImmutableList.java | 188 ------------------------- src/utils/lombok/core/JavaIdentifiers.java | 2 +- src/utils/lombok/core/LombokImmutableList.java | 188 +++++++++++++++++++++++++ 6 files changed, 196 insertions(+), 196 deletions(-) delete mode 100644 src/utils/lombok/core/ImmutableList.java create mode 100644 src/utils/lombok/core/LombokImmutableList.java (limited to 'src/core/lombok/eclipse/EclipseAST.java') diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index e6721b80..6fed0252 100644 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -174,7 +174,7 @@ public abstract class AST, L extends LombokNode, oldChild.parent = targetNode; } - targetNode.children = ImmutableList.copyOf(children); + targetNode.children = LombokImmutableList.copyOf(children); return targetNode; } diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java index 30bacc56..07c62151 100644 --- a/src/core/lombok/core/LombokNode.java +++ b/src/core/lombok/core/LombokNode.java @@ -42,7 +42,7 @@ public abstract class LombokNode, L extends LombokNode children; + protected LombokImmutableList children; protected L parent; /** structurally significant are those nodes that can be annotated in java 1.6 or are method-like toplevels, @@ -62,7 +62,7 @@ public abstract class LombokNode, L extends LombokNodeof(); + this.children = children != null ? LombokImmutableList.copyOf(children) : LombokImmutableList.of(); for (L child : this.children) { child.parent = (L) this; if (!child.isStructurallySignificant) @@ -176,7 +176,7 @@ public abstract class LombokNode, L extends LombokNode down() { + public LombokImmutableList down() { return children; } @@ -253,7 +253,7 @@ public abstract class LombokNode, L extends LombokNode { } void traverseChildren(EclipseASTVisitor visitor, EclipseNode node) { - ImmutableList children = node.down(); + LombokImmutableList children = node.down(); int len = children.size(); for (int i = 0; i < len; i++) { children.get(i).traverse(visitor); diff --git a/src/utils/lombok/core/ImmutableList.java b/src/utils/lombok/core/ImmutableList.java deleted file mode 100644 index 8b478dbc..00000000 --- a/src/utils/lombok/core/ImmutableList.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (C) 2013 The Project Lombok Authors. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * 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.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -public final class ImmutableList implements Iterable { - private Object[] content; - private static final ImmutableList EMPTY = new ImmutableList(new Object[0]); - - @SuppressWarnings("unchecked") - public static ImmutableList of() { - return (ImmutableList) EMPTY; - } - - public static ImmutableList of(T a) { - return new ImmutableList(new Object[] {a}); - } - - public static ImmutableList of(T a, T b) { - return new ImmutableList(new Object[] {a, b}); - } - - public static ImmutableList of(T a, T b, T c) { - return new ImmutableList(new Object[] {a, b, c}); - } - - public static ImmutableList of(T a, T b, T c, T d) { - return new ImmutableList(new Object[] {a, b, c, d}); - } - - public static ImmutableList of(T a, T b, T c, T d, T e) { - return new ImmutableList(new Object[] {a, b, c, d, e}); - } - - public static ImmutableList of(T a, T b, T c, T d, T e, T f, T... g) { - Object[] rest = g == null ? new Object[] {null} : g; - Object[] val = new Object[rest.length + 6]; - System.arraycopy(rest, 0, val, 6, rest.length); - val[0] = a; - val[1] = b; - val[2] = c; - val[3] = d; - val[4] = e; - val[5] = f; - return new ImmutableList(val); - } - - public static ImmutableList copyOf(Collection list) { - return new ImmutableList(list.toArray()); - } - - public static ImmutableList copyOf(Iterable iterable) { - List list = new ArrayList(); - for (T o : iterable) list.add(o); - return copyOf(list); - } - - private ImmutableList(Object[] content) { - this.content = content; - } - - public ImmutableList replaceElementAt(int idx, T newValue) { - Object[] newContent = content.clone(); - newContent[idx] = newValue; - return new ImmutableList(newContent); - } - - public ImmutableList append(T newValue) { - int len = content.length; - Object[] newContent = new Object[len + 1]; - System.arraycopy(content, 0, newContent, 0, len); - newContent[len] = newValue; - return new ImmutableList(newContent); - } - - public ImmutableList prepend(T newValue) { - int len = content.length; - Object[] newContent = new Object[len + 1]; - System.arraycopy(content, 0, newContent, 1, len); - newContent[0] = newValue; - return new ImmutableList(newContent); - } - - public int indexOf(T val) { - int len = content.length; - if (val == null) { - for (int i = 0; i < len; i++) if (content[i] == null) return i; - return -1; - } - - for (int i = 0; i < len; i++) if (val.equals(content[i])) return i; - return -1; - } - - public ImmutableList removeElement(T val) { - int idx = indexOf(val); - return idx == -1 ? this : removeElementAt(idx); - } - - public ImmutableList removeElementAt(int idx) { - int len = content.length; - Object[] newContent = new Object[len - 1]; - if (idx > 0) System.arraycopy(content, 0, newContent, 0, idx); - if (idx < len - 1) System.arraycopy(content, idx + 1, newContent, idx, len - idx - 1); - return new ImmutableList(newContent); - } - - public boolean isEmpty() { - return content.length == 0; - } - - public int size() { - return content.length; - } - - @SuppressWarnings("unchecked") - public T get(int idx) { - return (T) content[idx]; - } - - public boolean contains(T in) { - if (in == null) { - for (Object e : content) if (e == null) return true; - return false; - } - - for (Object e : content) if (in.equals(e)) return true; - return false; - } - - public Iterator iterator() { - return new Iterator() { - private int idx = 0; - @Override public boolean hasNext() { - return idx < content.length; - } - - @SuppressWarnings("unchecked") - @Override public T next() { - if (idx < content.length) return (T) content[idx++]; - throw new NoSuchElementException(); - } - - @Override public void remove() { - throw new UnsupportedOperationException("List is immutable"); - } - }; - } - - @Override public String toString() { - return Arrays.toString(content); - } - - @Override public boolean equals(Object obj) { - if (!(obj instanceof ImmutableList)) return false; - if (obj == this) return true; - return Arrays.equals(content, ((ImmutableList) obj).content); - } - - @Override public int hashCode() { - return Arrays.hashCode(content); - } -} diff --git a/src/utils/lombok/core/JavaIdentifiers.java b/src/utils/lombok/core/JavaIdentifiers.java index dfec8815..cbe90eed 100644 --- a/src/utils/lombok/core/JavaIdentifiers.java +++ b/src/utils/lombok/core/JavaIdentifiers.java @@ -27,7 +27,7 @@ package lombok.core; public class JavaIdentifiers { private JavaIdentifiers() {} - private static final ImmutableList KEYWORDS = ImmutableList.of( + private static final LombokImmutableList KEYWORDS = LombokImmutableList.of( "public", "private", "protected", "default", "switch", "case", "for", "do", "goto", "const", "strictfp", "while", "if", "else", diff --git a/src/utils/lombok/core/LombokImmutableList.java b/src/utils/lombok/core/LombokImmutableList.java new file mode 100644 index 00000000..e0e1136c --- /dev/null +++ b/src/utils/lombok/core/LombokImmutableList.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2013 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * 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.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +public final class LombokImmutableList implements Iterable { + private Object[] content; + private static final LombokImmutableList EMPTY = new LombokImmutableList(new Object[0]); + + @SuppressWarnings("unchecked") + public static LombokImmutableList of() { + return (LombokImmutableList) EMPTY; + } + + public static LombokImmutableList of(T a) { + return new LombokImmutableList(new Object[] {a}); + } + + public static LombokImmutableList of(T a, T b) { + return new LombokImmutableList(new Object[] {a, b}); + } + + public static LombokImmutableList of(T a, T b, T c) { + return new LombokImmutableList(new Object[] {a, b, c}); + } + + public static LombokImmutableList of(T a, T b, T c, T d) { + return new LombokImmutableList(new Object[] {a, b, c, d}); + } + + public static LombokImmutableList of(T a, T b, T c, T d, T e) { + return new LombokImmutableList(new Object[] {a, b, c, d, e}); + } + + public static LombokImmutableList of(T a, T b, T c, T d, T e, T f, T... g) { + Object[] rest = g == null ? new Object[] {null} : g; + Object[] val = new Object[rest.length + 6]; + System.arraycopy(rest, 0, val, 6, rest.length); + val[0] = a; + val[1] = b; + val[2] = c; + val[3] = d; + val[4] = e; + val[5] = f; + return new LombokImmutableList(val); + } + + public static LombokImmutableList copyOf(Collection list) { + return new LombokImmutableList(list.toArray()); + } + + public static LombokImmutableList copyOf(Iterable iterable) { + List list = new ArrayList(); + for (T o : iterable) list.add(o); + return copyOf(list); + } + + private LombokImmutableList(Object[] content) { + this.content = content; + } + + public LombokImmutableList replaceElementAt(int idx, T newValue) { + Object[] newContent = content.clone(); + newContent[idx] = newValue; + return new LombokImmutableList(newContent); + } + + public LombokImmutableList append(T newValue) { + int len = content.length; + Object[] newContent = new Object[len + 1]; + System.arraycopy(content, 0, newContent, 0, len); + newContent[len] = newValue; + return new LombokImmutableList(newContent); + } + + public LombokImmutableList prepend(T newValue) { + int len = content.length; + Object[] newContent = new Object[len + 1]; + System.arraycopy(content, 0, newContent, 1, len); + newContent[0] = newValue; + return new LombokImmutableList(newContent); + } + + public int indexOf(T val) { + int len = content.length; + if (val == null) { + for (int i = 0; i < len; i++) if (content[i] == null) return i; + return -1; + } + + for (int i = 0; i < len; i++) if (val.equals(content[i])) return i; + return -1; + } + + public LombokImmutableList removeElement(T val) { + int idx = indexOf(val); + return idx == -1 ? this : removeElementAt(idx); + } + + public LombokImmutableList removeElementAt(int idx) { + int len = content.length; + Object[] newContent = new Object[len - 1]; + if (idx > 0) System.arraycopy(content, 0, newContent, 0, idx); + if (idx < len - 1) System.arraycopy(content, idx + 1, newContent, idx, len - idx - 1); + return new LombokImmutableList(newContent); + } + + public boolean isEmpty() { + return content.length == 0; + } + + public int size() { + return content.length; + } + + @SuppressWarnings("unchecked") + public T get(int idx) { + return (T) content[idx]; + } + + public boolean contains(T in) { + if (in == null) { + for (Object e : content) if (e == null) return true; + return false; + } + + for (Object e : content) if (in.equals(e)) return true; + return false; + } + + public Iterator iterator() { + return new Iterator() { + private int idx = 0; + @Override public boolean hasNext() { + return idx < content.length; + } + + @SuppressWarnings("unchecked") + @Override public T next() { + if (idx < content.length) return (T) content[idx++]; + throw new NoSuchElementException(); + } + + @Override public void remove() { + throw new UnsupportedOperationException("List is immutable"); + } + }; + } + + @Override public String toString() { + return Arrays.toString(content); + } + + @Override public boolean equals(Object obj) { + if (!(obj instanceof LombokImmutableList)) return false; + if (obj == this) return true; + return Arrays.equals(content, ((LombokImmutableList) obj).content); + } + + @Override public int hashCode() { + return Arrays.hashCode(content); + } +} -- cgit