Community
Participate
Working Groups
We pass the following code in to AST.parseCompilationUnit(char[], String, IJavaProject): public class Hello{ static void ___run(java.lang.String[] args) throws Throwable { java.lang.Object[] obj= new Object[10]; } public static void main (String[] args){ } } We get an AST returned with no errors, however, when we visit the node corresponding to the java.lang.Object[] declaraction (ArrayType node), calling node.getElementType().resolveBinding() returns null. We debugged this a little bit. The first sign of trouble is in the following method: /* * Method declared on BindingResolver. */ ITypeBinding resolveType(Type type) { if (this.checkModificationCount && this.modificationCount != type.getAST().modificationCount()) { return null; } // retrieve the old ast node AstNode node = (AstNode) this.newAstToOldAst.get(type); if (node != null) { ... } return null; } The call to retrieve the old ast node is returning null.
For clarification, the method above is defined in DefaultBindingResolver.
I will check that as soon as I finish the performance tests.
Fix and released in HEAD.
I'm still getting a null binding returned. Some info from debugging the method DefaultBindingResolver.resolveType(Type): 1. The method is called with an org.eclipse.jdt.core.dom.ArrayType 2. The parentType is an org.eclipse.jdt.core.dom.ArrayCreation 3. The while loop is never entered 4. The index is 0, so the method falls into the old code: "node = (ASTNode) this.newAstToOldAst.get(type) 5. The node is null after this call, so null is returned It looks like the problem stems from the fact that the ArrayType's parent is an ArrayCreation, which isn't an array type.
I will investigate.
The firs problem has been fixed, but now you are referring to the java.lang.Object[10] part of the source. On my point of view, this is a different bug. It might look the same for you, but it is another bug. However this one is fixed now and should be released in the next integration build. I will double-check the way we resolve ArrayReference and ArrayInitializer.
For the code "java.lang.Object[] obj= new Object[10]", we get three requests to resolveBinding(Type). It looks like the first two binding requests are now working properly, but there's a third request that's failing now. Just evaluating the code "new Object[10]" is the simplest test case now. When we visit the AST, we first visit an ArrayCreation node and then an ArrayType node. This results in two binding resolution requests from us. The first is an ArrayType with an ArrayCreation parent. This works. The second is a SimpleType with an ArrayType parent. This fails. Some info gleaned while debugging: In the first pass, it falls into your new code ("if (parent instanceof ArrayCreation)") and it appears to return a good binding. In the second pass, it falls into the while loop for one iteration, setting index to 1, parentType to an ArrayCreation, and arrayType to an ArrayType It then falls into this code: if (index != 0) { node = (AstNode) this.newAstToOldAst.get(arrayType); } which returns null node.
For the simple type request, I guess you expected the element type binding of the array binding to be returned?
Hopefully this is finally fixed.