Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for an upcoming change to TypeMetadata #3827

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sun.tools.javac.code.Type.StructuralTypeMapping;
import com.sun.tools.javac.code.TypeMetadata;
import com.sun.tools.javac.code.Types;
import java.lang.reflect.Method;

/** Utility method to produce {@link Api} objects from javac {@link MethodSymbol}. */
public final class ApiFactory {
Expand Down Expand Up @@ -58,15 +59,30 @@ public Type visitType(Type t, Void unused) {

@Override
public Type visitClassType(Type.ClassType t, Void unused) {
return super.visitClassType(t.cloneWithMetadata(TypeMetadata.EMPTY), unused);
return super.visitClassType((Type.ClassType) cloneWithoutMetadata(t), unused);
}

// Remove annotations from all enclosing containers
@Override
public Type visitArrayType(Type.ArrayType t, Void unused) {
return super.visitArrayType(t.cloneWithMetadata(TypeMetadata.EMPTY), unused);
return super.visitArrayType((Type.ArrayType) cloneWithoutMetadata(t), unused);
}
};

public static Type cloneWithoutMetadata(Type type) {
try {
try {
Method method = Type.class.getMethod("cloneWithMetadata", TypeMetadata.class);
return (Type) method.invoke(type, TypeMetadata.class.getField("EMPTY").get(null));
} catch (NoSuchMethodException e) {
Class<?> annotations = Class.forName("com.sun.tools.javac.code.TypeMetadata$Annotations");
Method method = Type.class.getMethod("dropMetadata", Class.class);
return (Type) method.invoke(type, annotations);
}
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private ApiFactory() {}
}