use of org.checkerframework.checker.interning.qual.CompareToMethod in project checker-framework by typetools.
the class InterningVisitor method visitMethod.
// Ensure that method annotations are not written on methods they don't apply to.
@Override
public Void visitMethod(MethodTree node, Void p) {
ExecutableElement methElt = TreeUtils.elementFromDeclaration(node);
boolean hasCompareToMethodAnno = atypeFactory.getDeclAnnotation(methElt, CompareToMethod.class) != null;
boolean hasEqualsMethodAnno = atypeFactory.getDeclAnnotation(methElt, EqualsMethod.class) != null;
boolean hasInternMethodAnno = atypeFactory.getDeclAnnotation(methElt, InternMethod.class) != null;
int params = methElt.getParameters().size();
if (hasCompareToMethodAnno && !(params == 1 || params == 2)) {
checker.reportError(node, "invalid.method.annotation", "@CompareToMethod", "1 or 2", methElt, params);
} else if (hasEqualsMethodAnno && !(params == 1 || params == 2)) {
checker.reportError(node, "invalid.method.annotation", "@EqualsMethod", "1 or 2", methElt, params);
} else if (hasInternMethodAnno && !(params == 0)) {
checker.reportError(node, "invalid.method.annotation", "@InternMethod", "0", methElt, params);
}
return super.visitMethod(node, p);
}
Aggregations