Search in sources :

Example 11 with TypeAnnotationPosition

use of com.sun.tools.javac.code.TypeAnnotationPosition in project checker-framework by typetools.

the class TypesIntoElements method storeMethod.

private static void storeMethod(ProcessingEnvironment processingEnv, Types types, AnnotatedTypeFactory atypeFactory, MethodTree meth) {
    AnnotatedExecutableType mtype = atypeFactory.getAnnotatedType(meth);
    MethodSymbol sym = (MethodSymbol) TreeUtils.elementFromDeclaration(meth);
    TypeAnnotationPosition tapos;
    List<Attribute.TypeCompound> tcs = List.nil();
    storeTypeParameters(processingEnv, types, atypeFactory, meth.getTypeParameters(), sym);
    {
        // return type
        JCTree ret = ((JCTree.JCMethodDecl) meth).getReturnType();
        if (ret != null) {
            tapos = TypeAnnotationUtils.methodReturnTAPosition(ret.pos);
            tcs = tcs.appendList(generateTypeCompounds(processingEnv, mtype.getReturnType(), tapos));
        }
    }
    {
        // receiver
        JCTree recv = ((JCTree.JCMethodDecl) meth).getReceiverParameter();
        if (recv != null) {
            tapos = TypeAnnotationUtils.methodReceiverTAPosition(recv.pos);
            tcs = tcs.appendList(generateTypeCompounds(processingEnv, mtype.getReceiverType(), tapos));
        }
    }
    {
        // parameters
        int pidx = 0;
        java.util.List<AnnotatedTypeMirror> ptypes = mtype.getParameterTypes();
        for (JCTree param : ((JCTree.JCMethodDecl) meth).getParameters()) {
            tapos = TypeAnnotationUtils.methodParameterTAPosition(pidx, param.pos);
            tcs = tcs.appendList(generateTypeCompounds(processingEnv, ptypes.get(pidx), tapos));
            ++pidx;
        }
    }
    {
        // throws clauses
        int tidx = 0;
        java.util.List<AnnotatedTypeMirror> ttypes = mtype.getThrownTypes();
        for (JCTree thr : ((JCTree.JCMethodDecl) meth).getThrows()) {
            tapos = TypeAnnotationUtils.methodThrowsTAPosition(tidx, thr.pos);
            tcs = tcs.appendList(generateTypeCompounds(processingEnv, ttypes.get(tidx), tapos));
            ++tidx;
        }
    }
    addUniqueTypeCompounds(types, sym, tcs);
}
Also used : TypeCompound(com.sun.tools.javac.code.Attribute.TypeCompound) AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) JCTree(com.sun.tools.javac.tree.JCTree) List(com.sun.tools.javac.util.List) TypeAnnotationPosition(com.sun.tools.javac.code.TypeAnnotationPosition)

Example 12 with TypeAnnotationPosition

use of com.sun.tools.javac.code.TypeAnnotationPosition in project checker-framework by typetools.

the class TypesIntoElements method storeClassExtends.

// TODO: see usage in comments above
@SuppressWarnings("unused")
private static void storeClassExtends(ProcessingEnvironment processingEnv, Types types, AnnotatedTypeFactory atypeFactory, Tree ext, Symbol.ClassSymbol csym, int implidx) {
    AnnotatedTypeMirror type;
    int pos;
    if (ext == null) {
        // The implicit superclass is always java.lang.Object.
        // TODO: is this a good way to get the type?
        type = atypeFactory.fromElement(csym.getSuperclass().asElement());
        pos = -1;
    } else {
        type = atypeFactory.getAnnotatedTypeFromTypeTree(ext);
        pos = ((JCTree) ext).pos;
    }
    TypeAnnotationPosition tapos = TypeAnnotationUtils.classExtendsTAPosition(implidx, pos);
    List<Attribute.TypeCompound> tcs;
    tcs = generateTypeCompounds(processingEnv, type, tapos);
    addUniqueTypeCompounds(types, csym, tcs);
}
Also used : TypeCompound(com.sun.tools.javac.code.Attribute.TypeCompound) TypeAnnotationPosition(com.sun.tools.javac.code.TypeAnnotationPosition)

Example 13 with TypeAnnotationPosition

use of com.sun.tools.javac.code.TypeAnnotationPosition in project checker-framework by typetools.

the class TypeAnnotationUtils method methodTypeParameterTAPosition.

public static TypeAnnotationPosition methodTypeParameterTAPosition(final int tpidx, final int pos) {
    TypeAnnotationPosition tapos = new TypeAnnotationPosition();
    tapos.type = TargetType.METHOD_TYPE_PARAMETER;
    tapos.parameter_index = tpidx;
    tapos.pos = pos;
    return tapos;
}
Also used : TypeAnnotationPosition(com.sun.tools.javac.code.TypeAnnotationPosition)

Example 14 with TypeAnnotationPosition

use of com.sun.tools.javac.code.TypeAnnotationPosition in project checker-framework by typetools.

the class TypeAnnotationUtils method methodThrowsTAPosition.

public static TypeAnnotationPosition methodThrowsTAPosition(final int tidx, final int pos) {
    TypeAnnotationPosition tapos = new TypeAnnotationPosition();
    tapos.type = TargetType.THROWS;
    tapos.type_index = tidx;
    tapos.pos = pos;
    return tapos;
}
Also used : TypeAnnotationPosition(com.sun.tools.javac.code.TypeAnnotationPosition)

Example 15 with TypeAnnotationPosition

use of com.sun.tools.javac.code.TypeAnnotationPosition in project checker-framework by typetools.

the class TypeAnnotationUtils method methodReceiverTAPosition.

public static TypeAnnotationPosition methodReceiverTAPosition(final int pos) {
    TypeAnnotationPosition tapos = new TypeAnnotationPosition();
    tapos.type = TargetType.METHOD_RECEIVER;
    tapos.pos = pos;
    return tapos;
}
Also used : TypeAnnotationPosition(com.sun.tools.javac.code.TypeAnnotationPosition)

Aggregations

TypeAnnotationPosition (com.sun.tools.javac.code.TypeAnnotationPosition)18 TypeCompound (com.sun.tools.javac.code.Attribute.TypeCompound)5 Attribute (com.sun.tools.javac.code.Attribute)2 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)2 JCTree (com.sun.tools.javac.tree.JCTree)2 List (com.sun.tools.javac.util.List)2 ArrayList (java.util.ArrayList)2 TypeParameterTree (com.sun.source.tree.TypeParameterTree)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1 AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)1 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)1