Skip to content

Commit

Permalink
Fix various binding and problem conversion issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Jul 2, 2024
1 parent 29050ac commit c6dc4d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ IMethodBinding resolveMethod(MethodInvocation method) {
javacElement = javacMethodInvocation.getMethodSelect();
}
if (javacElement instanceof JCIdent ident && ident.sym instanceof MethodSymbol methodSymbol) {
return this.bindings.getMethodBinding(ident.type.asMethodType(), methodSymbol);
return this.bindings.getMethodBinding(ident.type != null ? ident.type.asMethodType() : methodSymbol.asType().asMethodType(), methodSymbol);
}
if (javacElement instanceof JCFieldAccess fieldAccess && fieldAccess.sym instanceof MethodSymbol methodSymbol
&& fieldAccess.type != null /* when there are syntax errors */) {
Expand Down Expand Up @@ -515,7 +515,7 @@ IMethodBinding resolveConstructor(SuperConstructorInvocation expression) {
javacElement = javacMethodInvocation.getMethodSelect();
}
if (javacElement instanceof JCIdent ident && ident.sym instanceof MethodSymbol methodSymbol) {
return this.bindings.getMethodBinding(ident.type.asMethodType(), methodSymbol);
return this.bindings.getMethodBinding(ident.type != null ? ident.type.asMethodType() : methodSymbol.asType().asMethodType(), methodSymbol);
}
if (javacElement instanceof JCFieldAccess fieldAccess && fieldAccess.sym instanceof MethodSymbol methodSymbol) {
return this.bindings.getMethodBinding(fieldAccess.type.asMethodType(), methodSymbol);
Expand Down Expand Up @@ -715,7 +715,7 @@ IMethodBinding resolveConstructor(ConstructorInvocation invocation) {
javacElement = javacMethodInvocation.getMethodSelect();
}
if (javacElement instanceof JCIdent ident && ident.sym instanceof MethodSymbol methodSymbol) {
return this.bindings.getMethodBinding(ident.type.asMethodType(), methodSymbol);
return this.bindings.getMethodBinding(ident.type != null ? ident.type.asMethodType() : methodSymbol.type.asMethodType(), methodSymbol);
}
if (javacElement instanceof JCFieldAccess fieldAccess && fieldAccess.sym instanceof MethodSymbol methodSymbol) {
return this.bindings.getMethodBinding(fieldAccess.type.asMethodType(), methodSymbol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ public int toProblemId(Diagnostic<? extends JavaFileObject> diagnostic) {
case "compiler.warn.empty.if" -> IProblem.EmptyControlFlowStatement;
case "compiler.warn.redundant.cast" -> IProblem.UnnecessaryCast;
case "compiler.err.illegal.char" -> IProblem.InvalidCharacterConstant;
case "compiler.err.enum.label.must.be.unqualified.enum" -> IProblem.UndefinedField;
// next are javadoc; defaulting to JavadocUnexpectedText when no better problem could be found
case "compiler.err.dc.bad.entity" -> IProblem.JavadocUnexpectedText;
case "compiler.err.dc.bad.inline.tag" -> IProblem.JavadocUnexpectedText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.sun.tools.javac.code.Type.PackageType;
import com.sun.tools.javac.code.Type.TypeVar;
import com.sun.tools.javac.code.Type.WildcardType;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;

Expand Down Expand Up @@ -152,6 +153,10 @@ static void getKey(StringBuilder builder, Type typeToBuild, boolean isLeaf) {
if (typeToBuild instanceof Type.JCNoType) {
return;
}
if (typeToBuild.hasTag(TypeTag.UNKNOWN)) {
builder.append('*');
return;
}
if (typeToBuild instanceof ArrayType arrayType) {
builder.append('[');
getKey(builder, arrayType.elemtype, isLeaf);
Expand Down Expand Up @@ -513,9 +518,12 @@ public ITypeBinding getSuperclass() {

@Override
public IAnnotationBinding[] getTypeAnnotations() {
return this.typeSymbol.getAnnotationMirrors().stream()
.map(annotation -> this.resolver.bindings.getAnnotationBinding(annotation, this))
.toArray(IAnnotationBinding[]::new);
if (this.typeSymbol.hasTypeAnnotations()) {
return new IAnnotationBinding[0];
}
// TODO implement this correctly (used to be returning
// same as getAnnotations() which is incorrect
return new IAnnotationBinding[0];
}

@Override
Expand Down

0 comments on commit c6dc4d0

Please sign in to comment.