Search in sources :

Example 1 with LiteralTreeAnnotator

use of org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator in project checker-framework by typetools.

the class SignatureAnnotatedTypeFactory method signatureLiteralTreeAnnotator.

/**
 * Create a LiteralTreeAnnotator for the Signature Checker.
 *
 * @param atypeFactory the type factory
 * @return a LiteralTreeAnnotator for the Signature Checker
 */
private LiteralTreeAnnotator signatureLiteralTreeAnnotator(AnnotatedTypeFactory atypeFactory) {
    LiteralTreeAnnotator result = new LiteralTreeAnnotator(atypeFactory);
    result.addStandardLiteralQualifiers();
    // The below code achieves the same effect as writing a meta-annotation
    // @QualifierForLiterals(stringPatterns = "...")
    // on each type qualifier definition.  Annotation elements cannot be computations (not even
    // string concatenations of literal strings) and cannot be not references to compile-time
    // constants such as effectively-final fields.  So every `stringPatterns = "..."` would have
    // to be a literal string, which would be verbose ard hard to maintain.
    result.addStringPattern(SignatureRegexes.ArrayWithoutPackageRegex, AnnotationBuilder.fromClass(elements, ArrayWithoutPackage.class));
    result.addStringPattern(SignatureRegexes.BinaryNameRegex, AnnotationBuilder.fromClass(elements, BinaryName.class));
    result.addStringPattern(SignatureRegexes.BinaryNameOrPrimitiveTypeRegex, AnnotationBuilder.fromClass(elements, BinaryNameOrPrimitiveType.class));
    result.addStringPattern(SignatureRegexes.BinaryNameWithoutPackageRegex, AnnotationBuilder.fromClass(elements, BinaryNameWithoutPackage.class));
    result.addStringPattern(SignatureRegexes.ClassGetNameRegex, AnnotationBuilder.fromClass(elements, ClassGetName.class));
    result.addStringPattern(SignatureRegexes.ClassGetSimpleNameRegex, AnnotationBuilder.fromClass(elements, ClassGetSimpleName.class));
    result.addStringPattern(SignatureRegexes.DotSeparatedIdentifiersRegex, AnnotationBuilder.fromClass(elements, DotSeparatedIdentifiers.class));
    result.addStringPattern(SignatureRegexes.DotSeparatedIdentifiersOrPrimitiveTypeRegex, AnnotationBuilder.fromClass(elements, DotSeparatedIdentifiersOrPrimitiveType.class));
    result.addStringPattern(SignatureRegexes.FieldDescriptorRegex, AnnotationBuilder.fromClass(elements, FieldDescriptor.class));
    result.addStringPattern(SignatureRegexes.FieldDescriptorForPrimitiveRegex, AnnotationBuilder.fromClass(elements, FieldDescriptorForPrimitive.class));
    result.addStringPattern(SignatureRegexes.FieldDescriptorWithoutPackageRegex, AnnotationBuilder.fromClass(elements, FieldDescriptorWithoutPackage.class));
    result.addStringPattern(SignatureRegexes.FqBinaryNameRegex, AnnotationBuilder.fromClass(elements, FqBinaryName.class));
    result.addStringPattern(SignatureRegexes.FullyQualifiedNameRegex, AnnotationBuilder.fromClass(elements, FullyQualifiedName.class));
    result.addStringPattern(SignatureRegexes.IdentifierRegex, AnnotationBuilder.fromClass(elements, Identifier.class));
    result.addStringPattern(SignatureRegexes.IdentifierOrPrimitiveTypeRegex, AnnotationBuilder.fromClass(elements, IdentifierOrPrimitiveType.class));
    result.addStringPattern(SignatureRegexes.InternalFormRegex, AnnotationBuilder.fromClass(elements, InternalForm.class));
    result.addStringPattern(SignatureRegexes.PrimitiveTypeRegex, AnnotationBuilder.fromClass(elements, PrimitiveType.class));
    return result;
}
Also used : InternalForm(org.checkerframework.checker.signature.qual.InternalForm) LiteralTreeAnnotator(org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator) BinaryNameWithoutPackage(org.checkerframework.checker.signature.qual.BinaryNameWithoutPackage) ClassGetSimpleName(org.checkerframework.checker.signature.qual.ClassGetSimpleName) FieldDescriptorForPrimitive(org.checkerframework.checker.signature.qual.FieldDescriptorForPrimitive) BinaryNameOrPrimitiveType(org.checkerframework.checker.signature.qual.BinaryNameOrPrimitiveType) ClassGetName(org.checkerframework.checker.signature.qual.ClassGetName) FieldDescriptorWithoutPackage(org.checkerframework.checker.signature.qual.FieldDescriptorWithoutPackage) FullyQualifiedName(org.checkerframework.checker.signature.qual.FullyQualifiedName) DotSeparatedIdentifiersOrPrimitiveType(org.checkerframework.checker.signature.qual.DotSeparatedIdentifiersOrPrimitiveType) FqBinaryName(org.checkerframework.checker.signature.qual.FqBinaryName) DotSeparatedIdentifiers(org.checkerframework.checker.signature.qual.DotSeparatedIdentifiers) FieldDescriptor(org.checkerframework.checker.signature.qual.FieldDescriptor) Identifier(org.checkerframework.checker.signature.qual.Identifier) ArrayWithoutPackage(org.checkerframework.checker.signature.qual.ArrayWithoutPackage) IdentifierOrPrimitiveType(org.checkerframework.checker.signature.qual.IdentifierOrPrimitiveType) BinaryName(org.checkerframework.checker.signature.qual.BinaryName) FqBinaryName(org.checkerframework.checker.signature.qual.FqBinaryName) CanonicalNameAndBinaryName(org.checkerframework.checker.signature.qual.CanonicalNameAndBinaryName) DotSeparatedIdentifiersOrPrimitiveType(org.checkerframework.checker.signature.qual.DotSeparatedIdentifiersOrPrimitiveType) PrimitiveType(org.checkerframework.checker.signature.qual.PrimitiveType) IdentifierOrPrimitiveType(org.checkerframework.checker.signature.qual.IdentifierOrPrimitiveType) BinaryNameOrPrimitiveType(org.checkerframework.checker.signature.qual.BinaryNameOrPrimitiveType)

Example 2 with LiteralTreeAnnotator

use of org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method createTreeAnnotator.

/**
 * Returns a {@link TreeAnnotator} that adds annotations to a type based on the contents of a
 * tree.
 *
 * <p>The default tree annotator is a {@link ListTreeAnnotator} of the following:
 *
 * <ol>
 *   <li>{@link PropagationTreeAnnotator}: Propagates annotations from subtrees
 *   <li>{@link LiteralTreeAnnotator}: Adds annotations based on {@link QualifierForLiterals}
 *       meta-annotations
 *   <li>{@link DependentTypesTreeAnnotator}: Adapts dependent annotations based on context
 * </ol>
 *
 * <p>Subclasses may override this method to specify additional tree annotators, for example:
 *
 * <pre>
 * new ListTreeAnnotator(super.createTreeAnnotator(), new KeyLookupTreeAnnotator(this));
 * </pre>
 *
 * @return a tree annotator
 */
protected TreeAnnotator createTreeAnnotator() {
    List<TreeAnnotator> treeAnnotators = new ArrayList<>(2);
    treeAnnotators.add(new PropagationTreeAnnotator(this));
    treeAnnotators.add(new LiteralTreeAnnotator(this).addStandardLiteralQualifiers());
    if (dependentTypesHelper.hasDependentAnnotations()) {
        treeAnnotators.add(dependentTypesHelper.createDependentTypesTreeAnnotator());
    }
    return new ListTreeAnnotator(treeAnnotators);
}
Also used : LiteralTreeAnnotator(org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator) PropagationTreeAnnotator(org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator) ArrayList(java.util.ArrayList) LiteralTreeAnnotator(org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator) PropagationTreeAnnotator(org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator) TreeAnnotator(org.checkerframework.framework.type.treeannotator.TreeAnnotator) ListTreeAnnotator(org.checkerframework.framework.type.treeannotator.ListTreeAnnotator) DependentTypesTreeAnnotator(org.checkerframework.framework.util.dependenttypes.DependentTypesTreeAnnotator) ListTreeAnnotator(org.checkerframework.framework.type.treeannotator.ListTreeAnnotator)

Example 3 with LiteralTreeAnnotator

use of org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator in project checker-framework by typetools.

the class AinferTestAnnotatedTypeFactory method createTreeAnnotator.

@Override
public TreeAnnotator createTreeAnnotator() {
    LiteralTreeAnnotator literalTreeAnnotator = new LiteralTreeAnnotator(this);
    literalTreeAnnotator.addLiteralKind(LiteralKind.INT, BOTTOM);
    literalTreeAnnotator.addStandardLiteralQualifiers();
    return new ListTreeAnnotator(new PropagationTreeAnnotator(this), literalTreeAnnotator);
}
Also used : LiteralTreeAnnotator(org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator) PropagationTreeAnnotator(org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator) ListTreeAnnotator(org.checkerframework.framework.type.treeannotator.ListTreeAnnotator)

Example 4 with LiteralTreeAnnotator

use of org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator in project checker-framework by typetools.

the class ReflectionTestAnnotatedTypeFactory method createTreeAnnotator.

@Override
public TreeAnnotator createTreeAnnotator() {
    LiteralTreeAnnotator literalTreeAnnotator = new LiteralTreeAnnotator(this);
    AnnotationMirror bottom = AnnotationBuilder.fromClass(elements, ReflectBottom.class);
    literalTreeAnnotator.addLiteralKind(LiteralKind.INT, bottom);
    literalTreeAnnotator.addStandardLiteralQualifiers();
    return new ListTreeAnnotator(new PropagationTreeAnnotator(this), literalTreeAnnotator);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) LiteralTreeAnnotator(org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator) PropagationTreeAnnotator(org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator) ListTreeAnnotator(org.checkerframework.framework.type.treeannotator.ListTreeAnnotator)

Aggregations

LiteralTreeAnnotator (org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator)4 ListTreeAnnotator (org.checkerframework.framework.type.treeannotator.ListTreeAnnotator)3 PropagationTreeAnnotator (org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator)3 ArrayList (java.util.ArrayList)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 ArrayWithoutPackage (org.checkerframework.checker.signature.qual.ArrayWithoutPackage)1 BinaryName (org.checkerframework.checker.signature.qual.BinaryName)1 BinaryNameOrPrimitiveType (org.checkerframework.checker.signature.qual.BinaryNameOrPrimitiveType)1 BinaryNameWithoutPackage (org.checkerframework.checker.signature.qual.BinaryNameWithoutPackage)1 CanonicalNameAndBinaryName (org.checkerframework.checker.signature.qual.CanonicalNameAndBinaryName)1 ClassGetName (org.checkerframework.checker.signature.qual.ClassGetName)1 ClassGetSimpleName (org.checkerframework.checker.signature.qual.ClassGetSimpleName)1 DotSeparatedIdentifiers (org.checkerframework.checker.signature.qual.DotSeparatedIdentifiers)1 DotSeparatedIdentifiersOrPrimitiveType (org.checkerframework.checker.signature.qual.DotSeparatedIdentifiersOrPrimitiveType)1 FieldDescriptor (org.checkerframework.checker.signature.qual.FieldDescriptor)1 FieldDescriptorForPrimitive (org.checkerframework.checker.signature.qual.FieldDescriptorForPrimitive)1 FieldDescriptorWithoutPackage (org.checkerframework.checker.signature.qual.FieldDescriptorWithoutPackage)1 FqBinaryName (org.checkerframework.checker.signature.qual.FqBinaryName)1 FullyQualifiedName (org.checkerframework.checker.signature.qual.FullyQualifiedName)1 Identifier (org.checkerframework.checker.signature.qual.Identifier)1