@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; }
protected static boolean isDelegatedRefactoring(AbstractRefactoring abstractRefactoring) { return abstractRefactoring.getContext().lookup(DelegatedRefactoring.class) != null; } }
protected CsmModificationRefactoringPlugin(AbstractRefactoring refactoring) { this.refactoring = refactoring; this.startReferenceObject = refactoring.getRefactoringSource().lookup(CsmObject.class); this.editorContext = refactoring.getRefactoringSource().lookup(CsmContext.class); assert startReferenceObject != null || editorContext != null: "no start reference or editor context"; modificationHooks = new ArrayList<CheckModificationHook>(refactoring.getContext().lookupAll(CheckModificationHook.class)); if (modificationHooks.isEmpty()) { modificationHooks.add(new DefaultHookImpl()); } }
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)); } }
@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 public GuardedBlockHandler createInstance(AbstractRefactoring refactoring) { RefactoringInfo refInfo = refactoring.getContext().lookup(RefactoringInfo.class); return new GuardedBlockHandlerImpl(refInfo); }
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 GuardedBlockHandler createInstance(AbstractRefactoring refactoring) { /* * It is unknown for me why custom refactoring InstaceRenameRefactoring * is not passed here as argument ( never I mean ). * Instead of InstaceRenameRefactoring refactoring engine * passes here delegate refactoring instances . In my case * this is two RenameRefactoring ( if accessor is also refactored ). * So I changed code to support RenameRefactoring with special Context. if ( refactoring instanceof InstaceRenameRefactoring ){ return new GuardedBlockHandlerImpl( (InstaceRenameRefactoring) refactoring ); }*/ if ( refactoring instanceof RenameRefactoring && refactoring.getContext().lookup( InstaceRenameRefactoring.RefactoringInfo.class )!= null ) { return new GuardedBlockHandlerImpl( refactoring ); } return null; }
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 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]; } }
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);
CsmProject[] prjs = refactoring.getContext().lookup(CsmProject[].class); if (prjs != null && prjs.length != 0) { for (CsmReference csmReference : refs) {
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); }
Collection<CsmFile> relevantFiles = new HashSet<CsmFile>(); Collection<CsmProject> relevantPrjs = new HashSet<CsmProject>(); CsmProject[] prjs = refactoring.getContext().lookup(CsmProject[].class); CsmFile declFile = CsmRefactoringUtils.getCsmFile(referencedObject); if (prjs == null || prjs.length == 0 || declFile == null) {
@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 void processFile(CsmFile csmFile, ModificationResult mr, AtomicReference<Problem> outProblem) { InsertPoint insPt = refactoring.getContext().lookup(InsertPoint.class); CsmField field = refactoring.getSourceField(); CsmFile classDeclarationFile = refactoring.getClassDeclarationFile();
@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 ); } }