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; }
public FileObject getFileObject() { return parent.getFileObject(); }
public Element resolveElement(CompilationInfo info) { return delegateElementHandle.resolveElement(info); }
public Problem prepare(RefactoringElementsBag refactoringElements) { if (semafor.get() == null) { semafor.set(new Object()); //TODO: should be improved. Object element = refactoring.getRefactoringSource().lookup(Object.class); LOGGER.fine("Prepare refactoring: " + element); // NOI18N if (element instanceof TreePathHandle) { treePathHandle = (TreePathHandle)element; if (treePathHandle != null && TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())){ Project project = FileOwnerQuery.getOwner(treePathHandle.getFileObject()); if (project != null){ Element resElement = JSFRefactoringUtils.resolveElement(refactoring, treePathHandle); TypeElement type = (TypeElement) resElement; String fqnc = type.getQualifiedName().toString(); List <Occurrences.OccurrenceItem> items = Occurrences.getAllOccurrences(project, fqnc,""); for (Occurrences.OccurrenceItem item : items) { refactoringElements.add(refactoring, new JSFWhereUsedElement(item)); } } } } semafor.set(null); } return null; }
/** * 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)); }
return new TreePathHandle(new EmptyDelegate(url, treePath.getLeaf().getKind())); 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())); Position pos = createPositionRef(file, position, Bias.Forward); TreePath current = treePath; Element correspondingElement = info.getTrees().getElement(current); || current.getLeaf().getKind() == Kind.METHOD) { Element loc = info.getTrees().getElement(current); if (isSupported(loc)) { if (child && info.getTreeUtilities().isSynthetic(info.getCompilationUnit(), current.getLeaf())) { elementHandle = createHandle(element); if (correspondingElement != null && isSupported(correspondingElement)) { correspondingElementHandle = createHandle(correspondingElement); return new TreePathHandle(new TreeDelegate(pos, new TreeDelegate.KindPath(treePath), file, elementHandle, correspondingElementHandle));
public Tree.Kind getKind() { return delegateElementHandle.getKind(); }
public TreePath resolve(CompilationInfo info) { return delegateElementHandle.resolve(info); }
if (treePathHandle != null && TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())){ project = FileOwnerQuery.getOwner(treePathHandle.getFileObject()); if (project != null){ Element resElement = JSFRefactoringUtils.resolveElement(refactoring, treePathHandle);
public Problem prepare(RefactoringElementsBag refactoringElementsBag) { if (!refactoring.getBooleanValue(WhereUsedQuery.FIND_REFERENCES)) { return null; } final TreePathHandle treePathHandle = refactoring.getRefactoringSource().lookup(TreePathHandle.class); if (treePathHandle != null && treePathHandle.getKind() == Kind.METHOD) { return prepareMethodRefactoring(refactoringElementsBag, treePathHandle); } if (treePathHandle != null && TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())) { return prepareClassRefactoring(refactoringElementsBag, treePathHandle); } return null; }
private ExpressionTree getArgument(CompilationInfo cinfo) { StatementTree stmtTree = (StatementTree) stmtTreePathHandle.resolve(cinfo).getLeaf(); //StatementTree stmtTree = method.findPropertyStatement(cinfo, beanName, setterName); if (stmtTree != null) { // #137584 Fixing IndexOutOfBoundsException. List<? extends ExpressionTree> list = getMethodInvocationTree(cinfo, stmtTree).getArguments(); return list.isEmpty() ? null : list.get(0); } return null; }
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);
if (treePathHandle != null && TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())) { Project project = FileOwnerQuery.getOwner(treePathHandle.getFileObject()); if (project != null) { Element resElement = JSFRefactoringUtils.resolveElement(refactoring, treePathHandle); String newPackageName = JSFRefactoringUtils.getPackageName(targetUrl); String newFQN = newPackageName.length() == 0 ? type.getSimpleName().toString() : newPackageName + '.' + type.getSimpleName().toString(); if (isTargetOtherProject(treePathHandle.getFileObject(), refactoring)) { List<Occurrences.OccurrenceItem> items = Occurrences.getAllOccurrences(project, oldFQN, newFQN); for (Occurrences.OccurrenceItem item : items) {
public Problem handleChange(RefactoringElementImplementation proposedChange, Collection<RefactoringElementImplementation> replacements, Collection<Transaction> transaction) { FileObject changedFileObject = proposedChange.getParentFile(); TreePathHandle handle = myRefactoring.getRefactoringSource().lookup( TreePathHandle.class ); boolean flag = ( handle!= null ) && handle.getFileObject()!=null && handle.getFileObject().equals( changedFileObject ); if ( flag ) { //proposedChange.setStatus(RefactoringElementImplementation.NORMAL); //proposedChange.setEnabled( false ); proposedChange = new GuardedElementImplementation(proposedChange); } replacements.add(proposedChange); return null; }
public Element resolveElement(CompilationInfo info) { return parent.resolveElement(info); }
public Problem prepare(RefactoringElementsBag refactoringElements) { TreePathHandle treePathHandle = refactoring.getRefactoringSource().lookup(TreePathHandle.class); if (treePathHandle != null && treePathHandle.getKind() == Kind.METHOD) { return prepareMethodRefactoring(refactoringElements, treePathHandle); } return prepareClassRefactoring(refactoringElements, treePathHandle); }
public TreePath resolve(CompilationInfo compilationInfo) throws IllegalArgumentException { TreePath p = parent.resolve(compilationInfo); if (p == null) return null; List<Tree> children = listChildren(p.getLeaf()); if (index < children.size()) { Tree t = children.get(index); if (t.getKind() == kind) { return new TreePath(p, t); } } return null; }
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);
if (treePathHandle != null && TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())){ Project project = FileOwnerQuery.getOwner(treePathHandle.getFileObject()); if (project != null){ Element resElement = JSFRefactoringUtils.resolveElement(refactoring, treePathHandle);
private FileObject getRefactoringSource(AbstractRefactoring refactoring) { FileObject source = refactoring.getRefactoringSource().lookup(FileObject.class); if (source != null) { return source; } TreePathHandle tph = refactoring.getRefactoringSource().lookup(TreePathHandle.class); if (tph != null) { return tph.getFileObject(); } NonRecursiveFolder folder = refactoring.getRefactoringSource().lookup(NonRecursiveFolder.class); if (folder != null) { return folder.getFolder(); } return null; }