Bug 23734 - AST: CompilationUnit.findDeclaringNode only finds bindings from its own ast
Summary: AST: CompilationUnit.findDeclaringNode only finds bindings from its own ast
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.1 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-18 11:11 EDT by Martin Aeschlimann CLA
Modified: 2002-10-17 10:18 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2002-09-18 11:11:28 EDT
20020917

1. CU A has a expression that has a TypeBinding to a type in CU B.
   I need to get the type declaration in B
2. I create an AST for B and do CompilationUnit.findDeclaringNode(typeBinding).
   Unfortunatly, the binding is not found: It seems typeBinding.equals goes for 
identity, but is not comparing keys.
Comment 1 Olivier Thomann CLA 2002-09-19 11:25:17 EDT
TypeBinding equals is using the Object's implementation. I will see how to
improve this.
Comment 2 Olivier Thomann CLA 2002-09-20 10:17:47 EDT
This method is only intended to be used to retrieve declaring node from a
binding created in the same compilation unit.
Jim - we might want to propose a new mecanism to achieve this.
Comment 3 Jim des Rivieres CLA 2002-09-20 13:00:11 EDT
Keys are our general mechanism for relating bindings arising from one AST to 
those from another AST. This suggests adding a new API method
CompilationUnit.findDeclaringNode(String key) so that a binding key can be 
used to do the lookup. Martin: would like solve your problem?
Comment 4 Martin Aeschlimann CLA 2002-09-21 08:39:16 EDT
That would solve the problem!
Comment 5 Jim des Rivieres CLA 2002-09-23 09:55:58 EDT
Added API method; marked it @since 2.1; added other minor clarifications.
Comment 6 Jim des Rivieres CLA 2002-09-23 11:21:43 EDT
Ignore previous comment. We won't add the method until implementation is ready.
Here is the API spec for the new method:

	/**
	 * Finds the corresponding AST node in the given compilation unit from 
	 * which the binding with the given key originated. Returns
	 * <code>null</code> if the corresponding node cannot be determined.
	 * This method always returns <code>null</code> if bindings were not 
requested
	 * when this AST was built.
	 * <p>
	 * The following table indicates the expected node type for the various
	 * different kinds of binding keys:
	 * <ul>
	 * <li></li>
	 * <li>package - a <code>PackageDeclaration</code></li>
	 * <li>class or interface - a <code>TypeDeclaration</code> or a
	 *    <code>ClassInstanceCreation</code> (for anonymous classes) </li>
	 * <li>primitive type - none</li>
	 * <li>array type - none</li>
	 * <li>field - a <code>VariableDeclarationFragment</code> in a 
	 *    <code>FieldDeclaration</code> </li>
	 * <li>local variable - a <code>SingleVariableDeclaration</code>, or
	 *    a <code>VariableDeclarationFragment</code> in a 
	 *    <code>VariableDeclarationStatement</code> or 
	 *    <code>VariableDeclarationExpression</code></li>
	 * <li>method - a <code>MethodDeclaration</code> </li>
	 * <li>constructor - a <code>MethodDeclaration</code> </li>
	 * </ul>
	 * </p>
	 * 
	 * @param key the binding key, or <code>null</code>
	 * @return the corresponding node where a binding with the given
	 * key is declared, or <code>null</code> if the key is 
<code>null</code>
	 * or if the key does not correspond to a node in this compilation unit
	 * or if bindings were not requested when this AST was built
	 * @see IBinding#getKey
	 * @since 2.1
	 */
	public ASTNode findDeclaringNode(String key)

When this method is added, the Javadoc for the other method should be changed 
to add:
	 * Use <code>findDeclaringNode(binding.getKey())</code> when the 
binding comes
	 * from a different AST.
and
	 * @see #findDeclaringNode(java.lang.String)

Comment 7 Olivier Thomann CLA 2002-09-23 11:35:36 EDT
Is this urgent? In the next weeks, I will spend time on the DOM side only if 
the bug needs to be fixed asap, otherwise I will defer its resolution.
Comment 8 Olivier Thomann CLA 2002-09-23 11:37:03 EDT
Jim - put the previous version of CompilationUnit as an attachement. You had a 
change to the findDeclaringNode(IBinding) method API as well. As soon as the 
implementation is ready I will release the version attached to this PR in the 
same time.
Comment 9 Olivier Thomann CLA 2002-09-23 12:37:54 EDT
Ok, I released it. If you find any problem with it, reopen it or create a new bug.
Fixed and released in 2.1 stream. Regression tests added.
Comment 10 David Audel CLA 2002-10-17 10:18:56 EDT
Verified.