private String getNewFQN(){ return RefactoringUtil.renameClass(oldFqn, rename.getNewName()); }
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);
/** * @return true if the given refactoring represents a package rename. */ public static boolean isPackage(RenameRefactoring rename){ return rename.getRefactoringSource().lookup(NonRecursiveFolder.class) != null; }
public Problem checkParameters() { newName = panel.getNameValue(); refactoring.setNewName(newName); return refactoring.fastCheckParameters(); }
public Problem setParameters() { newName = panel.getNameValue(); refactoring.setNewName(newName); refactoring.setSearchInComments(panel.searchJavadoc()); return refactoring.checkParameters(); }
public org.netbeans.modules.refactoring.api.Problem setParameters() { newName = getPanelName(); if (refactoring instanceof RenameRefactoring) { ((RenameRefactoring) refactoring).setNewName(newName); ((RenameRefactoring) refactoring).setSearchInComments(panel.searchJavadoc()); }// else { // ((MoveClassRefactoring) refactoring).setTargetPackageName(newName); // } return refactoring.checkParameters(); }
@Override public Problem prepare(RefactoringElementsBag refactoringElements){ RefactoringSession refactoringSession = refactoringElements.getSession(); FileObject refactoringSourcefileObject = getRenameRefactoring().getRefactoringSource().lookup(FileObject.class); if (refactoringSourcefileObject != null) { if (FacesRefactoringUtils.isFileUnderDocumentRoot(refactoringSourcefileObject)) { String newName = getRenameRefactoring().getNewName(); if (newName == null) { return new Problem(true, NbBundle.getMessage(FacesJspFileRenameRefactoringPlugin.class, "ERR_NewNameCannotBeNull")); // NOI18N RenameRefactoring javaRenameRefactoring = new RenameRefactoring(Lookups.singleton(javaFileObject)); javaRenameRefactoring.setNewName(newName); javaRenameRefactoring.setSearchInComments(getRenameRefactoring().isSearchInComments()); javaRenameRefactoring.getContext().add(classpathInfo); javaRenameRefactoring.getContext().add(FacesRefactoringsPluginFactory.DELEGATED_REFACTORING); Problem problem = javaRenameRefactoring.prepare(refactoringSession); if (problem != null) { return problem;
return rename.getNewName() + "." + JavaIdentifiers.unqualify(fqn); final FileObject folder = rename.getRefactoringSource().lookup(FileObject.class); final ClassPath classPath = ClassPath.getClassPath(folder, ClassPath.SOURCE); if (classPath == null) { final String prefix = FileUtil.getRelativePath(root, folder.getParent()).replace('/','.'); final String oldName = buildName(prefix, folder.getName()); final String newName = buildName(prefix, rename.getNewName()); final int oldNameIndex = fqn.lastIndexOf(oldName) + oldName.length();
methodRenameRefactoring[0].setNewName("get" + newBeanName); methodRenameRefactoring[0].getContext().add(FacesRefactoringsPluginFactory.DELEGATED_REFACTORING); Problem problem = methodRenameRefactoring[0].prepare(refactoringElements.getSession()); if (problem != null) { return problem; String newName = getRenameRefactoring().getNewName(); methodRenameRefactoring[0].setNewName("get" + newBeanName); methodRenameRefactoring[0].getContext().add(FacesRefactoringsPluginFactory.DELEGATED_REFACTORING); Problem problem = methodRenameRefactoring[0].prepare(refactoringElements.getSession()); if (problem != null) { return problem;
private static void doRenameRefactoring(FormDataObject dao, String newName, TreePathHandle handle) throws IOException { if(handle==null){ //this would only happen if setName were called without the correct component being //selected some how... return; } FormEditorSupport fes = (FormEditorSupport)dao.getFormEditorSupport(); if (fes.isModified()) { fes.saveDocument(); } //ok, so we are now ready to actually setup our RenameRefactoring...we need the element TreePathHandle Lookup rnl = Lookups.singleton(handle); RefactoringSession renameSession = RefactoringSession.create("Change variable name");//NOI18N RenameRefactoring refactoring = new RenameRefactoring(rnl); Problem pre = refactoring.preCheck(); if(pre!=null&&pre.isFatal()){ Logger.getLogger("global").log(Level.WARNING, "There were problems trying to perform the refactoring."); } Problem p = null; if( (!(pre!=null&&pre.isFatal())) && !emptyOrWhite(newName) ){ refactoring.setNewName(newName); p = refactoring.prepare(renameSession); } if( (!(p!=null&&p.isFatal())) && !emptyOrWhite(newName) ){ renameSession.doRefactoring(true); } }
public CPRenameRefactoringUI(RefactoringElementContext context) { this.context = context; Collection<Object> lookupContent = new ArrayList<>(); lookupContent.add(context); this.refactoring = new RenameRefactoring(Lookups.fixed(lookupContent.toArray())); }
void setNewGetterName(String name) { if ( myMethodRenameRefactoring != null ){ myMethodRenameRefactoring.setNewName(name); } }
@Override protected Collection<CsmFile> getRefactoredFiles() { Collection<? extends CsmObject> objs = getRefactoredObjects(); if (objs == null || objs.isEmpty()) { return Collections.emptySet(); } Collection<CsmFile> files = new HashSet<CsmFile>(); CsmFile startFile = getStartCsmFile(); for (CsmObject obj : objs) { Collection<CsmProject> prjs = CsmRefactoringUtils.getRelatedCsmProjects(obj, null); CsmProject[] ar = prjs.toArray(new CsmProject[prjs.size()]); refactoring.getContext().add(ar); files.addAll(getRelevantFiles(startFile, obj, refactoring)); } return files; }
public Problem prepare(RefactoringElementsBag refactoringElements) { RefactoringSession session = refactoringElements.getSession(); if ( myRefactoring.getListener() != null ){ session.addProgressListener( myRefactoring.getListener() ); } Problem problem = myFieldRenameRefactoring.prepare(session); if ( myMethodRenameRefactoring != null ){ Problem methodProblem = myMethodRenameRefactoring.prepare(session); if ( problem == null ){ problem = methodProblem; } else if ( methodProblem!= null ) { Problem last = problem; while( last.getNext() != null ){ last=last.getNext(); } last.setNext( methodProblem ); } } myRefactoring.setResult( problem ); return problem; }
Project project = FileOwnerQuery.getOwner(refactoringSourcefileObject); if (FacesRefactoringUtils.isJavaFileObjectOfInterest(refactoringSourcefileObject)) { String newName = getRenameRefactoring().getNewName(); methodRenameRefactoring[0] = new RenameRefactoring(Lookups.fixed(treePathHandle)); methodRenameRefactoring[0].getContext().add(compilationController); methodRenameRefactoring[0].setNewName("get" + newBeanName); methodRenameRefactoring[0].setSearchInComments(getRenameRefactoring().isSearchInComments()); methodRenameRefactoring[0].getContext().add(FacesRefactoringsPluginFactory.DELEGATED_REFACTORING); Problem problem = methodRenameRefactoring[0].prepare(refactoringElements.getSession()); if (problem != null) { return problem; FileObject jspFileObject = FacesModel.getJspForJava(refactoringSourcefileObject); if (jspFileObject != null) { RenameRefactoring jspRenameRefactoring = new RenameRefactoring(Lookups.singleton(jspFileObject)); jspRenameRefactoring.setNewName(newName); jspRenameRefactoring.setSearchInComments(getRenameRefactoring().isSearchInComments()); jspRenameRefactoring.getContext().add(FacesRefactoringsPluginFactory.DELEGATED_REFACTORING); Problem problem = jspRenameRefactoring.prepare(refactoringElements.getSession()); if (problem != null) { return problem;
semafor.set(new Object()); FileObject fileObject = refactoring.getRefactoringSource().lookup(FileObject.class); NonRecursiveFolder nonRecursivefolder = refactoring.getRefactoringSource().lookup(NonRecursiveFolder.class); treePathHandle = refactoring.getRefactoringSource().lookup(TreePathHandle.class); String oldName = (prefix.length() == 0 ? fileObject.getName() : prefix + "." + fileObject.getName()); String newName = (prefix.length() == 0 ? refactoring.getNewName() : prefix + "." + refactoring.getNewName()); String newName = refactoring.getNewName(); String newFQN = renameClass(oldFQN, refactoring.getNewName()); List <Occurrences.OccurrenceItem> items = Occurrences.getAllOccurrences(project, oldFQN, newFQN); Modifications modification = new Modifications();
RenameRefactoringUI(FileObject jmiObject, String newName, JsElementCtx handle) { if (handle!=null) { this.refactoring = new RenameRefactoring(Lookups.fixed(jmiObject, handle)); } else { this.refactoring = new RenameRefactoring(Lookups.fixed(jmiObject)); } //this.jmiObject = jmiObject; oldName = newName; //[FIXME] this should be oldName of refactored object this.dispOldName = newName; // XXX: parsingapi // ClasspathInfo cpInfo = handle==null?RetoucheUtils.getClasspathInfoFor(jmiObject):RetoucheUtils.getClasspathInfoFor(handle); // if (cpInfo != null) { // refactoring.getContext().add(cpInfo); // } fromListener = true; // Force refresh! this.refactoring.getContext().add(true); }
void setNewFieldName(String name) { myFieldRenameRefactoring.setNewName(name); }
@Override public org.netbeans.modules.refactoring.api.Problem setParameters() { if (!panel.isUpdateReferences()) { return null; } newName = panel.getNameValue(); if (refactoring instanceof RenameRefactoring) { ((RenameRefactoring) refactoring).setNewName(newName); ((RenameRefactoring) refactoring).setSearchInComments(panel.searchInComments()); } return refactoring.checkParameters(); }
public @Override void run(ResultIterator co) throws Exception { if (co.getSnapshot().getMimeType().equals(JsTokenId.JAVASCRIPT_MIME_TYPE)) { JsParseResult rpr = AstUtilities.getParseResult(co.getParserResult()); org.mozilla.nb.javascript.Node root = rpr.getRootNode(); if (root != null) { AnalysisResult ar = rpr.getStructure(); List<? extends AstElement> els = ar.getElements(); if (els.size() > 0) { // TODO - try to find the outermost or most "relevant" module/class in the file? // In Java, we look for a class with the name corresponding to the file. // It's not as simple in Js. AstElement element = null; for (AstElement astElement : els) { if (astElement.getName().equals(co.getSnapshot().getSource().getFileObject().getName())) { element = astElement; } } if (element != null) { org.mozilla.nb.javascript.Node node = element.getNode(); treePathHandle = new JsElementCtx(root, node, element, rpr.getSnapshot().getSource().getFileObject(), rpr); refactoring.getContext().add(co); } } } } } });