Community
Participate
Working Groups
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
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.
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 ?
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
I'll try (it's pretty late in the M5 process already)
Note that constantPoolName() returns a fully qualified name (e.g. 'my/package/A$1').
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();
Added API and implementation. Added tests ASTConverter2.test0503a() to test0503h()
Verified that this is included in 200311201600. Jérôme, could you please verify it is working as expected?
Tests ASTConverter2.test0503a() to test0503h() show that it is working as expected.
Verified.
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.
Reopening to make suggested fix.
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.
Should remain in M5 land, where the API was originally added. Though it got further tuned during M6.