Search in sources :

Example 6 with BaseTypeChecker

use of org.checkerframework.common.basetype.BaseTypeChecker in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method getTypeFactoryOfSubchecker.

/**
 * Returns the type factory used by a subchecker. Returns null if no matching subchecker was found
 * or if the type factory is null. The caller must know the exact checker class to request.
 *
 * <p>Because the visitor path is copied, call this method each time a subfactory is needed rather
 * than store the returned subfactory in a field.
 *
 * @param subCheckerClass the exact class of the subchecker
 * @param <T> the type of {@code subCheckerClass}'s {@link AnnotatedTypeFactory}
 * @return the AnnotatedTypeFactory of the subchecker or null if no subchecker exists
 */
// Intentional abuse
@SuppressWarnings("TypeParameterUnusedInFormals")
@Nullable
public <T extends GenericAnnotatedTypeFactory<?, ?, ?, ?>> T getTypeFactoryOfSubchecker(Class<? extends BaseTypeChecker> subCheckerClass) {
    BaseTypeChecker subchecker = checker.getSubchecker(subCheckerClass);
    if (subchecker == null) {
        return null;
    }
    @SuppressWarnings(// This might not be safe, but the caller of the method should use the correct
    "unchecked") T subFactory = (T) subchecker.getTypeFactory();
    if (subFactory != null) {
        subFactory.setVisitorTreePath(getVisitorTreePath());
    }
    return subFactory;
}
Also used : UnderlyingAST(org.checkerframework.dataflow.cfg.UnderlyingAST) BaseTypeChecker(org.checkerframework.common.basetype.BaseTypeChecker) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

BaseTypeChecker (org.checkerframework.common.basetype.BaseTypeChecker)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 ExpressionTree (com.sun.source.tree.ExpressionTree)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ProcessingEnvironment (javax.annotation.processing.ProcessingEnvironment)1 UnderlyingAST (org.checkerframework.dataflow.cfg.UnderlyingAST)1 StubFiles (org.checkerframework.framework.qual.StubFiles)1 UserError (org.checkerframework.javacutil.UserError)1