Bug 78183 - TypeBinding#getQualifiedName() does not honor Javadocs
Summary: TypeBinding#getQualifiedName() does not honor Javadocs
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 77360
Blocks:
  Show dependency tree
 
Reported: 2004-11-09 11:48 EST by Markus Keller CLA
Modified: 2004-12-15 12:16 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-11-09 11:48:15 EST
I200411050810

TypeBinding#getQualifiedName() doesn't do what its Javadocs promise.
Differences I found:

- #getQualifiedName() does not include type arguments, although the Javadoc says
it should. #getName() already includes type arguments as well as type
parameters, which suggests that #getQualifiedName() should also include both.

- #getQualifiedName() for List's type argument in 'List<? extends Object>'
returns 'java.util.? extends Object' instead of '? extends java.lang.Object'
Comment 1 Markus Keller CLA 2004-11-09 11:55:07 EST
- #getQualifiedName() for type variables is undefined
Comment 2 Olivier Thomann CLA 2004-11-09 16:52:49 EST
Jim, could you please specify what is expected for the type variables?
Because we are in the bindings' world, I think for:
class X<T>

we should have:
X<T extends java.lang.Object>

Move it back to me when the spec is updated. I will take care of the implementation.
Comment 3 Olivier Thomann CLA 2004-11-09 18:00:46 EST
Type variables are covered by the actual documentation.
	 * <li>For type variables, the fully qualified name is just the name of the
	 * type variable (type bounds are not included).
	 * Example: <code>"X"</code>.</li>

This is what is implemented right now.
Comment 4 Olivier Thomann CLA 2004-11-09 18:22:30 EST
Fixed and released in HEAD.
Regression test added.
Comment 5 Martin Aeschlimann CLA 2004-11-15 10:43:03 EST
Can we review that again? The Javadoc is still slightly inconsistent and I also
have problems to use the current implementation, especially as we still don't
have a method getRawType

 * <li>For type bindings that correspond to particular instances of a generic
 * type arising from a parameterized type reference,
 * the fully qualified name is the fully qualified name of the erasure
 * type followed by the fully qualified names of the type arguments surrounded
by "&lt;&gt;" and separated by ",".
 * Example: <code>"java.util.Collection&lt;java.lang.String&gt;"</code>.

-> erasure of Collection<String> is Collection<E> -> qualified name
'j.u.Collection<E><String> ?

The open question I have is: What happens if a type is inside a generic type.

class MyGeneric<A> {
  class MyInner {}
}

In type signatures, such inner types are referenced like
 a.b.MyGeneric.MyInner a;
-> no type parameters for the outer types

The current implementation returns a.b.MyGeneric<A>.MyInner, which is hard to
use. (However consistent with the first sentence in the Javadoc)
Comment 6 Olivier Thomann CLA 2004-11-15 11:09:02 EST
Reopen. Need 77360 fixed before we fix this one.
Comment 7 Olivier Thomann CLA 2004-11-15 11:09:46 EST
Jim,

Could you please clarify the specs with Martin? When this is done, move it back
to me and I will take care of the implementation.
Comment 8 Martin Aeschlimann CLA 2004-11-15 13:51:31 EST
Jim, in our discussion here we can't agree on the right solution for
getQualifiedName. In your opinion, what should be the use of this method from a
model point of view.

Comment 9 Jim des Rivieres CLA 2004-11-19 11:14:24 EST
These methods are trying to provide useful names for clients to display to 
users if they need to. It's hard to promise much more than that; in 
particular, we cannot promise that these names would necessarily be useful for 
inserting into source code. Howewever, the current specs for getName and 
getQualifiedName are confused.

Here's a proposal for what they should do:
1) the name of a type (declaration) is the same regardless of whether it is 
generic. E.g., The binding for the declaration of Collection has 
name "Collection".
2) the name of a parameterized type reference includes the type arguments.
E.g., The binding for Collection<String> has name "Collection<String>".
3) the name of a raw type reference is the same as the name of the type it 
references.
E.g., The binding for a reference to Collection without type arguments has 
name "Collection".
4) the qualified name of a member type is prefixed by the qualified name of 
the enclosing type

Examples:

package p;
class Gen<X> {
   class Inn {
   }
}
Gen<String> v1;
Gen<String>.Inn v2;
Gen v3;
Gen.Inn v4;

ITypeBinding for declaration of Gen
name "Gen"  ** currently spec'd as "Gen<X>"
qualifiedName "p.Gen" ** currently spec'd as "p.Gen<X>"
isClass
isGenericType
isTopLevel

ITypeBinding for declaration of Gen.Inn
name "Inn"
qualifiedName "p.Gen.Inn" ** currently spec'd as "p.Gen<X>.Inn"
isClass
isMember
isNested

ITypeBinding for variable v1
name "Gen<String>"
qualifiedName "p.Gen<java.lang.String>"
isClass
isParameterizedType
isTopLevel

ITypeBinding for variable v2
name "Inn"
qualifiedName "p.Gen<java.lang.String>.Inn"
isClass
isMember
isNested

ITypeBinding for variable v3
name "Gen"
qualifiedName "p.Gen"
isClass
isRawType
isTopLevel

ITypeBinding for variable v4
name "Gen.Inn"
qualifiedName "p.Gen.Inn"
isClass
isMember
isNested

Martin, Would these names be useful?
Comment 10 Martin Aeschlimann CLA 2004-11-19 16:08:14 EST
Yes, that looks very good. To avoid the type variable names in the generic 
type names is a good change.

The most common use of the qualified name was to serve as a unique type 
identifier that could be used amongst other things to brigde between the Java 
Model IType and the AST TypeDeclaration. That is currently broken with the 
variable names in type names so that's why I support the suggested change.

(It has to be noted that the bridging problem is now partly solved with the 
new API IBinding.getJavaElement)
Comment 11 Jim des Rivieres CLA 2004-11-19 20:02:06 EST
I've revised the specs for ITypeBinding.getName() and getQualifiedName().

Olivier, over to you
Comment 12 Olivier Thomann CLA 2004-11-25 23:51:59 EST
Jim,

Are you sure that the name for v4 is "Gen.Inn". I would say it should be "Inn"
according to the spec of getName().
Comment 13 Olivier Thomann CLA 2004-11-26 00:04:16 EST
Jim,

According to your answer, I will reopen this PR or consider it as fixed.
Fixed and released in HEAD.
Regression test added.
Comment 14 Jim des Rivieres CLA 2004-11-26 09:56:59 EST
My mistake. The name of v4 should be "Inn", not "Gen.Inn". 
Comment 15 Jim des Rivieres CLA 2004-11-26 10:18:03 EST
I've also corrected the specs for both methods re: wildcard types to mention 
that "super" can appear as well as "extends" (and that there are single spaces
before and after the keyword).
Comment 16 Jerome Lanneluc CLA 2004-12-15 12:16:41 EST
Regression test is ASTConverter15Test#test0063.
Verified (in I20041214-2000) that this test ensures that the qualified name of a
parameterized type binding with wild card argument is correct.