From 653eb56883a6be109ee7e767fae920cae70f569d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 11 Mar 2013 22:06:09 +0100 Subject: changed the pattern for writing dependencies to the various lib/ directories to be organization-name.jar instead of just name.jar, in order to account for the ever lovely and wonderful apache's crazy decision to call the entirely separate log4j v2.0 also 'log4j'. This does mean you'll have to 'ant clean'. --- test/core/src/lombok/RunTestsViaEcj.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/core/src/lombok/RunTestsViaEcj.java') diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 0bf97213..ca443620 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -129,10 +129,11 @@ public class RunTestsViaEcj extends AbstractRunTests { } } classpath.add("dist/lombok.jar"); - classpath.add("lib/test/commons-logging.jar"); - classpath.add("lib/test/slf4j-api.jar"); - classpath.add("lib/test/slf4j-ext.jar"); - classpath.add("lib/test/log4j.jar"); + classpath.add("lib/test/commons-logging-commons-logging.jar"); + classpath.add("lib/test/org.slf4j-slf4j-api.jar"); + classpath.add("lib/test/org.slf4j-slf4j-ext.jar"); + classpath.add("lib/test/log4j-log4j.jar"); + classpath.add("lib/test/org.apache.logging.log4j-log4j-api.jar"); return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8"); } } -- cgit From 6b5a0e2cb349a4fb7d8bb5f943e57a0b65596ca0 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 24 May 2013 00:52:37 +0200 Subject: Fixed more issues related to java7's try-with-resources, and updated ECJ version detection. --- src/core/lombok/core/AST.java | 28 ++++++++++++--------- src/core/lombok/javac/JavacAST.java | 43 ++++++++++++++++++++++++++++++++ src/utils/lombok/eclipse/Eclipse.java | 41 +++++++++++++++++++++++++++++- test/core/src/lombok/RunTestsViaEcj.java | 8 +++--- 4 files changed, 103 insertions(+), 17 deletions(-) (limited to 'test/core/src/lombok/RunTestsViaEcj.java') diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index 30297418..e6721b80 100644 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -54,7 +54,7 @@ public abstract class AST, L extends LombokNode, private final String fileName; private final String packageDeclaration; private final ImportList imports; - Map identityDetector = new IdentityHashMap(); + Map identityDetector = new IdentityHashMap(); private Map nodeMap = new IdentityHashMap(); private boolean changed = false; @@ -105,7 +105,7 @@ public abstract class AST, L extends LombokNode, */ protected L putInMap(L node) { nodeMap.put(node.get(), node); - identityDetector.put(node.get(), null); + identityDetector.put(node.get(), node.get()); return node; } @@ -117,7 +117,7 @@ public abstract class AST, L extends LombokNode, /** Clears the registry that avoids endless loops, and empties the node map. The existing node map * object is left untouched, and instead a new map is created. */ protected void clearState() { - identityDetector = new IdentityHashMap(); + identityDetector = new IdentityHashMap(); nodeMap = new IdentityHashMap(); } @@ -127,9 +127,7 @@ public abstract class AST, L extends LombokNode, * case you should do nothing lest the AST build process loops endlessly. */ protected boolean setAndGetAsHandled(N node) { - if (identityDetector.containsKey(node)) return true; - identityDetector.put(node, null); - return false; + return identityDetector.put(node, node) != null; } public String getFileName() { @@ -234,14 +232,12 @@ public abstract class AST, L extends LombokNode, } } - for (Class statementType : getStatementTypes()) { - if (statementType.isAssignableFrom(t)) { - f.setAccessible(true); - fields.add(new FieldAccess(f, dim)); - break; - } + if (shouldDrill(c, t, f.getName())) { + f.setAccessible(true); + fields.add(new FieldAccess(f, dim)); } } + getFields(c.getSuperclass(), fields); } @@ -258,6 +254,14 @@ public abstract class AST, L extends LombokNode, * though some platforms (such as Eclipse) group these under one common supertype. */ protected abstract Collection> getStatementTypes(); + protected boolean shouldDrill(Class parentType, Class childType, String fieldName) { + for (Class statementType : getStatementTypes()) { + if (statementType.isAssignableFrom(childType)) return true; + } + + return false; + } + /** * buildTree implementation that uses reflection to find all child nodes by way of inspecting * the fields. */ diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java index 8197dae6..5a91258c 100644 --- a/src/core/lombok/javac/JavacAST.java +++ b/src/core/lombok/javac/JavacAST.java @@ -24,6 +24,7 @@ package lombok.javac; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import javax.annotation.processing.Messager; @@ -39,6 +40,7 @@ import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.model.JavacTypes; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCatch; +import com.sun.tools.javac.tree.JCTree.JCTry; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCBlock; @@ -224,6 +226,46 @@ public class JavacAST extends AST { return putInMap(new JavacNode(this, local, childNodes, kind)); } + private static boolean JCTRY_RESOURCES_FIELD_INITIALIZED; + private static Field JCTRY_RESOURCES_FIELD; + + @SuppressWarnings("unchecked") + private static List getResourcesForTryNode(JCTry tryNode) { + if (!JCTRY_RESOURCES_FIELD_INITIALIZED) { + try { + JCTRY_RESOURCES_FIELD = JCTry.class.getField("resources"); + } catch (NoSuchFieldException ignore) { + // Java 1.6 or lower won't have this at all. + } catch (Exception ignore) { + // Shouldn't happen. Best thing we can do is just carry on and break on try/catch. + } + JCTRY_RESOURCES_FIELD_INITIALIZED = true; + } + + if (JCTRY_RESOURCES_FIELD == null) return Collections.emptyList(); + Object rv = null; + try { + rv = JCTRY_RESOURCES_FIELD.get(tryNode); + } catch (Exception ignore) {} + + if (rv instanceof List) return (List) rv; + return Collections.emptyList(); + } + + private JavacNode buildTry(JCTry tryNode) { + if (setAndGetAsHandled(tryNode)) return null; + List childNodes = new ArrayList(); + for (JCTree varDecl : getResourcesForTryNode(tryNode)) { + if (varDecl instanceof JCVariableDecl) { + addIfNotNull(childNodes, buildLocalVar((JCVariableDecl) varDecl, Kind.LOCAL)); + } + } + addIfNotNull(childNodes, buildStatement(tryNode.body)); + for (JCCatch jcc : tryNode.catchers) addIfNotNull(childNodes, buildTree(jcc, Kind.STATEMENT)); + addIfNotNull(childNodes, buildStatement(tryNode.finalizer)); + return putInMap(new JavacNode(this, tryNode, childNodes, Kind.STATEMENT)); + } + private JavacNode buildInitializer(JCBlock initializer) { if (setAndGetAsHandled(initializer)) return null; List childNodes = new ArrayList(); @@ -265,6 +307,7 @@ public class JavacAST extends AST { if (statement instanceof JCAnnotation) return null; if (statement instanceof JCClassDecl) return buildType((JCClassDecl)statement); if (statement instanceof JCVariableDecl) return buildLocalVar((JCVariableDecl)statement, Kind.LOCAL); + if (statement instanceof JCTry) return buildTry((JCTry) statement); if (setAndGetAsHandled(statement)) return null; diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index edfe1536..c2a863d5 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -37,8 +37,10 @@ import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.Literal; import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.TryStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; @@ -180,8 +182,31 @@ public class Eclipse { return null; } - private static int ecjCompilerVersionCached = -1; + private static long latestEcjCompilerVersionConstantCached = 0; + + public static long getLatestEcjCompilerVersionConstant() { + if (latestEcjCompilerVersionConstantCached != 0) return latestEcjCompilerVersionConstantCached; + + int highestVersionSoFar = 0; + for (Field f : ClassFileConstants.class.getDeclaredFields()) { + try { + if (f.getName().startsWith("JDK1_")) { + int thisVersion = Integer.parseInt(f.getName().substring("JDK1_".length())); + if (thisVersion > highestVersionSoFar) { + highestVersionSoFar = thisVersion; + latestEcjCompilerVersionConstantCached = (Long) f.get(null); + } + } + } catch (Exception ignore) {} + } + + if (highestVersionSoFar > 6 && !ecjSupportsJava7Features()) { + latestEcjCompilerVersionConstantCached = ClassFileConstants.JDK1_6; + } + return latestEcjCompilerVersionConstantCached; + } + private static int ecjCompilerVersionCached = -1; public static int getEcjCompilerVersion() { if (ecjCompilerVersionCached >= 0) return ecjCompilerVersionCached; @@ -194,6 +219,20 @@ public class Eclipse { } if (ecjCompilerVersionCached < 5) ecjCompilerVersionCached = 5; + if (!ecjSupportsJava7Features()) ecjCompilerVersionCached = Math.min(6, ecjCompilerVersionCached); return ecjCompilerVersionCached; } + + /** + * Certain ECJ versions that only go up to -source 6 report that they support -source 7 and even fail to error when -source 7 is applied. + * We detect this and correctly say that no more than -source 6 is supported. (when this is the case, this method returns false). + */ + private static boolean ecjSupportsJava7Features() { + try { + TryStatement.class.getDeclaredField("resources"); + return true; + } catch (NoSuchFieldException e) { + return false; + } + } } diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index ca443620..12f2e252 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -33,6 +33,7 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import lombok.eclipse.Eclipse; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; import org.eclipse.jdt.core.compiler.CategorizedProblem; @@ -43,7 +44,6 @@ 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.problem.DefaultProblemFactory; @@ -51,9 +51,9 @@ import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; public class RunTestsViaEcj extends AbstractRunTests { protected CompilerOptions ecjCompilerOptions() { CompilerOptions options = new CompilerOptions(); - options.complianceLevel = ClassFileConstants.JDK1_6; - options.sourceLevel = ClassFileConstants.JDK1_6; - options.targetJDK = ClassFileConstants.JDK1_6; + options.complianceLevel = Eclipse.getLatestEcjCompilerVersionConstant(); + options.sourceLevel = Eclipse.getLatestEcjCompilerVersionConstant(); + options.targetJDK = Eclipse.getLatestEcjCompilerVersionConstant(); options.parseLiteralExpressionsAsConstants = true; options.inlineJsrBytecode = true; options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false; -- cgit From bf8e2afed07b4062ac3d3fee8b2f8981d1213f7e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 8 Jul 2013 20:56:50 +0200 Subject: gave up on adding support for moving javadoc to getter/setter in eclipse. Eclipse breaks the javadoc out of the raw source and we can't modify that without breaking a billion things. To solve this issue we'd have to write some very complicated patches to intercept this process and somehow propagate the node that the javadoc is attached to AND translate from the ast model to dom or whatever is being used there. Not gonna happen for this low priority feature. --- .../lombok/javac/handlers/JavacHandlerUtil.java | 4 +- test/core/src/lombok/RunTestsViaEcj.java | 2 +- .../resource/after-ecj/GetterSetterJavadoc.java | 60 ++++++++++++++++++++++ .../resource/after-ecj/JavadocGenerally.java | 11 ++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 test/transform/resource/after-ecj/GetterSetterJavadoc.java create mode 100644 test/transform/resource/after-ecj/JavadocGenerally.java (limited to 'test/core/src/lombok/RunTestsViaEcj.java') diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 87493e39..6aed5508 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1165,7 +1165,7 @@ public class JavacHandlerUtil { return (JCExpression) in; } - private static final Pattern SECTION_FINDER = Pattern.compile("^\\s*\\**\\s*[-*][-*]+\\s*(GETTER|SETTER)\\s*[-*][-*]+\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + private static final Pattern SECTION_FINDER = Pattern.compile("^\\s*\\**\\s*[-*][-*]+\\s*([GS]ETTER)\\s*[-*][-*]+\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); private static String stripLinesWithTagFromJavadoc(String javadoc, String regexpFragment) { Pattern p = Pattern.compile("^\\s*\\**\\s*" + regexpFragment + "\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); @@ -1201,7 +1201,7 @@ public class JavacHandlerUtil { public static enum CopyJavadoc { VERBATIM, GETTER { @Override public String[] split(String javadoc) { - // step 1: Check if there is a 'GETTER' section. If yes, that becomes the new one and we strip that from the original. + // step 1: Check if there is a 'GETTER' section. If yes, that becomes the new method's javadoc and we strip that from the original. String[] out = splitJavadocOnSectionIfPresent(javadoc, "GETTER"); if (out != null) return out; // failing that, create a copy, but strip @return from the original and @param from the copy. diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 12f2e252..f7294f1f 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -54,6 +54,7 @@ public class RunTestsViaEcj extends AbstractRunTests { options.complianceLevel = Eclipse.getLatestEcjCompilerVersionConstant(); options.sourceLevel = Eclipse.getLatestEcjCompilerVersionConstant(); options.targetJDK = Eclipse.getLatestEcjCompilerVersionConstant(); + options.docCommentSupport = false; options.parseLiteralExpressionsAsConstants = true; options.inlineJsrBytecode = true; options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false; @@ -64,7 +65,6 @@ public class RunTestsViaEcj extends AbstractRunTests { options.reportUnusedParameterWhenOverridingConcrete = false; options.reportDeadCodeInTrivialIfStatement = false; options.generateClassFiles = false; - options.docCommentSupport = false; Map warnings = new HashMap(); warnings.put(CompilerOptions.OPTION_ReportUnusedLocal, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore"); diff --git a/test/transform/resource/after-ecj/GetterSetterJavadoc.java b/test/transform/resource/after-ecj/GetterSetterJavadoc.java new file mode 100644 index 00000000..73f26180 --- /dev/null +++ b/test/transform/resource/after-ecj/GetterSetterJavadoc.java @@ -0,0 +1,60 @@ +@lombok.Data class GetterSetterJavadoc1 { + private int fieldName; + public @java.lang.SuppressWarnings("all") int getFieldName() { + return this.fieldName; + } + public @java.lang.SuppressWarnings("all") void setFieldName(final int fieldName) { + this.fieldName = fieldName; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof GetterSetterJavadoc1))) + return false; + final @java.lang.SuppressWarnings("all") GetterSetterJavadoc1 other = (GetterSetterJavadoc1) o; + if ((! other.canEqual((java.lang.Object) this))) + return false; + if ((this.getFieldName() != other.getFieldName())) + return false; + return true; + } + public @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + return (other instanceof GetterSetterJavadoc1); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int PRIME = 31; + int result = 1; + result = ((result * PRIME) + this.getFieldName()); + return result; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("GetterSetterJavadoc1(fieldName=" + this.getFieldName()) + ")"); + } + public @java.lang.SuppressWarnings("all") GetterSetterJavadoc1() { + super(); + } +} +class GetterSetterJavadoc2 { + private @lombok.Getter @lombok.Setter int fieldName; + GetterSetterJavadoc2() { + super(); + } + public @java.lang.SuppressWarnings("all") int getFieldName() { + return this.fieldName; + } + public @java.lang.SuppressWarnings("all") void setFieldName(final int fieldName) { + this.fieldName = fieldName; + } +} +class GetterSetterJavadoc3 { + private @lombok.Getter @lombok.Setter int fieldName; + GetterSetterJavadoc3() { + super(); + } + public @java.lang.SuppressWarnings("all") int getFieldName() { + return this.fieldName; + } + public @java.lang.SuppressWarnings("all") void setFieldName(final int fieldName) { + this.fieldName = fieldName; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/JavadocGenerally.java b/test/transform/resource/after-ecj/JavadocGenerally.java new file mode 100644 index 00000000..be9ed756 --- /dev/null +++ b/test/transform/resource/after-ecj/JavadocGenerally.java @@ -0,0 +1,11 @@ +package testPackage; +class JavadocGenerally { + public interface TestingInner { + } + private int someField; + JavadocGenerally() { + super(); + } + public void test() { + } +} \ No newline at end of file -- cgit