### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/core/IMethod.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMethod.java,v retrieving revision 1.33 diff -u -r1.33 IMethod.java --- model/org/eclipse/jdt/core/IMethod.java 23 Apr 2010 13:11:05 -0000 1.33 +++ model/org/eclipse/jdt/core/IMethod.java 9 Feb 2011 16:28:53 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation 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 @@ -100,6 +100,16 @@ * @return the number of parameters of this method */ int getNumberOfParameters(); + +/** + * Returns the array of annotations for the parameter at the given index. + * + * @param index the index or order of the method parameter. + * @return the array of annotations for the specified parameter + * @throws JavaModelException + * @since 3.7 + */ +IAnnotation[] getParameterAnnotations(int index) throws JavaModelException; /** * Returns the binding key for this method only if the given method is {@link #isResolved() resolved}. * A binding key is a key that uniquely identifies this method. It allows access Index: model/org/eclipse/jdt/internal/core/BinaryMethod.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java,v retrieving revision 1.111 diff -u -r1.111 BinaryMethod.java --- model/org/eclipse/jdt/internal/core/BinaryMethod.java 20 Jan 2011 02:28:43 -0000 1.111 +++ model/org/eclipse/jdt/internal/core/BinaryMethod.java 9 Feb 2011 16:28:53 -0000 @@ -61,6 +61,15 @@ IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); return getAnnotations(binaryAnnotations, info.getTagBits()); } +/** + * @see IMethod#getParameterAnnotations(int) + */ +public IAnnotation[] getParameterAnnotations(int index) throws JavaModelException { + IBinaryMethod info = (IBinaryMethod) getElementInfo(); + IBinaryAnnotation[] binaryAnnotations = info.getParameterAnnotations(index); + return getAnnotations(binaryAnnotations, info.getTagBits()); +} + public IMemberValuePair getDefaultValue() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); Object defaultValue = info.getDefaultValue(); Index: model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java,v retrieving revision 1.87 diff -u -r1.87 CompilationUnitStructureRequestor.java --- model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 28 Jul 2010 16:17:01 -0000 1.87 +++ model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 9 Feb 2011 16:28:53 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation 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 @@ -22,6 +22,7 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.ISourceElementRequestor; +import org.eclipse.jdt.internal.compiler.ast.Argument; import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer; import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess; import org.eclipse.jdt.internal.compiler.ast.Expression; @@ -427,8 +428,44 @@ acceptAnnotation(annotation, info, handle); } } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783 + // Process the parameter annotations from the arguments + if (methodInfo.node != null && methodInfo.node.arguments != null) { + info.paramAnnotations = acceptParamAnnotations(methodInfo.node.arguments, handle, methodInfo); + } return info; } +private Annotation[][] acceptParamAnnotations(Argument[] arguments, JavaElement methodHandle, MethodInfo methodInfo) { + Annotation[][] paramAnnotations = new Annotation[methodInfo.node.arguments.length][]; + + for(int i = 0; i < methodInfo.node.arguments.length; i++) { + Argument argument = methodInfo.node.arguments[i]; + if (methodInfo.node.arguments[i].annotations != null) { + paramAnnotations[i] = new Annotation[argument.annotations.length]; + for (int j = 0; j < argument.annotations.length; j++ ) { + org.eclipse.jdt.internal.compiler.ast.Annotation annotation = argument.annotations[j]; + + String nameString = new String(CharOperation.concatWith(annotation.type.getTypeName(), '.')); + LocalVariable localVar = null; + String paramTypeSig = JavaModelManager.getJavaModelManager().intern(Signature.createTypeSignature(methodInfo.parameterTypes[i], false)); + // Create a ILocalVariable on the fly with already given information as this is a pseudo-element anyway. + localVar = new LocalVariable( + methodHandle, + new String(argument.name), + argument.declarationSourceStart, + argument. declarationSourceEnd, + argument.sourceStart, + argument.sourceEnd, + paramTypeSig, + argument.annotations, + argument.modifiers, + true); + paramAnnotations[i][j] = createAnnotation(localVar, nameString); + } + } + } + return paramAnnotations; +} /** * @see ISourceElementRequestor */ Index: model/org/eclipse/jdt/internal/core/SourceMethod.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethod.java,v retrieving revision 1.68 diff -u -r1.68 SourceMethod.java --- model/org/eclipse/jdt/internal/core/SourceMethod.java 27 Jun 2008 16:03:51 -0000 1.68 +++ model/org/eclipse/jdt/internal/core/SourceMethod.java 9 Feb 2011 16:28:53 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation 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 @@ -316,4 +316,12 @@ buffer.append(this.occurrenceCount); } } +/** + * @see IMethod#getParameterAnnotations(int) + */ +public IAnnotation[] getParameterAnnotations(int index) throws JavaModelException { + Object object = getElementInfo(); + IAnnotation[] paramAnnots = ((SourceMethodInfo) object).getParamAnnotations(index); + return paramAnnots; +} } Index: model/org/eclipse/jdt/internal/core/SourceMethodElementInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethodElementInfo.java,v retrieving revision 1.22 diff -u -r1.22 SourceMethodElementInfo.java --- model/org/eclipse/jdt/internal/core/SourceMethodElementInfo.java 27 Jun 2008 16:03:50 -0000 1.22 +++ model/org/eclipse/jdt/internal/core/SourceMethodElementInfo.java 9 Feb 2011 16:28:53 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation 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 @@ -38,7 +38,15 @@ * For example, Hashtable or java.util.Hashtable. */ protected char[][] exceptionTypes; + + /** + * Array of annotations if any associated with the parameters of this method. + */ + protected Annotation[][] paramAnnotations; + public IAnnotation[] getParamAnnotations(int index) { + return this.paramAnnotations[index]; + } /* * The type parameters of this source type. Empty if none. */ #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java,v retrieving revision 1.14 diff -u -r1.14 TypeResolveTests.java --- src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java 27 Jun 2008 16:02:40 -0000 1.14 +++ src/org/eclipse/jdt/core/tests/model/TypeResolveTests.java 9 Feb 2011 16:28:55 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation 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 @@ -10,9 +10,12 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.model; +import java.io.IOException; + import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.*; import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.LocalVariable; import junit.framework.Test; @@ -299,4 +302,71 @@ "p4.A.Inner", types); } +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations() throws CoreException { + try { + createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); + String source = "package p;" + + "public class X {\n" + + " X field;\n" + + " @Inject " + + " public void Test(@Default String processor) {}" + + "}" + + "@interface Inject{\n" + + "}" + + "@interface Default{\n" + + "}"; + createFolder("/P/src/p"); + createFile( + "/P/src/p/X.java", + source + ); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + IJavaElement[] variable = ((ICodeAssist) unit).codeSelect(source.indexOf("processor"), "processor".length()); + + assertEquals(1, variable.length); + String annotationString = "@Default (not open) [in processor [in Test(String) [in X [in X.java [in p [in src [in P]]]]]]]"; + assertEquals(annotationString, ((LocalVariable)variable[0]).getAnnotations()[0].toString()); + IType type = unit.getType("X"); + + IMethod method = type.getMethods()[0]; + assertEquals(annotationString, method.getParameterAnnotations(0)[0].toString()); + } finally { + deleteProject("P"); + } +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations2() throws CoreException, IOException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); + String[] pathAndContents = new String[]{"p/X.java", + "package p;" + + "public class X {\n" + + " X field;\n" + + " @Inject " + + " public void Test(@Default String processor) {}" + + "}" + + "@interface Inject{\n" + + "}" + + "@interface Default{\n" + + "}"}; + addLibrary(project, "lib334783.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5); + + waitForAutoBuild(); + IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783.jar")); + IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); + String annotationString = "@p.Default (not open) [in Test(java.lang.String) [in X [in X.class [in p [in lib334783.jar [in P]]]]]]"; + + IMethod method = type.getMethods()[1]; + assertEquals(annotationString, method.getParameterAnnotations(0)[0].toString()); + } finally { + deleteProject("P"); + } +} }