Skip to content

Commit

Permalink
Skip early when class generics detected (#43)
Browse files Browse the repository at this point in the history
* Test problematic OrOrElseThrow

* Extract common methods to compile per test class

* Return early when class has generics

* Delete test again that required Java 11
  • Loading branch information
timtebeek authored Dec 16, 2023
1 parent 368f8b4 commit 4aa4d3d
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit 4aa4d3d

Please sign in to comment.