Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 416027 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.apt.pluggable.tests/.classpath (-1 / +1 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6
	<classpathentry kind="output" path="bin"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
7
</classpath>
(-)a/org.eclipse.jdt.apt.pluggable.tests/plugin.xml (+3 lines)
Lines 34-39 Link Here
34
         <java6processor
34
         <java6processor
35
               class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc">
35
               class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc">
36
         </java6processor>
36
         </java6processor>
37
         <java6processor
38
               class="org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTester8Proc">
39
         </java6processor>
37
      </java6processors>
40
      </java6processors>
38
   </extension>
41
   </extension>
39
</plugin>
42
</plugin>
(-)a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/ModelTests.java (+67 lines)
Lines 14-24 package org.eclipse.jdt.apt.pluggable.tests; Link Here
14
import junit.framework.Test;
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
15
import junit.framework.TestSuite;
16
16
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.jdt.apt.core.util.AptConfig;
23
import org.eclipse.jdt.apt.core.util.AptConfig;
24
import org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTester8Proc;
20
import org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc;
25
import org.eclipse.jdt.apt.pluggable.tests.processors.modeltester.ModelTesterProc;
21
import org.eclipse.jdt.core.IJavaProject;
26
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
22
28
23
/**
29
/**
24
 * Basic tests for the typesystem model interfaces in the IDE.
30
 * Basic tests for the typesystem model interfaces in the IDE.
Lines 81-84 public class ModelTests extends TestBase Link Here
81
		assertTrue("Processor did not run", ProcessorTestStatus.processorRan());
87
		assertTrue("Processor did not run", ProcessorTestStatus.processorRan());
82
		assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
88
		assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
83
	}	
89
	}	
90
91
	/**
92
	 * Call ModelTester8Proc.testMethodParameters(), which checks the type of a method
93
	 */
94
	@SuppressWarnings("restriction")
95
	public void testMethodParameters() throws Throwable {
96
		ProcessorTestStatus.reset();
97
		IJavaProject jproj = createJava8Project(_projectName);
98
		jproj.setOption(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
99
		jproj.setOption(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE);
100
		disableJava5Factories(jproj);
101
		IProject proj = jproj.getProject();
102
		IPath projPath = proj.getFullPath();
103
104
		env.addClass(projPath.append("src"), 
105
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_PKG,
106
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_CLASS,
107
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_SOURCE);
108
		env.addClass(projPath.append("src"), 
109
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_PKG,
110
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_CLASS,
111
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_SOURCE);
112
		fullBuild();
113
		expectingNoProblems();
114
		assertFalse("Processor ran too early", ProcessorTestStatus.processorRan());
115
116
		keepBinaryOnly(jproj,
117
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_PKG,
118
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE1_CLASS);
119
120
		keepBinaryOnly(jproj,
121
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_PKG,
122
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE2_CLASS);
123
124
		fullBuild();
125
126
		env.addClass(projPath.append("src"), 
127
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE3_PKG,
128
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE3_CLASS,
129
				ModelTester8Proc.TEST_METHOD_PARAMETERS_TYPE3_SOURCE);
130
		
131
		AptConfig.setEnabled(jproj, true);
132
		
133
		fullBuild();
134
		expectingNoProblems();
135
		assertTrue("Processor did not run", ProcessorTestStatus.processorRan());
136
		assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
137
	}
138
139
	private void keepBinaryOnly(IJavaProject jproj, String packageName, String className) throws CoreException {
140
		IFile realSourceFile = jproj.getProject().getFolder("src").getFolder(packageName).getFile(className + ".java");
141
		IFile compiledClassFile = jproj.getProject().getFolder("bin").getFolder(packageName).getFile(className + ".class");
142
		assertTrue("No compiled class for " + packageName + "." + className + ": ",compiledClassFile.exists());
143
		IFile prebuiltClassFile = jproj.getProject().getFolder("prebuilt").getFolder(packageName).getFile(className + ".class");
144
		assertFalse("Compiled class already in src: ",prebuiltClassFile.exists());
145
		compiledClassFile.copy(prebuiltClassFile.getFullPath(), true, new NullProgressMonitor());
146
		assertTrue("Compiled class not copied to src",prebuiltClassFile.exists());
147
		realSourceFile.delete(true, new NullProgressMonitor());
148
		assertFalse("Still source?: ", realSourceFile.exists());
149
	}
150
84
}
151
}
(-)a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/TestBase.java (-1 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 BEA Systems, Inc. and others.
2
 * Copyright (c) 2007, 2013 BEA Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     BEA Systems, Inc. - initial API and implementation
9
 *     BEA Systems, Inc. - initial API and implementation
10
 *    Jesper Steen Moller - Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.apt.pluggable.tests;
12
package org.eclipse.jdt.apt.pluggable.tests;
12
13
Lines 19-24 import org.eclipse.core.resources.IFile; Link Here
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
22
import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
24
import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
23
import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
25
import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
24
import org.eclipse.jdt.apt.core.internal.util.FactoryContainer.FactoryType;
26
import org.eclipse.jdt.apt.core.internal.util.FactoryContainer.FactoryType;
Lines 31-36 public class TestBase extends BuilderTests Link Here
31
{
33
{
32
34
33
	protected static final String JAVA_16_COMPLIANCE = "1.6";
35
	protected static final String JAVA_16_COMPLIANCE = "1.6";
36
	protected static final String JAVA_18_COMPLIANCE = "1.8";
34
	
37
	
35
	protected String _projectName;
38
	protected String _projectName;
36
	protected static int _projectSerial = 0; // used to create unique project names, to avoid resource deletion problems
39
	protected static int _projectSerial = 0; // used to create unique project names, to avoid resource deletion problems
Lines 81-86 public class TestBase extends BuilderTests Link Here
81
		addAnnotationJar(javaProj);
84
		addAnnotationJar(javaProj);
82
		return javaProj;
85
		return javaProj;
83
	}
86
	}
87
88
	/**
89
	 * Create a java project with java libraries and test annotations on classpath
90
	 * (compiler level is 1.8). Use "src" as source folder and "bin" as output folder. APT
91
	 * is not enabled.
92
	 * 
93
	 * @param projectName
94
	 * @return a java project that has been added to the current workspace.
95
	 * @throws Exception
96
	 */
97
	protected static IJavaProject createJava8Project(final String projectName) throws Exception
98
	{
99
		IPath projectPath = env.addProject(projectName, JAVA_18_COMPLIANCE);
100
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
101
		
102
		// remove old package fragment root so that names don't collide
103
		env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
104
		env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
105
		env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
106
		final IJavaProject javaProj = env.getJavaProject(projectPath);
107
		javaProj.getProject().getFolder("prebuilt").create(true, true, null);
108
		javaProj.getProject().getFolder("prebuilt").getFolder("p").create(true, true, null);
109
		env.addClassFolder(projectPath, projectPath.append("prebuilt"), true);
110
		addAnnotationJar(javaProj);
111
		return javaProj;
112
	}
84
	
113
	
85
	/**
114
	/**
86
	 * Ensure that there are no Java 5 processors on the factory path, as they can cause
115
	 * Ensure that there are no Java 5 processors on the factory path, as they can cause
(-)a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/annotations/ModelTest8Trigger.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Jesper Steen Moller and others.  
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Jesper Steen Moller - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.apt.pluggable.tests.annotations;
14
15
/**
16
 * 
17
 * @since 3.5
18
 */
19
public @interface ModelTest8Trigger {
20
	/** Name of test method to run */
21
	String test();
22
	
23
	/** Arbitrary argument */
24
	String arg0() default "";
25
26
	/** Arbitrary argument */
27
	String arg1() default "";
28
}
(-)a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/modeltester/ModelTester8Proc.java (+253 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2013 Jesper Steen Moller and others.  
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Jesper Steen Moller - initial API and implementation
10
 *    
11
 *******************************************************************************/
12
13
package org.eclipse.jdt.apt.pluggable.tests.processors.modeltester;
14
15
import java.lang.reflect.InvocationTargetException;
16
import java.lang.reflect.Method;
17
import java.util.HashMap;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22
23
import javax.annotation.processing.AbstractProcessor;
24
import javax.annotation.processing.ProcessingEnvironment;
25
import javax.annotation.processing.RoundEnvironment;
26
import javax.annotation.processing.SupportedAnnotationTypes;
27
import javax.annotation.processing.SupportedOptions;
28
import javax.annotation.processing.SupportedSourceVersion;
29
import javax.lang.model.SourceVersion;
30
import javax.lang.model.element.Element;
31
import javax.lang.model.element.ElementKind;
32
import javax.lang.model.element.ExecutableElement;
33
import javax.lang.model.element.TypeElement;
34
import javax.lang.model.element.VariableElement;
35
import javax.lang.model.type.DeclaredType;
36
import javax.lang.model.type.TypeKind;
37
import javax.lang.model.type.TypeMirror;
38
import javax.lang.model.util.ElementFilter;
39
40
import org.eclipse.jdt.apt.pluggable.tests.ProcessorTestStatus;
41
import org.eclipse.jdt.apt.pluggable.tests.annotations.LookAt;
42
import org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTest8Trigger;
43
44
/**
45
 * This processor tests features specific to JEP 118.
46
 * One processor can run many tests. The JUnit tests specify which test to run by passing its name in to the
47
 * ModelTest8Trigger annotation.
48
 * 
49
 * @since 3.9 BETA_JAVA8
50
 */
51
@SupportedAnnotationTypes( { "org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTest8Trigger" })
52
@SupportedSourceVersion(SourceVersion.RELEASE_8)
53
@SupportedOptions( {})
54
public class ModelTester8Proc extends AbstractProcessor {
55
	public static final String TEST_METHOD_PARAMETERS_TYPE1_PKG = "p";
56
	public static final String TEST_METHOD_PARAMETERS_TYPE1_CLASS = "Bar";
57
	public static final String TEST_METHOD_PARAMETERS_TYPE1_SOURCE =
58
			"package p;\n" +
59
					"public class Bar {\n" +
60
					"    public void otherStuff(final double fun, String beans) { }\n" +
61
					"}";
62
	
63
	public static final String TEST_METHOD_PARAMETERS_TYPE2_PKG = "p";
64
	public static final String TEST_METHOD_PARAMETERS_TYPE2_CLASS = "MyEnum";
65
	public static final String TEST_METHOD_PARAMETERS_TYPE2_SOURCE =
66
			"package p;\n" +
67
					"\n" + 
68
					"public enum MyEnum {\n" + 
69
					"	ONE(1), TWO(2);\n" + 
70
					"	\n" + 
71
					"	private MyEnum(final int finalIntValue) { this.var = finalIntValue; }\n" + 
72
					"	int var;\n" + 
73
					"}\n";
74
	
75
	public static final String TEST_METHOD_PARAMETERS_TYPE3_PKG = "p";
76
	public static final String TEST_METHOD_PARAMETERS_TYPE3_CLASS = "Foo";
77
	public static final String TEST_METHOD_PARAMETERS_TYPE3_SOURCE =
78
		"package p;\n" +
79
		"import org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTest8Trigger;\n" +
80
		"import org.eclipse.jdt.apt.pluggable.tests.annotations.LookAt;\n" +
81
		"@ModelTest8Trigger(test = \"testMethodParameters\")" +
82
		"public class Foo {\n" +
83
		"    @LookAt\n" +
84
		"    public Bar doStuff(final int number, String textual) { return null; }\n" +
85
		"    @LookAt\n" +
86
		"    public MyEnum guess(final int isItOne) { return isItOne == 1 ? MyEnum.ONE : MyEnum.TWO; }\n" +
87
		"}";
88
89
90
	@SuppressWarnings("unused")
91
	private ProcessingEnvironment _processingEnv;
92
	
93
	/*
94
	 * (non-Javadoc)
95
	 * 
96
	 * @see javax.annotation.processing.AbstractProcessor#init(javax.annotation.processing.ProcessingEnvironment)
97
	 */
98
	@Override
99
	public synchronized void init(ProcessingEnvironment processingEnv) {
100
		super.init(processingEnv);
101
		_processingEnv = processingEnv;
102
	}
103
104
	/*
105
	 * (non-Javadoc)
106
	 * 
107
	 * @see javax.annotation.processing.AbstractProcessor#process(java.util.Set,
108
	 *      javax.annotation.processing.RoundEnvironment)
109
	 */
110
	@Override
111
	public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
112
		ProcessorTestStatus.setProcessorRan();
113
		if (!roundEnv.processingOver() && !annotations.isEmpty()) {
114
			round(annotations, roundEnv);
115
		}
116
		return true;
117
	}
118
119
	/**
120
	 * Perform a round of processing: for a given annotation instance, determine what test method it
121
	 * specifies, and invoke that method, passing in the annotated element.
122
	 */
123
	private void round(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
124
		TypeElement modelTesterAnno = annotations.iterator().next();
125
		Set<? extends Element> annotatedEls = roundEnv.getElementsAnnotatedWith(modelTesterAnno);
126
		for (Element annotatedEl : annotatedEls) {
127
			ModelTest8Trigger modelTesterMirror = annotatedEl.getAnnotation(ModelTest8Trigger.class);
128
			String testMethodName = modelTesterMirror.test();
129
			String arg0 = modelTesterMirror.arg0();
130
			String arg1 = modelTesterMirror.arg1();
131
			if (null != testMethodName && testMethodName.length() > 0) {
132
				try {
133
					Method testMethod = ModelTester8Proc.class.getMethod(testMethodName, 
134
							RoundEnvironment.class, Element.class, String.class, String.class);
135
					testMethod.invoke(this, roundEnv, annotatedEl, arg0, arg1);
136
				} catch (Exception e) {
137
					Throwable t;
138
					t = (e instanceof InvocationTargetException) ? t = e.getCause() : e;
139
					t.printStackTrace();
140
					// IllegalStateException probably means test method called ProcessorTestStatus.fail()
141
					String msg = (t instanceof IllegalStateException) ?
142
							t.getMessage() :
143
							t.getClass().getSimpleName() + " invoking test method " + 
144
							testMethodName + " - see console for details";
145
					ProcessorTestStatus.fail(msg);
146
				}
147
			}
148
		}
149
	}
150
151
	
152
	/**
153
	 * Check the types of some methods (check that the annotation processing uses the parsed MethodParameters
154
	 * attribute from class files according to JEP 118)
155
	 * @see #TEST_METHOD_PARAMETERS_TYPE1_SOURCE
156
	 * @see #TEST_METHOD_PARAMETERS_TYPE2_SOURCE
157
	 * @see #TEST_METHOD_PARAMETERS_TYPE3_SOURCE
158
	 */
159
	public void testMethodParameters(RoundEnvironment roundEnv, Element e, String arg0, String arg1) 
160
			throws Exception 
161
	{
162
		Map<String, ExecutableElement> methods = new HashMap<String, ExecutableElement>();
163
		Iterable<? extends Element> elements;
164
165
		elements = roundEnv.getElementsAnnotatedWith(LookAt.class);
166
		for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
167
			methods.put(method.getSimpleName().toString(), method);
168
		}
169
170
		// Examine the easy case, the Foo.doStuff method
171
		ExecutableElement mDoStuff = methods.get("doStuff");
172
		if (mDoStuff == null) {
173
			ProcessorTestStatus.fail("Method doStuff() was not found");
174
		}
175
		if (mDoStuff.getKind() != ElementKind.METHOD) {
176
			ProcessorTestStatus.fail("ElementKind of method doStuff() was " + mDoStuff.getKind() + 
177
					", expected METHOD");
178
		}
179
		// Examine parameters
180
		List<? extends VariableElement> parameters = mDoStuff.getParameters();
181
		if (parameters.size() != 2) {
182
			ProcessorTestStatus.fail("Expected two parameters for doStuff()");
183
		}
184
		ProcessorTestStatus.assertEquals("Wrong name", "number", parameters.get(0).getSimpleName().toString());
185
		ProcessorTestStatus.assertEquals("Wrong name", "textual", parameters.get(1).getSimpleName().toString());
186
		
187
		///////////////////////////////////////////////////////////////////////////////////
188
		
189
		// Cool, now check 'p.Bar.otherStuff' which is also the return type of doStuff
190
		TypeMirror returnType = mDoStuff.getReturnType();
191
		if (returnType.getKind() != TypeKind.DECLARED)
192
			ProcessorTestStatus.fail("TypeKind of method doStuff()'s return type " + returnType.getKind() + 
193
					", expected DECLARED");
194
195
		DeclaredType barType = (DeclaredType) returnType;
196
		TypeElement bar = (TypeElement) barType.asElement();
197
		
198
		for (Element method : bar.getEnclosedElements()) {
199
			if (method.getKind() == ElementKind.METHOD)
200
				methods.put(method.getSimpleName().toString(), (ExecutableElement)method);
201
		}
202
		
203
		ExecutableElement mOtherStuff = methods.get("otherStuff");
204
		if (mOtherStuff == null) {
205
			ProcessorTestStatus.fail("Method otherStuff() was not found");
206
		}
207
		if (mOtherStuff.getKind() != ElementKind.METHOD) {
208
			ProcessorTestStatus.fail("ElementKind of method otherStuff() was " + mOtherStuff.getKind() + 
209
					", expected METHOD");
210
		}
211
		// Examine parameters
212
		List<? extends VariableElement> otherParameters = mOtherStuff.getParameters();
213
		if (otherParameters.size() != 2) {
214
			ProcessorTestStatus.fail("Expected two parameters for otherStuff()");
215
		}
216
		ProcessorTestStatus.assertEquals("Wrong name", "fun", otherParameters.get(0).getSimpleName().toString());
217
		ProcessorTestStatus.assertEquals("Wrong name", "beans", otherParameters.get(1).getSimpleName().toString());
218
219
		///////////////////////////////////////////////////////////////////////////////////
220
221
		// Examine the enum as returned by Foo.guess method
222
		ExecutableElement mGuess = methods.get("guess");
223
		if (mGuess == null) {
224
			ProcessorTestStatus.fail("Method guess() was not found");
225
		}
226
		if (mGuess.getKind() != ElementKind.METHOD) {
227
			ProcessorTestStatus.fail("ElementKind of method doStuff() was " + mGuess.getKind() + 
228
					", expected METHOD");
229
		}
230
		
231
		// Cool, now check 'p.Bar.otherStuff' which is also the return type of doStuff
232
		TypeMirror guessReturnType = mGuess.getReturnType();
233
		if (guessReturnType.getKind() != TypeKind.DECLARED)
234
			ProcessorTestStatus.fail("TypeKind of method guess()'s return type " + guessReturnType.getKind() + 
235
					", expected DECLARED");
236
237
		DeclaredType myEnumType = (DeclaredType) guessReturnType;
238
		TypeElement myEnumClass = (TypeElement) myEnumType.asElement();
239
240
		List<ExecutableElement> ctors = new LinkedList<ExecutableElement>();
241
		for (Element method : myEnumClass.getEnclosedElements()) {
242
			if (method.getKind() == ElementKind.CONSTRUCTOR) {
243
				ctors.add((ExecutableElement)method);
244
			}
245
		}
246
247
		ProcessorTestStatus.assertEquals("Bad # of constructors for MyEnum", 1, ctors.size());
248
		// Examine parameters
249
		List<? extends VariableElement> ctorParameters = ctors.get(0).getParameters();
250
		ProcessorTestStatus.assertEquals("Bad # of parameters for MyEnum ctor", 1, ctorParameters.size());
251
		ProcessorTestStatus.assertEquals("Wrong name", "finalIntValue", ctorParameters.get(0).getSimpleName().toString());
252
	}
253
}
(-)a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java (-36 / +16 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *    Jesper Steen Moller - Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.apt.model;
12
package org.eclipse.jdt.internal.compiler.apt.model;
12
13
Lines 35-41 import org.eclipse.jdt.internal.compiler.ast.Argument; Link Here
35
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.AnnotationHolder;
37
import org.eclipse.jdt.internal.compiler.lookup.AnnotationHolder;
37
import org.eclipse.jdt.internal.compiler.lookup.AptBinaryLocalVariableBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.AptBinaryLocalVariableBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
39
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
39
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
40
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
40
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
41
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
41
import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier;
Lines 143-191 public class ExecutableElementImpl extends ElementImpl implements Link Here
143
				}
143
				}
144
			} else {
144
			} else {
145
				// binary method
145
				// binary method
146
				boolean isEnumConstructor = binding.isConstructor()
147
						&& binding.declaringClass.isEnum()
148
						&& binding.declaringClass.isBinaryBinding()
149
						&& ((binding.modifiers & ExtraCompilerModifiers.AccGenericSignature) == 0);
150
				AnnotationBinding[][] parameterAnnotationBindings = null;
146
				AnnotationBinding[][] parameterAnnotationBindings = null;
151
				AnnotationHolder annotationHolder = binding.declaringClass.retrieveAnnotationHolder(binding, false);
147
				AnnotationHolder annotationHolder = binding.declaringClass.retrieveAnnotationHolder(binding, false);
152
				if (annotationHolder != null) {
148
				if (annotationHolder != null) {
153
					parameterAnnotationBindings = annotationHolder.getParameterAnnotations();
149
					parameterAnnotationBindings = annotationHolder.getParameterAnnotations();
154
				}
150
				}
155
				// we need to filter the synthetic arguments
151
				// we need to filter the synthetic arguments
156
				if (isEnumConstructor) {
152
				int i = 0;
157
					if (length == 2) {
153
				for (TypeBinding typeBinding : binding.parameters) {
158
						// the two arguments are only the two synthetic arguments
154
					char name[] = binding.parameterNames.length > i ? binding.parameterNames[i] : null;
159
						return Collections.emptyList();
155
					if (name == null) {
160
					}
156
 						StringBuilder builder = new StringBuilder("arg");//$NON-NLS-1$
161
					for (int i = 2; i < length; i++) {
162
						TypeBinding typeBinding = binding.parameters[i];
163
						StringBuilder builder = new StringBuilder("arg");//$NON-NLS-1$
164
						builder.append(i - 2);
165
						VariableElement param = new VariableElementImpl(_env,
166
								new AptBinaryLocalVariableBinding(
167
										String.valueOf(builder).toCharArray(),
168
										typeBinding,
169
										0,
170
										null,
171
										binding));
172
						params.add(param);
173
					}
174
				} else {
175
					int i = 0;
176
					for (TypeBinding typeBinding : binding.parameters) {
177
						StringBuilder builder = new StringBuilder("arg");//$NON-NLS-1$
178
						builder.append(i);
157
						builder.append(i);
179
						VariableElement param = new VariableElementImpl(_env,
158
						name = String.valueOf(builder).toCharArray();
180
								new AptBinaryLocalVariableBinding(
181
										String.valueOf(builder).toCharArray(),
182
										typeBinding,
183
										0,
184
										parameterAnnotationBindings != null ? parameterAnnotationBindings[i] : null,
185
										binding));
186
						params.add(param);
187
						i++;
188
					}
159
					}
160
					VariableElement param = new VariableElementImpl(_env,
161
							new AptBinaryLocalVariableBinding(
162
									name,
163
									typeBinding,
164
									0,
165
									parameterAnnotationBindings != null ? parameterAnnotationBindings[i] : null,
166
									binding));
167
					params.add(param);
168
					i++;
189
				}
169
				}
190
			}
170
			}
191
			return Collections.unmodifiableList(params);
171
			return Collections.unmodifiableList(params);

Return to bug 416027