Community
Participate
Working Groups
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.
Please provide test cases. Do you have syntax errors?
Here is an example: class A { public void foo() { int x= 10; x= x + 1; // ^ resolveTypeBinding on this simple name returns null } }
I will investigate.
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.
Please provide additional steps. I can successfully resolve type bindings for 'x' in your example. Without further information, I will close it as WORKSFORME.
I will try to provide additional information today.
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.
Close as WORKSFORME. Please reopen if you have more information.