Bug 120640 - type.getTypeQualifiedName('.') has ambiguous spec
Summary: type.getTypeQualifiedName('.') has ambiguous spec
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-13 12:28 EST by Markus Keller CLA
Modified: 2005-12-14 07:18 EST (History)
3 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 2005-12-13 12:28:53 EST
I20051213-0010

'Navigate > Open External Javadoc' fails for nested binary types, e.g. java.util.Map.Entry (1.4 and 1.5) or java.lang.Thread.State (1.5 only)

The constructed URL is e.g.:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Map$Entry.html
but correct would be:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Map.Entry.html
Comment 1 Martin Aeschlimann CLA 2005-12-13 16:55:18 EST
To contruct the URL we use type.getTypeQualifiedName('.').
The returned name is 'Map$Entry' but I specified to use '.' as separator.

Olivier, you also have this code (in jdt.core), but manually replaced all '$' in '.'. This also look like a bug as types can contain '$' in their names.
Comment 2 Olivier Thomann CLA 2005-12-13 21:31:32 EST
I will investigate.
Comment 3 Olivier Thomann CLA 2005-12-13 21:56:44 EST
getTypeQualifiedName('.') returns what is specified. One of the examples is wrong.  For a binary type, it is spec'd to return the name of the class file without the '.class' extension.
Replacing '$' with '.' is wrong, but since there is no way to know the name of the  enclosing type through API this is the best that can be done for now.
The .class file has information about the enclosing type in the inner class info, but I don't see how to retrieve this through API.
Comment 4 Olivier Thomann CLA 2005-12-13 22:10:49 EST
I was wrong. Using getDeclaringType() is good enough.
Comment 5 Olivier Thomann CLA 2005-12-13 22:24:18 EST
Fixed and released in HEAD.
Existing tests are already testing this case.
Navigate> Open External Javadoc still needs to be fixed.
Comment 6 Martin Aeschlimann CLA 2005-12-14 04:36:51 EST
The spec in getTypeQualifiedName was ambiguous. You could have changed it both ways, but I realize that the implementation returns '$', so changing that might break some clients, But then it would many bugs in our code, as we weren't aware of that issue, and I guess nobody expects a '$' here (have to check all our references). I have no idea whats the use case for a qualified name like 'java.util.Map$Entry'. If you would want that you would use getFullyQualifiedName ('$').
Also in the AST you would get 'java.util.Map.Entry' as qualified name.

BTW. Also getFullyQualifiedName has the 'bad' example.

I added a util again to JavaModelUtil, and will have to change all our references to the jdt.core to use the util again. 

public static String getTypeQualifiedName(IType type) {
  try {
    if (type.isBinary() && !type.isAnonymous()) {
      IType declaringType= type.getDeclaringType();
      if (declaringType != null) {
        return getTypeQualifiedName(declaringType) + '.' + type.getElementName();
      }
    }
  } catch (JavaModelException e) {
   // ignore
  }	
  return type.getTypeQualifiedName('.');
}


Comment 7 Martin Aeschlimann CLA 2005-12-14 04:41:04 EST
To fix the problem in our code (as described in comment 6) I opened bug 120831.
Comment 8 Frederic Fusier CLA 2005-12-14 07:18:32 EST
Verified for 3.2 M4 using build I20051214-0010.