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);
}
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;
}
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);
}
}
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());
}
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);
}
Aggregations