private Iterable<? extends TreePath> fullPrepareThis(TreePath tp) { //XXX: is there a faster way to do this? Collection<TreePath> result = new LinkedList<TreePath>(); Scope scope = info.getTrees().getScope(tp); TypeElement lastClass = null; while (scope != null && scope.getEnclosingClass() != null) { if (lastClass != scope.getEnclosingClass()) { ExpressionTree thisTree = info.getTreeUtilities().parseExpression("this", new SourcePositions[1]); info.getTreeUtilities().attributeTree(thisTree, scope); result.add(new TreePath(tp, thisTree)); } scope = scope.getEnclosingScope(); } return result; }
ci.getTreeUtilities().attributeTree(tree, scope);
/** * Creates a new BlockTree for provided <tt>bodyText</tt>. * * @param lambda figures out the scope for attribution. * @param bodyText text which will be used for lambda body creation. * @return a new tree for <tt>bodyText</tt>. * @since 2.19 */ public BlockTree createLambdaBody(LambdaExpressionTree lambda, String bodyText) { SourcePositions[] positions = new SourcePositions[1]; final TreeUtilities treeUtils = copy.getTreeUtilities(); StatementTree body = treeUtils.parseStatement(bodyText, positions); assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), lambda)); treeUtils.attributeTree(body, scope); mapComments((BlockTree) body, bodyText, copy, handler, positions[0]); new TreePosCleaner().scan(body, null); return (BlockTree) body; }
/** * Creates a new BlockTree for provided <tt>bodyText</tt>. * * @param method figures out the scope for attribution. * @param bodyText text which will be used for method body creation. * @return a new tree for <tt>bodyText</tt>. */ public BlockTree createMethodBody(MethodTree method, String bodyText) { SourcePositions[] positions = new SourcePositions[1]; final TreeUtilities treeUtils = copy.getTreeUtilities(); StatementTree body = treeUtils.parseStatement(bodyText, positions); assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), method)); treeUtils.attributeTree(body, scope); mapComments((BlockTree) body, bodyText, copy, handler, positions[0]); new TreePosCleaner().scan(body, null); return (BlockTree) body; }
copy.getTreeUtilities().attributeTree(body, s); body = importFQNs(body); copy.rewrite(method.getBody(), body);