public FileObject getFileObject() { return parent.getFileObject(); }
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; }
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; }
JavaSource source = JavaSource.forFileObject(treePathHandle.getFileObject()); if (source == null) { return null;
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; }
JavaSource source = JavaSource.forFileObject(handle.getFileObject()); try { source.runUserActionTask(new Task<CompilationController>() {
public static Element resolveElement(final AbstractRefactoring refactoring, final TreePathHandle treePathHandle) { final ClasspathInfo cpInfo = refactoring.getContext().lookup(ClasspathInfo.class); final Element[] element = new Element[1]; JavaSource source = JavaSource.create(cpInfo, new FileObject[]{treePathHandle.getFileObject()}); try { source.runUserActionTask(new Task<CompilationController>() { @Override public void run(CompilationController info) throws Exception { info.toPhase(JavaSource.Phase.RESOLVED); element[0] = treePathHandle.resolveElement(info); } }, true); } catch (IOException exception) { LOGGER.log(Level.WARNING, "Exception by refactoring:", exception); //NOI18NN } return element[0]; } }
final TreePathHandle tph = refactoring.getRefactoringSource().lookup(TreePathHandle.class); if (tph != null) { FileObject fo = tph.getFileObject(); if (fo != null) { try {
project = FileOwnerQuery.getOwner(treePathHandle.getFileObject()); if (project != null){ Element resElement = JSFRefactoringUtils.resolveElement(refactoring, treePathHandle);
private Problem prepareClassRefactoring(RefactoringElementsBag refactoringElementsBag, final TreePathHandle treePathHandle) { FileObject fo = treePathHandle.getFileObject(); SpringScope scope = SpringScope.getSpringScope(fo); if (scope == null) { return null; } try { JavaSource source = JavaSource.forFileObject(fo); final String[] className = new String[] { null }; source.runUserActionTask(new Task<CompilationController>() { public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(JavaSource.Phase.RESOLVED); TypeElement type = (TypeElement) treePathHandle.resolveElement(compilationController); if (type != null) { className[0] = ElementUtilities.getBinaryName(type); } } }, true); if (className[0] != null) { for (Occurrences.Occurrence item : Occurrences.getJavaClassOccurrences(className[0], scope)) { refactoringElementsBag.add(refactoring, SpringRefactoringElement.create(item)); } } } catch (IOException e) { Exceptions.printStackTrace(e); } return null; }
private Problem prepareMethodRefactoring(RefactoringElementsBag refactoringElements, final TreePathHandle treePathHandle) { FileObject fo = treePathHandle.getFileObject(); try { RenamedProperty prop = null; JavaSource js = JavaSource.forFileObject(fo); if (js != null) { prop = SpringRefactorings.getRenamedProperty(treePathHandle, js, null); } SpringScope scope = SpringScope.getSpringScope(fo); if (scope == null) { return null; } if (prop != null) { String oldName = prop.getOldName(); if (oldName != null) { for (Occurrence occurrence : Occurrences.getPropertyOccurrences(prop, js, scope)) { refactoringElements.add(refactoring, SpringRefactoringElement.create(occurrence)); } } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } return null; } }
sourceFO = handle.getFileObject(); } else if (pkg != null){ sourceFO = pkg.getFolder();
primaryFile = tpHandle.getFileObject(); if (RefactoringInfo.isJavaFileOfForm(primaryFile)) { JavaSource source = JavaSource.forFileObject(tpHandle.getFileObject()); final RefactoringInfo.ChangeType[] changeTypes = new RefactoringInfo.ChangeType[1]; final String[] oldNames = new String[1];
for (TreePathHandle treePathHandle : treePathHandles) { 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) {
private Problem prepareMethodRefactoring(RefactoringElementsBag refactoringElements, final TreePathHandle treePathHandle) { FileObject fo = treePathHandle.getFileObject();
Project project = FileOwnerQuery.getOwner(treePathHandle.getFileObject()); if (project != null){ Element resElement = JSFRefactoringUtils.resolveElement(refactoring, treePathHandle);
private Problem prepareClassRefactoring(RefactoringElementsBag refactoringElements, TreePathHandle treePathHandle) { FileObject fo = null; if (treePathHandle != null && TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())) { fo = treePathHandle.getFileObject();
/** * 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)); }