Bug 45199 - resolveTypeBinding returns null for some expression
Summary: resolveTypeBinding returns null for some expression
Status: RESOLVED WORKSFORME
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.0 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-20 07:06 EDT by Dirk Baeumer CLA
Modified: 2003-10-21 22:52 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 Dirk Baeumer CLA 2003-10-20 07:06:12 EDT
I200310150800

Calling resolveTypeBinding returns null for expressions referring to local 
variables. Also speced in the doc I don't understand why and when this is the 
case. IMO all expression refer to a type.
Comment 1 Olivier Thomann CLA 2003-10-20 10:33:01 EDT
Please provide test cases. Do you have syntax errors?
Comment 2 Dirk Baeumer CLA 2003-10-20 11:01:20 EDT
Here is an example:

class A {
  public void foo() {
     int x= 10;
     x= x + 1;
     // ^ resolveTypeBinding on this simple name returns null
  }
}
Comment 3 Olivier Thomann CLA 2003-10-20 13:25:34 EDT
I will investigate.
Comment 4 Olivier Thomann CLA 2003-10-20 14:13:14 EDT
Are you sure that you actually requested the bindings?
I tried your example and I could not reproduce.
I used this example:
class A {
  public void foo() {
     int x= 10;
     x= x + 1;
  }
}

And I successfully resolved the type binding for x in x = x + 1. Both 'x' have
the right type binding (type binding for int in this example).

Here is my test case:

	/**
	 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=45199
	 */
	public void test0499() throws JavaModelException {
		ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "", "test0499",
"A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
		ASTNode result = runConversion(sourceUnit, true);
		assertTrue("not a compilation unit", result.getNodeType() ==
ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
		CompilationUnit unit = (CompilationUnit) result;
		assertEquals("Wrong number of problems", 1, unit.getProblems().length);
//$NON-NLS-1$
		ASTNode node = getASTNode(unit, 0, 0, 1);
		assertNotNull(node);
		assertTrue("Not an expression statement", node.getNodeType() ==
ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
		Expression expression = ((ExpressionStatement) node).getExpression();
		assertTrue("Not an assignment", expression.getNodeType() ==
ASTNode.ASSIGNMENT); //$NON-NLS-1$
		Assignment assignment = (Assignment) expression;
		Expression expression2 = assignment.getRightHandSide();
		assertTrue("Not an infix expression", expression2.getNodeType() ==
ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
		InfixExpression infixExpression = (InfixExpression) expression2;
		Expression expression3 = infixExpression.getLeftOperand();
		assertTrue("Not a simple name", expression3.getNodeType() ==
ASTNode.SIMPLE_NAME); //$NON-NLS-1$
		ITypeBinding binding = expression3.resolveTypeBinding();
		assertNotNull("No binding", binding);
		Expression expression4 = assignment.getLeftHandSide();
		assertTrue("Not a simple name", expression4.getNodeType() ==
ASTNode.SIMPLE_NAME); //$NON-NLS-1$
		ITypeBinding binding2 = expression4.resolveTypeBinding();
		assertNotNull("No binding", binding2);
		assertTrue("Should be the same", binding == binding2);
	}
I will release it as a test case for this bug report.
Comment 5 Olivier Thomann CLA 2003-10-21 10:02:50 EDT
Please provide additional steps. I can successfully resolve type bindings for
'x' in your example.
Without further information, I will close it as WORKSFORME.
Comment 6 Dirk Baeumer CLA 2003-10-21 11:03:38 EDT
I will try to provide additional information today.
Comment 7 Dirk Baeumer CLA 2003-10-21 12:16:47 EDT
Tried to reproduce again and wasn't able to do so (but I am pretty sure that 
it returned null the last time I tested it). 

Frank Tip, saw the same behaviour. I will ask Frank if he can provide a test 
case. 

Olivier, you can close the PR. We reopen when we have a test case.
Comment 8 Olivier Thomann CLA 2003-10-21 22:52:02 EDT
Close as WORKSFORME. Please reopen if you have more information.