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; }
for (CompilationUnitTree unit : Collections.singletonList(info.getCompilationUnit())) { TreePath path = new TreePath(unit); Scope scope = trees.getScope(path); while (scope != null && scope instanceof JavacScope && !((JavacScope)scope).isStarImportScope()) { for (Element local : scope.getLocalElements()) {
parent = getElementByFQN(((MemberSelectTree)qualIdent).getExpression().toString()); if (parent != null && (parent.getKind().isClass() || parent.getKind().isInterface())) { Scope s = trees.getScope(new TreePath(cut)); for (Element e : parent.getEnclosedElements()) { if (name == e.getSimpleName() && e.getModifiers().contains(Modifier.STATIC) && trees.isAccessible(s, e, (DeclaredType)parent.asType()))
final Scope scope = trees.getScope(context); String qName = fqn; StringBuilder sqName = new StringBuilder();
Scope scope = controller.getTrees().getScope(path); Element subjectClass = scope.getEnclosingClass(); Element method = controller.getTrees().getElement(
/** * 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; }
/** * 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; }
path = new TreePath(copy.getCompilationUnit()); Scope s = trees.getScope(path); BlockTree body = method.getBody(); copy.getTreeUtilities().attributeTree(body, s);
methodName = ((IdentifierTree) identifier).getName().toString(); TreePath iPath = TreePath.getPath(cu, identifier); TypeElement te = trees.getScope(iPath).getEnclosingClass(); if (te == null) {
return null; // No path to the identifier... TypeElement te = trees.getScope(iPath).getEnclosingClass(); if (te == null) {
path = new TreePath(path, tree); Scope scope = info.getTrees().getScope(path); if (TreeUtilities.CLASS_TREE_KINDS.contains(path.getLeaf().getKind())) { TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
Scope scope = controller.getTrees().getScope(path); path = tu.pathFor(new TreePath(pPath, block), offset, sourcePositions); if (upToOffset) { break; case ARROW: scope = controller.getTrees().getScope(blockPath); scope = tu.reattributeTreeTo(block, scope, lambdaBody); return new Env(offset, prefix, controller, path, sourcePositions, scope); scope = controller.getTrees().getScope(blockPath); scope = tu.reattributeTreeTo(block, scope, lambdaBody); break; scope = controller.getTrees().getScope(new TreePath(path, lambdaBody)); bodyPos = (int) sourcePositions.getStartPosition(root, lambdaBody); if (bodyPos >= offset) { Scope scope = controller.getTrees().getScope(path); final int initPos = (int) sourcePositions.getStartPosition(root, tree); String initText = controller.getText().substring(initPos, upToOffset ? offset : (int) sourcePositions.getEndPosition(root, tree)); controller.toPhase(withinAnonymousOrLocalClass(tu, path) ? JavaSource.Phase.RESOLVED : JavaSource.Phase.ELEMENTS_RESOLVED); tree = ((VariableTree) tree).getInitializer(); Scope scope = controller.getTrees().getScope(new TreePath(path, tree)); final int initPos = (int) sourcePositions.getStartPosition(root, tree); String initText = controller.getText().substring(initPos, offset);