Skip to content

Commit

Permalink
ASTParser.createAST looses ability to resolve some bindings
Browse files Browse the repository at this point in the history
Having root unit set in the lookupEnvironment (when focusing on a single
unit) can be necessary for
further binding resolution.

Fixes eclipse-jdt#1915
  • Loading branch information
mickaelistria committed Mar 27, 2024
1 parent aa8844b commit 7724cfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7867,13 +7867,13 @@ public void test0238() throws JavaModelException {
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=173338
*/
public void test0238_2() throws JavaModelException {
this.workingCopy = getWorkingCopy("/Converter15/src/test0238/X.java", true/*resolve*/);
String contents =
"package test0238;\n" +
"public class X extends A {\n" +
"}";
this.workingCopy = getWorkingCopy("/Converter15/src/test0238/X.java",
"""
package test0238;
public class X extends A {
}""", true/*resolve*/);
ASTNode node = buildAST(
contents,
this.workingCopy.getSource(),
this.workingCopy,
false,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ private CompilationUnitDeclaration resolve(
if (unit == null) {
unit = this.unitsToProcess[0]; // fall back to old behavior
}
if (this.totalUnits == 1 && this.lookupEnvironment.unitBeingCompleted == null) {
this.lookupEnvironment.unitBeingCompleted = unit;
}
} else {
// initial type binding creation
this.lookupEnvironment.buildTypeBindings(unit, null /*no access restriction*/);
Expand Down

0 comments on commit 7724cfc

Please sign in to comment.