Skip to content

Commit

Permalink
Fix testTypeReference22
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>

Small change as per suggestion

Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Dec 2, 2024
1 parent d0be67c commit f546e96
Showing 1 changed file with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ private JavacPackageBinding preferentiallyInsertPackageBinding(JavacPackageBindi
public JavacTypeBinding getTypeBinding(JCTree tree, com.sun.tools.javac.code.Type type) {
return getTypeBinding(type, tree instanceof JCClassDecl);
}


public JavacTypeBinding getTypeBinding(com.sun.tools.javac.code.Type type) {
if (type == null) {
return null;
Expand Down Expand Up @@ -565,7 +567,8 @@ public ITypeBinding resolveType(Type type) {
return this.bindings.getTypeBinding(ident.type);
}
if (jcTree instanceof JCFieldAccess access) {
return this.bindings.getTypeBinding(access.type);
IBinding b = this.getFieldAccessBinding(access);
return b instanceof ITypeBinding tb ? tb : null;
}
if (jcTree instanceof JCPrimitiveTypeTree primitive && primitive.type != null) {
return this.bindings.getTypeBinding(primitive.type);
Expand Down Expand Up @@ -1165,37 +1168,7 @@ IBinding resolveNameToJavac(Name name, JCTree tree) {
return this.bindings.getTypeBinding(variableDecl.type);
}
if (tree instanceof JCFieldAccess fieldAccess) {
JCFieldAccess jcfa2 = (fieldAccess.sym == null && fieldAccess.selected instanceof JCFieldAccess jcfa3) ? jcfa3 : fieldAccess;
if( jcfa2.sym != null ) {
com.sun.tools.javac.code.Type typeToUse = jcfa2.type;
if(jcfa2.selected instanceof JCTypeApply) {
typeToUse = jcfa2.sym.type;
}
IBinding bRet = this.bindings.getBinding(jcfa2.sym, typeToUse);
if( jcfa2 != fieldAccess && bRet instanceof ITypeBinding itb ) {
String fieldAccessIdentifier = fieldAccess.getIdentifier().toString();
// If we changed the field access, we need to go one generation lower
Function<IBinding[], IBinding> func = bindings -> {
for( int i = 0; i < bindings.length; i++ ) {
String childName = bindings[i].getName();
if( childName.equals(fieldAccessIdentifier)) {
return bindings[i];
}
}
return null;
};
IBinding ret = func.apply(itb.getDeclaredTypes());
if( ret != null )
return ret;
ret = func.apply(itb.getDeclaredFields());
if( ret != null )
return ret;
ret = func.apply(itb.getDeclaredMethods());
if( ret != null )
return ret;
}
return bRet;
}
return this.bindings.getFieldAccessBinding(fieldAccess);
}
if (tree instanceof JCMethodInvocation methodInvocation && methodInvocation.meth.type != null) {
return this.bindings.getBinding(((JCFieldAccess)methodInvocation.meth).sym, methodInvocation.meth.type);
Expand Down Expand Up @@ -1687,6 +1660,40 @@ private IBinding resolveReferenceImpl(MethodRef ref) {
return null;
}

private IBinding getFieldAccessBinding(JCFieldAccess fieldAccess) {
JCFieldAccess jcfa2 = (fieldAccess.sym == null && fieldAccess.selected instanceof JCFieldAccess jcfa3) ? jcfa3 : fieldAccess;
if( jcfa2.sym != null ) {
com.sun.tools.javac.code.Type typeToUse = jcfa2.type;
if(jcfa2.selected instanceof JCTypeApply) {
typeToUse = jcfa2.sym.type;
}
IBinding bRet = this.bindings.getBinding(jcfa2.sym, typeToUse);
if( jcfa2 != fieldAccess && bRet instanceof ITypeBinding itb ) {
String fieldAccessIdentifier = fieldAccess.getIdentifier().toString();
// If we changed the field access, we need to go one generation lower
Function<IBinding[], IBinding> func = bindings -> {
for( int i = 0; i < bindings.length; i++ ) {
String childName = bindings[i].getName();
if( childName.equals(fieldAccessIdentifier)) {
return bindings[i];
}
}
return null;
};
IBinding ret = func.apply(itb.getDeclaredTypes());
if( ret != null )
return ret;
ret = func.apply(itb.getDeclaredFields());
if( ret != null )
return ret;
ret = func.apply(itb.getDeclaredMethods());
if( ret != null )
return ret;
}
return bRet;
}
return null;
}
@Override
IBinding resolveReference(MemberRef ref) {
return resolveCached(ref, (n) -> resolveReferenceImpl((MemberRef)n));
Expand Down

0 comments on commit f546e96

Please sign in to comment.