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

Skip early when class generics detected #43

Merged
merged 5 commits into from
Dec 16, 2023
Merged
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 @@ -678,11 +678,16 @@ private TemplateDescriptor validate(Context context, JCCompilationUnit cu) {
return null;
}

if (classDecl.typarams != null && !classDecl.typarams.isEmpty()) {
printNoteOnce("Generics are currently not supported", classDecl.sym);
return null;
}

boolean valid = true;
for (JCTree member : classDecl.getMembers()) {
if (member instanceof JCTree.JCMethodDecl && !beforeTemplates.contains(member) && member != afterTemplate) {
for (JCTree.JCAnnotation annotation : getTemplateAnnotations(((JCTree.JCMethodDecl) member), UNSUPPORTED_ANNOTATIONS::contains)) {
printNoteOnce("The @" + annotation.annotationType + " is currently not supported", ((JCTree.JCMethodDecl) member));
printNoteOnce("The @" + annotation.annotationType + " is currently not supported", ((JCTree.JCMethodDecl) member).sym);
valid = false;
}
}
Expand All @@ -703,22 +708,22 @@ private boolean validateTemplateMethod(JCTree.JCMethodDecl template) {
boolean valid = true;
// TODO: support all Refaster method-level annotations
for (JCTree.JCAnnotation annotation : getTemplateAnnotations(template, UNSUPPORTED_ANNOTATIONS::contains)) {
printNoteOnce("The @" + annotation.annotationType + " is currently not supported", template);
printNoteOnce("The @" + annotation.annotationType + " is currently not supported", template.sym);
valid = false;
}
// TODO: support all Refaster parameter-level annotations
for (JCTree.JCVariableDecl parameter : template.getParameters()) {
for (JCTree.JCAnnotation annotation : getTemplateAnnotations(parameter, UNSUPPORTED_ANNOTATIONS::contains)) {
printNoteOnce("The @" + annotation.annotationType + " annotation is currently not supported", template);
printNoteOnce("The @" + annotation.annotationType + " annotation is currently not supported", template.sym);
valid = false;
}
if (parameter.vartype instanceof ParameterizedTypeTree || parameter.vartype.type instanceof Type.TypeVar) {
printNoteOnce("Generics are currently not supported", template);
printNoteOnce("Generics are currently not supported", template.sym);
valid = false;
}
}
if (template.restype instanceof ParameterizedTypeTree || template.restype.type instanceof Type.TypeVar) {
printNoteOnce("Generics are currently not supported", template);
printNoteOnce("Generics are currently not supported", template.sym);
valid = false;
}
valid &= new TreeScanner() {
Expand All @@ -733,7 +738,7 @@ boolean validate(JCTree tree) {
public void visitIdent(JCTree.JCIdent jcIdent) {
if (jcIdent.sym != null
&& jcIdent.sym.packge().getQualifiedName().contentEquals("com.google.errorprone.refaster")) {
printNoteOnce(jcIdent.type.tsym.getQualifiedName() + " is not supported", template);
printNoteOnce(jcIdent.type.tsym.getQualifiedName() + " is not supported", template.sym);
valid = false;
}
}
Expand Down Expand Up @@ -769,9 +774,9 @@ private boolean resolve(Context context, JCCompilationUnit cu) {

private final Set<String> printedMessages = new HashSet<>();

private void printNoteOnce(String message, JCTree.JCMethodDecl template) {
private void printNoteOnce(String message, Symbol symbol) {
if (printedMessages.add(message)) {
processingEnv.getMessager().printMessage(Kind.NOTE, message, template.sym);
processingEnv.getMessager().printMessage(Kind.NOTE, message, symbol);
}
}

Expand Down