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 188895 Details for
Bug 334783
[API] Add new API to ease the retrieval of the parameter annotations for an IMethod
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Modified patch
bug_334783_markus.txt (text/plain), 16.43 KB, created by
Jay Arthanareeswaran
on 2011-02-14 07:40:16 EST
(
hide
)
Description:
Modified patch
Filename:
MIME Type:
Creator:
Jay Arthanareeswaran
Created:
2011-02-14 07:40:16 EST
Size:
16.43 KB
patch
obsolete
>### 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 14 Feb 2011 12:17:21 -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,17 @@ > * @return the number of parameters of this method > */ > int getNumberOfParameters(); >+ >+/** >+ * Returns a two-dimensional array of annotations for this method's parameters. If the >+ * number of parameters is zero, <code>null</code> is returned. >+ * >+ * @return the array of annotations for the specified parameter >+ * @throws JavaModelException >+ * @since 3.7 >+ */ >+IAnnotation[][] getParameterAnnotations() 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 14 Feb 2011 12:17:21 -0000 >@@ -11,7 +11,15 @@ > package org.eclipse.jdt.internal.core; > > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.jdt.core.*; >+import org.eclipse.jdt.core.Flags; >+import org.eclipse.jdt.core.IAnnotation; >+import org.eclipse.jdt.core.IMemberValuePair; >+import org.eclipse.jdt.core.IMethod; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.ITypeParameter; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.Signature; > import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; >@@ -61,6 +69,19 @@ > IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); > return getAnnotations(binaryAnnotations, info.getTagBits()); > } >+/** >+ * @see IMethod#getParameterAnnotations() >+ */ >+public IAnnotation[][] getParameterAnnotations() throws JavaModelException { >+ IBinaryMethod info = (IBinaryMethod) getElementInfo(); >+ if (this.parameterTypes.length == 0) return null; >+ IAnnotation[][] annotations = new IAnnotation[this.parameterTypes.length][]; >+ for (int i=0; i < this.parameterTypes.length; i++) { >+ annotations[i] = getAnnotations(info.getParameterAnnotations(i), info.getTagBits()); >+ } >+ return annotations; >+} >+ > 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 14 Feb 2011 12:17:21 -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,55 @@ > 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.arguments = acceptMethodParameters(methodInfo.node.arguments, handle, methodInfo); >+ } > return info; > } >+private LocalVariable[] acceptMethodParameters(Argument[] arguments, JavaElement methodHandle, MethodInfo methodInfo) { >+ if (arguments == null) return null; >+ LocalVariable[] result = new LocalVariable[arguments.length]; >+ Annotation[][] paramAnnotations = new Annotation[arguments.length][]; >+ for(int i = 0; i < arguments.length; i++) { >+ Argument argument = arguments[i]; >+ LocalVariableInfo argumentInfo = new LocalVariableInfo(); >+ LocalVariableInfo localVarInfo = new LocalVariableInfo(); >+ localVarInfo.sourceRangeStart = argument.declarationSourceStart; >+ localVarInfo.sourceRangeEnd = argument.declarationSourceStart; >+ localVarInfo.nameStart = argument.sourceStart; >+ localVarInfo.nameEnd = argument.sourceEnd; >+ localVarInfo.isParameter = true; >+ >+ String paramTypeSig = JavaModelManager.getJavaModelManager().intern(Signature.createTypeSignature(methodInfo.parameterTypes[i], false)); >+ result[i] = new LocalVariable( >+ methodHandle, >+ new String(argument.name), >+ argument.declarationSourceStart, >+ argument. declarationSourceEnd, >+ argument.sourceStart, >+ argument.sourceEnd, >+ paramTypeSig, >+ argument.annotations, >+ argument.modifiers, >+ true); >+ this.newElements.put(result[i], argumentInfo); >+ this.infoStack.push(argumentInfo); >+ this.handleStack.push(result[i]); >+ if (argument.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]; >+ acceptAnnotation(annotation, localVarInfo, result[i]); >+ } >+ } >+ this.infoStack.pop(); >+ this.handleStack.pop(); >+ } >+ return result; >+} >+ > /** > * @see ISourceElementRequestor > */ >Index: model/org/eclipse/jdt/internal/core/LocalVariableInfo.java >=================================================================== >RCS file: model/org/eclipse/jdt/internal/core/LocalVariableInfo.java >diff -N model/org/eclipse/jdt/internal/core/LocalVariableInfo.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ model/org/eclipse/jdt/internal/core/LocalVariableInfo.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+package org.eclipse.jdt.internal.core; >+ >+public class LocalVariableInfo extends AnnotatableInfo { >+ >+ /* >+ * Mentions whether or not this local variable is a method parameter. >+ */ >+ public boolean isParameter; >+} >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 14 Feb 2011 12:17:25 -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 >@@ -135,6 +135,20 @@ > return info.typeParameters; > } > >+public IAnnotation[][] getParameterAnnotations() throws JavaModelException { >+ ILocalVariable[] arguments = ((SourceMethodElementInfo) getElementInfo()).arguments; >+ if (arguments == null) return null; >+ IAnnotation[][] annotations = new IAnnotation[arguments.length][]; >+ for (int i=0; i <arguments.length; i++) { >+ LocalVariable argument = (LocalVariable) arguments[i]; >+ annotations[i] = new Annotation[argument.annotations.length]; >+ for (int j=0; j < argument.annotations.length; j++) { >+ annotations[i][j] = argument.annotations[j]; >+ } >+ } >+ return annotations; >+} >+ > /** > * @see IMethod#getTypeParameterSignatures() > * @since 3.0 >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 14 Feb 2011 12:17:25 -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,6 +38,8 @@ > * For example, Hashtable or java.util.Hashtable. > */ > protected char[][] exceptionTypes; >+ >+ protected ILocalVariable[] arguments; > > /* > * 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 14 Feb 2011 12:17:27 -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; > >@@ -95,7 +98,7 @@ > } > static { > // TESTS_NUMBERS = new int[] { 182, 183 }; >-// TESTS_NAMES = new String[] {"test0177"}; >+// TESTS_NAMES = new String[] {"testParamAnnotations2"}; > } > public static Test suite() { > return buildModelTestSuite(TypeResolveTests.class); >@@ -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<T> {\n" + >+ " X<String> 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 [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<T> {\n" + >+ " X<String> 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"); >+ } >+} > } >#P org.eclipse.jdt.jeview >Index: src/org/eclipse/jdt/jeview/views/JavaElement.java >=================================================================== >RCS file: /cvsroot/eclipse/jdt-ui-home/plugins/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElement.java,v >retrieving revision 1.16 >diff -u -r1.16 JavaElement.java >--- src/org/eclipse/jdt/jeview/views/JavaElement.java 8 Mar 2010 16:28:55 -0000 1.16 >+++ src/org/eclipse/jdt/jeview/views/JavaElement.java 14 Feb 2011 12:17:30 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2010 IBM Corporation and others. >+ * Copyright (c) 2005, 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 >@@ -486,7 +486,23 @@ > result.add(new JavaElementChildrenProperty(this, "PARAMETER NAMES") { > @Override > protected JEAttribute[] computeChildren() throws JavaModelException { >- return createStrings(this, method.getParameterNames()); >+ String[] strings = method.getParameterNames(); >+ JEAttribute[] children= new JEAttribute[strings.length]; >+ for (int i= 0; i < strings.length; i++) { >+ final int index= i; >+ final IAnnotation[][] annotations = method.getParameterAnnotations(); >+ children[i]= new JavaElementProperty(this, null, strings[i]) { >+ @Override >+ public JEAttribute[] getChildren() { >+ try { >+ return createJavaElements(this, annotations[index]); >+ } catch (Exception e) { >+ return new JEAttribute[] {new Error(this, "", e)}; >+ } >+ } >+ }; >+ } >+ return children; > } > }); > result.add(new JavaElementChildrenProperty(this, "PARAMETER TYPES") {
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 334783
:
188592
|
188599
|
188610
|
188895
|
189128
|
189195
|
189196
|
189202
|
189233
|
189390