5252import com .sun .tools .javac .api .JavacTaskImpl ;
5353import com .sun .tools .javac .api .JavacTrees ;
5454import com .sun .tools .javac .code .Attribute ;
55+ import com .sun .tools .javac .code .Attribute .Compound ;
5556import com .sun .tools .javac .code .ClassFinder ;
5657import com .sun .tools .javac .code .Symbol ;
57- import com .sun .tools .javac .code .Symtab ;
58- import com .sun .tools .javac .code .TypeTag ;
59- import com .sun .tools .javac .code .Types ;
60- import com .sun .tools .javac .code .Attribute .Compound ;
6158import com .sun .tools .javac .code .Symbol .ClassSymbol ;
6259import com .sun .tools .javac .code .Symbol .CompletionFailure ;
6360import com .sun .tools .javac .code .Symbol .MethodSymbol ;
6764import com .sun .tools .javac .code .Symbol .TypeSymbol ;
6865import com .sun .tools .javac .code .Symbol .TypeVariableSymbol ;
6966import com .sun .tools .javac .code .Symbol .VarSymbol ;
67+ import com .sun .tools .javac .code .Symtab ;
7068import com .sun .tools .javac .code .Type .ArrayType ;
7169import com .sun .tools .javac .code .Type .ClassType ;
7270import com .sun .tools .javac .code .Type .ErrorType ;
7876import com .sun .tools .javac .code .Type .ModuleType ;
7977import com .sun .tools .javac .code .Type .PackageType ;
8078import com .sun .tools .javac .code .Type .TypeVar ;
79+ import com .sun .tools .javac .code .TypeTag ;
80+ import com .sun .tools .javac .code .Types ;
8181import com .sun .tools .javac .comp .Modules ;
8282import com .sun .tools .javac .tree .JCTree ;
83- import com .sun .tools .javac .tree .TreeInfo ;
8483import com .sun .tools .javac .tree .JCTree .JCAnnotatedType ;
8584import com .sun .tools .javac .tree .JCTree .JCAnnotation ;
8685import com .sun .tools .javac .tree .JCTree .JCArrayTypeTree ;
107106import com .sun .tools .javac .tree .JCTree .JCTypeUnion ;
108107import com .sun .tools .javac .tree .JCTree .JCVariableDecl ;
109108import com .sun .tools .javac .tree .JCTree .JCWildcard ;
109+ import com .sun .tools .javac .tree .TreeInfo ;
110110import com .sun .tools .javac .util .Context ;
111111import com .sun .tools .javac .util .Names ;
112112
@@ -159,24 +159,29 @@ public JavacMemberValuePairBinding getDefaultMemberValuePairBinding(IMethodBindi
159159 }
160160 //
161161 private Map <JavacMethodBinding , JavacMethodBinding > methodBindings = new HashMap <>();
162- public JavacMethodBinding getMethodBinding (MethodType methodType , MethodSymbol sym , com .sun .tools .javac .code .Type type ,
163- boolean isSynthetic , boolean isDeclaration ) {
162+ public JavacMethodBinding getMethodBinding (MethodType methodType , MethodSymbol sym ,
163+ com .sun .tools .javac .code .Type type ,
164+ boolean isSynthetic , boolean isDeclaration ,
165+ List <com .sun .tools .javac .code .Type > typeArgs ) {
164166 if ( isSynthetic ) {
165- return getSyntheticMethodBinding (methodType , sym , type );
167+ return getSyntheticMethodBinding (methodType , sym , type , typeArgs );
166168 } else {
167- return getMethodBinding (methodType , sym , type , isDeclaration );
169+ return getMethodBinding (methodType , sym , type , isDeclaration , typeArgs );
168170 }
169171 }
170172
171- public JavacMethodBinding getMethodBinding (MethodType methodType , MethodSymbol methodSymbol , com .sun .tools .javac .code .Type parentType , boolean isDeclaration ) {
172- JavacMethodBinding newInstance = new JavacMethodBinding (methodType , methodSymbol , parentType , JavacBindingResolver .this , false , isDeclaration ) { };
173+ public JavacMethodBinding getMethodBinding (MethodType methodType , MethodSymbol methodSymbol ,
174+ com .sun .tools .javac .code .Type parentType , boolean isDeclaration ,
175+ List <com .sun .tools .javac .code .Type > resolvedTypeArgs ) {
176+ JavacMethodBinding newInstance = new JavacMethodBinding (methodType , methodSymbol , parentType , JavacBindingResolver .this , false , isDeclaration , resolvedTypeArgs ) { };
173177 return insertAndReturn (newInstance );
174178 }
175- public JavacMethodBinding getSyntheticMethodBinding (MethodType methodType , MethodSymbol methodSymbol , com .sun .tools .javac .code .Type parentType ) {
176- JavacMethodBinding newInstance = new JavacMethodBinding (methodType , methodSymbol , parentType , JavacBindingResolver .this , true , false ) { };
179+ public JavacMethodBinding getSyntheticMethodBinding (MethodType methodType , MethodSymbol methodSymbol ,
180+ com .sun .tools .javac .code .Type parentType , List <com .sun .tools .javac .code .Type > resolvedTypeArgs ) {
181+ JavacMethodBinding newInstance = new JavacMethodBinding (methodType , methodSymbol , parentType , JavacBindingResolver .this , true , false , resolvedTypeArgs ) { };
177182 return insertAndReturn (newInstance );
178183 }
179- public JavacMethodBinding getErrorMethodBinding (MethodType methodType , Symbol originatingSymbol ) {
184+ public JavacMethodBinding getErrorMethodBinding (MethodType methodType , Symbol originatingSymbol , List < com . sun . tools . javac . code . Type > typeArgs ) {
180185 JavacMethodBinding newInstance = new JavacErrorMethodBinding (originatingSymbol , methodType , JavacBindingResolver .this ) { };
181186 return insertAndReturn (newInstance );
182187 }
@@ -370,7 +375,7 @@ public IBinding getBinding(final Symbol owner, final com.sun.tools.javac.code.Ty
370375 }
371376 if (type != null && (type instanceof ErrorType || owner == null || owner .owner == null || owner .owner .type == com .sun .tools .javac .code .Type .noType )) {
372377 if (type .getOriginalType () instanceof MethodType missingMethodType ) {
373- return getErrorMethodBinding (missingMethodType , owner );
378+ return getErrorMethodBinding (missingMethodType , owner , null );
374379 }
375380 }
376381 if (owner instanceof final PackageSymbol other ) {
@@ -391,7 +396,7 @@ public IBinding getBinding(final Symbol owner, final com.sun.tools.javac.code.Ty
391396 owner .type != null ? owner .type .asMethodType () :
392397 null ;
393398 if (methodType != null ) {
394- return getMethodBinding (methodType , other , null , false );
399+ return getMethodBinding (methodType , other , null , false , null );
395400 }
396401 } else if (owner instanceof final VarSymbol other ) {
397402 return getVariableBinding (other );
@@ -858,8 +863,9 @@ IVariableBinding resolveField(SuperFieldAccess fieldAccess) {
858863 IMethodBinding resolveMethod (MethodInvocation method ) {
859864 resolve ();
860865 JCTree javacElement = this .converter .domToJavac .get (method );
861- List <com .sun .tools .javac .code .Type > typeArgs = List . of () ;
866+ List <com .sun .tools .javac .code .Type > typeArgs = null ;
862867 if (javacElement instanceof JCMethodInvocation javacMethodInvocation ) {
868+ typeArgs = List .of ();
863869 javacElement = javacMethodInvocation .getMethodSelect ();
864870 typeArgs = javacMethodInvocation .getTypeArguments ().stream ().map (jcExpr -> jcExpr .type ).toList ();
865871 }
@@ -879,7 +885,7 @@ IMethodBinding resolveMethod(MethodInvocation method) {
879885 if (type != null &&
880886 type .tsym .members ().findFirst (ident .getName (), MethodSymbol .class ::isInstance ) instanceof MethodSymbol methodSymbol &&
881887 methodSymbol .type instanceof MethodType methodType ) {
882- var res = this .bindings .getMethodBinding (methodType , methodSymbol , null , false );
888+ var res = this .bindings .getMethodBinding (methodType , methodSymbol , null , false , typeArgs );
883889 if (res != null ) {
884890 return res ;
885891 }
@@ -903,10 +909,10 @@ IMethodBinding resolveMethod(MethodInvocation method) {
903909 if (sym .owner instanceof TypeSymbol typeSymbol ) {
904910 Iterator <Symbol > methods = typeSymbol .members ().getSymbolsByName (sym .getSimpleName (), m -> m instanceof MethodSymbol && methodType .equals (m .type )).iterator ();
905911 if (methods .hasNext ()) {
906- return this .bindings .getMethodBinding (methodType , (MethodSymbol )methods .next (), null , false );
912+ return this .bindings .getMethodBinding (methodType , (MethodSymbol )methods .next (), null , false , typeArgs );
907913 }
908914 }
909- return this .bindings .getErrorMethodBinding (methodType , sym );
915+ return this .bindings .getErrorMethodBinding (methodType , sym , typeArgs );
910916 }
911917 }
912918
@@ -923,21 +929,23 @@ && resolveExpressionType(method.getExpression()) instanceof JavacTypeBinding exp
923929 parentType = ownerClass .type ;
924930 }
925931 }
926- return this .bindings .getMethodBinding (methodType , methodSymbol , parentType , false );
932+ return this .bindings .getMethodBinding (methodType , methodSymbol , parentType , false , typeArgs );
927933 }
928934 if (type == null && sym instanceof MethodSymbol methodSym && methodSym .type instanceof ForAll methodTemplateType ) {
929935 // build type from template
930936 Map <TypeVar , com .sun .tools .javac .code .Type > resolutionMapping = new HashMap <>();
931937 var templateParameters = methodTemplateType .getTypeVariables ();
932- for (int i = 0 ; i < typeArgs .size () && i < templateParameters .size (); i ++) {
933- resolutionMapping .put (templateParameters .get (i ), typeArgs .get (i ));
938+ if ( typeArgs != null ) {
939+ for (int i = 0 ; i < typeArgs .size () && i < templateParameters .size (); i ++) {
940+ resolutionMapping .put (templateParameters .get (i ), typeArgs .get (i ));
941+ }
934942 }
935943 MethodType methodType = new MethodType (
936944 methodTemplateType .asMethodType ().getParameterTypes ().map (t -> applyType (t , resolutionMapping )),
937945 applyType (methodTemplateType .asMethodType ().getReturnType (), resolutionMapping ),
938946 methodTemplateType .asMethodType ().getThrownTypes ().map (t -> applyType (t , resolutionMapping )),
939947 methodTemplateType .tsym );
940- return this .bindings .getMethodBinding (methodType , methodSym , methodSym .owner .type , false );
948+ return this .bindings .getMethodBinding (methodType , methodSym , methodSym .owner .type , false , typeArgs );
941949 }
942950 if (type == null && sym != null && sym .type .isErroneous ()
943951 && sym .owner .type instanceof ClassType classType ) {
@@ -1010,10 +1018,10 @@ IMethodBinding resolveMethod(MethodDeclaration method) {
10101018 JCTree javacElement = this .converter .domToJavac .get (method );
10111019 if (javacElement instanceof JCMethodDecl methodDecl && !(methodDecl .type instanceof ErrorType )) {
10121020 if (methodDecl .type != null ) {
1013- return this .bindings .getMethodBinding (methodDecl .type .asMethodType (), methodDecl .sym , null , true );
1021+ return this .bindings .getMethodBinding (methodDecl .type .asMethodType (), methodDecl .sym , null , true , null );
10141022 }
10151023 if (methodDecl .sym instanceof MethodSymbol methodSymbol && methodSymbol .type != null ) {
1016- return this .bindings .getMethodBinding (methodSymbol .type .asMethodType (), methodSymbol , null , true );
1024+ return this .bindings .getMethodBinding (methodSymbol .type .asMethodType (), methodSymbol , null , true , null );
10171025 }
10181026 }
10191027 return null ;
@@ -1037,22 +1045,28 @@ IMethodBinding resolveMethod(MethodReference methodReference) {
10371045 resolve ();
10381046 JCTree javacElement = this .converter .domToJavac .get (methodReference );
10391047 if (javacElement instanceof JCMemberReference memberRef && memberRef .sym instanceof MethodSymbol methodSymbol ) {
1048+ List <com .sun .tools .javac .code .Type > typeArgs = streamOfTreeType (memberRef .getTypeArguments ());
10401049 if (memberRef .referentType != null && memberRef .referentType instanceof MethodType ) {
1041- return this .bindings .getMethodBinding (memberRef .referentType .asMethodType (), methodSymbol , null , false );
1050+ return this .bindings .getMethodBinding (memberRef .referentType .asMethodType (), methodSymbol , null , false , typeArgs );
10421051 }
10431052 if (methodSymbol .type instanceof MethodType ) {
1044- return this .bindings .getMethodBinding (methodSymbol .type .asMethodType (), methodSymbol , null , false );
1053+ return this .bindings .getMethodBinding (methodSymbol .type .asMethodType (), methodSymbol , null , false , typeArgs );
10451054 }
10461055 }
10471056 return null ;
10481057 }
10491058
1059+ private List <com .sun .tools .javac .code .Type > streamOfTreeType (List <? extends JCTree > items ) {
1060+ return items != null ? items .stream ().map (x -> x .type ).toList () : new ArrayList <com .sun .tools .javac .code .Type >();
1061+ }
1062+
10501063 @ Override
10511064 IMethodBinding resolveMember (AnnotationTypeMemberDeclaration member ) {
10521065 resolve ();
10531066 JCTree javacElement = this .converter .domToJavac .get (member );
10541067 if (javacElement instanceof JCMethodDecl methodDecl ) {
1055- return this .bindings .getMethodBinding (methodDecl .type .asMethodType (), methodDecl .sym , null , true );
1068+ List <com .sun .tools .javac .code .Type > typeArgs = streamOfTreeType (methodDecl .getTypeParameters ());
1069+ return this .bindings .getMethodBinding (methodDecl .type .asMethodType (), methodDecl .sym , null , true , typeArgs );
10561070 }
10571071 return null ;
10581072 }
@@ -1064,10 +1078,11 @@ IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaratio
10641078 if ( javacElement instanceof JCVariableDecl jcvd ) {
10651079 javacElement = jcvd .init ;
10661080 }
1067- return javacElement instanceof JCNewClass jcExpr
1068- && !jcExpr .constructor .type .isErroneous ()?
1069- this .bindings .getMethodBinding (jcExpr .constructor .type .asMethodType (), (MethodSymbol )jcExpr .constructor , null , true ) :
1070- null ;
1081+ if (javacElement instanceof JCNewClass jcExpr && !jcExpr .constructor .type .isErroneous ()) {
1082+ List <com .sun .tools .javac .code .Type > typeArgs = streamOfTreeType (jcExpr .typeargs );
1083+ return this .bindings .getMethodBinding (jcExpr .constructor .type .asMethodType (), (MethodSymbol )jcExpr .constructor , null , true , typeArgs );
1084+ }
1085+ return null ;
10711086 }
10721087
10731088 @ Override
@@ -1079,13 +1094,13 @@ IMethodBinding resolveConstructor(SuperConstructorInvocation expression) {
10791094 }
10801095 if (javacElement instanceof JCIdent ident && ident .sym instanceof MethodSymbol methodSymbol ) {
10811096 if (ident .type != null && (ident .type instanceof MethodType || ident .type instanceof ForAll )) {
1082- return this .bindings .getMethodBinding (ident .type .asMethodType (), methodSymbol , null , false );
1097+ return this .bindings .getMethodBinding (ident .type .asMethodType (), methodSymbol , null , false , null );
10831098 } else if (methodSymbol .asType () instanceof MethodType || methodSymbol .asType () instanceof ForAll ) {
1084- return this .bindings .getMethodBinding (methodSymbol .asType ().asMethodType (), methodSymbol , null , false );
1099+ return this .bindings .getMethodBinding (methodSymbol .asType ().asMethodType (), methodSymbol , null , false , null );
10851100 }
10861101 }
10871102 if (javacElement instanceof JCFieldAccess fieldAccess && fieldAccess .sym instanceof MethodSymbol methodSymbol ) {
1088- return this .bindings .getMethodBinding (fieldAccess .type .asMethodType (), methodSymbol , null , false );
1103+ return this .bindings .getMethodBinding (fieldAccess .type .asMethodType (), methodSymbol , null , false , null );
10891104 }
10901105 return null ;
10911106 }
@@ -1098,11 +1113,11 @@ IMethodBinding resolveMethod(SuperMethodInvocation method) {
10981113 javacElement = javacMethodInvocation .getMethodSelect ();
10991114 }
11001115 if (javacElement instanceof JCIdent ident && ident .sym instanceof MethodSymbol methodSymbol ) {
1101- return this .bindings .getMethodBinding (ident .type .asMethodType (), methodSymbol , null , false );
1116+ return this .bindings .getMethodBinding (ident .type .asMethodType (), methodSymbol , null , false , null );
11021117 }
11031118 if (javacElement instanceof JCFieldAccess fieldAccess && fieldAccess .sym instanceof MethodSymbol methodSymbol
11041119 && fieldAccess .type != null /* when there are syntax errors */ ) {
1105- return this .bindings .getMethodBinding (fieldAccess .type .asMethodType (), methodSymbol , null , false );
1120+ return this .bindings .getMethodBinding (fieldAccess .type .asMethodType (), methodSymbol , null , false , null );
11061121 }
11071122 return null ;
11081123 }
@@ -1509,7 +1524,9 @@ private IMethodBinding resolveConstructorImpl(ClassInstanceCreation expression)
15091524 resolve ();
15101525 if (this .converter .domToJavac .get (expression ) instanceof JCNewClass jcExpr ) {
15111526 if (jcExpr .constructor != null && !jcExpr .constructor .type .isErroneous ()) {
1512- return this .bindings .getMethodBinding (jcExpr .constructor .type .asMethodType (), (MethodSymbol )jcExpr .constructor , jcExpr .type , false );
1527+ List <com .sun .tools .javac .code .Type > javacTypeArgs =
1528+ jcExpr .getTypeArguments ().stream ().map (jc -> jc .type ).toList ();
1529+ return this .bindings .getMethodBinding (jcExpr .constructor .type .asMethodType (), (MethodSymbol )jcExpr .constructor , jcExpr .type , false , javacTypeArgs );
15131530 }
15141531 }
15151532 ITypeBinding type = resolveType (expression .getType ());
@@ -1575,10 +1592,11 @@ private IMethodBinding resolveConstructorImpl(ConstructorInvocation invocation)
15751592 javacElement = javacMethodInvocation .getMethodSelect ();
15761593 }
15771594 if (javacElement instanceof JCIdent ident && ident .sym instanceof MethodSymbol methodSymbol ) {
1578- return this .bindings .getMethodBinding (ident .type != null && ident .type .getKind () == TypeKind .EXECUTABLE ? ident .type .asMethodType () : methodSymbol .type .asMethodType (), methodSymbol , null , false );
1595+ MethodType mt = ident .type != null && ident .type .getKind () == TypeKind .EXECUTABLE ? ident .type .asMethodType () : methodSymbol .type .asMethodType ();
1596+ return this .bindings .getMethodBinding (mt , methodSymbol , null , false , null );
15791597 }
15801598 if (javacElement instanceof JCFieldAccess fieldAccess && fieldAccess .sym instanceof MethodSymbol methodSymbol ) {
1581- return this .bindings .getMethodBinding (fieldAccess .type .asMethodType (), methodSymbol , null , false );
1599+ return this .bindings .getMethodBinding (fieldAccess .type .asMethodType (), methodSymbol , null , false , null );
15821600 }
15831601 return null ;
15841602 }
0 commit comments