1 From 3f580c8bf7bc692f640accb8f6edad0165768519 Mon Sep 17 00:00:00 2001 2 From: Tor Norbye <tnorbye (a] google.com> 3 Date: Wed, 1 Jan 2014 19:28:00 -0800 4 Subject: [PATCH] Add support for ecj 4.2, and update version to 0.2.2 5 6 This changeset updates Lombok AST's ECJ converter to work with ECJ 4.2 7 (it was using 3.6.2), and in particular it no longer aborts when it 8 encounters a multi-catch statement. (Note that it doesn't actually 9 support the Java 7 syntax; for that, the Lombok AST API itself will 10 have to be enhanced (and the other parsers and parse tree converters 11 updated as well). It does however mean that rather than abort with a 12 fatal error encountering an unknown ECJ AST node, it will simply use 13 the first multi catch type reference instead. 14 15 Also updates the version number to Lombok AST 0.2.2, and stores native 16 nodes from ECJ on the Node native field. 17 18 Finally, some build script tweaks used in the Android version of 19 Lombok AST are included, to basically strip out the bundled (and 20 repackaged) parboiled (and thereby ASM 3.3) bits, as well as the 21 command line reader and the repackaged Guava r09 version. Clients 22 using these portions of Lombok should add these libraries on their 23 own, which lint already does. 24 --- 25 .gitignore | 2 ++ 26 build.xml | 6 +++--- 27 buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml | 14 -------------- 28 buildScripts/ivy.xml | 4 ++-- 29 src/ecjTransformer/lombok/ast/ecj/EcjTreeBuilder.java | 14 ++++++-------- 30 src/ecjTransformer/lombok/ast/ecj/EcjTreeConverter.java | 16 ++++++++++++++++ 31 src/ecjTransformer/lombok/ast/ecj/EcjTreeVisitor.java | 10 +++++++++- 32 src/main/lombok/ast/Version.java | 2 +- 33 8 files changed, 39 insertions(+), 29 deletions(-) 34 delete mode 100644 buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml 35 36 diff --git a/.gitignore b/.gitignore 37 index 486c70c..679717f 100644 38 --- a/.gitignore 39 +++ b/.gitignore 40 @@ -2,6 +2,8 @@ 41 /.project 42 /.classpath 43 /.factorypath 44 +/.idea 45 +/*.iml 46 /bin 47 /build 48 /dist 49 diff --git a/build.xml b/build.xml 50 index c1fd965..24c13d0 100644 51 --- a/build.xml 52 +++ b/build.xml 53 @@ -241,6 +241,9 @@ 54 <unjar dest="build/lombok.ast"> 55 <path refid="runtime.path" /> 56 </unjar> 57 + <delete dir="build/lombok.ast/com/google" /> 58 + <delete dir="build/lombok.ast/org/parboiled" /> 59 + <delete dir="build/lombok.ast/com/zwitserloot" /> 60 </target> 61 62 <target name="dist" depends="compile, version, unpackLibs" description="Creates distributable."> 63 @@ -250,9 +253,6 @@ 64 <fileset dir="build/lombok.ast" /> 65 <fileset dir="." includes="LICENSE" /> 66 <fileset dir="." includes="AUTHORS" /> 67 - <rule pattern="com.google.common.**" result="lombok.ast.libs.com.google.common.@1" /> 68 - <rule pattern="org.parboiled.**" result="lombok.ast.libs.org.parboiled.@1" /> 69 - <rule pattern="com.zwitserloot.cmdreader.**" result="lombok.ast.libs.com.zwitserloot.cmdreader.@1" /> 70 <manifest> 71 <attribute name="Main-Class" value="lombok.ast.app.Main" /> 72 <attribute name="Lombok-Ast-Version" value="${lombok.ast.version}" /> 73 diff --git a/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml b/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml 74 deleted file mode 100644 75 index fc9fa66..0000000 76 --- a/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml 77 +++ /dev/null 78 @@ -1,14 +0,0 @@ 79 -<ivy-module version="2.0"> 80 - <info organisation="org.eclipse.custom" module="ecj" revision="3.6.2" publication="20110401190400"> 81 - <license name="Eclipse Public Licence v1.0" url="http://www.eclipse.org/org/documents/epl-v10.php" /> 82 - <description homepage="http://www.eclipse.org/eclipse/" /> 83 - </info> 84 - <configurations> 85 - <conf name="default" /> 86 - <conf name="sources" /> 87 - </configurations> 88 - <publications> 89 - <artifact conf="default" url="http://projectlombok.org/ivyrepo/eclipse/ecj-3.6.2.jar" /> 90 - <artifact type="zip" conf="sources" url="http://projectlombok.org/ivyrepo/eclipse/ecjsrc-3.6.2.zip" /> 91 - </publications> 92 -</ivy-module> 93 diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml 94 index d95fd1c..5865aa2 100644 95 --- a/buildScripts/ivy.xml 96 +++ b/buildScripts/ivy.xml 97 @@ -11,10 +11,10 @@ 98 <dependency org="org.projectlombok" name="lombok" rev="0.10.8" conf="build->default" /> 99 <dependency org="org.projectlombok" name="lombok-utils" rev="0.10.8" conf="runtime->default" /> 100 <dependency org="com.github.parboiled.custom" name="parboiled" rev="0.9.7.2" conf="build; runtime; contrib->sources" /> 101 - <dependency org="com.google.guava" name="guava" rev="r09" conf="runtime->default; build->default; contrib->sources" /> 102 + <dependency org="com.google.guava" name="guava" rev="15.0" conf="runtime->default; build->default; contrib->sources" /> 103 <dependency org="junit" name="junit" rev="4.8.2" conf="test->default" /> 104 <dependency org="net.java.openjdk.custom" name="javac6" rev="1.6.0.18" conf="build->default; contrib->sources" /> 105 - <dependency org="org.eclipse.custom" name="ecj" rev="3.6.2" conf="build->default; contrib->sources" /> 106 + <dependency org="org.eclipse.jdt.core.compiler" name="ecj" rev="4.2.2" conf="build->default; contrib->sources" /> 107 <dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.4.1" conf="test->runtime" /> 108 <dependency org="net.sourceforge.cobertura" name="cobertura-runtime" rev="1.9.4.1" conf="test->runtime" /> 109 <dependency org="com.googlecode.jarjar" name="jarjar" rev="1.1" conf="build->default" /> 110 diff --git a/src/ecjTransformer/lombok/ast/ecj/EcjTreeBuilder.java b/src/ecjTransformer/lombok/ast/ecj/EcjTreeBuilder.java 111 index 5d0ce70..8df0205 100644 112 --- a/src/ecjTransformer/lombok/ast/ecj/EcjTreeBuilder.java 113 +++ b/src/ecjTransformer/lombok/ast/ecj/EcjTreeBuilder.java 114 @@ -1117,15 +1117,13 @@ public class EcjTreeBuilder { 115 if (node.astOperand() instanceof lombok.ast.IntegralLiteral && node.astOperand().getParens() == 0) { 116 lombok.ast.IntegralLiteral lit = (lombok.ast.IntegralLiteral)node.astOperand(); 117 if (!lit.astMarkedAsLong() && lit.astIntValue() == Integer.MIN_VALUE) { 118 - IntLiteralMinValue minLiteral = new IntLiteralMinValue(); 119 - minLiteral.sourceStart = start(node); 120 - minLiteral.sourceEnd = end(node); 121 + IntLiteralMinValue minLiteral = new IntLiteralMinValue( 122 + lit.rawValue().toCharArray(), null, start(node), end(node)); 123 return set(node, minLiteral); 124 } 125 if (lit.astMarkedAsLong() && lit.astLongValue() == Long.MIN_VALUE) { 126 - LongLiteralMinValue minLiteral = new LongLiteralMinValue(); 127 - minLiteral.sourceStart = start(node); 128 - minLiteral.sourceEnd = end(node); 129 + LongLiteralMinValue minLiteral = new LongLiteralMinValue( 130 + lit.rawValue().toCharArray(), null, start(node), end(node)); 131 return set(node, minLiteral); 132 } 133 } 134 @@ -1419,9 +1417,9 @@ public class EcjTreeBuilder { 135 @Override 136 public boolean visitIntegralLiteral(lombok.ast.IntegralLiteral node) { 137 if (node.astMarkedAsLong()) { 138 - return set(node, new LongLiteral(node.rawValue().toCharArray(), start(node), end(node))); 139 + return set(node, LongLiteral.buildLongLiteral(node.rawValue().toCharArray(), start(node), end(node))); 140 } 141 - return set(node, new IntLiteral(node.rawValue().toCharArray(), start(node), end(node))); 142 + return set(node, IntLiteral.buildIntLiteral(node.rawValue().toCharArray(), start(node), end(node))); 143 } 144 145 @Override 146 diff --git a/src/ecjTransformer/lombok/ast/ecj/EcjTreeConverter.java b/src/ecjTransformer/lombok/ast/ecj/EcjTreeConverter.java 147 index b825771..b0f6e88 100644 148 --- a/src/ecjTransformer/lombok/ast/ecj/EcjTreeConverter.java 149 +++ b/src/ecjTransformer/lombok/ast/ecj/EcjTreeConverter.java 150 @@ -128,6 +128,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; 151 import org.eclipse.jdt.internal.compiler.ast.TypeParameter; 152 import org.eclipse.jdt.internal.compiler.ast.TypeReference; 153 import org.eclipse.jdt.internal.compiler.ast.UnaryExpression; 154 +import org.eclipse.jdt.internal.compiler.ast.UnionTypeReference; 155 import org.eclipse.jdt.internal.compiler.ast.WhileStatement; 156 import org.eclipse.jdt.internal.compiler.ast.Wildcard; 157 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 158 @@ -208,6 +209,7 @@ public class EcjTreeConverter { 159 List<Node> result = Lists.newArrayList(); 160 if (value != null) result.add(value); 161 this.result = result; 162 + if (value != null) value.setNativeNode(node); 163 } 164 165 @SuppressWarnings("unused") 166 @@ -216,6 +218,9 @@ public class EcjTreeConverter { 167 168 if (result != null) throw new IllegalStateException("result is already set"); 169 this.result = values; 170 + for (Node value : values) { 171 + value.setNativeNode(node); 172 + } 173 } 174 175 private Node toTree(ASTNode node, FlagKey... keys) { 176 @@ -1306,6 +1311,17 @@ public class EcjTreeConverter { 177 set(node, setPosition(node, element)); 178 } 179 180 + @Override public void visitUnionTypeReference(UnionTypeReference node) { 181 + // For now, just use the FIRST type reference; we need the Lombok AST API 182 + // enhanced in order to properly hold all these 183 + if (node.typeReferences.length > 0) { 184 + TypeReference ref = node.typeReferences[0]; 185 + if (ref != null) { 186 + visitEcjNode(ref); 187 + } 188 + } 189 + } 190 + 191 @Override public void visitJavadoc(Javadoc node) { 192 if (node == null) { 193 set(node, (Node)null); 194 diff --git a/src/ecjTransformer/lombok/ast/ecj/EcjTreeVisitor.java b/src/ecjTransformer/lombok/ast/ecj/EcjTreeVisitor.java 195 index 1504543..361b4b6 100644 196 --- a/src/ecjTransformer/lombok/ast/ecj/EcjTreeVisitor.java 197 +++ b/src/ecjTransformer/lombok/ast/ecj/EcjTreeVisitor.java 198 @@ -356,6 +356,10 @@ public abstract class EcjTreeVisitor { 199 visitJavadoc((Javadoc) node); 200 return; 201 } 202 + if (clazz == UnionTypeReference.class) { 203 + visitUnionTypeReference((UnionTypeReference) node); 204 + return; 205 + } 206 207 visitOther(node); 208 } 209 @@ -695,4 +699,8 @@ public abstract class EcjTreeVisitor { 210 public void visitJavadoc(Javadoc node) { 211 visitAny(node); 212 } 213 -} 214 \ No newline at end of file 215 + 216 + public void visitUnionTypeReference(UnionTypeReference node) { 217 + visitAny(node); 218 + } 219 +} 220 diff --git a/src/main/lombok/ast/Version.java b/src/main/lombok/ast/Version.java 221 index e188bd3..88f51c0 100644 222 --- a/src/main/lombok/ast/Version.java 223 +++ b/src/main/lombok/ast/Version.java 224 @@ -28,7 +28,7 @@ public class Version { 225 // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). 226 // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. 227 // Official builds always end in an even number. 228 - private static final String VERSION = "0.2.1"; 229 + private static final String VERSION = "0.2.2"; 230 231 private Version() { 232 //Prevent instantiation 233 -- 234 1.8.4.3 235 236