Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 234840 Details for
Bug 416027
[1.8] Enable reflected parameter names during annotation processing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Jesper's patch brought forward from bug 412150
apt.patch (text/plain), 26.89 KB, created by
Srikanth Sankaran
on 2013-08-28 06:30:19 EDT
(
hide
)
Description:
Jesper's patch brought forward from bug 412150
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2013-08-28 06:30:19 EDT
Size:
26.89 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.apt.pluggable.tests/.classpath b/org.eclipse.jdt.apt.pluggable.tests/.classpath >index 121e527..22f3064 100644 >--- a/org.eclipse.jdt.apt.pluggable.tests/.classpath >+++ b/org.eclipse.jdt.apt.pluggable.tests/.classpath >@@ -1,7 +1,7 @@ > <?xml version="1.0" encoding="UTF-8"?> > <classpath> > <classpathentry kind="src" path="src"/> >- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> >+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> > <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> > <classpathentry kind="output" path="bin"/> > </classpath> >diff --git a/org.eclipse.jdt.apt.pluggable.tests/lib/annotations.jar b/org.eclipse.jdt.apt.pluggable.tests/lib/annotations.jar >index 693ee8154d8c087dd7fb0e0834d3e4b0a86d65b8..3b2f93959b6971ebe958fc29d2209228379b683e 100644 >GIT binary patch >delta 656 >zcmdld`A>!~z?+#xgn<JH4{?h-Pvnbbnac>I^S^=V&8{5mj65(EAeqVQnH)B+WMpE5 >z$ggK|fwI0c*Fabx6_eL;i%mYu`U0Y8CtC-j&`u6<X9gtT&M^5sxAEi;OdRzVAw`+# >z>8V9}$vKI|#i{-0y_gLJj_u!ab#47>g}qh6do5mheh8T`PlW$1x6k(E6GD?zPyQ;9 >zt6`A$n&Vm^$bY!zPujE7)6cK}&d*RjBUD0CCux()*797jtZl73bg%q67j>^<q0-Kj >zM*>L?A0?gmBD4L`^{)5VPey95Japv2lKO|{YUdALI=yV-u8<q17V<9=9J}K)4PMF{ >zSnS?YB~=!#x-&t(<kZP~5_9;(`#+tUd!74_Pd@Lr@QvPEb>@mU|J+}3eee6$i+?v> >z>#M6>Q>pE9@%g>W>%?r&S_BmQU|(SqWO?YLd4M-N2fzO&?rXp>FlS_72=HcP5@7%Z >zJsTwKCr5EQfx~O^0?srD!=6WKvI>{k<bEFM$pu_o5J4_3DW*IoVBi@|UdbpnIgg76 >zB3=g+-@*(HR8f$)0w}^b_sG2v2HLj_i0zTWpMl{I3)m0`ZfS@C@!V33HIv@~BV{eO >z5?Jr)sP;<=Kz%2G*bYVSK6ap99|cgPB74dmMUfXL)HNI`s8Jl?&B_K+$q9s)nHd<S >Ha)EdNC0*67 > >delta 395 >zcmew-vrm#Qz?+#xgn<JHAF>wMPUMSaQCsC|J2C$onBH8&<irSOO|D^bm^^_;Y_bH) >zJBSn)YYmdrDYkzQ;WO+Vj4UgFW^K-7WM|}KWD;ROm_K<bmlMRe*Ia23#yM`O$@$!7 >zljV366hKzrVBg7kg@J*=l#zkK4M-!vLZ-=u+(tl0D1jAn?vZ;T3{<oXi0u)ofUK9y >zV1-_+{5k>N2nT>nzmw|x_#9A)CWh&mtYA&2*u*C9<K_X|a5}2}k^)fS2_UvZv0*hE >vSTPR=ABqhiZ{L2A`)C$W@g*SkM$u%>0o3F#!pa5`1%-GVGXsMcCx{0Cw?0(! > >diff --git a/org.eclipse.jdt.apt.pluggable.tests/plugin.xml b/org.eclipse.jdt.apt.pluggable.tests/plugin.xml >index cd521de..c0f7fd2 100644 >--- a/org.eclipse.jdt.apt.pluggable.tests/plugin.xml >+++ b/org.eclipse.jdt.apt.pluggable.tests/plugin.xml >@@ -34,6 +34,9 @@ > <java6processor > class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc"> > </java6processor> >+ <java6processor >+ class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTester8Proc"> >+ </java6processor> > </java6processors> > </extension> > </plugin> >diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/ModelTests.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/ModelTests.java >index 98c20e6..7fec114 100644 >--- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/ModelTests.java >+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/ModelTests.java >@@ -14,11 +14,17 @@ package org.eclipse.jdt.apt.pluggable.tests; > import junit.framework.Test; > import junit.framework.TestSuite; > >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; > import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.jdt.apt.core.util.AptConfig; >+import org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTester8Proc; > import org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc; > import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > > /** > * Basic tests for the typesystem model interfaces in the IDE. >@@ -81,4 +87,65 @@ public class ModelTests extends TestBase > assertTrue("Processor did not run", ProcessorTestStatus.processorRan()); > assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors()); > } >+ >+ /** >+ * Call ModelTester8Proc.testMethodParameters(), which checks the type of a method >+ */ >+ @SuppressWarnings("restriction") >+ public void testMethodParameters() throws Throwable { >+ ProcessorTestStatus.reset(); >+ IJavaProject jproj = createJava8Project(_projectName); >+ jproj.setOption(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); >+ jproj.setOption(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE); >+ disableJava5Factories(jproj); >+ IProject proj = jproj.getProject(); >+ IPath projPath = proj.getFullPath(); >+ >+ env.addClass(projPath.append("src"), >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_PKG, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_CLASS, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_SOURCE); >+ env.addClass(projPath.append("src"), >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_PKG, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_CLASS, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_SOURCE); >+ fullBuild(); >+ expectingNoProblems(); >+ assertFalse("Processor ran too early", ProcessorTestStatus.processorRan()); >+ >+ keepBinaryOnly(jproj, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_PKG, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_CLASS); >+ >+ keepBinaryOnly(jproj, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_PKG, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_CLASS); >+ >+ fullBuild(); >+ >+ env.addClass(projPath.append("src"), >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE3_PKG, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE3_CLASS, >+ ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE3_SOURCE); >+ >+ AptConfig.setEnabled(jproj, true); >+ >+ fullBuild(); >+ expectingNoProblems(); >+ assertTrue("Processor did not run", ProcessorTestStatus.processorRan()); >+ assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors()); >+ } >+ >+ private void keepBinaryOnly(IJavaProject jproj, String packageName, String className) throws CoreException { >+ IFile realSourceFile = jproj.getProject().getFolder("src").getFolder(packageName).getFile(className + ".java"); >+ IFile compiledClassFile = jproj.getProject().getFolder("bin").getFolder(packageName).getFile(className + ".class"); >+ assertTrue("No compiled class for " + packageName + "." + className + ": ",compiledClassFile.exists()); >+ IFile prebuiltClassFile = jproj.getProject().getFolder("prebuilt").getFolder(packageName).getFile(className + ".class"); >+ assertFalse("Compiled class already in src: ",prebuiltClassFile.exists()); >+ compiledClassFile.copy(prebuiltClassFile.getFullPath(), true, new NullProgressMonitor()); >+ assertTrue("Compiled class not copied to src",prebuiltClassFile.exists()); >+ realSourceFile.delete(true, new NullProgressMonitor()); >+ assertFalse("Still source?: ", realSourceFile.exists()); >+ } >+ > } >diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java >index 99789a0..2f3fa36 100644 >--- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java >+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2008 BEA Systems, Inc. and others. >+ * Copyright (c) 2007, 2013 BEA Systems, Inc. and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * BEA Systems, Inc. - initial API and implementation >+ * Jesper Steen Moller - Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing > *******************************************************************************/ > package org.eclipse.jdt.apt.pluggable.tests; > >@@ -19,6 +20,7 @@ import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.apt.core.internal.util.FactoryContainer; > import org.eclipse.jdt.apt.core.internal.util.FactoryPath; > import org.eclipse.jdt.apt.core.internal.util.FactoryContainer.FactoryType; >@@ -31,6 +33,7 @@ public class TestBase extends BuilderTests > { > > protected static final String JAVA_16_COMPLIANCE = "1.6"; >+ protected static final String JAVA_18_COMPLIANCE = "1.8"; > > protected String _projectName; > protected static int _projectSerial = 0; // used to create unique project names, to avoid resource deletion problems >@@ -81,6 +84,32 @@ public class TestBase extends BuilderTests > addAnnotationJar(javaProj); > return javaProj; > } >+ >+ /** >+ * Create a java project with java libraries and test annotations on classpath >+ * (compiler level is 1.8). Use "src" as source folder and "bin" as output folder. APT >+ * is not enabled. >+ * >+ * @param projectName >+ * @return a java project that has been added to the current workspace. >+ * @throws Exception >+ */ >+ protected static IJavaProject createJava8Project(final String projectName) throws Exception >+ { >+ IPath projectPath = env.addProject(projectName, JAVA_18_COMPLIANCE); >+ env.addExternalJars(projectPath, Util.getJavaClassLibs()); >+ >+ // remove old package fragment root so that names don't collide >+ env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ >+ env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ >+ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ >+ final IJavaProject javaProj = env.getJavaProject(projectPath); >+ javaProj.getProject().getFolder("prebuilt").create(true, true, null); >+ javaProj.getProject().getFolder("prebuilt").getFolder("p").create(true, true, null); >+ env.addClassFolder(projectPath, projectPath.append("prebuilt"), true); >+ addAnnotationJar(javaProj); >+ return javaProj; >+ } > > /** > * Ensure that there are no Java 5 processors on the factory path, as they can cause >diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/ModelTest8Trigger.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/ModelTest8Trigger.java >new file mode 100644 >index 0000000..426d595 >--- /dev/null >+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/ModelTest8Trigger.java >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * Copyright (c) 2013 Jesper Steen Moller and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Jesper Steen Moller - initial API and implementation >+ * >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.apt.pluggable.tests.annotations; >+ >+/** >+ * >+ * @since 3.5 >+ */ >+public @interface ModelTest8Trigger { >+ /** Name of test method to run */ >+ String test(); >+ >+ /** Arbitrary argument */ >+ String arg0() default ""; >+ >+ /** Arbitrary argument */ >+ String arg1() default ""; >+} >diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/modeltester/ModelTester8Proc.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/modeltester/ModelTester8Proc.java >new file mode 100644 >index 0000000..f612626 >--- /dev/null >+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/modeltester/ModelTester8Proc.java >@@ -0,0 +1,253 @@ >+/******************************************************************************* >+ * Copyright (c) 2013 Jesper Steen Moller and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Jesper Steen Moller - initial API and implementation >+ * >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.apt.pluggable.tests.processors.modeltester; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+import java.util.HashMap; >+import java.util.LinkedList; >+import java.util.List; >+import java.util.Map; >+import java.util.Set; >+ >+import javax.annotation.processing.AbstractProcessor; >+import javax.annotation.processing.ProcessingEnvironment; >+import javax.annotation.processing.RoundEnvironment; >+import javax.annotation.processing.SupportedAnnotationTypes; >+import javax.annotation.processing.SupportedOptions; >+import javax.annotation.processing.SupportedSourceVersion; >+import javax.lang.model.SourceVersion; >+import javax.lang.model.element.Element; >+import javax.lang.model.element.ElementKind; >+import javax.lang.model.element.ExecutableElement; >+import javax.lang.model.element.TypeElement; >+import javax.lang.model.element.VariableElement; >+import javax.lang.model.type.DeclaredType; >+import javax.lang.model.type.TypeKind; >+import javax.lang.model.type.TypeMirror; >+import javax.lang.model.util.ElementFilter; >+ >+import org.eclipse.jdt.apt.pluggable.tests.ProcessorTestStatus; >+import org.eclipse.jdt.apt.pluggable.tests.annotations.LookAt; >+import org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTest8Trigger; >+ >+/** >+ * This processor tests features specific to JEP 118. >+ * One processor can run many tests. The JUnit tests specify which test to run by passing its name in to the >+ * ModelTest8Trigger annotation. >+ * >+ * @since 3.9 BETA_JAVA8 >+ */ >+@SupportedAnnotationTypes( { "org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTest8Trigger" }) >+@SupportedSourceVersion(SourceVersion.RELEASE_8) >+@SupportedOptions( {}) >+public class ModelTester8Proc extends AbstractProcessor { >+ public static final String TEST_METHOD_PARAMETERS_TYPE1_PKG = "p"; >+ public static final String TEST_METHOD_PARAMETERS_TYPE1_CLASS = "Bar"; >+ public static final String TEST_METHOD_PARAMETERS_TYPE1_SOURCE = >+ "package p;\n" + >+ "public class Bar {\n" + >+ " public void otherStuff(final double fun, String beans) { }\n" + >+ "}"; >+ >+ public static final String TEST_METHOD_PARAMETERS_TYPE2_PKG = "p"; >+ public static final String TEST_METHOD_PARAMETERS_TYPE2_CLASS = "MyEnum"; >+ public static final String TEST_METHOD_PARAMETERS_TYPE2_SOURCE = >+ "package p;\n" + >+ "\n" + >+ "public enum MyEnum {\n" + >+ " ONE(1), TWO(2);\n" + >+ " \n" + >+ " private MyEnum(final int finalIntValue) { this.var = finalIntValue; }\n" + >+ " int var;\n" + >+ "}\n"; >+ >+ public static final String TEST_METHOD_PARAMETERS_TYPE3_PKG = "p"; >+ public static final String TEST_METHOD_PARAMETERS_TYPE3_CLASS = "Foo"; >+ public static final String TEST_METHOD_PARAMETERS_TYPE3_SOURCE = >+ "package p;\n" + >+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTest8Trigger;\n" + >+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.LookAt;\n" + >+ "@ModelTest8Trigger(test = \"testMethodParameters\")" + >+ "public class Foo {\n" + >+ " @LookAt\n" + >+ " public Bar doStuff(final int number, String textual) { return null; }\n" + >+ " @LookAt\n" + >+ " public MyEnum guess(final int isItOne) { return isItOne == 1 ? MyEnum.ONE : MyEnum.TWO; }\n" + >+ "}"; >+ >+ >+ @SuppressWarnings("unused") >+ private ProcessingEnvironment _processingEnv; >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see javax.annotation.processing.AbstractProcessor#init(javax.annotation.processing.ProcessingEnvironment) >+ */ >+ @Override >+ public synchronized void init(ProcessingEnvironment processingEnv) { >+ super.init(processingEnv); >+ _processingEnv = processingEnv; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see javax.annotation.processing.AbstractProcessor#process(java.util.Set, >+ * javax.annotation.processing.RoundEnvironment) >+ */ >+ @Override >+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { >+ ProcessorTestStatus.setProcessorRan(); >+ if (!roundEnv.processingOver() && !annotations.isEmpty()) { >+ round(annotations, roundEnv); >+ } >+ return true; >+ } >+ >+ /** >+ * Perform a round of processing: for a given annotation instance, determine what test method it >+ * specifies, and invoke that method, passing in the annotated element. >+ */ >+ private void round(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { >+ TypeElement modelTesterAnno = annotations.iterator().next(); >+ Set<? extends Element> annotatedEls = roundEnv.getElementsAnnotatedWith(modelTesterAnno); >+ for (Element annotatedEl : annotatedEls) { >+ ModelTest8Trigger modelTesterMirror = annotatedEl.getAnnotation(ModelTest8Trigger.class); >+ String testMethodName = modelTesterMirror.test(); >+ String arg0 = modelTesterMirror.arg0(); >+ String arg1 = modelTesterMirror.arg1(); >+ if (null != testMethodName && testMethodName.length() > 0) { >+ try { >+ Method testMethod = ModelTester8Proc.class.getMethod(testMethodName, >+ RoundEnvironment.class, Element.class, String.class, String.class); >+ testMethod.invoke(this, roundEnv, annotatedEl, arg0, arg1); >+ } catch (Exception e) { >+ Throwable t; >+ t = (e instanceof InvocationTargetException) ? t = e.getCause() : e; >+ t.printStackTrace(); >+ // IllegalStateException probably means test method called ProcessorTestStatus.fail() >+ String msg = (t instanceof IllegalStateException) ? >+ t.getMessage() : >+ t.getClass().getSimpleName() + " invoking test method " + >+ testMethodName + " - see console for details"; >+ ProcessorTestStatus.fail(msg); >+ } >+ } >+ } >+ } >+ >+ >+ /** >+ * Check the types of some methods (check that the annotation processing uses the parsed MethodParameters >+ * attribute from class files according to JEP 118) >+ * @see #TEST_METHOD_PARAMETERS_TYPE1_SOURCE >+ * @see #TEST_METHOD_PARAMETERS_TYPE2_SOURCE >+ * @see #TEST_METHOD_PARAMETERS_TYPE3_SOURCE >+ */ >+ public void testMethodParameters(RoundEnvironment roundEnv, Element e, String arg0, String arg1) >+ throws Exception >+ { >+ Map<String, ExecutableElement> methods = new HashMap<String, ExecutableElement>(); >+ Iterable<? extends Element> elements; >+ >+ elements = roundEnv.getElementsAnnotatedWith(LookAt.class); >+ for (ExecutableElement method : ElementFilter.methodsIn(elements)) { >+ methods.put(method.getSimpleName().toString(), method); >+ } >+ >+ // Examine the easy case, the Foo.doStuff method >+ ExecutableElement mDoStuff = methods.get("doStuff"); >+ if (mDoStuff == null) { >+ ProcessorTestStatus.fail("Method doStuff() was not found"); >+ } >+ if (mDoStuff.getKind() != ElementKind.METHOD) { >+ ProcessorTestStatus.fail("ElementKind of method doStuff() was " + mDoStuff.getKind() + >+ ", expected METHOD"); >+ } >+ // Examine parameters >+ List<? extends VariableElement> parameters = mDoStuff.getParameters(); >+ if (parameters.size() != 2) { >+ ProcessorTestStatus.fail("Expected two parameters for doStuff()"); >+ } >+ ProcessorTestStatus.assertEquals("Wrong name", "number", parameters.get(0).getSimpleName().toString()); >+ ProcessorTestStatus.assertEquals("Wrong name", "textual", parameters.get(1).getSimpleName().toString()); >+ >+ /////////////////////////////////////////////////////////////////////////////////// >+ >+ // Cool, now check 'p.Bar.otherStuff' which is also the return type of doStuff >+ TypeMirror returnType = mDoStuff.getReturnType(); >+ if (returnType.getKind() != TypeKind.DECLARED) >+ ProcessorTestStatus.fail("TypeKind of method doStuff()'s return type " + returnType.getKind() + >+ ", expected DECLARED"); >+ >+ DeclaredType barType = (DeclaredType) returnType; >+ TypeElement bar = (TypeElement) barType.asElement(); >+ >+ for (Element method : bar.getEnclosedElements()) { >+ if (method.getKind() == ElementKind.METHOD) >+ methods.put(method.getSimpleName().toString(), (ExecutableElement)method); >+ } >+ >+ ExecutableElement mOtherStuff = methods.get("otherStuff"); >+ if (mOtherStuff == null) { >+ ProcessorTestStatus.fail("Method otherStuff() was not found"); >+ } >+ if (mOtherStuff.getKind() != ElementKind.METHOD) { >+ ProcessorTestStatus.fail("ElementKind of method otherStuff() was " + mOtherStuff.getKind() + >+ ", expected METHOD"); >+ } >+ // Examine parameters >+ List<? extends VariableElement> otherParameters = mOtherStuff.getParameters(); >+ if (otherParameters.size() != 2) { >+ ProcessorTestStatus.fail("Expected two parameters for otherStuff()"); >+ } >+ ProcessorTestStatus.assertEquals("Wrong name", "fun", otherParameters.get(0).getSimpleName().toString()); >+ ProcessorTestStatus.assertEquals("Wrong name", "beans", otherParameters.get(1).getSimpleName().toString()); >+ >+ /////////////////////////////////////////////////////////////////////////////////// >+ >+ // Examine the enum as returned by Foo.guess method >+ ExecutableElement mGuess = methods.get("guess"); >+ if (mGuess == null) { >+ ProcessorTestStatus.fail("Method guess() was not found"); >+ } >+ if (mGuess.getKind() != ElementKind.METHOD) { >+ ProcessorTestStatus.fail("ElementKind of method doStuff() was " + mGuess.getKind() + >+ ", expected METHOD"); >+ } >+ >+ // Cool, now check 'p.Bar.otherStuff' which is also the return type of doStuff >+ TypeMirror guessReturnType = mGuess.getReturnType(); >+ if (guessReturnType.getKind() != TypeKind.DECLARED) >+ ProcessorTestStatus.fail("TypeKind of method guess()'s return type " + guessReturnType.getKind() + >+ ", expected DECLARED"); >+ >+ DeclaredType myEnumType = (DeclaredType) guessReturnType; >+ TypeElement myEnumClass = (TypeElement) myEnumType.asElement(); >+ >+ List<ExecutableElement> ctors = new LinkedList<ExecutableElement>(); >+ for (Element method : myEnumClass.getEnclosedElements()) { >+ if (method.getKind() == ElementKind.CONSTRUCTOR) { >+ ctors.add((ExecutableElement)method); >+ } >+ } >+ >+ ProcessorTestStatus.assertEquals("Bad # of constructors for MyEnum", 1, ctors.size()); >+ // Examine parameters >+ List<? extends VariableElement> ctorParameters = ctors.get(0).getParameters(); >+ ProcessorTestStatus.assertEquals("Bad # of parameters for MyEnum ctor", 1, ctorParameters.size()); >+ ProcessorTestStatus.assertEquals("Wrong name", "finalIntValue", ctorParameters.get(0).getSimpleName().toString()); >+ } >+} >diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java >index 33b8241..b8f2367 100644 >--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java >+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Jesper Steen Moller - Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.apt.model; > >@@ -35,7 +36,6 @@ import org.eclipse.jdt.internal.compiler.ast.Argument; > import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; > import org.eclipse.jdt.internal.compiler.lookup.AnnotationHolder; > import org.eclipse.jdt.internal.compiler.lookup.AptBinaryLocalVariableBinding; >-import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; > import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; > import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; > import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier; >@@ -143,49 +143,29 @@ public class ExecutableElementImpl extends ElementImpl implements > } > } else { > // binary method >- boolean isEnumConstructor = binding.isConstructor() >- && binding.declaringClass.isEnum() >- && binding.declaringClass.isBinaryBinding() >- && ((binding.modifiers & ExtraCompilerModifiers.AccGenericSignature) == 0); > AnnotationBinding[][] parameterAnnotationBindings = null; > AnnotationHolder annotationHolder = binding.declaringClass.retrieveAnnotationHolder(binding, false); > if (annotationHolder != null) { > parameterAnnotationBindings = annotationHolder.getParameterAnnotations(); > } > // we need to filter the synthetic arguments >- if (isEnumConstructor) { >- if (length == 2) { >- // the two arguments are only the two synthetic arguments >- return Collections.emptyList(); >- } >- for (int i = 2; i < length; i++) { >- TypeBinding typeBinding = binding.parameters[i]; >- StringBuilder builder = new StringBuilder("arg");//$NON-NLS-1$ >- builder.append(i - 2); >- VariableElement param = new VariableElementImpl(_env, >- new AptBinaryLocalVariableBinding( >- String.valueOf(builder).toCharArray(), >- typeBinding, >- 0, >- null, >- binding)); >- params.add(param); >- } >- } else { >- int i = 0; >- for (TypeBinding typeBinding : binding.parameters) { >- StringBuilder builder = new StringBuilder("arg");//$NON-NLS-1$ >+ int i = 0; >+ for (TypeBinding typeBinding : binding.parameters) { >+ char name[] = binding.parameterNames.length > i ? binding.parameterNames[i] : null; >+ if (name == null) { >+ StringBuilder builder = new StringBuilder("arg");//$NON-NLS-1$ > builder.append(i); >- VariableElement param = new VariableElementImpl(_env, >- new AptBinaryLocalVariableBinding( >- String.valueOf(builder).toCharArray(), >- typeBinding, >- 0, >- parameterAnnotationBindings != null ? parameterAnnotationBindings[i] : null, >- binding)); >- params.add(param); >- i++; >+ name = String.valueOf(builder).toCharArray(); > } >+ VariableElement param = new VariableElementImpl(_env, >+ new AptBinaryLocalVariableBinding( >+ name, >+ typeBinding, >+ 0, >+ parameterAnnotationBindings != null ? parameterAnnotationBindings[i] : null, >+ binding)); >+ params.add(param); >+ i++; > } > } > return Collections.unmodifiableList(params); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 416027
: 234840 |
242394