Search in sources :

Example 91 with AnnotatedTypeMirror

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

the class IndexUtil method getMinLenFromTree.

/**
 * Looks up the minlen of a member select tree. The tree must be an access to a sequence length.
 */
public static Integer getMinLenFromTree(Tree tree, ValueAnnotatedTypeFactory valueATF) {
    AnnotatedTypeMirror minLenType = valueATF.getAnnotatedType(tree);
    Long min = valueATF.getMinimumIntegralValue(minLenType);
    if (min == null) {
        return null;
    }
    if (min < 0 || min > Integer.MAX_VALUE) {
        min = 0L;
    }
    return min.intValue();
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 92 with AnnotatedTypeMirror

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

the class LessThanAnnotatedTypeFactory method isLessThan.

/**
 * @return Is left less than right?
 */
public boolean isLessThan(Tree left, String right) {
    AnnotatedTypeMirror leftATM = getAnnotatedType(left);
    if (leftATM.getAnnotations().size() != 1) {
        return false;
    }
    List<String> expressions = getLessThanExpressions(leftATM.getAnnotations().iterator().next());
    if (expressions == null) {
        return true;
    }
    return expressions.contains(right);
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 93 with AnnotatedTypeMirror

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

the class LowerBoundAnnotatedTypeFactory method addComputedTypeAnnotations.

/**
 * Handles cases 1, 2, and 3.
 */
@Override
public void addComputedTypeAnnotations(Element element, AnnotatedTypeMirror type) {
    super.addComputedTypeAnnotations(element, type);
    if (element != null) {
        AnnotatedTypeMirror valueType = getValueAnnotatedTypeFactory().getAnnotatedType(element);
        addLowerBoundTypeFromValueType(valueType, type);
    }
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 94 with AnnotatedTypeMirror

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

the class LowerBoundAnnotatedTypeFactory method addComputedTypeAnnotations.

/**
 * Handles cases 1, 2, and 3.
 */
@Override
public void addComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) {
    super.addComputedTypeAnnotations(tree, type, iUseFlow);
    // "int i = 1; --i;" fails.)
    if (iUseFlow && tree != null && TreeUtils.isExpressionTree(tree)) {
        AnnotatedTypeMirror valueType = getValueAnnotatedTypeFactory().getAnnotatedType(tree);
        addLowerBoundTypeFromValueType(valueType, type);
    }
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 95 with AnnotatedTypeMirror

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

the class WholeProgramInferenceScenes method updateInferredMethodParameterTypes.

/**
 * Updates the parameter types of the method {@code methodElt} in the Scene of the method's
 * enclosing class based on the overridden method {@code overriddenMethod} parameter types.
 *
 * <p>For each method parameter in methodElt:
 *
 * <ul>
 *   <li>If the Scene does not contain an annotated type for that parameter, then the type of
 *       the respective parameter on the overridden method will be added to the parameter in the
 *       Scene.
 *   <li>If the Scene previously contained an annotated type for that parameter, then its new
 *       type will be the LUB between the previous type and the type of the respective parameter
 *       on the overridden method.
 * </ul>
 *
 * <p>
 *
 * @param methodTree the tree of the method that contains the parameter
 * @param methodElt the element of the method
 * @param overriddenMethod the AnnotatedExecutableType of the overridden method
 * @param atf the annotated type factory of a given type system, whose type hierarchy will be
 *     used to update the parameter type
 */
@Override
public void updateInferredMethodParameterTypes(MethodTree methodTree, ExecutableElement methodElt, AnnotatedExecutableType overriddenMethod, AnnotatedTypeFactory atf) {
    ClassSymbol classSymbol = getEnclosingClassSymbol(methodTree);
    String className = classSymbol.flatname.toString();
    String jaifPath = helper.getJaifPath(className);
    AClass clazz = helper.getAClass(className, jaifPath);
    String methodName = JVMNames.getJVMMethodName(methodElt);
    AMethod method = clazz.methods.vivify(methodName);
    for (int i = 0; i < overriddenMethod.getParameterTypes().size(); i++) {
        VariableElement ve = methodElt.getParameters().get(i);
        AnnotatedTypeMirror paramATM = atf.getAnnotatedType(ve);
        AnnotatedTypeMirror argATM = overriddenMethod.getParameterTypes().get(i);
        AField param = method.parameters.vivify(i);
        helper.updateAnnotationSetInScene(param.type, atf, jaifPath, argATM, paramATM, TypeUseLocation.PARAMETER);
    }
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) AClass(scenelib.annotations.el.AClass) VariableElement(javax.lang.model.element.VariableElement) AMethod(scenelib.annotations.el.AMethod) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) AField(scenelib.annotations.el.AField)

Aggregations

AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)188 AnnotationMirror (javax.lang.model.element.AnnotationMirror)42 ExpressionTree (com.sun.source.tree.ExpressionTree)32 AnnotatedDeclaredType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)27 Tree (com.sun.source.tree.Tree)25 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)25 VariableTree (com.sun.source.tree.VariableTree)22 ArrayList (java.util.ArrayList)22 AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)21 MethodTree (com.sun.source.tree.MethodTree)20 TypeVariable (javax.lang.model.type.TypeVariable)19 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)18 AnnotatedArrayType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType)17 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)16 TypeMirror (javax.lang.model.type.TypeMirror)16 VariableElement (javax.lang.model.element.VariableElement)15 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)13 MemberSelectTree (com.sun.source.tree.MemberSelectTree)13 NewClassTree (com.sun.source.tree.NewClassTree)13 Element (javax.lang.model.element.Element)13