Search in sources :

Example 41 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class InitializationAnnotatedTypeFactory method createFreeAnnotation.

/**
 * Returns a {@link UnderInitialization} annotation with a given type frame.
 */
public AnnotationMirror createFreeAnnotation(Class<?> typeFrame) {
    assert typeFrame != null;
    assert useFbc : "The rawness type system does not have a @UnderInitialization annotation.";
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, UnderInitialization.class);
    builder.setValue("value", typeFrame);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder)

Example 42 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class KeyForAnnotatedTypeFactory method createKeyForAnnotationMirrorWithValue.

/*
     * Given a string array 'values', returns an AnnotationMirror corresponding to @KeyFor(values)
     */
public AnnotationMirror createKeyForAnnotationMirrorWithValue(LinkedHashSet<String> values) {
    // Create an AnnotationBuilder with the ArrayList
    AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), KeyFor.class);
    builder.setValue("value", values.toArray());
    // Return the resulting AnnotationMirror
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder)

Example 43 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class UnitsAnnotationClassLoader method isSupportedAnnotationClass.

/**
 * Custom filter for units annotations:
 *
 * <p>This filter will ignore (by returning false) any units annotation which is an alias of
 * another base unit annotation (identified via {@link UnitsMultiple} meta-annotation). Alias
 * annotations can still be used in source code; they are converted into a base annotation by
 * {@link UnitsAnnotatedTypeFactory#aliasedAnnotation(AnnotationMirror)}. This filter simply
 * makes sure that the alias annotations themselves don't become part of the type hierarchy as
 * their base annotations already are in the hierarchy.
 */
@Override
protected boolean isSupportedAnnotationClass(Class<? extends Annotation> annoClass) {
    // build the initial annotation mirror (missing prefix)
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, annoClass);
    AnnotationMirror initialResult = builder.build();
    // further refine to see if the annotation is an alias of some other SI Unit annotation
    for (AnnotationMirror metaAnno : initialResult.getAnnotationType().asElement().getAnnotationMirrors()) {
        // base units
        if (AnnotationUtils.areSameByClass(metaAnno, UnitsMultiple.class)) {
            return false;
        }
    }
    // Not an alias unit
    return true;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder)

Example 44 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class UnitsRelationsTools method buildAnnoMirrorWithSpecificPrefix.

/**
 * Creates an AnnotationMirror representing a unit defined by annoClass, with the specific
 * Prefix p
 *
 * @param env the Checker Processing Environment, provided as a parameter in init() of a
 *     UnitsRelations implementation
 * @param annoClass the Class of an Annotation representing a Unit (eg m.class for meters)
 * @param p a Prefix value
 * @return an AnnotationMirror of the Unit with the Prefix p, or null if it cannot be
 *     constructed
 */
@Nullable
public static AnnotationMirror buildAnnoMirrorWithSpecificPrefix(final ProcessingEnvironment env, final Class<? extends Annotation> annoClass, final Prefix p) {
    if (env == null || annoClass == null || p == null) {
        return null;
    }
    AnnotationBuilder builder = new AnnotationBuilder(env, annoClass);
    builder.setValue("value", p);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 45 with AnnotationBuilder

use of org.checkerframework.javacutil.AnnotationBuilder in project checker-framework by typetools.

the class FormatterTreeUtil method stringToInvalidFormatAnnotation.

/**
 * Takes an invalid formatter string and, returns a syntax trees element that represents a
 * {@link InvalidFormat} annotation with the invalid formatter string as value.
 */
// package-private
AnnotationMirror stringToInvalidFormatAnnotation(String invalidFormatString) {
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, InvalidFormat.class.getCanonicalName());
    builder.setValue("value", invalidFormatString);
    return builder.build();
}
Also used : InvalidFormat(org.checkerframework.checker.formatter.qual.InvalidFormat) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder)

Aggregations

AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)63 Test (org.junit.Test)30 AnnotationMirror (javax.lang.model.element.AnnotationMirror)11 ArrayList (java.util.ArrayList)3 InvalidFormat (org.checkerframework.checker.formatter.qual.InvalidFormat)3 I18nInvalidFormat (org.checkerframework.checker.i18nformatter.qual.I18nInvalidFormat)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Elements (javax.lang.model.util.Elements)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)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 Annotation (java.lang.annotation.Annotation)1 List (java.util.List)1 TypeElement (javax.lang.model.element.TypeElement)1