Search in sources :

Example 36 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project checker-framework by typetools.

the class TypesUtils method isFunctionalInterface.

/**
 * Returns whether or not {@code type} is a functional interface type (as defined in JLS 9.8).
 *
 * @param type possible functional interface type
 * @param env ProcessingEnvironment
 * @return whether or not {@code type} is a functional interface type (as defined in JLS 9.8)
 */
public static boolean isFunctionalInterface(TypeMirror type, ProcessingEnvironment env) {
    Context ctx = ((JavacProcessingEnvironment) env).getContext();
    com.sun.tools.javac.code.Types javacTypes = com.sun.tools.javac.code.Types.instance(ctx);
    return javacTypes.isFunctionalInterface((Type) type);
}
Also used : Context(com.sun.tools.javac.util.Context) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Example 37 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project checker-framework by typetools.

the class TypesUtils method getObjectTypeMirror.

/**
 * Returns the {@code DeclaredType} for {@code java.lang.Object}.
 *
 * @param env {@link ProcessingEnvironment}
 * @return the {@code DeclaredType} for {@code java.lang.Object}
 */
public static DeclaredType getObjectTypeMirror(ProcessingEnvironment env) {
    Context context = ((JavacProcessingEnvironment) env).getContext();
    Symtab syms = Symtab.instance(context);
    return (DeclaredType) syms.objectType;
}
Also used : Context(com.sun.tools.javac.util.Context) Symtab(com.sun.tools.javac.code.Symtab) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) DeclaredType(javax.lang.model.type.DeclaredType)

Example 38 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project checker-framework by typetools.

the class TypesUtils method wildUpperBound.

/**
 * Version of com.sun.tools.javac.code.Types.wildUpperBound(Type) that works with both jdk8
 * (called upperBound there) and jdk8u.
 */
// TODO: contrast to upperBound.
public static Type wildUpperBound(TypeMirror tm, ProcessingEnvironment env) {
    Type t = (Type) tm;
    if (t.hasTag(TypeTag.WILDCARD)) {
        Context context = ((JavacProcessingEnvironment) env).getContext();
        Type.WildcardType w = (Type.WildcardType) TypeAnnotationUtils.unannotatedType(t);
        if (w.isSuperBound()) {
            // returns true if w is unbound
            Symtab syms = Symtab.instance(context);
            // w.bound is null if the wildcard is from bytecode.
            return w.bound == null ? syms.objectType : w.bound.getUpperBound();
        } else {
            return wildUpperBound(w.type, env);
        }
    } else {
        return TypeAnnotationUtils.unannotatedType(t);
    }
}
Also used : Context(com.sun.tools.javac.util.Context) Symtab(com.sun.tools.javac.code.Symtab) ClassType(com.sun.tools.javac.code.Type.ClassType) CapturedType(com.sun.tools.javac.code.Type.CapturedType) DeclaredType(javax.lang.model.type.DeclaredType) WildcardType(javax.lang.model.type.WildcardType) ArrayType(javax.lang.model.type.ArrayType) UnionType(javax.lang.model.type.UnionType) PrimitiveType(javax.lang.model.type.PrimitiveType) Type(com.sun.tools.javac.code.Type) WildcardType(javax.lang.model.type.WildcardType) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Example 39 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project checker-framework by typetools.

the class TreeUtils method findFunction.

/**
 * The type of the lambda or method reference tree is a functional interface type. This method
 * returns the single abstract method declared by that functional interface. (The type of this
 * method is referred to as the function type.)
 *
 * @param tree lambda or member reference tree
 * @param env ProcessingEnvironment
 * @return the single abstract method declared by the type of the tree
 */
public static Symbol findFunction(Tree tree, ProcessingEnvironment env) {
    Context ctx = ((JavacProcessingEnvironment) env).getContext();
    Types javacTypes = Types.instance(ctx);
    return javacTypes.findDescriptorSymbol(((Type) typeOf(tree)).asElement());
}
Also used : Context(com.sun.tools.javac.util.Context) Types(com.sun.tools.javac.code.Types) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Example 40 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project checker-framework by typetools.

the class AbstractTypeProcessor method init.

/**
 * {@inheritDoc}
 *
 * <p>Register a TaskListener that will get called after FLOW.
 */
@Override
public synchronized void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment) processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError, CompileState.FLOW);
    compiler.shouldStopPolicyIfError = CompileState.max(compiler.shouldStopPolicyIfError, CompileState.FLOW);
}
Also used : Context(com.sun.tools.javac.util.Context) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Aggregations

JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)49 Context (com.sun.tools.javac.util.Context)30 Type (com.sun.tools.javac.code.Type)13 WildcardType (javax.lang.model.type.WildcardType)11 DeclaredType (javax.lang.model.type.DeclaredType)9 ArrayList (java.util.ArrayList)7 ArrayType (javax.lang.model.type.ArrayType)7 TreePath (com.sun.source.util.TreePath)6 Symtab (com.sun.tools.javac.code.Symtab)6 CapturedType (com.sun.tools.javac.code.Type.CapturedType)6 ClassType (com.sun.tools.javac.code.Type.ClassType)6 PrimitiveType (javax.lang.model.type.PrimitiveType)6 UnionType (javax.lang.model.type.UnionType)6 Symbol (com.sun.tools.javac.code.Symbol)5 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)5 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)5 Types (com.sun.tools.javac.code.Types)5 VariableTree (com.sun.source.tree.VariableTree)4 AttrContext (com.sun.tools.javac.comp.AttrContext)4 Log (com.sun.tools.javac.util.Log)3