1919import java .util .Set ;
2020import java .util .stream .Collectors ;
2121
22- import org .eclipse .jdt .core .IJavaElement ;
2322import org .eclipse .jdt .core .IMethod ;
2423import org .eclipse .jdt .core .IType ;
2524import org .eclipse .jdt .core .JavaModelException ;
3231import org .eclipse .jdt .core .dom .ITypeBinding ;
3332import org .eclipse .jdt .core .dom .IVariableBinding ;
3433import org .eclipse .jdt .core .dom .JavacBindingResolver ;
35- import org .eclipse .jdt .core .dom .JavacBindingResolver .BindingKeyException ;
3634import org .eclipse .jdt .core .dom .LambdaExpression ;
3735import org .eclipse .jdt .core .dom .MethodDeclaration ;
3836import org .eclipse .jdt .core .dom .Modifier ;
3937import org .eclipse .jdt .core .dom .SingleVariableDeclaration ;
4038import org .eclipse .jdt .core .dom .TypeParameter ;
39+ import org .eclipse .jdt .core .dom .JavacBindingResolver .BindingKeyException ;
4140import org .eclipse .jdt .internal .codeassist .DOMCompletionUtil ;
4241import org .eclipse .jdt .internal .core .BinaryMethod ;
4342import org .eclipse .jdt .internal .core .JavaElement ;
5049import com .sun .tools .javac .code .Flags ;
5150import com .sun .tools .javac .code .Kinds ;
5251import com .sun .tools .javac .code .Symbol ;
52+ import com .sun .tools .javac .code .Type ;
5353import com .sun .tools .javac .code .Symbol .ClassSymbol ;
5454import com .sun .tools .javac .code .Symbol .MethodSymbol ;
5555import com .sun .tools .javac .code .Symbol .TypeSymbol ;
5656import com .sun .tools .javac .code .Symbol .VarSymbol ;
57- import com .sun .tools .javac .code .Type ;
5857import com .sun .tools .javac .code .Type .ForAll ;
5958import com .sun .tools .javac .code .Type .JCNoType ;
6059import com .sun .tools .javac .code .Type .MethodType ;
@@ -74,7 +73,7 @@ public abstract class JavacMethodBinding implements IMethodBinding {
7473 final boolean explicitSynthetic ;
7574 // allows to discriminate generic vs parameterized
7675 private final boolean isDeclaration ;
77- private IJavaElement javaElement ;
76+ private IMethod javaElement ;
7877 private String key ;
7978
8079 /**
@@ -202,14 +201,19 @@ public boolean isSynthetic() {
202201 }
203202
204203 @ Override
205- public IJavaElement getJavaElement () {
204+ public IMethod getJavaElement () {
205+ this .javaElement = resolved (getUnresolvedJavaElement ());
206+ return this .javaElement ;
207+ }
208+
209+ IMethod getUnresolvedJavaElement () {
206210 if (this .javaElement == null ) {
207- this .javaElement = computeJavaElement ();
211+ this .javaElement = computeUnresolvedJavaElement ();
208212 }
209213 return this .javaElement ;
210- }
214+ }
211215
212- private IJavaElement computeJavaElement () {
216+ private IMethod computeUnresolvedJavaElement () {
213217 if (this .methodSymbol == null ) {
214218 return null ;
215219 }
@@ -231,7 +235,7 @@ private IJavaElement computeJavaElement() {
231235 .toArray (String []::new );
232236 IMethod [] methods = currentType .findMethods (currentType .getMethod (getName (), parametersResolved ));
233237 if (methods != null && methods .length > 0 ) {
234- return resolved ( methods [0 ]) ;
238+ return methods [0 ];
235239 }
236240 var parametersNotResolved = this .methodSymbol .params ().stream ()
237241 .map (varSymbol -> varSymbol .type )
@@ -241,14 +245,14 @@ private IJavaElement computeJavaElement() {
241245 .toArray (String []::new );
242246 methods = currentType .findMethods (currentType .getMethod (getName (), parametersNotResolved ));
243247 if (methods != null && methods .length > 0 ) {
244- return resolved ( methods [0 ]) ;
248+ return methods [0 ];
245249 }
246250 }
247251 }
248252 return null ;
249253 }
250254
251- private IJavaElement getJavaElementForMethodDeclaration (IType currentType , MethodDeclaration methodDeclaration ) {
255+ private IMethod getJavaElementForMethodDeclaration (IType currentType , MethodDeclaration methodDeclaration ) {
252256 ArrayList <String > typeParamsList = new ArrayList <>();
253257 List <TypeParameter > typeParams = null ;
254258 typeParams = methodDeclaration .typeParameters ();
@@ -270,7 +274,7 @@ private IJavaElement getJavaElementForMethodDeclaration(IType currentType, Metho
270274 }).toArray (String []::new );
271275 IMethod result = currentType .getMethod (getName (), params );
272276 if (currentType .isBinary () || result .exists ()) {
273- return resolved ( result ) ;
277+ return result ;
274278 }
275279 IMethod [] methods = null ;
276280 try {
@@ -282,10 +286,16 @@ private IJavaElement getJavaElementForMethodDeclaration(IType currentType, Metho
282286 IMethod [] candidates = Member .findMethods (result , methods );
283287 if (candidates == null || candidates .length == 0 )
284288 return null ;
285- return resolved ( candidates [0 ]) ;
289+ return candidates [0 ];
286290 }
287291
288292 private IMethod resolved (IMethod from ) {
293+ if (from == null ) {
294+ return null ;
295+ }
296+ if (from .isResolved ()) {
297+ return from ;
298+ }
289299 if (from instanceof SourceMethod && !(from instanceof ResolvedSourceMethod )) {
290300 return new ResolvedSourceMethod ((JavaElement )from .getParent (), from .getElementName (), from .getParameterTypes (), computeKeyWithThrowsFromJavadoc (from ), from .getOccurrenceCount ());
291301 }
@@ -313,7 +323,7 @@ private String computeKeyWithThrowsFromJavadoc(IMethod method) {
313323 return getKey () + Arrays .stream (exceptions ).map (t -> '|' + t .replace ('.' , '/' )).collect (Collectors .joining ());
314324 }
315325
316- private IJavaElement getJavaElementForAnnotationTypeMemberDeclaration (IType currentType , AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration ) {
326+ private IMethod getJavaElementForAnnotationTypeMemberDeclaration (IType currentType , AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration ) {
317327 IMethod result = currentType .getMethod (getName (), new String [0 ]);
318328 if (currentType .isBinary () || result .exists ()) {
319329 return result ;
0 commit comments