/** * Only for members (i.e. generated constructor): */ public static List<? extends Tree> filterHidden(CompilationInfo info, TreePath basePath, Iterable<? extends Tree> members) { List<Tree> result = new LinkedList<Tree>(); for (Tree t : members) { if (!info.getTreeUtilities().isSynthetic(new TreePath(basePath, t))) { result.add(t); } } return result; }
@Override public Void scan(Tree node, Void p) { if (node == null) return null; boolean oldSynthetic = synthetic; try { synthetic |= getTreeUtilities().isSynthetic(diffContext.origUnit, node); if (!synthetic) { oldTrees.add(node); } addSyntheticTrees(diffContext, node); return super.scan(node, p); } finally { synthetic = oldSynthetic; } }
private UsageStatus getUseStatus(TreePath path) { if (cinfo.getTreeUtilities().isSynthetic(path)) { return UsageStatus.NOT_USED; } Element el = cinfo.getTrees().getElement(path); if (el != null && elementAndNames.containsKey(el)) { if(getEnclosingMethodName(path).equals("_init")) { return UsageStatus.INIT_USE_ONLY; }else { return UsageStatus.USED; } } return UsageStatus.NOT_USED; }
/**Returns whether or not the given tree is synthetic - generated by the parser. * Please note that this method does not check trees transitively - a child of a syntetic tree * may be considered non-syntetic. * * @return true if the given tree is synthetic, false otherwise * @throws NullPointerException if the given tree is null */ public boolean isSynthetic(TreePath path) throws NullPointerException { if (path == null) throw new NullPointerException(); while (path != null) { if (isSynthetic(path.getCompilationUnit(), path.getLeaf())) return true; path = path.getParentPath(); } return false; }
private MethodTree getPublicConstructor(CompilationInfo cinfo, ClassTree ctree) { for(Tree tree : ctree.getMembers()) { if(Tree.Kind.METHOD == tree.getKind()) { MethodTree mtree = (MethodTree)tree; if(mtree.getName().toString().equals(Method.CTOR) && !cinfo.getTreeUtilities().isSynthetic(TreeUtils.getTreePath(cinfo, ctree))) { return mtree; } } } return null; }
private void renameIfMatch(TreePath path, Tree tree) { if (workingCopy.getTreeUtilities().isSynthetic(path)) { return; } Element el = workingCopy.getTrees().getElement(path); if(el != null && elementAndNames.containsKey(el)) { Tree nju = make.setLabel(tree, elementAndNames.get(el)); workingCopy.rewrite(tree, nju); } } }
@Override public Void visitMethod(MethodTree node, Void p) { if (info.getTreeUtilities().isSynthetic(/*should not be used:*/getCurrentPath().getCompilationUnit(), node)) return null; return super.visitMethod(node, p); }
private void transformStringLiteral(TreePath literalTreePath, LiteralTree literalTree) { if (workingCopy.getTreeUtilities().isSynthetic(literalTreePath)) { return; } Object valueObject = literalTree.getValue(); if (valueObject instanceof String) { String value = (String) valueObject; switch (matchKind) { case EXACT: if (value.equals(oldString)) { Tree newLiteralTree = make.Literal(newString); workingCopy.rewrite(literalTree, newLiteralTree); } break; case PREFIX: if (value.startsWith(oldString)) { Tree newLiteralTree = make.Literal(newString + value.substring(oldString.length())); workingCopy.rewrite(literalTree, newLiteralTree); } break; case SUFFIX: if (value.endsWith(oldString)) { Tree newLiteralTree = make.Literal(value.substring(0, value.length() - oldString.length()) + newString); workingCopy.rewrite(literalTree, newLiteralTree); } break; } } } }
private TreePath getParentPath(TreePath tp, Tree t) { Tree parent; if (tp != null) { while (tp.getLeaf().getKind() != Kind.COMPILATION_UNIT && getTreeUtilities().isSynthetic(tp)) { tp = tp.getParentPath(); } parent = tp.getLeaf(); } else { parent = t; } TreePath c = tree2Path.get(parent); if (c == null) { c = tp != null ? tp : new TreePath((CompilationUnitTree) t); tree2Path.put(parent, c); } return c; }
private void addSyntheticTrees(DiffContext diffContext, Tree node) { if (node == null) return ; if (((JCTree) node).pos == (-1)) { diffContext.syntheticTrees.add(node); return ; } if (node.getKind() == Kind.EXPRESSION_STATEMENT) { ExpressionTree est = ((ExpressionStatementTree) node).getExpression(); if (est.getKind() == Kind.METHOD_INVOCATION) { ExpressionTree select = ((MethodInvocationTree) est).getMethodSelect(); if (select.getKind() == Kind.IDENTIFIER && ((IdentifierTree) select).getName().contentEquals("super")) { if (getTreeUtilities().isSynthetic(diffContext.origUnit, node)) { diffContext.syntheticTrees.add(node); } } } } }
private boolean canSkip(TreePath path) { if (cinfo.getTreeUtilities().isSynthetic(path)) { return false; } Element el = cinfo.getTrees().getElement(path); if (el != null && elementAndNames.containsKey(el)) { TreePath declPath = cinfo.getTrees().getPath(el); if(declPath.getLeaf().equals(path.getLeaf())) { return true; } } return false; }
private void renameIfMatch(TreePath path, Tree tree, Element elemToRename) { if (workingCopy.getTreeUtilities().isSynthetic(path)) return; Element el = workingCopy.getTrees().getElement(path); if (el != null && el.equals(elemToRename)) { Tree nju = workingCopy.getTreeMaker().setLabel(tree, newName); workingCopy.rewrite(tree, nju); } } }
static void ensureCommentsMapped(CompilationInfo info, @NullAllowed Tree tree, CommentSetImpl set) { if (!set.areCommentsMapped() && tree != null) { boolean assertsEnabled = false; boolean automap = true; assert assertsEnabled = true; TreePath tp = info.getCompilationUnit() == tree ? new TreePath(info.getCompilationUnit()) : TreePath.getPath(info.getCompilationUnit(), tree); if (tp == null) { if (assertsEnabled && !info.getTreeUtilities().isSynthetic(info.getCompilationUnit(), tree)) { // HACK: if info is a working copy, the tree might be introduced by rewriting; // in that case, no log should be printed if (!(info instanceof WorkingCopy) || !((WorkingCopy)info).validateIsReplacement(tree)) { Logger.getLogger(TreeUtilities.class.getName()).log(assertsEnabled ? Level.WARNING : Level.FINE, "Comment automap requested for Tree not from the root compilation info. Please, make sure to call GeneratorUtilities.importComments before Treeutilities.getComments. Tree: {0}", tree); Logger.getLogger(TreeUtilities.class.getName()).log(assertsEnabled ? Level.INFO : Level.FINE, "Caller", new Exception()); } } automap = false; } if (automap) { GeneratorUtilities.importComments(info, tree, info.getCompilationUnit()); } } }
if (isSynthetic(info.getCompilationUnit(), method)) { return null;
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, TreePath decl) { if (info.getTreeUtilities().isSynthetic(decl)) return null; VariableTree var = (VariableTree) leaf; boolean typeSynthetic = var.getType() == null || info.getTreeUtilities().isSynthetic(new TreePath(decl, var.getType())); return findIdentifierSpanImpl(info, leaf, typeSynthetic ? null : var.getType(),
@Override public Void visitMethod(MethodTree tree, EnumSet<UseTypes> d) { if (info.getTreeUtilities().isSynthetic(getCurrentPath())) { return super.visitMethod(tree, d);
if (cnt == 1) { Tree mt = clazz.getMembers().get(0); if (mt.getKind() == Tree.Kind.METHOD && info.getTreeUtilities().isSynthetic(new TreePath(new TreePath(unit), mt))) { cnt--;
@Override public Void visitIdentifier(IdentifierTree tree, EnumSet<UseTypes> d) { if (info.getTreeUtilities().isSynthetic(getCurrentPath())) return null; // if ("l".equals(tree.toString())) { // Thread.dumpStack(); // } // handlePossibleIdentifier(tree); // //also possible type: (like in Collections.EMPTY_LIST): // resolveType(tree); // Thread.dumpStack(); tl.moveToOffset(sourcePositions.getStartPosition(info.getCompilationUnit(), tree)); if (memberSelectBypass != (-1)) { tl.moveToOffset(memberSelectBypass); memberSelectBypass = -1; } tl.identifierHere(tree, tree2Token); if (d != null) { handlePossibleIdentifier(getCurrentPath(), d); } super.visitIdentifier(tree, null); return null; } //
limit = -1; mapComments |= tree == commentMapTarget; if ((commentMapTarget != null) && info.getTreeUtilities().isSynthetic(new TreePath(new TreePath(unit), tree))) return null; limit = setupLimit(tree);
Element loc = info.getTrees().getElement(current); if (isSupported(loc)) { if (child && info.getTreeUtilities().isSynthetic(info.getCompilationUnit(), current.getLeaf())) {