### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/core/ITypeParameter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ITypeParameter.java,v retrieving revision 1.10 diff -u -r1.10 ITypeParameter.java --- model/org/eclipse/jdt/core/ITypeParameter.java 27 Jun 2008 16:04:01 -0000 1.10 +++ model/org/eclipse/jdt/core/ITypeParameter.java 19 Feb 2010 09:43:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2010 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 @@ -42,6 +42,23 @@ String[] getBounds() throws JavaModelException; /** + * Returns the signatures for this type parameter's bounds. The type parameter may have + * been declared as part of a type or a method. The signatures represent only the individual + * bounds and do not include the type variable name or the extends keyword. + *

+ * The signatures may be either unresolved (for source types) or resolved (for binary types). + * See {@link Signature} for details. + *

+ * + * @return the signature for this formal type parameter + * @throws JavaModelException + * if this element doesn't exist or if an exception occurs while accessing its corresponding resource. + * @see Signature + * @since 3.6 + */ + String[] getBoundsSignatures() throws JavaModelException; + + /** * Returns the declaring member of this type parameter. This can be either an IType * or an IMethod. *

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.47 diff -u -r1.47 ClassFileInfo.java --- model/org/eclipse/jdt/internal/core/ClassFileInfo.java 11 Feb 2010 20:16:08 -0000 1.47 +++ model/org/eclipse/jdt/internal/core/ClassFileInfo.java 19 Feb 2010 09:43:46 -0000 @@ -296,16 +296,17 @@ for (int i = 0, typeParameterCount = typeParameterSignatures.length; i < typeParameterCount; i++) { char[] typeParameterSignature = typeParameterSignatures[i]; char[] typeParameterName = Signature.getTypeVariable(typeParameterSignature); + CharOperation.replace(typeParameterSignature, '/', '.'); char[][] typeParameterBoundSignatures = Signature.getTypeParameterBounds(typeParameterSignature); int boundLength = typeParameterBoundSignatures.length; char[][] typeParameterBounds = new char[boundLength][]; for (int j = 0; j < boundLength; j++) { typeParameterBounds[j] = Signature.toCharArray(typeParameterBoundSignatures[j]); - CharOperation.replace(typeParameterBounds[j], '/', '.'); } TypeParameter typeParameter = new TypeParameter(parent, new String(typeParameterName)); TypeParameterElementInfo info = new TypeParameterElementInfo(); info.bounds = typeParameterBounds; + info.boundsSignatures = typeParameterBoundSignatures; typeParameterHandles.add(typeParameter); // ensure that 2 binary methods with the same signature but with different return types have different occurence counts. Index: model/org/eclipse/jdt/internal/core/TypeParameter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/TypeParameter.java,v retrieving revision 1.15 diff -u -r1.15 TypeParameter.java --- model/org/eclipse/jdt/internal/core/TypeParameter.java 27 Aug 2009 15:27:02 -0000 1.15 +++ model/org/eclipse/jdt/internal/core/TypeParameter.java 19 Feb 2010 09:43:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 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 @@ -33,7 +33,35 @@ TypeParameterElementInfo info = (TypeParameterElementInfo) getElementInfo(); return CharOperation.toStrings(info.bounds); } - + + public String[] getBoundsSignatures() throws JavaModelException { + + String[] boundSignatures = null; + TypeParameterElementInfo info = (TypeParameterElementInfo) this.getElementInfo(); + + // For a binary type or method, the signature is already available from the .class file. + // No need to construct again + if (this.parent instanceof BinaryMember) { + char[][] boundsSignatures = info.boundsSignatures; + if (boundsSignatures == null || boundsSignatures.length == 0) { + return CharOperation.NO_STRINGS; + } + return CharOperation.toStrings(info.boundsSignatures); + } + + char[][] bounds = info.bounds; + if (bounds == null || bounds.length == 0) { + return CharOperation.NO_STRINGS; + } + + int boundsLength = bounds.length; + boundSignatures = new String[boundsLength]; + for (int i = 0; i < boundsLength; i++) { + boundSignatures[i] = new String(Signature.createCharArrayTypeSignature(bounds[i], false)); + } + return boundSignatures; + } + public IMember getDeclaringMember() { return (IMember) getParent(); } Index: model/org/eclipse/jdt/internal/core/TypeParameterElementInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/TypeParameterElementInfo.java,v retrieving revision 1.7 diff -u -r1.7 TypeParameterElementInfo.java --- model/org/eclipse/jdt/internal/core/TypeParameterElementInfo.java 7 Mar 2009 01:08:07 -0000 1.7 +++ model/org/eclipse/jdt/internal/core/TypeParameterElementInfo.java 19 Feb 2010 09:43:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 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 @@ -28,4 +28,9 @@ * The bounds names of this type parameter. */ public char[][] bounds; + + /* + * The bounds' signatures for this type parameter. + */ + public char[][] boundsSignatures; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ClassFileTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java,v retrieving revision 1.48 diff -u -r1.48 ClassFileTests.java --- src/org/eclipse/jdt/core/tests/model/ClassFileTests.java 10 Nov 2009 16:53:05 -0000 1.48 +++ src/org/eclipse/jdt/core/tests/model/ClassFileTests.java 19 Feb 2010 09:43:57 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -60,7 +60,7 @@ " X foo(X x) throws RuntimeException, U {\n" + " return null;\n" + " }\n" + - " V foo(K key, V value) throws Exception {\n" + + " V foo(K key, V value) throws Exception {\n" + " return value;\n" + " }\n" + "}", @@ -1094,7 +1094,7 @@ assertStringsEqual( "Unexpected type parameters", "K:Ljava.lang.Object;\n" + - "V:Ljava.lang.Object;\n", + "V:TT;\n", method.getTypeParameterSignatures()); } @@ -1523,4 +1523,25 @@ "Ljava.util.Collection;", field.getTypeSignature()); } + + public void testBug246594() throws JavaModelException { + IType type = this.jarRoot.getPackageFragment("generic").getClassFile( + "Z.class").getType(); + ITypeParameter typeParam = type.getTypeParameter("T"); + assertNotNull(typeParam); + assertStringsEqual("type parameter bound signatures", + "Ljava.lang.Object;\n" + + "Lgeneric.I<-TT;>;\n", + typeParam.getBoundsSignatures()); + } + + public void testBug246594a() throws JavaModelException { + IType type = this.jarRoot.getPackageFragment("generic").getClassFile( + "X.class").getType(); + IMethod method = type.getMethod("foo", new String[] { "TK;", "TV;" }); + ITypeParameter typeParam = method.getTypeParameter("V"); + assertStringsEqual("type parameter bound signatures", + "TT;\n", typeParam.getBoundsSignatures()); + } + } Index: src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java,v retrieving revision 1.70 diff -u -r1.70 CompilationUnitTests.java --- src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 10 Nov 2009 16:53:04 -0000 1.70 +++ src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 19 Feb 2010 09:44:00 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -2436,4 +2436,37 @@ annotations); } +public void testBug246594() throws CoreException { + createWorkingCopy( + "package p;\n" + + "public class Z> {\n" + + "}\n" + + "public interface I {}" + ); + IType type = this.workingCopy.getType("Z"); + ITypeParameter[] typeParameters = type.getTypeParameters(); + assertStringsEqual("Type parameter signature", "T:QObject;:QI<-QT;>;\n", type.getTypeParameterSignatures()); + assertStringsEqual("Type parameter signature", + "QObject;\n" + + "QI<-QT;>;\n", + typeParameters[0].getBoundsSignatures()); +} +public void testBug246594a() throws CoreException { + createWorkingCopy( + "package p;\n" + + "interface Collection {\n" + + "public boolean containsAll(Collection c);\n" + + "public > boolean addAll(Collection c);\n" + + "}" + + "public interface I {}"); + IMethod[] methods = this.workingCopy.getType("Collection").getMethods();// + ITypeParameter[] typeParameters = methods[1].getTypeParameters(); + assertStringsEqual("Type parameter signature", + "QE;\n" + + "QI<-QString;>;\n", + typeParameters[0].getBoundsSignatures()); + +} + + }