/** Returns true if the tree references its enclosing class. */ public static boolean referencesOuter(Tree tree, Symbol owner, VisitorState state) { CanBeStaticAnalyzer scanner = new CanBeStaticAnalyzer(owner, state); ((JCTree) tree).accept(scanner); return !scanner.canPossiblyBeStatic || !scanner.outerReferences.isEmpty(); }
private Id elementToId(Element element, Class<? extends Annotation> annotation, int value) { JCTree tree = (JCTree) trees.getTree(element, getMirror(element, annotation)); if (tree != null) { // tree can be null if the references are compiled types and not source rScanner.reset(); tree.accept(rScanner); if (!rScanner.resourceIds.isEmpty()) { return rScanner.resourceIds.values().iterator().next(); } } return new Id(value); }
private Map<Integer, Id> elementToIds(Element element, Class<? extends Annotation> annotation, int[] values) { Map<Integer, Id> resourceIds = new LinkedHashMap<>(); JCTree tree = (JCTree) trees.getTree(element, getMirror(element, annotation)); if (tree != null) { // tree can be null if the references are compiled types and not source rScanner.reset(); tree.accept(rScanner); resourceIds = rScanner.resourceIds; } // Every value looked up should have an Id for (int value : values) { resourceIds.putIfAbsent(value, new Id(value)); } return resourceIds; }
public static CanBeStaticResult canBeStaticResult(Tree tree, Symbol owner, VisitorState state) { CanBeStaticAnalyzer scanner = new CanBeStaticAnalyzer(owner, state); ((JCTree) tree).accept(scanner); return CanBeStaticResult.of(scanner.canPossiblyBeStatic, scanner.outerReferences); }
List<ResourceValue> getResourcesInAnnotation(Element element, Class annotationClass, String resourceType, List<Integer> resourceValues) { List<ResourceValue> resources = new ArrayList<>(resourceValues.size()); JCTree tree = (JCTree) trees.getTree(element, getAnnotationMirror(element, annotationClass)); // tree can be null if the references are compiled types and not source if (tree != null) { // Collects details about the layout resource used for the annotation parameter scanner.clearResults(); scanner.setCurrentAnnotationDetails(element, annotationClass, resourceType); tree.accept(scanner); resources.addAll(scanner.getResults()); } // Resource values may not have been picked up by the scanner if they are hardcoded. // In that case we just use the hardcoded value without an R class if (resources.size() != resourceValues.size()) { for (int layoutValue : resourceValues) { if (!isLayoutValueInResources(resources, layoutValue)) { resources.add(new ResourceValue(layoutValue)); } } } return resources; }
/** * Renames the given {@link VariableTree} and its usages in the current compilation unit to {@code * replacement}. */ public static SuggestedFix renameVariable( VariableTree tree, final String replacement, VisitorState state) { String name = tree.getName().toString(); int typeEndPos = state.getEndPosition(tree.getType()); // handle implicit lambda parameter types int searchOffset = typeEndPos == -1 ? 0 : (typeEndPos - ((JCTree) tree).getStartPosition()); int pos = ((JCTree) tree).getStartPosition() + state.getSourceForNode(tree).indexOf(name, searchOffset); final SuggestedFix.Builder fix = SuggestedFix.builder().replace(pos, pos + name.length(), replacement); final Symbol.VarSymbol sym = getSymbol(tree); ((JCTree) state.getPath().getCompilationUnit()) .accept( new TreeScanner() { @Override public void visitIdent(JCTree.JCIdent tree) { if (sym.equals(getSymbol(tree))) { fix.replace(tree, replacement); } } }); return fix.build(); }
.accept( new com.sun.tools.javac.tree.TreeScanner() { @Override
.accept( new TreeScanner() { @Override
.accept( new TreeScanner() { @Override
/** * Scans a program tree. */ @Override public void scan(JCTree tree) { if (tree == null) { return; } enter(tree); try { tree.accept(this); } catch (RollbackException rollback) { if (rollback.getTarget() == tree) { onRollbacked(tree); if (rollback.getOnRollbacked() != null) { rollback.getOnRollbacked().accept(tree); } } else { throw rollback; } } catch (Exception e) { report(tree, JSweetProblem.INTERNAL_TRANSPILER_ERROR); dumpStackTrace(); e.printStackTrace(); } finally { exit(); } }
/** Visitor method: Scan a single node. */ public void scan(JCTree tree) { if(tree!=null) tree.accept(this); }
private void width(JCTree tree, int prec) { if (tree != null) { int prevPrec = this.prec; this.prec = prec; tree.accept(this); this.prec = prevPrec; } } public void visitTree(JCTree tree) {
public int estimateWidth(JCTree t, int maxwidth) { width = 0; this.maxwidth = maxwidth; t.accept(this); return width; } public int estimateWidth(JCTree t) {
public boolean needsLazyConstValue(JCTree tree) { InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); tree.accept(initTreeVisitor); return initTreeVisitor.result; }
public int estimateWidth(List<? extends JCTree> t, int maxwidth) { width = 0; this.maxwidth = maxwidth; while(t.nonEmpty() && this.width < this.maxwidth) { t.head.accept(this); t = t.tail; } return width; } private void open(int contextPrec, int ownPrec) {
/** Returns true if the tree references its enclosing class. */ public static boolean referencesOuter(Tree tree, Symbol owner, VisitorState state) { CanBeStaticAnalyzer scanner = new CanBeStaticAnalyzer(owner, state); ((JCTree) tree).accept(scanner); return !scanner.canPossiblyBeStatic || !scanner.outerReferences.isEmpty(); }
private Id elementToId(Element element, Class<? extends Annotation> annotation, int value) { JCTree tree = (JCTree) trees.getTree(element, getMirror(element, annotation)); if (tree != null) { // tree can be null if the references are compiled types and not source rScanner.reset(); tree.accept(rScanner); if (!rScanner.resourceIds.isEmpty()) { return rScanner.resourceIds.values().iterator().next(); } } return new Id(value); }
/** Visitor method: Validate a type expression, if it is not null, catching * and reporting any completion failures. */ void validate(JCTree tree) { try { if (tree != null) tree.accept(validator); } catch (CompletionFailure ex) { completionError(tree.pos(), ex); } }
/** Visitor method: Validate a type expression, if it is not null, catching * and reporting any completion failures. */ void validate(JCTree tree) { try { if (tree != null) tree.accept(validator); } catch (CompletionFailure ex) { completionError(tree.pos(), ex); } }