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

checker.src.org.checkerframework.checker.tainting.TaintingQualifiedTypeFactory 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.checker.tainting;

import com.sun.source.tree.LiteralTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import org.checkerframework.qualframework.base.QualifiedTypeMirror;
import org.checkerframework.qualframework.base.QualifierHierarchy;
import org.checkerframework.qualframework.base.SetQualifierVisitor;
import org.checkerframework.qualframework.base.TypeVariableSubstitutor;
import org.checkerframework.qualframework.poly.CombiningOperation;
import org.checkerframework.qualframework.poly.PolyQual;
import org.checkerframework.qualframework.poly.PolyQual.GroundQual;
import org.checkerframework.qualframework.poly.QualParams;
import org.checkerframework.qualframework.poly.QualifiedParameterTypeVariableSubstitutor;
import org.checkerframework.qualframework.poly.QualifierParameterTreeAnnotator;
import org.checkerframework.qualframework.poly.QualifierParameterTypeFactory;
import org.checkerframework.qualframework.poly.Wildcard;
import org.checkerframework.qualframework.util.ExtendedTypeMirror;
import org.checkerframework.qualframework.util.QualifierContext;

public class TaintingQualifiedTypeFactory extends QualifierParameterTypeFactory {

    public TaintingQualifiedTypeFactory(QualifierContext> context) {
        super(context);
    }

    @Override
    protected QualifierHierarchy createGroundQualifierHierarchy() {
        return new TaintingQualifierHierarchy();
    }

    @Override
    protected TaintingAnnotationConverter createAnnotationConverter() {
        return new TaintingAnnotationConverter();
    }

    @Override
    protected QualifierParameterTreeAnnotator createTreeAnnotator() {
        return new QualifierParameterTreeAnnotator(this) {
            @Override
            public QualifiedTypeMirror> visitLiteral(LiteralTree tree, ExtendedTypeMirror type) {
                QualifiedTypeMirror> result = super.visitLiteral(tree, type);
                if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
                    result = SetQualifierVisitor.apply(result, new QualParams<>(new GroundQual<>(Tainting.UNTAINTED)));
                } else if (tree.getKind() == Kind.NULL_LITERAL) {
                    return SetQualifierVisitor.apply(result, TaintingQualifiedTypeFactory.this.getQualifierHierarchy().getBottom());
                }
                return result;
            }
        };
    }

    private CombiningOperation lubOp = new CombiningOperation.Lub<>(new TaintingQualifierHierarchy());

    @Override
    public TypeVariableSubstitutor> createTypeVariableSubstitutor() {
        return new QualifiedParameterTypeVariableSubstitutor() {
            @Override
            protected Wildcard combineForSubstitution(Wildcard a, Wildcard b) {
                return a.combineWith(b, lubOp, lubOp);
            }

            @Override
            protected PolyQual combineForSubstitution(PolyQual a, PolyQual b) {
                return a.combineWith(b, lubOp);
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy