All Downloads are FREE. Search and download functionalities are using the official Maven repository.

framework.src.org.checkerframework.qualframework.base.TypeAnnotatorAdapter Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java’s type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.42.0
Show newest version
package org.checkerframework.qualframework.base;

import org.checkerframework.framework.type.AnnotatedTypeMirror;
import org.checkerframework.framework.type.typeannotator.ImplicitsTypeAnnotator;
import org.checkerframework.qualframework.qual.QualifierKey;
import org.checkerframework.qualframework.util.ExtendedTypeMirror;
import org.checkerframework.qualframework.util.WrappedAnnotatedTypeMirror;

/**
 * Adapter for {@link TypeAnnotator}, extending
 * {@link org.checkerframework.framework.type.typeannotator.TypeAnnotator org.checkerframework.framework.type.ImplicitsTypeAnnotator}.
 */
class TypeAnnotatorAdapter extends ImplicitsTypeAnnotator {
    private final TypeAnnotator underlying;
    private final TypeMirrorConverter converter;

    public TypeAnnotatorAdapter(TypeAnnotator underlying,
            TypeMirrorConverter converter,
            QualifiedTypeFactoryAdapter factoryAdapter) {
        super(factoryAdapter);
        this.underlying = underlying;
        this.converter = converter;
    }

    /**
     * Return the qualifier indicated by the @QualifierKey annotation on an
     * {@link ExtendedTypeMirror}, or null if there is no such
     * annotation.  The default {@link TypeAnnotator} implementation uses this
     * method to avoid re-processing a type more than once, which will likely
     * produce wrong results (since {@link TypeMirrorConverter} removes the
     * existing annotations when it adds the @QualifierKey).
     */
    public Q getExistingQualifier(ExtendedTypeMirror type) {
        if (type instanceof WrappedAnnotatedTypeMirror) {
            AnnotatedTypeMirror atm = ((WrappedAnnotatedTypeMirror)type).unwrap();
            if (atm.hasAnnotation(QualifierKey.class)) {
                return converter.getQualifier(atm);
            }
        }

        return null;
    }

    @Override
    protected Void scan(AnnotatedTypeMirror atm, Void p) {
        // Produce a qualified version of the ATM.
        WrappedAnnotatedTypeMirror watm = WrappedAnnotatedTypeMirror.wrap(atm);
        QualifiedTypeMirror qtm = underlying.visit(watm, null);

        // Update the input ATM with the new qualifiers.
        converter.applyQualifiers(qtm, atm);

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy