Search in sources :

Example 56 with AnnotationBuilder

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

the class AnnotationBuilderTest method listArrayObjectWrongType.

@Test(expected = SourceChecker.CheckerError.class)
public void listArrayObjectWrongType() {
    AnnotationBuilder builder = new AnnotationBuilder(env, B.class);
    builder.setValue("strings", new Object[] { "m", "n", 1 });
    assertEquals(1, builder.build().getElementValues().size());
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Test(org.junit.Test)

Example 57 with AnnotationBuilder

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

the class DependentTypesHelper method standardizeDependentTypeAnnotation.

/**
 * Standardizes a dependent type annotation.
 */
private AnnotationMirror standardizeDependentTypeAnnotation(FlowExpressionContext context, TreePath localScope, AnnotationMirror anno, boolean useLocalScope) {
    AnnotationBuilder builder = new AnnotationBuilder(factory.getProcessingEnv(), AnnotationUtils.annotationName(anno));
    for (String value : getListOfExpressionElements(anno)) {
        List<String> expressionStrings = AnnotationUtils.getElementValueArray(anno, value, String.class, true);
        List<String> standardizedStrings = new ArrayList<>();
        for (String expression : expressionStrings) {
            standardizedStrings.add(standardizeString(expression, context, localScope, useLocalScope));
        }
        builder.setValue(value, standardizedStrings);
    }
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) ArrayList(java.util.ArrayList)

Example 58 with AnnotationBuilder

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

the class ClassValAnnotatedTypeFactory method createClassVal.

private AnnotationMirror createClassVal(List<String> values) {
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, ClassVal.class.getCanonicalName());
    builder.setValue("value", values);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) ClassVal(org.checkerframework.common.reflection.qual.ClassVal)

Example 59 with AnnotationBuilder

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

the class ClassValAnnotatedTypeFactory method createClassBound.

private AnnotationMirror createClassBound(List<String> values) {
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, ClassBound.class.getCanonicalName());
    builder.setValue("value", values);
    return builder.build();
}
Also used : AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) ClassBound(org.checkerframework.common.reflection.qual.ClassBound)

Example 60 with AnnotationBuilder

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

the class MethodSignature method createMethodVal.

private AnnotationMirror createMethodVal(Set<MethodSignature> sigs) {
    List<String> classNames = new ArrayList<>();
    List<String> methodNames = new ArrayList<>();
    List<Integer> params = new ArrayList<>();
    for (MethodSignature sig : sigs) {
        classNames.add(sig.className);
        methodNames.add(sig.methodName);
        params.add(sig.params);
    }
    AnnotationBuilder builder = new AnnotationBuilder(processingEnv, MethodVal.class.getCanonicalName());
    builder.setValue("className", classNames);
    builder.setValue("methodName", methodNames);
    builder.setValue("params", params);
    return builder.build();
}
Also used : MethodVal(org.checkerframework.common.reflection.qual.MethodVal) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) ArrayList(java.util.ArrayList)

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