ResourceProcessor(ProcessingEnvironment processingEnv, ErrorLogger errorLogger, Elements elementUtils, Types typeUtils) { this.errorLogger = errorLogger; this.elementUtils = elementUtils; this.typeUtils = typeUtils; try { trees = Trees.instance(processingEnv); } catch (IllegalArgumentException ignored) { } }
@Override public synchronized void init(ProcessingEnvironment env) { super.init(env); String sdk = env.getOptions().get(OPTION_SDK_INT); if (sdk != null) { try { this.sdk = Integer.parseInt(sdk); } catch (NumberFormatException e) { env.getMessager() .printMessage(Kind.WARNING, "Unable to parse supplied minSdk option '" + sdk + "'. Falling back to API 1 support."); } } debuggable = !"false".equals(env.getOptions().get(OPTION_DEBUGGABLE)); typeUtils = env.getTypeUtils(); filer = env.getFiler(); try { trees = Trees.instance(processingEnv); } catch (IllegalArgumentException ignored) { } }
private static Trees getTreesInstance(VisitorState state) { return Trees.instance(JavacProcessingEnvironment.instance(state.context)); }
@Override public synchronized void init(ProcessingEnvironment pe) { super.init(pe); treeUtils = Trees.instance(pe); prepareContext(((JavacProcessingEnvironment)pe).getContext()); }
final Trees t = Trees.instance(processingEnv); final Collection<JCTree> toClean = new LinkedList<JCTree>();
private void captureJavadoc(TypeElement elem) { List<String> imports = new ArrayList<>(); List<? extends ImportTree> importLines = Trees.instance(env).getPath(elem).getCompilationUnit().getImports(); for (ImportTree importLine : importLines) { imports.add(importLine.getQualifiedIdentifier().toString());
@Nullable private VariableTree findDeclaration(VisitorState state, Symbol field) { JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context); TreePath fieldDeclPath = Trees.instance(javacEnv).getPath(field); // Skip fields declared in other compilation units since we can't make a fix for them here. if (fieldDeclPath != null && fieldDeclPath.getCompilationUnit() == state.getPath().getCompilationUnit() && (fieldDeclPath.getLeaf() instanceof VariableTree)) { return (VariableTree) fieldDeclPath.getLeaf(); } return null; }
@Nullable private VariableTree findDeclaration(VisitorState state, Symbol parameter) { JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context); TreePath declPath = Trees.instance(javacEnv).getPath(parameter); if (declPath != null && declPath.getCompilationUnit() == state.getPath().getCompilationUnit() && (declPath.getLeaf() instanceof VariableTree)) { return (VariableTree) declPath.getLeaf(); } return null; } }
@Nullable private ClassTree findEnclosingLocalOrAnonymousClass(ClassTree classTree) { Symbol.ClassSymbol symbol = ASTHelpers.getSymbol(classTree); // we need this while loop since we can have a NestingKind.NESTED class (i.e., a nested // class declared at the top-level within its enclosing class) nested (possibly deeply) // within a NestingKind.ANONYMOUS or NestingKind.LOCAL class while (symbol.getNestingKind().isNested()) { if (symbol.getNestingKind().equals(NestingKind.ANONYMOUS) || symbol.getNestingKind().equals(NestingKind.LOCAL)) { return Trees.instance(JavacProcessingEnvironment.instance(context)).getTree(symbol); } else { // symbol.owner is the enclosing element, which could be a class or a method. // if it's a class, the enclClass() method will (surprisingly) return the class itself, // so this works symbol = symbol.owner.enclClass(); } } return null; }
TreePath fieldDeclPath = Trees.instance(javacEnv).getPath(accessed.symbol);
/** * Returns a {@link MethodIntrospector} implementation for the given javac environment. * * @throws IllegalArgumentException if the environment is not from javac */ public static MethodIntrospector instance(ProcessingEnvironment env) { return new JavacMethodIntrospector(Trees.instance(env)); }
/** * Gets a DocTrees object for a given CompilationTask. * @param task the compilation task for which to get the Trees object * @throws IllegalArgumentException if the task does not support the Trees API. */ public static DocTrees instance(CompilationTask task) { return (DocTrees) Trees.instance(task); }
public DecoratedProcessingEnvironment(ProcessingEnvironment delegate, List<ElementDecoration> elementDecorations, List<TypeMirrorDecoration> typeMirrorDecorations, List<AnnotationMirrorDecoration> annotationMirrorDecorations) { this.elementDecorations = elementDecorations; this.typeMirrorDecorations = typeMirrorDecorations; this.annotationMirrorDecorations = annotationMirrorDecorations; while (delegate instanceof DecoratedProcessingEnvironment) { delegate = ((DecoratedProcessingEnvironment) delegate).delegate; } this.delegate = delegate; this.trees = Trees.instance(delegate); }
/** * Gets a DocTrees object for a given CompilationTask. * @param task the compilation task for which to get the Trees object * @throws IllegalArgumentException if the task does not support the Trees API. */ public static DocTrees instance(CompilationTask task) { return (DocTrees) Trees.instance(task); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); trees = Trees.instance(processingEnv); }
/** * Returns a {@link MethodIntrospector} implementation for the given javac environment. * * @throws IllegalArgumentException if the environment is not from javac */ public static MethodIntrospector instance(ProcessingEnvironment env) { return new JavacMethodIntrospector(Trees.instance(env)); }
public static void setProcessingEnvironment(ProcessingEnvironment pe, ConvertAnnotationProcessorEnvironment callback) { ConvertSourcePosition.callback = callback; //todo: keep a list of these if we start having multiple instances of ConvertAnnotationProcessorEnvironment try { ConvertSourcePosition.trees = Trees.instance(pe); ConvertSourcePosition.sourcePositions = trees.getSourcePositions(); } catch (Throwable e) { //e.printStackTrace(); // we aren't ALWAYS running under a sun compiler System.out.println(e.getMessage()); System.out.println("Must not be running with a sun compiler, so SourcePosition will not be available to the apt classes..."); } ConvertSourcePosition.types = pe.getTypeUtils(); }
@Override public void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); trees = Trees.instance(processingEnv); Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); treeMaker = TreeMaker.instance(context); messager = processingEnv.getMessager(); }
static HashMap<String, String> getImports(ProcessingEnvironment processingEnv, Data.MethodData methodData) { Trees trees = Trees.instance(processingEnv); TreePath tp = trees.getPath(methodData._method); TreePath lastTp = tp; while (tp != null) { lastTp = tp; tp = tp.getParentPath(); } ImportReader ir = new ImportReader(); ir.scan(lastTp, trees); return ir.imports; }
@Nullable private VariableTree findDeclaration(VisitorState state, Symbol field) { JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context); TreePath fieldDeclPath = Trees.instance(javacEnv).getPath(field); // Skip fields declared in other compilation units since we can't make a fix for them here. if (fieldDeclPath != null && fieldDeclPath.getCompilationUnit() == state.getPath().getCompilationUnit() && (fieldDeclPath.getLeaf() instanceof VariableTree)) { return (VariableTree) fieldDeclPath.getLeaf(); } return null; }