### 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 17 Feb 2011 15:28:18 -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,19 @@ * @return the number of parameters of this method */ int getNumberOfParameters(); + +/** + * Returns the parameters of this method. + *

An empty array is returned, if the method has no parameters.

+ *

If the method does not come from source, the positions and the flag of the parameters are irrelevant. + * These local variables can be used to retrieve the parameter annotations.

+ * + * @return the array of annotations for the specified parameter + * @throws JavaModelException + * @since 3.7 + */ +ILocalVariable[] getParameters() 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/Annotation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Annotation.java,v retrieving revision 1.7 diff -u -r1.7 Annotation.java --- model/org/eclipse/jdt/internal/core/Annotation.java 8 Jul 2009 06:32:33 -0000 1.7 +++ model/org/eclipse/jdt/internal/core/Annotation.java 17 Feb 2011 15:28:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 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 @@ -17,6 +17,7 @@ import org.eclipse.jdt.core.ISourceRange; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.SourceRange; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; import org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair; import org.eclipse.jdt.internal.core.util.Util; @@ -30,13 +31,20 @@ // require to distinguish same annotations in different member value pairs protected String memberValuePairName; + protected char[] argumentName; + public Annotation(JavaElement parent, String name) { this(parent, name, null); } public Annotation(JavaElement parent, String name, String memberValuePairName) { + this(parent, null, name, memberValuePairName); + } + + public Annotation(JavaElement parent, char[] argumentName, String name, String memberValuePairName) { super(parent); this.name = name; + this.argumentName = argumentName; this.memberValuePairName = memberValuePairName; } @@ -45,6 +53,13 @@ return false; } Annotation other = (Annotation) o; + if (this.argumentName == null) { + if (other.argumentName != null) { + return false; + } + } else if (!CharOperation.equals(this.argumentName, other.argumentName)) { + return false; + } if (this.memberValuePairName == null) { if (other.memberValuePairName != null) return false; @@ -129,6 +144,7 @@ final int prime = 31; int result = super.hashCode(); result = prime * result + ((this.memberValuePairName == null) ? 0 : this.memberValuePairName.hashCode()); + result = prime * result + ((this.argumentName == null) ? 0 : CharOperation.hashCode(this.argumentName)); result = prime * result + this.name.hashCode(); return result; } Index: model/org/eclipse/jdt/internal/core/BinaryMember.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMember.java,v retrieving revision 1.36 diff -u -r1.36 BinaryMember.java --- model/org/eclipse/jdt/internal/core/BinaryMember.java 28 Apr 2009 16:53:01 -0000 1.36 +++ model/org/eclipse/jdt/internal/core/BinaryMember.java 17 Feb 2011 15:28:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 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 @@ -47,9 +47,13 @@ return standardAnnotations; int length = binaryAnnotations.length; int standardLength = standardAnnotations.length; - IAnnotation[] annotations = new IAnnotation[length + standardLength]; + int fullLength = length + standardLength; + if (fullLength == 0) { + return Annotation.NO_ANNOTATIONS; + } + IAnnotation[] annotations = new IAnnotation[fullLength]; for (int i = 0; i < length; i++) { - annotations[i] = Util.getAnnotation(this, binaryAnnotations[i], null); + annotations[i] = Util.getAnnotation(this, null, binaryAnnotations[i], null); } System.arraycopy(standardAnnotations, 0, annotations, length, standardLength); return annotations; @@ -57,7 +61,7 @@ private IAnnotation getAnnotation(char[][] annotationName) { return new Annotation(this, new String(CharOperation.concatWith(annotationName, '.'))); } -private IAnnotation[] getStandardAnnotations(long tagBits) { +protected IAnnotation[] getStandardAnnotations(long tagBits) { if ((tagBits & TagBits.AllStandardAnnotationsMask) == 0) return Annotation.NO_ANNOTATIONS; ArrayList annotations = new ArrayList(); 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 17 Feb 2011 15:28:18 -0000 @@ -11,7 +11,16 @@ 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.ILocalVariable; +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 +70,48 @@ IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); return getAnnotations(binaryAnnotations, info.getTagBits()); } +public ILocalVariable[] getParameters() throws JavaModelException { + IBinaryMethod info = (IBinaryMethod) getElementInfo(); + int length = this.parameterTypes.length; + if (length == 0) { + return LocalVariable.NO_LOCAL_VARIABLES; + } + ILocalVariable[] localVariables = new ILocalVariable[length]; + char[][] argumentNames = info.getArgumentNames(); + if (argumentNames == null || argumentNames.length < length) { + argumentNames = new char[length][]; + for (int j = 0; j < length; j++) { + argumentNames[j] = ("arg" + j).toCharArray(); //$NON-NLS-1$ + } + } + for (int i= 0; i < length; i++) { + localVariables[i] = new LocalVariable( + this, + new String(argumentNames[i]), + -1, + -1, + -1, + -1, + this.parameterTypes[i], + getAnnotations(argumentNames[i], info.getParameterAnnotations(i), info.getTagBits()), + 0, + true); + } + return localVariables; +} +private IAnnotation[] getAnnotations(char[] argumentName, IBinaryAnnotation[] binaryAnnotations, long tagBits) { + IAnnotation[] standardAnnotations = getStandardAnnotations(tagBits); + if (binaryAnnotations == null) + return standardAnnotations; + int length = binaryAnnotations.length; + int standardLength = standardAnnotations.length; + IAnnotation[] annotations = new IAnnotation[length + standardLength]; + for (int i = 0; i < length; i++) { + annotations[i] = Util.getAnnotation(this, argumentName, binaryAnnotations[i], null); + } + System.arraycopy(standardAnnotations, 0, annotations, length, standardLength); + return annotations; +} public IMemberValuePair getDefaultValue() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); Object defaultValue = info.getDefaultValue(); Index: model/org/eclipse/jdt/internal/core/ClassFileInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java,v retrieving revision 1.49 diff -u -r1.49 ClassFileInfo.java --- model/org/eclipse/jdt/internal/core/ClassFileInfo.java 3 Sep 2010 15:20:03 -0000 1.49 +++ model/org/eclipse/jdt/internal/core/ClassFileInfo.java 17 Feb 2011 15:28:18 -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 @@ -41,25 +41,28 @@ */ protected ITypeParameter[] typeParameters; +private void generateAnnotationsInfos(BinaryMember member, IBinaryAnnotation[] binaryAnnotations, long tagBits, HashMap newElements) { + generateAnnotationsInfos(member, null, binaryAnnotations, tagBits, newElements); +} /** * Creates the handles and infos for the annotations of the given binary member. * Adds new handles to the given vector. */ -private void generateAnnotationsInfos(BinaryMember member, IBinaryAnnotation[] binaryAnnotations, long tagBits, HashMap newElements) { +private void generateAnnotationsInfos(BinaryMember member, char[] parameterName, IBinaryAnnotation[] binaryAnnotations, long tagBits, HashMap newElements) { if (binaryAnnotations != null) { for (int i = 0, length = binaryAnnotations.length; i < length; i++) { IBinaryAnnotation annotationInfo = binaryAnnotations[i]; - generateAnnotationInfo(member, newElements, annotationInfo); + generateAnnotationInfo(member, parameterName, newElements, annotationInfo, null); } } - generateStandardAnnotationsInfos(member, tagBits, newElements); -} -private void generateAnnotationInfo(JavaElement parent, HashMap newElements, IBinaryAnnotation annotationInfo) { - generateAnnotationInfo(parent, newElements, annotationInfo, null); + generateStandardAnnotationsInfos(member, parameterName, tagBits, newElements); } private void generateAnnotationInfo(JavaElement parent, HashMap newElements, IBinaryAnnotation annotationInfo, String memberValuePairName) { + generateAnnotationInfo(parent, null, newElements, annotationInfo, memberValuePairName); +} +private void generateAnnotationInfo(JavaElement parent, char[] parameterName, HashMap newElements, IBinaryAnnotation annotationInfo, String memberValuePairName) { char[] typeName = org.eclipse.jdt.core.Signature.toCharArray(CharOperation.replaceOnCopy(annotationInfo.getTypeName(), '/', '.')); - Annotation annotation = new Annotation(parent, new String(typeName), memberValuePairName); + Annotation annotation = new Annotation(parent, parameterName, new String(typeName), memberValuePairName); while (newElements.containsKey(annotation)) { annotation.occurrenceCount++; } @@ -81,7 +84,7 @@ } } } -private void generateStandardAnnotationsInfos(BinaryMember member, long tagBits, HashMap newElements) { +private void generateStandardAnnotationsInfos(BinaryMember member, char[] parameterName, long tagBits, HashMap newElements) { if ((tagBits & TagBits.AllStandardAnnotationsMask) == 0) return; if ((tagBits & TagBits.AnnotationTargetMASK) != 0) { @@ -268,7 +271,7 @@ final String[] parameterTypes = Signature.getParameterTypes(new String(descriptor)); pNames[0] = parameterTypes[0]; } - }catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // protect against malformed .class file (e.g. com/sun/crypto/provider/SunJCE_b.class has a 'a' generic signature) signature = methodInfo.getMethodDescriptor(); pNames = Signature.getParameterTypes(new String(signature)); @@ -290,13 +293,27 @@ BinaryMethod method = new BinaryMethod((JavaElement)type, selector, pNames); childrenHandles.add(method); - // ensure that 2 binary methods with the same signature but with different return types have different occurence counts. + // ensure that 2 binary methods with the same signature but with different return types have different occurrence counts. // (case of bridge methods in 1.5) while (newElements.containsKey(method)) method.occurrenceCount++; newElements.put(method, methodInfo); + int max = pNames.length; + char[][] argumentNames = methodInfo.getArgumentNames(); + if (argumentNames == null || argumentNames.length < max) { + argumentNames = new char[max][]; + for (int j = 0; j < max; j++) { + argumentNames[j] = ("arg" + j).toCharArray(); //$NON-NLS-1$ + } + } + for (int j = 0; j < max; j++) { + IBinaryAnnotation[] parameterAnnotations = methodInfo.getParameterAnnotations(j); + if (parameterAnnotations != null) { + generateAnnotationsInfos(method, argumentNames[j], parameterAnnotations, methodInfo.getTagBits(), newElements); + } + } generateTypeParameterInfos(method, signature, newElements, typeParameterHandles); generateAnnotationsInfos(method, methodInfo.getAnnotations(), methodInfo.getTagBits(), newElements); Object defaultValue = methodInfo.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 17 Feb 2011 15:28:18 -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 @@ -17,11 +17,19 @@ import java.util.Stack; import org.eclipse.core.runtime.Assert; -import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IMemberValuePair; +import org.eclipse.jdt.core.ITypeParameter; +import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.compiler.CategorizedProblem; 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.ASTNode; +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; @@ -39,7 +47,6 @@ import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt; import org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter; import org.eclipse.jdt.internal.core.util.Util; -import org.eclipse.jdt.internal.compiler.ast.ASTNode; /** * A requestor for the fuzzy parser, used to compute the children of an ICompilationUnit. */ @@ -427,8 +434,53 @@ 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]; + AnnotatableInfo localVarInfo = new AnnotatableInfo(); + localVarInfo.setSourceRangeStart(argument.declarationSourceStart); + localVarInfo.setSourceRangeEnd(argument.declarationSourceStart); + localVarInfo.setNameSourceStart(argument.sourceStart); + localVarInfo.setNameSourceEnd(argument.sourceEnd); + + 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], localVarInfo); + this.infoStack.push(localVarInfo); + 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/LocalVariable.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LocalVariable.java,v retrieving revision 1.31 diff -u -r1.31 LocalVariable.java --- model/org/eclipse/jdt/internal/core/LocalVariable.java 7 Sep 2010 19:14:26 -0000 1.31 +++ model/org/eclipse/jdt/internal/core/LocalVariable.java 17 Feb 2011 15:28:18 -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 @@ -34,6 +34,8 @@ public class LocalVariable extends SourceRefElement implements ILocalVariable { + public static final ILocalVariable[] NO_LOCAL_VARIABLES = new ILocalVariable[0]; + String name; public int declarationSourceStart, declarationSourceEnd; public int nameStart, nameEnd; @@ -66,6 +68,30 @@ this.isParameter = isParameter; } + public LocalVariable( + JavaElement parent, + String name, + int declarationSourceStart, + int declarationSourceEnd, + int nameStart, + int nameEnd, + String typeSignature, + IAnnotation[] annotations, + int flags, + boolean isParameter) { + + super(parent); + this.name = name; + this.declarationSourceStart = declarationSourceStart; + this.declarationSourceEnd = declarationSourceEnd; + this.nameStart = nameStart; + this.nameEnd = nameEnd; + this.typeSignature = typeSignature; + this.annotations = annotations; + this.flags = flags; + this.isParameter = isParameter; + } + protected void closing(Object info) { // a local variable has no info } Index: model/org/eclipse/jdt/internal/core/Member.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java,v retrieving revision 1.55 diff -u -r1.55 Member.java --- model/org/eclipse/jdt/internal/core/Member.java 24 Nov 2010 01:33:28 -0000 1.55 +++ model/org/eclipse/jdt/internal/core/Member.java 17 Feb 2011 15:28:18 -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 @@ -221,7 +221,7 @@ memento.nextToken(); // JEM_COUNT if (!memento.hasMoreTokens()) return this; boolean isParameter = Boolean.valueOf(memento.nextToken()).booleanValue(); - return new LocalVariable(this, varName, declarationStart, declarationEnd, nameStart, nameEnd, typeSignature, null, flags, isParameter); + return new LocalVariable(this, varName, declarationStart, declarationEnd, nameStart, nameEnd, typeSignature, Annotation.NO_ANNOTATIONS, flags, isParameter); case JEM_TYPE_PARAMETER: if (!memento.hasMoreTokens()) return this; String typeParameterName = memento.nextToken(); 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 17 Feb 2011 15:28:18 -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 @@ -134,7 +134,12 @@ SourceMethodElementInfo info = (SourceMethodElementInfo) getElementInfo(); return info.typeParameters; } - +public ILocalVariable[] getParameters() throws JavaModelException { + ILocalVariable[] arguments = ((SourceMethodElementInfo) getElementInfo()).arguments; + if (arguments == null) + return LocalVariable.NO_LOCAL_VARIABLES; + return arguments; +} /** * @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 17 Feb 2011 15:28:18 -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. Index: model/org/eclipse/jdt/internal/core/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v retrieving revision 1.145 diff -u -r1.145 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 6 Jan 2011 13:43:57 -0000 1.145 +++ model/org/eclipse/jdt/internal/core/util/Util.java 17 Feb 2011 15:28:18 -0000 @@ -3135,9 +3135,9 @@ } return typeArguments; } - public static IAnnotation getAnnotation(JavaElement parent, IBinaryAnnotation binaryAnnotation, String memberValuePairName) { + public static IAnnotation getAnnotation(JavaElement parent, char[] argumentName, IBinaryAnnotation binaryAnnotation, String memberValuePairName) { char[] typeName = org.eclipse.jdt.core.Signature.toCharArray(CharOperation.replaceOnCopy(binaryAnnotation.getTypeName(), '/', '.')); - return new Annotation(parent, new String(typeName), memberValuePairName); + return new Annotation(parent, argumentName, new String(typeName), memberValuePairName); } public static Object getAnnotationMemberValue(JavaElement parent, MemberValuePair memberValuePair, Object binaryValue) { @@ -3145,7 +3145,7 @@ return getAnnotationMemberValue(memberValuePair, (Constant) binaryValue); } else if (binaryValue instanceof IBinaryAnnotation) { memberValuePair.valueKind = IMemberValuePair.K_ANNOTATION; - return getAnnotation(parent, (IBinaryAnnotation) binaryValue, memberValuePair.getMemberName()); + return getAnnotation(parent, null, (IBinaryAnnotation) binaryValue, memberValuePair.getMemberName()); } else if (binaryValue instanceof ClassSignature) { memberValuePair.valueKind = IMemberValuePair.K_CLASS; char[] className = Signature.toCharArray(CharOperation.replaceOnCopy(((ClassSignature) binaryValue).getTypeName(), '/', '.')); #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v retrieving revision 1.82 diff -u -r1.82 Util.java --- src/org/eclipse/jdt/core/tests/util/Util.java 25 Oct 2010 10:30:15 -0000 1.82 +++ src/org/eclipse/jdt/core/tests/util/Util.java 17 Feb 2011 15:28:19 -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 @@ -382,7 +382,9 @@ } public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String[] classpath, String compliance, Map options) throws IOException { Map compileOptions = getCompileOptions(compliance); - compileOptions.putAll(options); + if (options != null) { + compileOptions.putAll(options); + } createJar(javaPathsAndContents, extraPathsAndContents, compileOptions, classpath, jarPath); } public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException { #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.242 diff -u -r1.242 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 6 Oct 2010 17:32:30 -0000 1.242 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 17 Feb 2011 15:28:19 -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 @@ -402,16 +402,28 @@ addLibraryEntry(javaProject, new Path(jarPath), true/*exported*/); } protected void addLibrary(String jarName, String sourceZipName, String[] pathAndContents, String compliance) throws CoreException, IOException { - addLibrary(this.currentProject, jarName, sourceZipName, pathAndContents, null/*no non-Java resources*/, null, null, compliance); + addLibrary(this.currentProject, jarName, sourceZipName, pathAndContents, null/*no non-Java resources*/, null, null, compliance, null); + } + protected void addLibrary(IJavaProject javaProject, String jarName, String sourceZipName, String[] pathAndContents, String compliance, Map options) throws CoreException, IOException { + addLibrary(javaProject, jarName, sourceZipName, pathAndContents, null/*no non-Java resources*/, null, null, compliance, options); } protected void addLibrary(IJavaProject javaProject, String jarName, String sourceZipName, String[] pathAndContents, String compliance) throws CoreException, IOException { - addLibrary(javaProject, jarName, sourceZipName, pathAndContents, null/*no non-Java resources*/, null, null, compliance); + addLibrary(javaProject, jarName, sourceZipName, pathAndContents, null/*no non-Java resources*/, null, null, compliance, null); } protected void addLibrary(IJavaProject javaProject, String jarName, String sourceZipName, String[] pathAndContents, String[] nonJavaResources, String compliance) throws CoreException, IOException { - addLibrary(javaProject, jarName, sourceZipName, pathAndContents, nonJavaResources, null, null, compliance); + addLibrary(javaProject, jarName, sourceZipName, pathAndContents, nonJavaResources, null, null, compliance, null); } - protected void addLibrary(IJavaProject javaProject, String jarName, String sourceZipName, String[] pathAndContents, String[] nonJavaResources, String[] librariesInclusionPatterns, String[] librariesExclusionPatterns, String compliance) throws CoreException, IOException { - IProject project = createLibrary(javaProject, jarName, sourceZipName, pathAndContents, nonJavaResources, compliance); + protected void addLibrary( + IJavaProject javaProject, + String jarName, + String sourceZipName, + String[] pathAndContents, + String[] nonJavaResources, + String[] librariesInclusionPatterns, + String[] librariesExclusionPatterns, + String compliance, + Map options) throws CoreException, IOException { + IProject project = createLibrary(javaProject, jarName, sourceZipName, pathAndContents, nonJavaResources, compliance, options); String projectPath = '/' + project.getName() + '/'; addLibraryEntry( javaProject, @@ -423,13 +435,29 @@ true ); } - - protected IProject createLibrary(IJavaProject javaProject, String jarName, String sourceZipName, String[] pathAndContents, String[] nonJavaResources, String compliance) throws IOException, CoreException { + protected IProject createLibrary( + IJavaProject javaProject, + String jarName, + String sourceZipName, + String[] pathAndContents, + String[] nonJavaResources, + String compliance) throws IOException, CoreException { + return createLibrary(javaProject, jarName, sourceZipName, pathAndContents, nonJavaResources, compliance, null); + } + + protected IProject createLibrary( + IJavaProject javaProject, + String jarName, + String sourceZipName, + String[] pathAndContents, + String[] nonJavaResources, + String compliance, + Map options) throws IOException, CoreException { IProject project = javaProject.getProject(); String projectLocation = project.getLocation().toOSString(); String jarPath = projectLocation + File.separator + jarName; String[] claspath = get15LibraryIfNeeded(compliance); - org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, nonJavaResources, jarPath, claspath, compliance); + org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, nonJavaResources, jarPath, claspath, compliance, options); if (pathAndContents != null && pathAndContents.length != 0) { String sourceZipPath = projectLocation + File.separator + sourceZipName; org.eclipse.jdt.core.tests.util.Util.createSourceZip(pathAndContents, sourceZipPath); @@ -1159,6 +1187,10 @@ org.eclipse.jdt.core.tests.util.Util.createJar(javaPathsAndContents, null,jarPath, classpath, compliance); } + protected void createJar(String[] javaPathsAndContents, String jarPath, String[] classpath, String compliance, Map options) throws IOException { + org.eclipse.jdt.core.tests.util.Util.createJar(javaPathsAndContents, null, jarPath, classpath, compliance, options); + } + /* } * Creates a Java project where prj=src=bin and with JCL_LIB on its classpath. Index: src/org/eclipse/jdt/core/tests/model/MementoTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/MementoTests.java,v retrieving revision 1.30 diff -u -r1.30 MementoTests.java --- src/org/eclipse/jdt/core/tests/model/MementoTests.java 22 Dec 2010 05:56:56 -0000 1.30 +++ src/org/eclipse/jdt/core/tests/model/MementoTests.java 17 Feb 2011 15:28:19 -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 @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.*; import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.Annotation; import org.eclipse.jdt.internal.core.JavaElement; import org.eclipse.jdt.internal.core.LocalVariable; @@ -486,7 +487,7 @@ IType type = getCompilationUnit("/P/src/p/X.java").getType("X"); IMethod method = type.getMethod("foo", new String[]{}); - ILocalVariable localVar = new LocalVariable((JavaElement)method, "var", 1, 2, 3, 4, "Z", null, 0, true); + ILocalVariable localVar = new LocalVariable((JavaElement)method, "var", 1, 2, 3, 4, "Z", Annotation.NO_ANNOTATIONS, 0, true); assertMemento( "=P/src {\n" + + " X field;\n" + + " @Inject\n" + + " public void Test(@Default String processor) {}\n" + + "}" + + "@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.getParameters()[0].getAnnotations()[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;\n" + + "public class X {\n" + + " X field;\n" + + " @Inject\n" + + " public void Test(@Default String processor) {}\n" + + "}" + + "@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 [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.getParameters()[0].getAnnotations()[0].toString()); + } finally { + deleteProject("P"); + } +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations3() throws CoreException { + try { + createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); + String source = "package p;\n" + + "public class X {\n" + + " X field;\n" + + " @Inject\n" + + " public void Test(int i, @Default @Marker(id=1) String processor, int k) {}\n" + + "}\n" + + "@interface Inject{\n" + + "}\n" + + "@interface Marker {\n" + + " int id() default 0;\n" + + "}\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 annotationString1 = "@Default [in processor [in Test(int, String, int) [in X [in X.java [in p [in src [in P]]]]]]]"; + String annotationString2 = "@Marker [in processor [in Test(int, String, int) [in X [in X.java [in p [in src [in P]]]]]]]"; + assertEquals(annotationString1, ((LocalVariable)variable[0]).getAnnotations()[0].toString()); + IType type = unit.getType("X"); + + IMethod method = type.getMethods()[0]; + IAnnotation[] parameterAnnotations = method.getParameters()[1].getAnnotations(); + assertEquals("Wrong length", 2, parameterAnnotations.length); + assertEquals(annotationString1, parameterAnnotations[0].toString()); + IAnnotation iAnnotation = parameterAnnotations[1]; + assertEquals(annotationString2, iAnnotation.toString()); + IMemberValuePair[] memberValuePairs = iAnnotation.getMemberValuePairs(); + assertEquals("Wrong number of pairs", 1, memberValuePairs.length); + StringBuffer output = new StringBuffer(); + output.append(memberValuePairs[0].getMemberName()); + output.append(' '); + output.append(memberValuePairs[0].getValue()); + assertEquals("Wrong value", "id 1", String.valueOf(output)); + assertEquals("Wrong length", 0, method.getParameters()[0].getAnnotations().length); + assertEquals("Wrong length", 0, method.getParameters()[2].getAnnotations().length); + } finally { + deleteProject("P"); + } +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations4() 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;\n" + + "public class X {\n" + + " X field;\n" + + " @Inject @Marker(id=3)\n" + + " public void Test(int i, @Default @Marker(id=1) String processor, int k) {}\n" + + "}", + "p/Inject.java", + "package p;\n"+ + "public @interface Inject{\n" + + "}", + "p/Marker.java", + "package p;\n" + + "public @interface Marker {\n" + + " int id() default 0;\n" + + "}", + "p/Default.java", + "package p;\n" + + "public @interface Default{\n" + + "}"}; + addLibrary(project, "lib334783_2.jar", "lib334783_2src.zip", pathAndContents, JavaCore.VERSION_1_5); + + waitForAutoBuild(); + IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783_2.jar")); + IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); + String annotationString1 = "@p.Default [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]"; + String annotationString2 = "@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]"; + IMethod method = type.getMethods()[1]; + IAnnotation[] annotations = method.getAnnotations(); + assertEquals("Wrong length", 2, annotations.length); + assertEquals("@p.Inject [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]", annotations[0].toString()); + IAnnotation annotation = annotations[1]; + assertEquals("@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]", annotation.toString()); + IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); + assertEquals("Wrong number of pairs", 1, memberValuePairs.length); + StringBuffer output = new StringBuffer(); + output.append(memberValuePairs[0].getMemberName()); + output.append(' '); + output.append(memberValuePairs[0].getValue()); + assertEquals("Wrong value", "id 3", String.valueOf(output)); + IAnnotation[] parameterAnnotations = method.getParameters()[1].getAnnotations(); + assertEquals("Wrong length", 2, parameterAnnotations.length); + assertEquals(annotationString1, parameterAnnotations[0].toString()); + annotation = parameterAnnotations[1]; + assertEquals(annotationString2, annotation.toString()); + memberValuePairs = annotation.getMemberValuePairs(); + assertEquals("Wrong number of pairs", 1, memberValuePairs.length); + output = new StringBuffer(); + output.append(memberValuePairs[0].getMemberName()); + output.append(' '); + output.append(memberValuePairs[0].getValue()); + assertEquals("Wrong value", "id 1", String.valueOf(output)); + assertEquals("Wrong length", 0, method.getParameters()[0].getAnnotations().length); + assertEquals("Wrong length", 0, method.getParameters()[2].getAnnotations().length); + } finally { + deleteProject("P"); + } +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations5() 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;\n" + + "public class X {\n" + + " X field;\n" + + " @Inject @Marker(id=3)\n" + + " public void Test(int i, @Default @Marker(id=1) String processor, int k) {}\n" + + "}", + "p/Inject.java", + "package p;\n"+ + "public @interface Inject{\n" + + "}", + "p/Marker.java", + "package p;\n" + + "public @interface Marker {\n" + + " int id() default 0;\n" + + "}", + "p/Default.java", + "package p;\n" + + "public @interface Default{\n" + + "}"}; + Map options = new HashMap(); + options.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.DO_NOT_GENERATE); + addLibrary(project, "lib334783_3.jar", "lib334783_3src.zip", pathAndContents, JavaCore.VERSION_1_5, options); + + waitForAutoBuild(); + IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783_3.jar")); + IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); + String annotationString1 = "@p.Default [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]"; + String annotationString2 = "@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]"; + IMethod method = type.getMethods()[1]; + IAnnotation[] annotations = method.getAnnotations(); + assertEquals("Wrong length", 2, annotations.length); + assertEquals("@p.Inject [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]", annotations[0].toString()); + IAnnotation annotation = annotations[1]; + assertEquals("@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]", annotation.toString()); + IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); + assertEquals("Wrong number of pairs", 1, memberValuePairs.length); + StringBuffer output = new StringBuffer(); + output.append(memberValuePairs[0].getMemberName()); + output.append(' '); + output.append(memberValuePairs[0].getValue()); + assertEquals("Wrong value", "id 3", String.valueOf(output)); + IAnnotation[] parameterAnnotations = method.getParameters()[1].getAnnotations(); + assertEquals("Wrong length", 2, parameterAnnotations.length); + assertEquals(annotationString1, parameterAnnotations[0].toString()); + annotation = parameterAnnotations[1]; + assertEquals(annotationString2, annotation.toString()); + memberValuePairs = annotation.getMemberValuePairs(); + assertEquals("Wrong number of pairs", 1, memberValuePairs.length); + output = new StringBuffer(); + output.append(memberValuePairs[0].getMemberName()); + output.append(' '); + output.append(memberValuePairs[0].getValue()); + assertEquals("Wrong value", "id 1", String.valueOf(output)); + assertEquals("Wrong length", 0, method.getParameters()[0].getAnnotations().length); + assertEquals("Wrong length", 0, method.getParameters()[2].getAnnotations().length); + } finally { + deleteProject("P"); + } +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations6() throws CoreException { + try { + createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); + String source = "package p;\n" + + "public class X {\n" + + " X field;\n" + + " public void Test() {}\n" + + "}"; + createFolder("/P/src/p"); + createFile( + "/P/src/p/X.java", + source + ); + waitForAutoBuild(); + + ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); + IType type = unit.getType("X"); + IMethod method = type.getMethods()[0]; + ILocalVariable[] localVariables = method.getParameters(); + assertNotNull(localVariables); + assertEquals("Wrong length", 0, localVariables.length); + } finally { + deleteProject("P"); + } +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" + */ +public void testParamAnnotations7() 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;\n" + + "public class X {\n" + + " X field;\n" + + " public void Test() {}\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(); + + IMethod method = type.getMethods()[1]; + ILocalVariable[] localVariables = method.getParameters(); + assertNotNull(localVariables); + assertEquals("Wrong length", 0, localVariables.length); + } finally { + deleteProject("P"); + } +} }