Skip to content

Commit c0dbb1e

Browse files
committed
Lazily resolve DOMCompletionContext.getEnclosingElement()
1 parent beebaed commit c0dbb1e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,12 @@ IBinding resolveName(Name name) {
10431043

10441044
private IBinding resolveNameImpl(Name name) {
10451045
resolve();
1046+
if (name.getParent() instanceof MemberRef memberRef) {
1047+
resolveReference(memberRef); // initialize symbols on Javadoc
1048+
}
1049+
if (name.getParent() instanceof MethodRef methodRef) {
1050+
resolveReference(methodRef);
1051+
}
10461052

10471053
// first, prefer parent if appropriate
10481054
ASTNode parent = name.getParent();

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/codeassist/DOMCompletionContext.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@
5151
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
5252

5353
class DOMCompletionContext extends CompletionContext {
54+
55+
private final CompilationUnit domUnit;
56+
private final ITypeRoot modelUnit;
5457
private final int offset;
5558
private final char[] token;
56-
private final IJavaElement enclosingElement;
59+
60+
private IJavaElement enclosingElement;
61+
private boolean enclosingElementComputed;
5762
private final Supplier<Stream<IBinding>> bindingsAcquirer;
5863
final ExpectedTypes expectedTypes;
5964
private boolean inJavadoc = false;
@@ -62,6 +67,8 @@ class DOMCompletionContext extends CompletionContext {
6267
private boolean isJustAfterStringLiteral;
6368

6469
DOMCompletionContext(CompilationUnit domUnit, ITypeRoot modelUnit, String textContent, int offset, AssistOptions assistOptions, Bindings bindings) {
70+
this.domUnit = domUnit;
71+
this.modelUnit = modelUnit;
6572
this.textContent = textContent;
6673
this.offset = offset;
6774
// Use the raw text to walk back the offset to the first non-whitespace spot
@@ -88,7 +95,6 @@ class DOMCompletionContext extends CompletionContext {
8895
: previousNodeBeforeWhitespaces; // use previous node
8996
this.expectedTypes = new ExpectedTypes(assistOptions, this.node, offset);
9097
this.token = tokenBefore(this.textContent).toCharArray();
91-
this.enclosingElement = computeEnclosingElement(domUnit, modelUnit);
9298
this.bindingsAcquirer = bindings::all;
9399
this.isJustAfterStringLiteral = this.node instanceof StringLiteral && this.node.getLength() > 1 && this.offset >= this.node.getStartPosition() + this.node.getLength() && textContent.charAt(this.offset - 1) == '"';
94100
}
@@ -175,6 +181,10 @@ public void setInJavadoc(boolean inJavadoc) {
175181

176182
@Override
177183
public IJavaElement getEnclosingElement() {
184+
if (!this.enclosingElementComputed) {
185+
this.enclosingElement = computeEnclosingElement(domUnit, modelUnit);
186+
this.enclosingElementComputed = true;
187+
}
178188
return this.enclosingElement;
179189
}
180190

0 commit comments

Comments
 (0)