diff options
55 files changed, 689 insertions, 130 deletions
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index a417d8ed..1d879a35 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Project Lombok Authors. + * Copyright (C) 2010-2012 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,57 +23,104 @@ package lombok; import java.io.File; import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import java.util.Locale; - -import lombok.eclipse.TransformEclipseAST; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; -import org.eclipse.jdt.internal.compiler.parser.Parser; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; -import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; public class RunTestsViaEcj extends AbstractRunTests { - protected static CompilerOptions ecjCompilerOptions() { + protected CompilerOptions ecjCompilerOptions() { CompilerOptions options = new CompilerOptions(); options.complianceLevel = ClassFileConstants.JDK1_6; options.sourceLevel = ClassFileConstants.JDK1_6; options.targetJDK = ClassFileConstants.JDK1_6; options.parseLiteralExpressionsAsConstants = true; + options.inlineJsrBytecode = true; + options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false; + options.reportUnusedDeclaredThrownExceptionIncludeDocCommentReference = false; + options.reportUnusedDeclaredThrownExceptionWhenOverriding = false; + options.reportUnusedParameterIncludeDocCommentReference = false; + options.reportUnusedParameterWhenImplementingAbstract = false; + options.reportUnusedParameterWhenOverridingConcrete = false; + options.reportDeadCodeInTrivialIfStatement = false; + options.generateClassFiles = false; + options.docCommentSupport = false; + Map<String, String> warnings = new HashMap<String, String>(); + warnings.put(CompilerOptions.OPTION_ReportUnusedLocal, "ignore"); + warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore"); + warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore"); + warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore"); + options.set(warnings); return options; } - @Override - public void transformCode(final StringBuilder messages, StringWriter result, File file) throws Throwable { - ProblemReporter problemReporter = new ProblemReporter(new IErrorHandlingPolicy() { - public boolean proceedOnErrors() { + protected IErrorHandlingPolicy ecjErrorHandlingPolicy() { + return new IErrorHandlingPolicy() { + @Override public boolean stopOnFirstError() { return true; } - public boolean stopOnFirstError() { + @Override public boolean proceedOnErrors() { return false; } - }, ecjCompilerOptions(), new DefaultProblemFactory(Locale.ENGLISH)); + }; + } + + @Override + public void transformCode(final StringBuilder messages, StringWriter result, File file) throws Throwable { + final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>(); + final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>(); + ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { + @Override public void acceptResult(CompilationResult result) { + compilationResult_.set(result); + } + }; + + List<String> classpath = new ArrayList<String>(); + classpath.addAll(Arrays.asList(System.getProperty("sun.boot.class.path").split(File.pathSeparator))); + classpath.add("dist/lombok.jar"); + classpath.add("lib/test/commons-logging.jar"); + classpath.add("lib/test/slf4j-api.jar"); + classpath.add("lib/test/log4j.jar"); + FileSystem fileAccess = new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8"); - Parser parser = new Parser(problemReporter, true); String source = readFile(file); - CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), "UTF-8"); - CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); - CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult); + final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), "UTF-8"); - TransformEclipseAST.transform(parser, cud); + Compiler ecjCompiler = new Compiler(fileAccess, ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) { + @Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) { + if (inUnit == sourceUnit) compilationUnit_.set(parsedUnit); + super.addCompilationUnit(inUnit, parsedUnit); + } + }; + + ecjCompiler.compile(new ICompilationUnit[] {sourceUnit}); + CompilationResult compilationResult = compilationResult_.get(); CategorizedProblem[] problems = compilationResult.getAllProblems(); if (problems != null) for (CategorizedProblem p : problems) { messages.append(String.format("%d %s %s\n", p.getSourceLineNumber(), p.isError() ? "error" : p.isWarning() ? "warning" : "unknown", p.getMessage())); } + CompilationUnitDeclaration cud = compilationUnit_.get(); + result.append(cud.toString()); } } diff --git a/test/transform/resource/after-delombok/Constructors.java b/test/transform/resource/after-delombok/Constructors.java index fb906c73..baea640f 100644 --- a/test/transform/resource/after-delombok/Constructors.java +++ b/test/transform/resource/after-delombok/Constructors.java @@ -39,7 +39,7 @@ class AllArgsConstructor1 { } } class NoArgsConstructor1 { - final int x; + int x; String name; @java.lang.SuppressWarnings("all") public NoArgsConstructor1() { diff --git a/test/transform/resource/after-delombok/DataPlain.java b/test/transform/resource/after-delombok/DataPlain.java index 5124fbeb..86d0ec18 100644 --- a/test/transform/resource/after-delombok/DataPlain.java +++ b/test/transform/resource/after-delombok/DataPlain.java @@ -144,7 +144,7 @@ final class Data3 { } } final class Data4 extends java.util.Timer { - final int x; + int x; Data4() { super(); } @@ -152,6 +152,10 @@ final class Data4 extends java.util.Timer { public int getX() { return this.x; } + @java.lang.SuppressWarnings("all") + public void setX(final int x) { + this.x = x; + } @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { diff --git a/test/transform/resource/after-delombok/DelegateOnGetter.java b/test/transform/resource/after-delombok/DelegateOnGetter.java index ee34018a..08d682a2 100644 --- a/test/transform/resource/after-delombok/DelegateOnGetter.java +++ b/test/transform/resource/after-delombok/DelegateOnGetter.java @@ -11,13 +11,14 @@ class DelegateOnGetter { synchronized (this.bar) { value = this.bar.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<Bar>(new Bar(){ + final Bar actualValue = new Bar(){ public void setList(java.util.ArrayList<String> list) { } public int getInt() { return 42; } - }); + }; + value = new java.util.concurrent.atomic.AtomicReference<Bar>(actualValue); this.bar.set(value); } } diff --git a/test/transform/resource/after-delombok/DelegateOnGetterNone.java b/test/transform/resource/after-delombok/DelegateOnGetterNone.java index b3258f25..9f9411f4 100644 --- a/test/transform/resource/after-delombok/DelegateOnGetterNone.java +++ b/test/transform/resource/after-delombok/DelegateOnGetterNone.java @@ -1,5 +1,5 @@ class DelegateOnGetterNone { - private final Bar bar; + private final Bar bar = null; private interface Bar { void setList(java.util.ArrayList<java.lang.String> list); int getInt(); diff --git a/test/transform/resource/after-delombok/GetterAlreadyExists.java b/test/transform/resource/after-delombok/GetterAlreadyExists.java index d0a01c88..8389ae31 100644 --- a/test/transform/resource/after-delombok/GetterAlreadyExists.java +++ b/test/transform/resource/after-delombok/GetterAlreadyExists.java @@ -123,7 +123,7 @@ class Getter15 { class Getter16 { String foo; static String hasFoo() { - return false; + return ""; } @java.lang.SuppressWarnings("all") public String getFoo() { @@ -133,7 +133,7 @@ class Getter16 { class Getter17 { String foo; static String isFoo() { - return false; + return ""; } @java.lang.SuppressWarnings("all") public String getFoo() { @@ -143,6 +143,6 @@ class Getter17 { class Getter18 { String foo; static String getFoo() { - return false; + return ""; } }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/GetterLazy.java b/test/transform/resource/after-delombok/GetterLazy.java index d7f97f0d..95be39e3 100644 --- a/test/transform/resource/after-delombok/GetterLazy.java +++ b/test/transform/resource/after-delombok/GetterLazy.java @@ -9,7 +9,8 @@ class GetterLazy { synchronized (this.fieldName) { value = this.fieldName.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<ValueType>(new ValueType()); + final ValueType actualValue = new ValueType(); + value = new java.util.concurrent.atomic.AtomicReference<ValueType>(actualValue); this.fieldName.set(value); } } diff --git a/test/transform/resource/after-delombok/GetterLazyEahcToString.java b/test/transform/resource/after-delombok/GetterLazyEahcToString.java index 74ce716e..a542061d 100644 --- a/test/transform/resource/after-delombok/GetterLazyEahcToString.java +++ b/test/transform/resource/after-delombok/GetterLazyEahcToString.java @@ -43,7 +43,8 @@ class GetterLazyEahcToString { synchronized (this.value) { value = this.value.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<String>(""); + final String actualValue = ""; + value = new java.util.concurrent.atomic.AtomicReference<String>(actualValue); this.value.set(value); } } diff --git a/test/transform/resource/after-delombok/GetterLazyNative.java b/test/transform/resource/after-delombok/GetterLazyNative.java index 650d0496..29e7d66d 100644 --- a/test/transform/resource/after-delombok/GetterLazyNative.java +++ b/test/transform/resource/after-delombok/GetterLazyNative.java @@ -15,7 +15,8 @@ class GetterLazyNative { synchronized (this.booleanField) { value = this.booleanField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>(true); + final boolean actualValue = true; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>(actualValue); this.booleanField.set(value); } } @@ -29,7 +30,8 @@ class GetterLazyNative { synchronized (this.byteField) { value = this.byteField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Byte>(1); + final byte actualValue = 1; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Byte>(actualValue); this.byteField.set(value); } } @@ -43,7 +45,8 @@ class GetterLazyNative { synchronized (this.shortField) { value = this.shortField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Short>(1); + final short actualValue = 1; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Short>(actualValue); this.shortField.set(value); } } @@ -57,7 +60,8 @@ class GetterLazyNative { synchronized (this.intField) { value = this.intField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Integer>(1); + final int actualValue = 1; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Integer>(actualValue); this.intField.set(value); } } @@ -71,7 +75,8 @@ class GetterLazyNative { synchronized (this.longField) { value = this.longField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Long>(1); + final long actualValue = 1; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Long>(actualValue); this.longField.set(value); } } @@ -85,7 +90,8 @@ class GetterLazyNative { synchronized (this.floatField) { value = this.floatField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Float>(1.0F); + final float actualValue = 1.0F; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Float>(actualValue); this.floatField.set(value); } } @@ -99,7 +105,8 @@ class GetterLazyNative { synchronized (this.doubleField) { value = this.doubleField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Double>(1.0); + final double actualValue = 1.0; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Double>(actualValue); this.doubleField.set(value); } } @@ -113,7 +120,8 @@ class GetterLazyNative { synchronized (this.charField) { value = this.charField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<java.lang.Character>('1'); + final char actualValue = '1'; + value = new java.util.concurrent.atomic.AtomicReference<java.lang.Character>(actualValue); this.charField.set(value); } } @@ -127,7 +135,8 @@ class GetterLazyNative { synchronized (this.intArrayField) { value = this.intArrayField.get(); if (value == null) { - value = new java.util.concurrent.atomic.AtomicReference<int[]>(new int[]{1}); + final int[] actualValue = new int[]{1}; + value = new java.util.concurrent.atomic.AtomicReference<int[]>(actualValue); this.intArrayField.set(value); } } diff --git a/test/transform/resource/after-delombok/ToStringInner.java b/test/transform/resource/after-delombok/ToStringInner.java index bd8967b7..7b1d5e21 100644 --- a/test/transform/resource/after-delombok/ToStringInner.java +++ b/test/transform/resource/after-delombok/ToStringInner.java @@ -1,8 +1,8 @@ class ToStringOuter { - final int x; + int x; String name; class ToStringInner { - final int y; + int y; @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { @@ -10,7 +10,7 @@ class ToStringOuter { } } static class ToStringStaticInner { - final int y; + int y; @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { @@ -19,7 +19,7 @@ class ToStringOuter { } class ToStringMiddle { class ToStringMoreInner { - final String name; + String name; @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { diff --git a/test/transform/resource/after-delombok/ToStringPlain.java b/test/transform/resource/after-delombok/ToStringPlain.java index 20227464..e6f3db7a 100644 --- a/test/transform/resource/after-delombok/ToStringPlain.java +++ b/test/transform/resource/after-delombok/ToStringPlain.java @@ -1,5 +1,5 @@ class ToString1 { - final int x; + int x; String name; @java.lang.Override @java.lang.SuppressWarnings("all") @@ -8,7 +8,7 @@ class ToString1 { } } class ToString2 { - final int x; + int x; String name; @java.lang.Override @java.lang.SuppressWarnings("all") diff --git a/test/transform/resource/after-delombok/ValComplex.java b/test/transform/resource/after-delombok/ValComplex.java index 54ef5c78..0df87fac 100644 --- a/test/transform/resource/after-delombok/ValComplex.java +++ b/test/transform/resource/after-delombok/ValComplex.java @@ -1,8 +1,8 @@ public class ValComplex { - private ValSimple field = new ValSimple(); + private String field = ""; private static final int CONSTANT = 20; - public void testReferencingOtherFiles() { - final java.lang.String shouldBeString = field.method(); + public void testComplex() { + final char[] shouldBeCharArray = field.toCharArray(); final int shouldBeInt = CONSTANT; final java.lang.Object lock = new Object(); synchronized (lock) { @@ -10,11 +10,11 @@ public class ValComplex { final int inner = 10; switch (field) { case 5: - final java.lang.String shouldBeString2 = shouldBeString; + final char[] shouldBeCharArray2 = shouldBeCharArray; final int innerInner = inner; } } - final ValSimple shouldBeValSimple = field; //Unshadowing + final java.lang.String shouldBeString = field; //Unshadowing } }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/ValInFor.java b/test/transform/resource/after-delombok/ValInFor.java index 013cd02e..de75803b 100644 --- a/test/transform/resource/after-delombok/ValInFor.java +++ b/test/transform/resource/after-delombok/ValInFor.java @@ -1,14 +1,4 @@ public class ValInFor { - { - final int x = 10; - final int x2 = -1; - final java.lang.String a = "Hello"; - for (final int y = x, z = x2; y < 20; y++) { - final int q = y; - final int w = z; - final java.lang.String v = a; - } - } public void enhancedFor() { java.util.List<String> list = java.util.Arrays.asList("Hello, World!"); for (final java.lang.String shouldBeString : list) { diff --git a/test/transform/resource/after-delombok/ValOutersWithGenerics.java b/test/transform/resource/after-delombok/ValOutersWithGenerics.java new file mode 100644 index 00000000..150e3a2a --- /dev/null +++ b/test/transform/resource/after-delombok/ValOutersWithGenerics.java @@ -0,0 +1,21 @@ +import java.util.*; +public class ValOutersWithGenerics<Z> { + class Inner { + } + public void testOutersWithGenerics() { + final java.lang.String foo = ""; + List<Inner> list = new ArrayList<Inner>(); + final ValOutersWithGenerics<Z>.Inner elem = list.get(0); + } + public void testLocalClasses() { + class Local<A> { + } + final Local<java.lang.String> q = new Local<String>(); + } + static class SubClass extends ValOutersWithGenerics<String> { + public void testSubClassOfOutersWithGenerics() { + List<Inner> list = new ArrayList<Inner>(); + final ValOutersWithGenerics<java.lang.String>.Inner elem = list.get(0); + } + } +} diff --git a/test/transform/resource/after-delombok/ValWeirdTypes.java b/test/transform/resource/after-delombok/ValWeirdTypes.java index 34beb80b..9eb211b3 100644 --- a/test/transform/resource/after-delombok/ValWeirdTypes.java +++ b/test/transform/resource/after-delombok/ValWeirdTypes.java @@ -1,6 +1,6 @@ import java.util.*; public class ValWeirdTypes<Z> { - private final List<Z> fieldList; + private List<Z> fieldList; public void testGenerics() { List<String> list = new ArrayList<String>(); list.add("Hello, World!"); diff --git a/test/transform/resource/after-ecj/Constructors.java b/test/transform/resource/after-ecj/Constructors.java index e47ec8b5..3b3a14da 100644 --- a/test/transform/resource/after-ecj/Constructors.java +++ b/test/transform/resource/after-ecj/Constructors.java |
