public static List<TreePathHandle> computeUnusedImports(CompilationInfo info) { final List<TreePathHandle> result = new ArrayList<>(); for (TreePath unused : process(info, new AtomicBoolean())) { result.add(TreePathHandle.create(unused, info)); } return result; }
int index = listChildren(treePath.getParentPath().getLeaf()).indexOf(treePath.getLeaf()); assert index != (-1); return new TreePathHandle(new CountingDelegate(TreePathHandle.create(treePath.getParentPath(), info), index, treePath.getLeaf().getKind()));
public void run(CompilationController co) throws Exception { co.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cut = co.getCompilationUnit(); List<? extends Tree> typeDecls = cut.getTypeDecls(); if (!typeDecls.isEmpty()){ treePathHandles.add(TreePathHandle.create(TreePath.getPath(cut, typeDecls.get(0)), co)); } } }, false);
public Object run(CompilationInfo cinfo) { StatementTree stmtTree = findPropertyStatement(cinfo, beanName, methodName); if(stmtTree != null) { return new Statement(TreePathHandle.create(TreeUtils.getTreePath(cinfo, stmtTree), cinfo), Method.this, beanName, methodName); } return null; } }, javaClass.getFileObject());
public void run(CompilationController co) throws Exception { co.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cut = co.getCompilationUnit(); if (cut.getTypeDecls().isEmpty()) { return; } result[0] = TreePathHandle.create(TreePath.getPath(cut, cut.getTypeDecls().get(0)), co); } }, true);
public void run(CompilationController co) throws Exception { co.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cut = co.getCompilationUnit(); if(!cut.getTypeDecls().isEmpty()){ treePathHandle = TreePathHandle.create(TreePath.getPath(cut, cut.getTypeDecls().get(0)), co); } } }, false);
public void run(CompilationController co) throws Exception { co.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cut = co.getCompilationUnit(); if (cut.getTypeDecls().isEmpty()){ return; } result[0] = TreePathHandle.create(TreePath.getPath(cut, cut.getTypeDecls().get(0)), co); }
public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.RESOLVED); Element element = elementHandle.resolve(compilationController); if (element != null && element.getKind() == ElementKind.METHOD) { ExecutableElement executableElement = (ExecutableElement) element; TypeMirror typeMirror = executableElement.getReturnType(); if (typeMirror != null && typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; TypeElement typeElement = (TypeElement) declaredType.asElement(); if (typeElement.getQualifiedName().toString().equals(finalRefactoringSourceFQN)) { TreePathHandle treePathHandle = TreePathHandle.create(compilationController.getTrees().getPath(element), compilationController); methodRenameRefactoring[0] = new RenameRefactoring(Lookups.fixed(treePathHandle)); methodRenameRefactoring[0].getContext().add(compilationController); } } } } }, true);
public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.RESOLVED); Element element = elementHandle.resolve(compilationController); if (element != null && element.getKind() == ElementKind.METHOD) { ExecutableElement executableElement = (ExecutableElement) element; TypeMirror typeMirror = executableElement.getReturnType(); if (typeMirror != null && typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; TypeElement typeElement = (TypeElement) declaredType.asElement(); if (typeElement.getQualifiedName().toString().equals(finalRefactoringSourceFQN)) { TreePathHandle treePathHandle = TreePathHandle.create(compilationController.getTrees().getPath(element), compilationController); methodRenameRefactoring[0] = new RenameRefactoring(Lookups.fixed(treePathHandle)); methodRenameRefactoring[0].getContext().add(compilationController); } } } } }, true);
public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.RESOLVED); Element element = elementHandle.resolve(compilationController); if (element != null && element.getKind() == ElementKind.METHOD) { ExecutableElement executableElement = (ExecutableElement) element; TypeMirror typeMirror = executableElement.getReturnType(); if (typeMirror != null && typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; TypeElement typeElement = (TypeElement) declaredType.asElement(); if (typeElement.getQualifiedName().toString().equals(finalRefactoringSourceFQN)) { TreePathHandle treePathHandle = TreePathHandle.create(compilationController.getTrees().getPath(element), compilationController); methodRenameRefactoring[0] = new RenameRefactoring(Lookups.fixed(treePathHandle)); methodRenameRefactoring[0].getContext().add(compilationController); } } } } }, true);
@Override public Void visitClass(ClassTree t, Void v) { if (variableElement == null) { // try to find the component's field variable in the class List<? extends Tree> members = (List<? extends Tree>) t.getMembers(); Iterator<? extends Tree> it = members.iterator(); while(it.hasNext()){ Tree tr = it.next(); if (tr.getKind() == Tree.Kind.VARIABLE) { Trees trees = info.getTrees(); TreePath path = new TreePath(getCurrentPath(), tr); Element el = trees.getElement(path); if (el != null) { // Issue 185420 String sname = el.getSimpleName().toString(); if(sname.equals(this.member)){ this.handle = TreePathHandle.create(path, info); variableElement = el; if (findUsages) { usagesPositions = new ArrayList<Integer>(); } } } } } } if (findUsages) { super.visitClass(t, v); } return null; }
public static Statement createStatementClass(CompilationInfo cinfo, StatementTree stmtTree, Method method) { MethodInvocationTree methInvkTree = getMethodInvocationTree(cinfo, stmtTree); MemberSelectTree memSelTree = (MemberSelectTree)methInvkTree.getMethodSelect(); String beanName = ((IdentifierTree)memSelTree.getExpression()).getName().toString(); String setterName = memSelTree.getIdentifier().toString(); return new Statement(TreePathHandle.create( TreeUtils.getTreePath(cinfo, stmtTree), cinfo), method, beanName, setterName); } /*
/** * Creates a new instance of ElementGrip */ public ElementGrip(TreePath treePath, CompilationInfo info) { this.delegateElementHandle = TreePathHandle.create(treePath, info); this.toString = UiUtils.getHeader(treePath, info, UiUtils.PrintPart.NAME); this.fileObject = info.getFileObject(); this.icon = UiUtils.getDeclarationIcon(info.getTrees().getElement(treePath)); }
/** * Factory method for creating {@link DocTreePathHandle}. * * @param docTreePath for which the {@link DocTreePathHandle} should be created. * @param javac * @return a new {@link DocTreePathHandle} * @throws java.lang.IllegalArgumentException if arguments are not supported */ public static DocTreePathHandle create(final DocTreePath docTreePath, CompilationInfo javac) throws IllegalArgumentException { Parameters.notNull("docTreePath", docTreePath); Parameters.notNull("javac", javac); TreePathHandle treePathHandle = TreePathHandle.create(docTreePath.getTreePath(), javac); if(treePathHandle.getFileObject() == null) { return null; } int position = (int) ((DCTree) docTreePath.getLeaf()).getSourcePosition((DCTree.DCDocComment)docTreePath.getDocComment()); if (position == (-1)) { DocTree docTree = docTreePath.getLeaf(); if(docTree == docTreePath.getDocComment()) { return new DocTreePathHandle(new DocCommentDelegate(treePathHandle)); } int index = listChildren(docTreePath.getParentPath().getLeaf()).indexOf(docTree); assert index != (-1); return new DocTreePathHandle(new CountingDelegate(treePathHandle, index, docTreePath.getLeaf().getKind())); } Position pos = createPositionRef(treePathHandle.getFileObject(), position, Bias.Forward); return new DocTreePathHandle(new DocTreeDelegate(pos, new DocTreeDelegate.KindPath(docTreePath), treePathHandle)); }