@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; }
@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 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);
RenameRefactoringUI(NonRecursiveFolder jmiObject, String newName) { this.refactoring = new RenameRefactoring(Lookups.singleton(jmiObject)); // XXX: parsingapi // ClasspathInfo classpath = RetoucheUtils.getClasspathInfoFor(jmiObject.getFolder()); // if (classpath != null) { // refactoring.getContext().add(classpath); // } //this.jmiObject = jmiObject; oldName = newName; //[FIXME] this should be oldName of refactored object this.dispOldName = newName; fromListener = true; pkgRename = true; // Force refresh! this.refactoring.getContext().add(UI.Constants.REQUEST_PREVIEW); }
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 final void run() { CsmObject ctx = CsmRefactoringUtils.findContextObject(context); if (!CsmRefactoringUtils.isSupportedReference(ctx)) { return; } ui = createRefactoringUI(ctx); Collection<? extends CheckModificationHook> hooks = context.lookupAll(CheckModificationHook.class); for (CheckModificationHook hook : hooks) { ui.getRefactoring().getContext().add(hook); } if (ui != null) { openRefactoringUI(ui); } else { JOptionPane.showMessageDialog(null, NbBundle.getMessage(RefactoringActionsProvider.class, "ERR_CannotRefactorLoc")); } }
@Override protected Collection<CsmFile> getRefactoredFiles() { if (enclosingClass == null) { return Collections.emptySet(); } Collection<CsmFile> files = new HashSet<CsmFile>(); CsmFile startFile = CsmRefactoringUtils.getCsmFile(enclosingClass); if (refactoring.isAlwaysUseAccessors()) { Collection<CsmProject> prjs = CsmRefactoringUtils.getRelatedCsmProjects(enclosingClass, null); CsmProject[] ar = prjs.toArray(new CsmProject[prjs.size()]); refactoring.getContext().add(ar); files.addAll(getRelevantFiles(startFile, enclosingClass, refactoring)); } else { // declarations are added to file with class declaration files.add(startFile); if (!refactoring.isMethodInline()) { // add files with definitions Collection<CsmFunction> extDefs = GeneratorUtils.getAllOutOfClassMethodDefinitions(enclosingClass); for (CsmFunction extDef : extDefs) { CsmFile defFile = CsmRefactoringUtils.getCsmFile(extDef); if (defFile != null) { files.add(defFile); } } } } return files; }
public RenameRefactoringUI(NonRecursiveFolder file) { this.refactoring = new RenameRefactoring(Lookups.singleton(file)); oldName = RetoucheUtils.getPackageName(file.getFolder()); // XXX: parsingapi // ClasspathInfo classpath = RetoucheUtils.getClasspathInfoFor(file.getFolder()); // if (classpath != null) { // refactoring.getContext().add(classpath); // } dispOldName = oldName; pkgRename = true; //this(jmiObject, (FileObject) null, true); // Force refresh! this.refactoring.getContext().add(UI.Constants.REQUEST_PREVIEW); }
public RenameRefactoringUI(JsElementCtx handle) { this.jmiObject = handle; stripPrefix = handle.getStripPrefix(); this.refactoring = new RenameRefactoring(Lookups.singleton(handle)); //oldName = handle.resolveElement(info).getSimpleName().toString(); oldName = handle.getSimpleName(); // XXX: parsingapi // ClasspathInfo classpath = RetoucheUtils.getClasspathInfoFor(handle); // if (classpath != null) { // refactoring.getContext().add(classpath); // } dispOldName = oldName; //this(jmiObject, (FileObject) null, true); // Force refresh! this.refactoring.getContext().add(UI.Constants.REQUEST_PREVIEW); }
InstanceRenamePlugin(InstaceRenameRefactoring refactoring) { myRefactoring = refactoring; refactoring.setPlugin( this ); Lookup lookup = refactoring.getRefactoringSource(); Collection<? extends TreePathHandle> collection = lookup.lookupAll( TreePathHandle.class ); Lookup methodLookup =null; Lookup fieldLookup =null; for (TreePathHandle treePathHandle : collection) { if ( treePathHandle.getKind() == Kind.METHOD ){ methodLookup = Lookups.singleton( treePathHandle ); } else if ( treePathHandle.getKind() == Kind.VARIABLE ){ fieldLookup = Lookups.singleton( treePathHandle ); } } if ( methodLookup != null ){ myMethodRenameRefactoring = new RenameRefactoring( methodLookup ); myMethodRenameRefactoring.getContext().add( InstaceRenameRefactoring.FLAG ); } if ( fieldLookup != null ){ myFieldRenameRefactoring = new RenameRefactoring( fieldLookup ); myFieldRenameRefactoring.getContext().add( InstaceRenameRefactoring.FLAG ); } }
public static Collection<RefactoringElementImplementation> getWhereUsed(CsmReference ref, Map<Object, Boolean> params, FiltersDescription filtersDescription) { CsmObject targetObject = ref.getReferencedObject(); Lookup lkp = Lookups.singleton(ref); WhereUsedQuery query = new WhereUsedQuery(lkp); Collection<CsmProject> prjs = CsmRefactoringUtils.getRelatedCsmProjects(targetObject, ref.getContainingFile().getProject()); CsmProject[] ar = prjs.toArray(new CsmProject[prjs.size()]); query.getContext().add(ar); // set parameters for (Map.Entry<Object, Boolean> entry : params.entrySet()) { query.putValue(entry.getKey(), entry.getValue()); } CsmWhereUsedQueryPlugin whereUsedPlugin = new CsmWhereUsedQueryPlugin(query); if (filtersDescription != null) { whereUsedPlugin.addFilters(filtersDescription); } whereUsedPlugin.checkSelectDeclarations(); Collection<RefactoringElementImplementation> elements = whereUsedPlugin.doPrepareElements(targetObject, null); if (filtersDescription != null) { whereUsedPlugin.enableFilters(filtersDescription); } return elements; }
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); }
private Problem setParameters(boolean checkOnly) { refactoring.setRefactorFields(panel.getAllFields()); refactoring.setMethodModifiers(panel.getMethodModifiers()); refactoring.setFieldModifiers(panel.getFieldModifiers()); refactoring.setAlwaysUseAccessors(panel.isCheckAccess()); refactoring.setMethodInline(panel.isMethodInline()); refactoring.getContext().add(panel.getInsertPoint()); refactoring.getContext().add(panel.getSortBy()); refactoring.getContext().add(panel.getDocumentation()); if (checkOnly) { return refactoring.fastCheckParameters(); } else { return refactoring.checkParameters(); } }
refactoring.getContext().add(InsertPoint.DEFAULT); refactoring.setMethodInline(false); Problem problem = refactoring.preCheck();
private void initRefactorings(Collection<EncapsulateFieldInfo> refactorFields, Set<CsmVisibility> methodModifier, Set<CsmVisibility> fieldModifier, boolean alwaysUseAccessors, boolean methodInline) { refactorings = new ArrayList<EncapsulateFieldRefactoringPlugin>(refactorFields.size()); CsmFile[] declDefFiles = null; for (EncapsulateFieldInfo info : refactorFields) { if (declDefFiles == null) { declDefFiles = GeneratorUtils.getDeclarationDefinitionFiles(info.getField().getContainingClass()); } EncapsulateFieldRefactoring ref = new EncapsulateFieldRefactoring(info.getField(), declDefFiles[0], declDefFiles[1]); ref.setGetterName(info.getGetterName()); ref.setSetterName(info.getSetterName()); ref.setMethodModifiers(methodModifier); ref.setFieldModifiers(fieldModifier); ref.setAlwaysUseAccessors(alwaysUseAccessors); ref.setMethodInline(methodInline); ref.setDefaultGetter(info.getDefaultGetter()); ref.setDefaultSetter(info.getDefaultSetter()); ref.getContext().add(refactoring.getContext().lookup(InsertPoint.class)); ref.getContext().add(refactoring.getContext().lookup(Documentation.class)); ref.getContext().add(refactoring.getContext().lookup(SortBy.class)); refactorings.add(new EncapsulateFieldRefactoringPlugin(ref)); } }
public RenameRefactoringUI(FileObject file, JsElementCtx handle) { if (handle!=null) { jmiObject = handle; this.refactoring = new RenameRefactoring(Lookups.fixed(file, handle)); //oldName = jmiObject.resolveElement(info).getSimpleName().toString(); oldName = jmiObject.getSimpleName(); } else { this.refactoring = new RenameRefactoring(Lookups.fixed(file)); oldName = file.getName(); } dispOldName = oldName; // XXX: parsingapi // ClasspathInfo cpInfo = handle==null?RetoucheUtils.getClasspathInfoFor(file):RetoucheUtils.getClasspathInfoFor(handle); // if (cpInfo != null) { // refactoring.getContext().add(cpInfo); // } //this(jmiObject, (FileObject) null, true); // Force refresh! this.refactoring.getContext().add(UI.Constants.REQUEST_PREVIEW); }
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); } } } } } });
@Override public Problem setParameters() { try { // handle parameters defined in panel assert panel != null; query.putValue(WhereUsedQuery.SEARCH_IN_COMMENTS,panel.isSearchInComments()); Collection<CsmProject> prjs = CsmRefactoringUtils.getRelatedCsmProjects(this.origObject, panel.getScopeProject()); CsmProject[] ar = prjs.toArray(new CsmProject[prjs.size()]); query.getContext().add(ar); CsmObject refObj = panel.getReferencedObject(); if (refObj == null) { query.setRefactoringSource(Lookup.EMPTY); } else { query.setRefactoringSource(Lookups.singleton(CsmRefactoringUtils.getHandler(refObj))); } if (panel.isVirtualMethod()) { setForMethod(); return query.checkParameters(); } else if (panel.isClass()) { setForClass(); return query.checkParameters(); } else { return null; } } finally { panel.uninitialize(); } }