Search in sources :

Example 26 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project bazel by bazelbuild.

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(ProcessingEnvironment env, TypeMirror tm) {
    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()) {
            Symtab syms = Symtab.instance(context);
            return w.bound == null ? syms.objectType : w.bound.bound;
        } else {
            return wildUpperBound(env, w.type);
        }
    } else {
        return TypeAnnotationUtils.unannotatedType(t);
    }
}
Also used : Context(com.sun.tools.javac.util.Context) Symtab(com.sun.tools.javac.code.Symtab) ArrayType(javax.lang.model.type.ArrayType) DeclaredType(javax.lang.model.type.DeclaredType) WildcardType(javax.lang.model.type.WildcardType) Type(com.sun.tools.javac.code.Type) WildcardType(javax.lang.model.type.WildcardType) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Example 27 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project error-prone by google.

the class RestrictedApiChecker method anyAnnotation.

private static Matcher<Tree> anyAnnotation(List<? extends TypeMirror> mirrors, VisitorState state) {
    JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context);
    ArrayList<Matcher<Tree>> matchers = new ArrayList<>(mirrors.size());
    for (TypeMirror mirror : mirrors) {
        TypeElement typeElem = (TypeElement) javacEnv.getTypeUtils().asElement(mirror);
        String name = mirror.toString();
        if (typeElem != null) {
            // Get the binary name if possible ($ to separate nested members). See b/36160747
            name = javacEnv.getElementUtils().getBinaryName(typeElem).toString();
        }
        matchers.add(Matchers.hasAnnotation(name));
    }
    return Matchers.anyOf(matchers);
}
Also used : NewClassTreeMatcher(com.google.errorprone.bugpatterns.BugChecker.NewClassTreeMatcher) Matcher(com.google.errorprone.matchers.Matcher) MethodInvocationTreeMatcher(com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) ArrayList(java.util.ArrayList)

Example 28 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project antlr4 by antlr.

the class CommentHasStringValueProcessor method init.

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    //		Messager messager = processingEnv.getMessager();
    //		messager.printMessage(Diagnostic.Kind.NOTE, "WOW INIT--------------------");
    JavacProcessingEnvironment javacProcessingEnv = (JavacProcessingEnvironment) processingEnv;
    utilities = javacProcessingEnv.getElementUtils();
    treeMaker = TreeMaker.instance(javacProcessingEnv.getContext());
}
Also used : JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Example 29 with JavacProcessingEnvironment

use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project com.revolsys.open by revolsys.

the class DocumentationProcessor method init.

@Override
public void init(final ProcessingEnvironment environment) {
    super.init(environment);
    if (environment instanceof JavacProcessingEnvironment) {
        final JavacProcessingEnvironment javacProcessingEnv = (JavacProcessingEnvironment) environment;
        this.elementUtils = javacProcessingEnv.getElementUtils();
        final Context context = javacProcessingEnv.getContext();
        this.maker = TreeMaker.instance(context);
        this.names = Names.instance(context);
    }
}
Also used : Context(com.sun.tools.javac.util.Context) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

Example 30 with JavacProcessingEnvironment

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

the class AggregateChecker method typeProcess.

// AbstractTypeProcessor delegation
@Override
public final void typeProcess(TypeElement element, TreePath tree) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    Log log = Log.instance(context);
    if (log.nerrors > this.errsOnLastExit) {
        // If there is a Java error, do not perform any of the component type checks, but come back
        // for the next compilation unit.
        this.errsOnLastExit = log.nerrors;
        return;
    }
    if (!allCheckersInited) {
        // error was already output. Just quit.
        return;
    }
    for (SourceChecker checker : checkers) {
        checker.errsOnLastExit = this.errsOnLastExit;
        checker.typeProcess(element, tree);
        if (checker.javacErrored) {
            this.javacErrored = true;
            return;
        }
        this.errsOnLastExit = checker.errsOnLastExit;
    }
}
Also used : Context(com.sun.tools.javac.util.Context) Log(com.sun.tools.javac.util.Log) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment)

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