Bug 46057 - need mechanism for retrieving the name of anonymous and local classes
Summary: need mechanism for retrieving the name of anonymous and local classes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-04 15:15 EST by Frank Tip CLA
Modified: 2003-11-26 17:10 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Tip CLA 2003-11-04 15:15:59 EST
I am involved in a project on change impact analysis, which combines
the use of Eclipse with the use of a framework of bytecode-level
analysis. We need to find out from Eclipse, what class names are
used internally for anonymous and local classes. What we need is 
something like A$1, A$1$LocalName, etc.

Specifically, I am requesting that the following methods are added:

in org.eclipse.jdt.core.dom.ITypeBinding:
    public String getLocalName();
in org.eclipse.jdt.core.dom.TypeBinding:
    public String getLocalName() {
        return String.valueOf(this.binding.constantPoolName();
    }

Thanks,
  -Frank
Comment 1 Philipe Mulet CLA 2003-11-04 15:27:47 EST
Sounds a fair request. 

The constant pool name is only available after flow analysis has performed, 
since we do optimize out local types in dead code. But in the DOM scenario this 
is ok, as resolving bindings will require these names to be computed.
Comment 2 Philipe Mulet CLA 2003-11-04 15:28:44 EST
So as to define the API name, Jerome please double check the VM spec for the 
proper name to use. I kind of remember: binaryName ?
Comment 3 Frank Tip CLA 2003-11-19 10:44:18 EST
Jerome,

Is there any way to put this small enhancement in for M5?  The absence
of this feature forces us to clone & modify the entire JDT UI plugin 
each time.

  -Frank
Comment 4 Jerome Lanneluc CLA 2003-11-19 11:13:22 EST
I'll try (it's pretty late in the M5 process already)
Comment 5 Jerome Lanneluc CLA 2003-11-19 11:26:49 EST
Note that constantPoolName() returns a fully qualified name 
(e.g. 'my/package/A$1').
Comment 6 Jerome Lanneluc CLA 2003-11-19 11:43:57 EST
Proposed spec on org.eclipse.jdt.core.dom.ITypeBinding:
/**
 * Returns the binary name (as defined in the Java Language 
 * Specification Chapter 13 Section 1) of this type binding.
 * Returns null if the type is defined in code that is unreachable.
 *
 * @return the binary name of this type
 */
String getBinaryName();
Comment 7 Jerome Lanneluc CLA 2003-11-20 07:23:57 EST
Added API and implementation.
Added tests ASTConverter2.test0503a() to test0503h()
Comment 8 Olivier Thomann CLA 2003-11-20 20:59:27 EST
Verified that this is included in 200311201600.
Jérôme, could you please verify it is working as expected?
Comment 9 Jerome Lanneluc CLA 2003-11-21 06:11:23 EST
Tests ASTConverter2.test0503a() to test0503h() show that it is working as 
expected.
Comment 10 David Audel CLA 2003-11-24 07:24:04 EST
Verified.
Comment 11 Jim des Rivieres CLA 2003-11-26 09:39:24 EST
Suggested improvement:

To be consistent, the result should be '.' -separated rather than '/' 
separated. Generally everything in AST API is based on JLS spec as much as 
possible. '/' is only used is the JVM spec.
Comment 12 Jim des Rivieres CLA 2003-11-26 09:46:00 EST
Reopening to make suggested fix.
Comment 13 Jerome Lanneluc CLA 2003-11-26 10:03:00 EST
Revised spec is:
 	/**
	 * Returns the binary name of this type binding.
	 * The binary name of a class is defined in the Java Language 
	 * Specification 2nd edition, section 13.1.
	 * <p>
	 * Note that in some cases, the binary name may be unavailable.
	 * This may happen, for example, for a local type declared in 
	 * unreachable code.
	 * </p>
	 *
	 * @return the binary name of this type, or <code>null</code> 
	 * if the binary name is unknown
	 * @since 3.0
	 */
	public String getBinaryName();

Changed implementation and tests to follow this spec.
Comment 14 Philipe Mulet CLA 2003-11-26 17:10:58 EST
Should remain in M5 land, where the API was originally added. Though it got 
further tuned during M6.