Search in sources :

Example 6 with CanonicalName

use of org.checkerframework.checker.signature.qual.CanonicalName in project checker-framework by typetools.

the class AnnotationUtils method getElementValueClassName.

/**
 * Get the Name of the class that is referenced by element {@code element}.
 *
 * <p>This is a convenience method for the most common use-case. It is like {@code
 * getElementValue(anno, element, ClassType.class).getQualifiedName()}, but this method ensures
 * consistent use of the qualified name.
 *
 * <p>This method is intended only for use by the framework. A checker implementation should use
 * {@code anno.getElementValues().get(someElement).getValue().asElement().getQualifiedName();}.
 *
 * @param anno the annotation to disassemble
 * @param element the element to access; it must be present in the annotation
 * @return the name of the class that is referenced by element with the given name; may be an
 *     empty name, for a local or anonymous class
 */
@CanonicalName
public static Name getElementValueClassName(AnnotationMirror anno, ExecutableElement element) {
    Type.ClassType ct = getElementValue(anno, element, Type.ClassType.class);
    if (ct == null) {
        throw new BugInCF("getElementValueClassName(%s, %s, ...)", anno, element);
    }
    // TODO:  Is it a problem that this returns the type parameters too?  Should I cut them off?
    @CanonicalName Name result = ct.asElement().getQualifiedName();
    return result;
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType) ElementType(java.lang.annotation.ElementType) Type(com.sun.tools.javac.code.Type) CanonicalName(org.checkerframework.checker.signature.qual.CanonicalName) BinaryName(org.checkerframework.checker.signature.qual.BinaryName) CanonicalName(org.checkerframework.checker.signature.qual.CanonicalName) Name(javax.lang.model.element.Name) CanonicalName(org.checkerframework.checker.signature.qual.CanonicalName)

Example 7 with CanonicalName

use of org.checkerframework.checker.signature.qual.CanonicalName in project checker-framework by typetools.

the class AnnotationUtils method annotationName.

// **********************************************************************
// Helper methods to handle annotations.  mainly workaround
// AnnotationMirror.equals undesired property
// (I think the undesired property is that it's reference equality.)
// **********************************************************************
/**
 * Returns the fully-qualified name of an annotation as a String.
 *
 * @param annotation the annotation whose name to return
 * @return the fully-qualified name of an annotation as a String
 */
@CanonicalName
public static final String annotationName(AnnotationMirror annotation) {
    if (annotation instanceof AnnotationBuilder.CheckerFrameworkAnnotationMirror) {
        return ((AnnotationBuilder.CheckerFrameworkAnnotationMirror) annotation).annotationName;
    }
    final DeclaredType annoType = annotation.getAnnotationType();
    final TypeElement elm = (TypeElement) annoType.asElement();
    // JDK needs annotations
    @SuppressWarnings("signature:assignment") @CanonicalName String name = elm.getQualifiedName().toString();
    return name;
}
Also used : CheckerFrameworkAnnotationMirror(org.checkerframework.javacutil.AnnotationBuilder.CheckerFrameworkAnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) CanonicalName(org.checkerframework.checker.signature.qual.CanonicalName) CanonicalName(org.checkerframework.checker.signature.qual.CanonicalName)

Example 8 with CanonicalName

use of org.checkerframework.checker.signature.qual.CanonicalName in project checker-framework by typetools.

the class InterningVisitor method typeToCheck.

/**
 * Returns the type to check.
 *
 * @return the type to check
 */
DeclaredType typeToCheck() {
    // user input
    @SuppressWarnings("signature:assignment") @CanonicalName String className = checker.getOption("checkclass");
    if (className == null) {
        return null;
    }
    TypeElement classElt = elements.getTypeElement(className);
    if (classElt == null) {
        return null;
    }
    return types.getDeclaredType(classElt);
}
Also used : TypeElement(javax.lang.model.element.TypeElement) CanonicalName(org.checkerframework.checker.signature.qual.CanonicalName)

Aggregations

CanonicalName (org.checkerframework.checker.signature.qual.CanonicalName)8 Name (javax.lang.model.element.Name)5 AnnotationMirror (javax.lang.model.element.AnnotationMirror)3 TypeElement (javax.lang.model.element.TypeElement)3 DeclaredType (javax.lang.model.type.DeclaredType)3 BinaryName (org.checkerframework.checker.signature.qual.BinaryName)3 FullyQualifiedName (org.checkerframework.checker.signature.qual.FullyQualifiedName)3 Type (com.sun.tools.javac.code.Type)2 ElementType (java.lang.annotation.ElementType)2 ArrayList (java.util.ArrayList)2 NodeList (com.github.javaparser.ast.NodeList)1 Expression (com.github.javaparser.ast.expr.Expression)1 MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)1 MemberValuePair (com.github.javaparser.ast.expr.MemberValuePair)1 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)1 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)1 List (java.util.List)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 DotSeparatedIdentifiers (org.checkerframework.checker.signature.qual.DotSeparatedIdentifiers)1 FieldInvariants (org.checkerframework.framework.util.FieldInvariants)1