Search in sources :

Example 36 with AnnotationBuilder

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

the class SameLenAnnotatedTypeFactory method createSameLen.

/**
 * Creates a @SameLen annotation whose values are the given strings.
 */
public AnnotationMirror createSameLen(String... val) {
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, SameLen.class);
    Arrays.sort(val);
    builder.setValue("value", val);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder)

Example 37 with AnnotationBuilder

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

the class ContractsUtils method getAnnotationMirrorOfQualifier.

/**
 * Returns the annotation mirror as specified by the "qualifier" element in {@code
 * qualifierAnno}. If {@code argumentAnno} is specified, then arguments are copied from {@code
 * argumentAnno} to the returned annotation, renamed according to {@code argumentMap}.
 *
 * <p>This is a helper method intended to be called from {@link
 * getAnnotationMirrorOfContractAnnotation} and {@link getAnnotationMirrorOfMetaAnnotation}. Use
 * one of those methods if possible.
 *
 * @param qualifierAnno annotation specifying the qualifier class
 * @param argumentAnno annotation containing the argument values, or {@code null}
 * @param argumentRenaming renaming of argument names, which maps from names in {@code
 *     argumentAnno} to names used in the returned annotation, or {@code null}
 */
private AnnotationMirror getAnnotationMirrorOfQualifier(AnnotationMirror qualifierAnno, AnnotationMirror argumentAnno, Map<String, String> argumentRenaming) {
    @SuppressWarnings("unchecked") Class<? extends Annotation> c = (Class<? extends Annotation>) AnnotationUtils.getElementValueClass(qualifierAnno, "qualifier", false);
    AnnotationMirror anno;
    if (argumentAnno == null || argumentRenaming.isEmpty()) {
        // If there are no arguments, use factory method that allows caching
        anno = AnnotationBuilder.fromClass(factory.getElementUtils(), c);
    } else {
        AnnotationBuilder builder = new AnnotationBuilder(factory.getProcessingEnv(), c);
        builder.copyRenameElementValuesFromAnnotation(argumentAnno, argumentRenaming);
        anno = builder.build();
    }
    if (factory.isSupportedQualifier(anno)) {
        return anno;
    } else {
        AnnotationMirror aliasedAnno = factory.aliasedAnnotation(anno);
        if (factory.isSupportedQualifier(aliasedAnno)) {
            return aliasedAnno;
        } else {
            return null;
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) PreconditionAnnotation(org.checkerframework.framework.qual.PreconditionAnnotation) Annotation(java.lang.annotation.Annotation) ConditionalPostconditionAnnotation(org.checkerframework.framework.qual.ConditionalPostconditionAnnotation) PostconditionAnnotation(org.checkerframework.framework.qual.PostconditionAnnotation)

Example 38 with AnnotationBuilder

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

the class SearchIndexAnnotatedTypeFactory method createSearchIndexFor.

/**
 * Create a new {@code @SearchIndexFor} annotation with the given arrays as its arguments.
 */
AnnotationMirror createSearchIndexFor(List<String> arrays) {
    if (arrays.size() == 0) {
        return UNKNOWN;
    }
    // remove duplicates
    arrays = new ArrayList<>(new HashSet<>(arrays));
    Collections.sort(arrays);
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, SearchIndexFor.class);
    builder.setValue("value", arrays);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 39 with AnnotationBuilder

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

the class SearchIndexAnnotatedTypeFactory method createNegativeIndexFor.

/**
 * Create a new {@code @NegativeIndexFor} annotation with the given arrays as its arguments.
 */
AnnotationMirror createNegativeIndexFor(List<String> arrays) {
    if (arrays.size() == 0) {
        return UNKNOWN;
    }
    // remove duplicates
    arrays = new ArrayList<>(new HashSet<>(arrays));
    Collections.sort(arrays);
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, NegativeIndexFor.class);
    builder.setValue("value", arrays);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 40 with AnnotationBuilder

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

the class InitializationAnnotatedTypeFactory method createUnclassifiedAnnotation.

/**
 * Returns a {@link UnknownInitialization} annotation with a given type frame.
 */
public AnnotationMirror createUnclassifiedAnnotation(TypeMirror typeFrame) {
    assert typeFrame != null;
    Class<? extends Annotation> clazz = useFbc ? UnknownInitialization.class : Raw.class;
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, clazz);
    builder.setValue("value", typeFrame);
    return builder.build();
}
Also used : 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