diff options
| author | Jan Rieke <rieke@subshell.com> | 2018-09-12 09:30:40 +0200 |
|---|---|---|
| committer | Jan Rieke <rieke@subshell.com> | 2018-09-12 09:30:40 +0200 |
| commit | da0020cd48bfd321ec68adc99af7ec46e1551231 (patch) | |
| tree | c85ff3b3a2bf2ed391bdeda50c349b8831d13e13 | |
| parent | ddd42acb599d45c432a200313a0f403a8a2a3928 (diff) | |
| parent | 2027ffc49f194da2892938e0cd5868cd286a06f6 (diff) | |
| download | lombok-da0020cd48bfd321ec68adc99af7ec46e1551231.tar.gz lombok-da0020cd48bfd321ec68adc99af7ec46e1551231.tar.bz2 lombok-da0020cd48bfd321ec68adc99af7ec46e1551231.zip | |
Merge remote-tracking branch 'upstream/master' into superToBuilder
32 files changed, 499 insertions, 200 deletions
@@ -32,7 +32,6 @@ the common tasks and can be called on to run the main aspects of all the sub-scr <property name="rt-openjdk8" location="lib/openJDK8Environment/openjdk8_rt.jar" /> <available file="${rt-openjdk6}" property="rt-openjdk6.available" /> <available file="${rt-openjdk8}" property="rt-openjdk8.available" /> - <property environment="env"/> <path id="build.path"> <fileset dir="lib/build"> @@ -368,43 +367,6 @@ lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating</echo> <property name="lombok.dist.built" value="true" /> </target> - <target name="-mvn-ext"> - <condition property="mvn-ext" value=".cmd" else=""> - <os family="windows" /> - </condition> - </target> - - <target name="generate-pom" depends="version,dist"> - <echo message="Lombok version: ${lombok.version}-SNAPSHOT" /> - - <echo file="build/pom.xml"><![CDATA[<project> - <modelVersion>4.0.0</modelVersion> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>]]>${lombok.version}-SNAPSHOT<![CDATA[</version> -</project>]]></echo> - </target> - - <target name="install-maven" depends="generate-pom,-mvn-ext" description="Install THE lombok.jar into the local maven repository using Apache Maven"> - <condition property="mvn-exe" value="${env.MAVEN_HOME}/bin/mvn${mvn-ext}" else="mvn${mvn-ext}"> - <isset property="env.MAVEN_HOME" /> - </condition> - - <exec executable="${mvn-exe}" failifexecutionfails="false" resultproperty="mvn-result"> - <arg value="install:install-file" /> - <arg value="-Dfile=dist/lombok-${lombok.version}.jar" /> - <arg value="-DgroupId=org.projectlombok" /> - <arg value="-DartifactId=lombok" /> - <arg value="-Dversion=${lombok.version}-SNAPSHOT" /> - <arg value="-Dpackaging=jar" /> - <arg value="-DpomFile=build/pom.xml" /> - </exec> - <condition property="mvn-notfound" value="true"> - <not><isset property="mvn-result" /></not> - </condition> - <fail message="mvn is not on your path and/or MAVEN_HOME is not set. Add mvn to your path or set MAVEN_HOME to continue." if="mvn-notfound" /> - </target> - <target name="dist-utils" description="Builds lombok-utils.jar, which is a library used by i.e. lombok.ast project." depends="version, compile"> <mkdir dir="dist" /> <jar destfile="dist/lombok-utils-${lombok.version}.jar"> @@ -835,7 +797,7 @@ You can also create your own by writing a 'testenvironment.properties' file. The </ant> </target> - <target name="maven" depends="version, dist, javadoc" description="Build a maven artifact bundle."> + <target name="-prepare-maven" depends="version, dist, javadoc"> <jar destfile="dist/lombok-${lombok.version}-javadoc.jar"> <fileset dir="doc/api" /> </jar> @@ -850,13 +812,18 @@ You can also create your own by writing a 'testenvironment.properties' file. The <fileset dir="test/core/src" /> </jar> <mkdir dir="build/mavenPublish" /> + <!-- Could already be set for edge releases --> + <property name="lombok.version.mvn" value="${lombok.version}" /> <copy tofile="build/mavenPublish/pom.xml" overwrite="true" file="doc/maven-pom.xml"> <filterchain> <replacetokens> - <token key="VERSION" value="${lombok.version}" /> + <token key="VERSION" value="${lombok.version.mvn}" /> </replacetokens> </filterchain> </copy> + </target> + + <target name="maven" depends="-prepare-maven" description="Build a maven artifact bundle."> <tar destfile="build/mavenPublish/mavenPublish.tar.bz2" compression="bzip2"> <tarfileset dir="dist"> <include name="lombok-${lombok.version}.jar" /> @@ -924,12 +891,13 @@ You can also create your own by writing a 'testenvironment.properties' file. The username="${ssh.username}" keyfile="${ssh.keyfile}" knownHosts="ssh.knownHosts" /> + <echo>WARNING: You should now immediately run an edge release!</echo> </target> <target name="publish-all" depends="clean, version, website-publish, maven-publish, publish" description="Publishes lombok itself, updates the maven repository and the website." /> - <target name="edge-release" depends="config-ssh, clean, version, dist" + <target name="edge-release" depends="config-ssh, clean, version, dist, make-edge-as-maven_snapshot_repo" description="Publishes an edge release for those who need to test a cutting edge build."> <ant antfile="buildScripts/website.ant.xml" target="edgeRelease" inheritAll="false"> <property name="lombok.version" value="${lombok.version}" /> @@ -991,7 +959,42 @@ You can also create your own by writing a 'testenvironment.properties' file. The <property name="ssh.keyfile" value="${ssh.keyfile}" /> </ant> </target> - + + <target name="-mvn-ext"> + <condition property="mvn-ext" value=".cmd" else=""> + <os family="windows" /> + </condition> + </target> + + <target name="-version-edge"> + <property name="lombok.version.mvn" value="edge-SNAPSHOT" /> + </target> + + <target name="make-edge-as-maven_snapshot_repo" depends="-version-edge,-mvn-ext,-prepare-maven" description="Create a maven repo for the current snapshot into a build dir. The intent is for you to put that on a server someplace. Will invoke your local mvn installation."> + <property environment="env" /> + <delete quiet="true" dir="build/edge-releases" /> + <mkdir dir="build/edge-releases" /> + <condition property="mvn-exe" value="${env.MAVEN_HOME}/bin/mvn${mvn-ext}" else="mvn${mvn-ext}"> + <isset property="env.MAVEN_HOME" /> + </condition> + + <exec executable="${mvn-exe}" failifexecutionfails="false" resultproperty="mvn-result"> + <arg value="deploy:deploy-file" /> + <arg value="-Dfile=dist/lombok-${lombok.version}.jar" /> + <arg value="-Dsources=dist/lombok-${lombok.version}-sources.jar" /> + <arg value="-Djavadoc=dist/lombok-${lombok.version}-javadoc.jar" /> + <arg value="-DgroupId=org.projectlombok" /> + <arg value="-DartifactId=lombok" /> + <arg value="-Dversion=edge-SNAPSHOT" /> + <arg value="-DpomFile=build/mavenPublish/pom.xml" /> + <arg value="-Durl=file://${basedir}/build/edge-releases" /> + </exec> + <condition property="mvn-notfound" value="true"> + <not><isset property="mvn-result" /></not> + </condition> + <fail message="mvn is not on your path and/or MAVEN_HOME is not set. Add mvn to your path or set MAVEN_HOME to continue." if="mvn-notfound" /> + </target> + <target name="testAp-compile" depends="ensureBuildDeps"> <delete file="build/testAP/META-INF/services/javax.annotation.processing.Processor" quiet="true" /> <ivy:compile destdir="build/testAP" source="1.7" target="1.7"> diff --git a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.24.xml b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.24.xml deleted file mode 100644 index 87e1594f..00000000 --- a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.24.xml +++ /dev/null @@ -1,14 +0,0 @@ -<ivy-module version="2.0"> - <info organisation="org.projectlombok" module="lombok.patcher" revision="0.24" publication="20171128000000"> - <license name="MIT License" url="http://www.opensource.org/licenses/mit-license.php" /> - <ivyauthor name="rzwitserloot" url="http://zwitserloot.com/" /> - <ivyauthor name="rspilker" url="http://github.com/rspilker" /> - <description homepage="https://projectlombok.org/" /> - </info> - <configurations> - <conf name="default" /> - </configurations> - <publications> - <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.24.jar" /> - </publications> -</ivy-module> diff --git a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.26.xml b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.28.xml index 6525604f..5ff77341 100644 --- a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.26.xml +++ b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.28.xml @@ -1,5 +1,5 @@ <ivy-module version="2.0"> - <info organisation="org.projectlombok" module="lombok.patcher" revision="0.26" publication="20180528200000"> + <info organisation="org.projectlombok" module="lombok.patcher" revision="0.28" publication="20180910222000"> <license name="MIT License" url="https://www.opensource.org/licenses/mit-license.php" /> <ivyauthor name="rzwitserloot" url="https://github.com/rzwitserloot" /> <ivyauthor name="rspilker" url="https://github.com/rspilker" /> @@ -9,6 +9,6 @@ <conf name="default" /> </configurations> <publications> - <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.26.jar" /> + <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.28.jar" /> </publications> </ivy-module> diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 4eed2fa6..15c03ed1 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -18,7 +18,7 @@ <conf name="supporters" /> </configurations> <dependencies> - <dependency org="org.projectlombok" name="lombok.patcher" rev="0.26" conf="buildBase->default; runtime->default" /> + <dependency org="org.projectlombok" name="lombok.patcher" rev="0.28" conf="buildBase->default; runtime->default" /> <dependency org="zwitserloot.com" name="cmdreader" rev="1.2" conf="buildBase->runtime; runtime" /> <dependency org="junit" name="junit" rev="4.8.2" conf="test->default; contrib->sources" /> diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml index 5c996fc6..a799e7fe 100644 --- a/buildScripts/website.ant.xml +++ b/buildScripts/website.ant.xml @@ -185,9 +185,11 @@ such as applying the templates to produce the website, converting the changelog <arg value="build/website-edge/download-edge.html" /> </java> <copy file="dist/lombok.jar" tofile="build/website-edge/lombok-edge.jar" /> - <tar destfile="dist/website-edge.tar.bz2" compression="bzip2"> <tarfileset dir="build/website-edge" /> + <tarfileset dir="build"> + <include name="edge-releases/**" /> + </tarfileset> </tar> </target> @@ -209,6 +211,23 @@ such as applying the templates to produce the website, converting the changelog username="${ssh.username}" keyfile="${ssh.keyfile}" knownHosts="ssh.knownHosts" /> + <exec executable="/usr/bin/git" failonerror="true"> + <arg value="merge-base" /> + <arg value="--is-ancestor" /> + <arg value="edge" /> + <arg value="master" /> + </exec> + <exec executable="/usr/bin/git"> + <arg value="branch" /> + <arg value="-f" /> + <arg value="edge" /> + <arg value="master" /> + </exec> + <exec executable="/usr/bin/git"> + <arg value="push" /> + <arg value="origin" /> + <arg value="edge:refs/heads/edge" /> + </exec> </target> <target name="javadoc" description="Generates the javadoc" depends="-ensure-version, -ensure-fullversion" unless="skip.javadoc"> diff --git a/doc/changelog.markdown b/doc/changelog.markdown index a294d6a1..04c9a052 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,10 +2,13 @@ Lombok Changelog ---------------- ### v1.18.3 "Edgy Guinea Pig" +* PLATFORM: Support for Eclipse Photon. [Issue #1831](https://github.com/rzwitserloot/lombok/issues/1831) * FEATURE: The `@FieldNameConstants` feature has been completely redesigned. [Issue #1774](https://github.com/rzwitserloot/lombok/issues/1774) [FieldNameConstants documentation](https://projectlombok.org/features/experimental/FieldNameConstants) * BUGFIX: When using lombok to compile modularized (`module-info.java`-style) code, if the module name has dots in it, it wouldn't work. [Issue #1808](https://github.com/rzwitserloot/lombok/issues/1808) * BUGFIX: Errors about lombok not reading a module providing `org.mapstruct.ap.spi` when trying to use lombok in jigsaw-mode on JDK 11. [Issue #1806](https://github.com/rzwitserloot/lombok/issues/1806) * BUGFIX: Fix NetBeans compile on save. [Issue #1770](https://github.com/rzwitserloot/lombok/issues/1770) +* PLATFORM: Angular IDE is now recognized by the installer [Issue #1830](https://github.com/rzwitserloot/lombok/issues/1830) + ### v1.18.2 (July 26th, 2018) * BUGFIX: mapstruct + lombok in eclipse should hopefully work again. [Issue #1359](https://github.com/rzwitserloot/lombok/issues/1359) and [mapstruct issue #1159](https://github.com/mapstruct/mapstruct/issues/1159) @@ -14,7 +17,6 @@ Lombok Changelog * BUGFIX: Lombok and gradle v4.9 didn't work together; that's been fixed. [Issue #1716](https://github.com/rzwitserloot/lombok/issues/1716) and [gradle-apt-plugin issue #87](https://github.com/tbroyer/gradle-apt-plugin/issues/87) * FEATURE: You can now make builders for type hierarchies, using the new (experimental) `@SuperBuilder` annotation. Thanks for the contribution, Jan Rieke. [`@SuperBuilder` documentation](https://projectlombok.org/features/experimental/SuperBuilder) * FEATURE: `@NoArgsConstructor`, including forcing one with `lombok.config: lombok.noArgsConstructor.extraPrivate=true` now take any defaults set with `@Builder.Default` into account. [Issue #1347](https://github.com/rzwitserloot/lombok/issues/1347) - ### v1.18.0 (June 5th, 2018) * BREAKING CHANGE: The in 1.16.22 introduced configuration key `lombok.noArgsConstructor.extraPrivate` is now `false` by default. [Issue #1708](https://github.com/rzwitserloot/lombok/issues/1708) * BUGFIX: Do not generate a private no-args constructor if that breaks the code. [Issue #1703](https://github.com/rzwitserloot/lombok/issues/1703), [Issue #1704](https://github.com/rzwitserloot/lombok/issues/1704), [Issue #1712](https://github.com/rzwitserloot/lombok/issues/1712) diff --git a/doc/maven-pom.xml b/doc/maven-pom.xml index baba7ca6..99643f64 100644 --- a/doc/maven-pom.xml +++ b/doc/maven-pom.xml @@ -21,8 +21,8 @@ <url>http://github.com/rzwitserloot/lombok</url> </scm> <issueManagement> - <system>Google Code</system> - <url>http://code.google.com/p/projectlombok/issues</url> + <system>GitHub Issues</system> + <url>https://github.com/rzwitserloot/lombok/issues</url> </issueManagement> <developers> <developer> @@ -30,18 +30,13 @@ <name>Reinier Zwitserloot</name> <email>reinier@projectlombok.org</email> <url>http://zwitserloot.com</url> - <timezone>+1</timezone> + <timezone>Europe/Amsterdam</timezone> </developer> <developer> <id>rspilker</id> <name>Roel Spilker</name> <email>roel@projectlombok.org</email> - <timezone>+1</timezone> - </developer> - <developer> - <id>rgrootjans</id> - <name>Robbert Jan Grootjans</name> - <timezone>+1</timezone> + <timezone>Europe/Amsterdam</timezone> </developer> </developers> </project> diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index b8c08047..00000000 --- a/jitpack.yml +++ /dev/null @@ -1,5 +0,0 @@ -jdk: -- openjdk10 -install: -- echo "Running a custom install command" -- ant install-maven
\ No newline at end of file diff --git a/src/core/lombok/eclipse/EclipseASTVisitor.java b/src/core/lombok/eclipse/EclipseASTVisitor.java index b2fd4b2f..37bda5e3 100644 --- a/src/core/lombok/eclipse/EclipseASTVisitor.java +++ b/src/core/lombok/eclipse/EclipseASTVisitor.java @@ -34,9 +34,14 @@ import org.eclipse.jdt.internal.compiler.ast.Argument; import org.eclipse.jdt.internal.compiler.ast.Block; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.Initializer; import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; +import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; +import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; +import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; @@ -351,7 +356,23 @@ public interface EclipseASTVisitor { } public void visitAnnotationOnMethod(AbstractMethodDeclaration method, EclipseNode node, Annotation annotation) { - forcePrint("<ANNOTATION%s: %s%s />", isGenerated(method) ? " (GENERATED)" : "", annotation, position(node)); + forcePrint("<ANNOTATION%s: %s%s>", isGenerated(method) ? " (GENERATED)" : "", annotation, position(node)); + if (annotation instanceof MarkerAnnotation || disablePrinting != 0) { + forcePrint("<ANNOTATION%s: %s%s />", isGenerated(method) ? " (GENERATED)" : "", annotation, position(node)); + } else { + forcePrint("<ANNOTATION%s: %s%s>", isGenerated(method) ? " (GENERATED)" : "", annotation, position(node)); + indent++; + if (annotation instanceof SingleMemberAnnotation) { + Expression expr = ((SingleMemberAnnotation) annotation).memberValue; + print("<SINGLE-MEMBER-VALUE %s /> %s", expr.getClass(), expr); + } + if (annotation instanceof NormalAnnotation) { + for (MemberValuePair mvp : ((NormalAnnotation) annotation).memberValuePairs) { + print("<Member %s: %s /> %s", new String(mvp.name), mvp.value.getClass(), mvp.value); + } + } + indent--; + } } public void endVisitMethod(EclipseNode node, AbstractMethodDeclaration method) { diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index f89ef061..1e29764a 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -24,8 +24,10 @@ package lombok.eclipse.handlers; import static lombok.core.handlers.HandlerUtil.*; import static lombok.eclipse.Eclipse.*; import static lombok.eclipse.EclipseAugments.*; +import static lombok.eclipse.handlers.EclipseHandlerUtil.EclipseReflectiveMembers.*; import java.lang.reflect.Constructor; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -64,14 +66,22 @@ import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; import org.eclipse.jdt.internal.compiler.ast.Block; import org.eclipse.jdt.internal.compiler.ast.CastExpression; +import org.eclipse.jdt.internal.compiler.ast.CharLiteral; +import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; +import org.eclipse.jdt.internal.compiler.ast.DoubleLiteral; import org.eclipse.jdt.internal.compiler.ast.EqualExpression; import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral; +import org.eclipse.jdt.internal.compiler.ast.FalseLiteral; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.FloatLiteral; import org.eclipse.jdt.internal.compiler.ast.IfStatement; import org.eclipse.jdt.internal.compiler.ast.IntLiteral; +import org.eclipse.jdt.internal.compiler.ast.Literal; +import org.eclipse.jdt.internal.compiler.ast.LongLiteral; import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; import org.eclipse.jdt.internal.compiler.ast.MessageSend; @@ -89,8 +99,10 @@ import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.StringLiteral; +import org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; +import org.eclipse.jdt.internal.compiler.ast.TrueLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.ast.TypeReference; @@ -250,6 +262,9 @@ public class EclipseHandlerUtil { MarkerAnnotation ann = new MarkerAnnotation(copyType(annotation.type, source), pS); setGeneratedBy(ann, source); ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = pE; + try { + reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, ann, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, annotation)); + } catch (Exception ignore) { /* Various eclipse versions don't have it */ } return ann; } @@ -257,8 +272,10 @@ public class EclipseHandlerUtil { SingleMemberAnnotation ann = new SingleMemberAnnotation(copyType(annotation.type, source), pS); setGeneratedBy(ann, source); ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = pE; - //TODO memberValue(s) need to be copied as well (same for copying a NormalAnnotation as below). - ann.memberValue = ((SingleMemberAnnotation)annotation).memberValue; + ann.memberValue = copyAnnotationMemberValue(((SingleMemberAnnotation) annotation).memberValue); + try { + reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, ann, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, annotation)); + } catch (Exception ignore) { /* Various eclipse versions don't have it */ } return ann; } @@ -266,13 +283,138 @@ public class EclipseHandlerUtil { NormalAnnotation ann = new NormalAnnotation(copyType(annotation.type, source), pS); setGeneratedBy(ann, source); ann.declarationSourceEnd = ann.statementEnd = ann.sourceEnd = pE; - ann.memberValuePairs = ((NormalAnnotation)annotation).memberValuePairs; + MemberValuePair[] inPairs = ((NormalAnnotation) annotation).memberValuePairs; + if (inPairs == null) { + ann.memberValuePairs = null; + } else { + ann.memberValuePairs = new MemberValuePair[inPairs.length]; + for (int i = 0; i < inPairs.length; i++) ann.memberValuePairs[i] = + new MemberValuePair(inPairs[i].name, inPairs[i].sourceStart, inPairs[i].sourceEnd, copyAnnotationMemberValue(inPairs[i].value)); + } + try { + reflectSet(ANNOTATION__MEMBER_VALUE_PAIR_NAME, ann, reflect(ANNOTATION__MEMBER_VALUE_PAIR_NAME, annotation)); + } catch (Exception ignore) { /* Various eclipse versions don't have it */ } return ann; } return annotation; } + static class EclipseReflectiveMembers { + public static final Field STRING_LITERAL__LINE_NUMBER; + public static final Field ANNOTATION__MEMBER_VALUE_PAIR_NAME; + public static final Field TYPE_REFERENCE__ANNOTATIONS; + static { + STRING_LITERAL__LINE_NUMBER = getField(StringLiteral.class, "lineNumber"); + ANNOTATION__MEMBER_VALUE_PAIR_NAME = getField(Annotation.class, "memberValuePairName"); + TYPE_REFERENCE__ANNOTATIONS = getField(TypeReference.class, "annotations"); + } + + public static int reflectInt(Field f, Object o) { + try { + return ((Number) f.get(o)).intValue(); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static void reflectSet(Field f, Object o, Object v) { + try { + f.set(o, v); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static Object reflect(Field f, Object o) { + try { + return f.get(o); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + private static Field getField(Class<?> c, String fName) { + try { + Field f = c.getDeclaredField(fName); + f.setAccessible(true); + return f; + } catch (Exception e) { + return null; + } + } + } + + private static Expression copyAnnotationMemberValue(Expression in) { + Expression out = copyAnnotationMemberValue0(in); + out.constant = in.constant; + return out; + } + + private static Expression copyAnnotationMemberValue0(Expression in) { + int s = in.sourceStart, e = in.sourceEnd; + + // literals + + if (in instanceof FalseLiteral) return new FalseLiteral(s, e); + if (in instanceof TrueLiteral) return new TrueLiteral(s, e); + if (in instanceof NullLiteral) return new NullLiteral(s, e); + + if (in instanceof CharLiteral) return new CharLiteral(((Literal) in).source(), s, e); + if (in instanceof DoubleLiteral) return new DoubleLiteral(((Literal) in).source(), s, e); + if (in instanceof FloatLiteral) return new FloatLiteral(((Literal) in).source(), s, e); + if (in instanceof IntLiteral) return IntLiteral.buildIntLiteral(((Literal) in).source(), s, e); + if (in instanceof LongLiteral) return LongLiteral.buildLongLiteral(((Literal) in).source(), s, e); + + if (in instanceof StringLiteral) return new StringLiteral(((Literal) in).source(), s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1); + if (in instanceof ExtendedStringLiteral) { + StringLiteral str = new StringLiteral(((Literal) in).source(), s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1); + StringLiteral empty = new StringLiteral(new char[0], s, e, reflectInt(STRING_LITERAL__LINE_NUMBER, in) + 1); + return new ExtendedStringLiteral(str, empty); + } + if (in instanceof StringLiteralConcatenation) { + Expression[] literals = ((StringLiteralConcatenation) in).literals; + // 0 and 1 len shouldn't happen. + if (literals.length == 0) return new StringLiteral(new char[0], s, e, 0); + if (literals.length == 1) return copyAnnotationMemberValue0(literals[0]); + StringLiteralConcatenation c = new StringLiteralConcatenation((StringLiteral) literals[0], (StringLiteral) literals[1]); + for (int i = 2; i < literals.length; i++) c = c.extendsWith((StringLiteral) literals[i]); + return c; + } + + // enums and field accesses (as long as those are references to compile time constant literals that's also acceptable) + + if (in instanceof SingleNameReference) { + SingleNameReference snr = (SingleNameReference) in; + long p = (long) s << 32 | e; + return new SingleNameReference(snr.token, p); + } + if (in instanceof QualifiedNameReference) { + QualifiedNameReference qnr = (QualifiedNameReference) in; + return new QualifiedNameReference(qnr.tokens, qnr.sourcePositions, s, e); + } + + // class refs + if (in instanceof ClassLiteralAccess) return new ClassLiteralAccess(e, copyType(((ClassLiteralAccess) in).type)); + + // arrays + if (in instanceof ArrayInitializer) { + Expression[] exprs = ((ArrayInitializer) in).expressions; + Expression[] copy = new Expression[exprs.length]; + for (int i = 0; i < exprs.length; i++) copy[i] = copyAnnotationMemberValue(exprs[i]); + ArrayInitializer out = new ArrayInitializer(); + out.sourceStart = s; + out.sourceEnd = e; + out.bits = in.bits; + out.implicitConversion = in.implicitConversion; + out.statementEnd = in.statementEnd; + out.expressions = copy; + return out; + } + + return in; + } + /** * You can't share TypeParameter objects or bad things happen; for example, one 'T' resolves differently * from another 'T', even for the same T in a single class file. Unfortunately the TypeParameter type hierarchy @@ -368,6 +510,7 @@ public class EclipseHandlerUtil { } TypeReference typeRef = new ParameterizedQualifiedTypeReference(iRef.tokens, args, iRef.dimensions(), copy(iRef.sourcePositions)); + copyTypeAnns(ref, typeRef); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } @@ -375,6 +518,7 @@ public class EclipseHandlerUtil { if (ref instanceof ArrayQualifiedTypeReference) { ArrayQualifiedTypeReference iRef = (ArrayQualifiedTypeReference) ref; TypeReference typeRef = new ArrayQualifiedTypeReference(iRef.tokens, iRef.dimensions(), copy(iRef.sourcePositions)); + copyTypeAnns(ref, typeRef); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } @@ -382,6 +526,7 @@ public class EclipseHandlerUtil { if (ref instanceof QualifiedTypeReference) { QualifiedTypeReference iRef = (QualifiedTypeReference) ref; TypeReference typeRef = new QualifiedTypeReference(iRef.tokens, copy(iRef.sourcePositions)); + copyTypeAnns(ref, typeRef); if (source != null) setGeneratedBy(typeRef, source); return typeRef; } @@ -398,32 +543,36 @@ public class EclipseHandlerUtil { } } |
