Search in sources :

Example 1 with CompareToMethod

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);
}
Also used : InternMethod(org.checkerframework.checker.interning.qual.InternMethod) ExecutableElement(javax.lang.model.element.ExecutableElement) CompareToMethod(org.checkerframework.checker.interning.qual.CompareToMethod) EqualsMethod(org.checkerframework.checker.interning.qual.EqualsMethod)

Aggregations

ExecutableElement (javax.lang.model.element.ExecutableElement)1 CompareToMethod (org.checkerframework.checker.interning.qual.CompareToMethod)1 EqualsMethod (org.checkerframework.checker.interning.qual.EqualsMethod)1 InternMethod (org.checkerframework.checker.interning.qual.InternMethod)1