@Override protected JPanel createDestinationRootPanel() { final List<VirtualFile> sourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject); if (sourceRoots.size() <= 1) return super.createDestinationRootPanel(); final JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder")); panel.add(label, BorderLayout.NORTH); label.setLabelFor(myDestinationFolderComboBox); myDestinationFolderComboBox.setData(myProject, myTargetDirectory, new Pass<String>() { @Override public void pass(String s) { } }, ((PackageNameReferenceEditorCombo)myPackageNameField).getChildComponent()); panel.add(myDestinationFolderComboBox, BorderLayout.CENTER); return panel; }
@Override public void substituteElementToRename(@NotNull PsiElement element, @NotNull final Editor editor, @NotNull final Pass<PsiElement> renameCallback) { final PsiMethod psiMethod = (PsiMethod)element; if (psiMethod.isConstructor()) { final PsiClass containingClass = psiMethod.getContainingClass(); if (containingClass == null) return; if (!Comparing.strEqual(psiMethod.getName(), containingClass.getName())) { renameCallback.pass(psiMethod); return; } super.substituteElementToRename(element, editor, renameCallback); } else { SuperMethodWarningUtil.checkSuperMethod(psiMethod, "Rename", new PsiElementProcessor<PsiMethod>() { @Override public boolean execute(@NotNull PsiMethod method) { if (!PsiElementRenameHandler.canRename(method.getProject(), editor, method)) return false; renameCallback.pass(method); return false; } }, editor); } }
public CopyClassDialog(PsiClass aClass, PsiDirectory defaultTargetDirectory, Project project, boolean doClone) { super(project, true); myProject = project; myDefaultTargetDirectory = defaultTargetDirectory; myDoClone = doClone; String text = myDoClone ? RefactoringBundle.message("copy.class.clone.0.1", UsageViewUtil.getType(aClass), UsageViewUtil.getLongName(aClass)) : RefactoringBundle.message("copy.class.copy.0.1", UsageViewUtil.getType(aClass), UsageViewUtil.getLongName(aClass)); myInformationLabel.setText(text); myInformationLabel.setFont(myInformationLabel.getFont().deriveFont(Font.BOLD)); init(); myDestinationCB.setData(myProject, defaultTargetDirectory, new Pass<String>() { @Override public void pass(String s) { setErrorText(s); } }, myTfPackage.getChildComponent()); myNameField.setText(UsageViewUtil.getShortName(aClass)); myNameField.selectAll(); }
private void doTestStopEditing(Pass<AbstractInplaceIntroducer> pass) { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); try { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); getEditor().getSettings().setVariableInplaceRenameEnabled(true); final AbstractInplaceIntroducer introducer = invokeRefactoring(); pass.pass(introducer); checkResultByFile(getBasePath() + name + "_after" + getExtension()); } finally { TemplateState state = TemplateManagerImpl.getTemplateState(getEditor()); if (state != null) { state.gotoEnd(true); } getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); } }
private void doTestReplaceChoice(OccurrencesChooser.ReplaceChoice choice, Pass<AbstractInplaceIntroducer> pass) { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); try { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); getEditor().getSettings().setVariableInplaceRenameEnabled(true); MyIntroduceHandler handler = createIntroduceHandler(); ((MyIntroduceVariableHandler)handler).setChoice(choice); final AbstractInplaceIntroducer introducer = invokeRefactoring(handler); if (pass != null) { pass.pass(introducer); } TemplateState state = TemplateManagerImpl.getTemplateState(getEditor()); assert state != null; state.gotoEnd(false); checkResultByFile(getBasePath() + name + "_after" + getExtension()); } finally { getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); } }
public void setTabActions(ActionGroup group) { removeOldActionPanel(); if (group == null) return; myActionPanel = new ActionPanel(myTabs, myInfo, new Pass<MouseEvent>() { public void pass(final MouseEvent event) { final MouseEvent me = SwingUtilities.convertMouseEvent(event.getComponent(), event, TabLabel.this); processMouseEvent(me); } }); toggleShowActions(false); add(myActionPanel, BorderLayout.EAST); myTabs.revalidateAndRepaint(false); }
protected void doTestEscape(Pass<AbstractInplaceIntroducer> pass) { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); try { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); getEditor().getSettings().setVariableInplaceRenameEnabled(true); final AbstractInplaceIntroducer introducer = invokeRefactoring(); if (pass != null) { pass.pass(introducer); } TemplateState state = TemplateManagerImpl.getTemplateState(getEditor()); assert state != null; state.gotoEnd(true); checkResultByFile(getBasePath() + name + "_after" + getExtension()); } finally { getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); } }
protected void doTest(final Pass<AbstractInplaceIntroducer> pass) { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); try { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); getEditor().getSettings().setVariableInplaceRenameEnabled(true); final AbstractInplaceIntroducer introducer = invokeRefactoring(); pass.pass(introducer); TemplateState state = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(getEditor())); assert state != null; state.gotoEnd(false); checkResultByFile(getBasePath() + name + "_after" + getExtension()); } finally { getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); } }
protected void performActionOnElementOccurrences(final IntroduceOperation operation) { final Editor editor = operation.getEditor(); if (editor.getSettings().isVariableInplaceRenameEnabled()) { ensureName(operation); if (operation.isReplaceAll() != null) { performInplaceIntroduce(operation); } else { OccurrencesChooser.simpleChooser(editor).showChooser(operation.getElement(), operation.getOccurrences(), new Pass<OccurrencesChooser.ReplaceChoice>() { @Override public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) { operation.setReplaceAll(replaceChoice == OccurrencesChooser.ReplaceChoice.ALL); performInplaceIntroduce(operation); } }); } } else { performIntroduceWithDialog(operation); } }
protected JComponent createTestTreeView() { tree = new TestNGTestTreeView(); final TestTreeStructure structure = new TestTreeStructure(project, rootNode); tree.attachToModel(this); treeBuilder = new TestTreeBuilder(tree, structure); Disposer.register(this, treeBuilder); animator = new TestsProgressAnimator(treeBuilder); openSourceListener = new OpenSourceSelectionListener(); tree.getSelectionModel().addTreeSelectionListener(openSourceListener); TrackRunningTestUtil.installStopListeners(tree, this, new Pass<AbstractTestProxy>() { @Override public void pass(AbstractTestProxy abstractTestProxy) { myLastSelected = (TestProxy)abstractTestProxy; } }); return tree; }
private static void invokeInplaceRename(PsiNameIdentifierOwner nameIdentifierOwner, final String... suggestedNames) { final PsiNameIdentifierOwner elementToRename = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(nameIdentifierOwner); final Editor editor = FileEditorManager.getInstance(nameIdentifierOwner.getProject()).getSelectedTextEditor(); if (editor == null) { return; } final PsiElement identifier = elementToRename.getNameIdentifier(); if (identifier == null) { return; } editor.getCaretModel().moveToOffset(identifier.getTextOffset()); final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename); if (!processor.isInplaceRenameSupported()) { return; } processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() { @Override public void pass(PsiElement substitutedElement) { final MemberInplaceRenamer renamer = new MemberInplaceRenamer(elementToRename, substitutedElement, editor); final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<String>(Arrays.asList(suggestedNames)); renamer.performInplaceRefactoring(nameSuggestions); } }); }
@Override public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable DataContext dataContext) { editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final SelectionModel model = editor.getSelectionModel(); if (model.hasSelection()) { invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd()); } else { final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, editor.getCaretModel().getOffset(), true); final Pass<GrExpression> callback = new Callback(project, editor, file); if (expressions.size() == 1) { callback.pass(expressions.get(0)); } else if (expressions.isEmpty()) { model.selectLineAtCaret(); invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd()); } else { IntroduceTargetChooser.showChooser(editor, expressions, callback, GrIntroduceHandlerBase.GR_EXPRESSION_RENDERER); } } }
@Override protected JPanel createDestinationRootPanel() { final VirtualFile[] sourceRoots = ProjectRootManager.getInstance(myProject).getContentSourceRoots(); if (sourceRoots.length <= 1) return super.createDestinationRootPanel(); final JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder")); panel.add(label, BorderLayout.NORTH); label.setLabelFor(myDestinationFolderComboBox); myDestinationFolderComboBox.setData(myProject, myTargetDirectory, new Pass<String>() { @Override public void pass(String s) { } }, ((PackageNameReferenceEditorCombo)myPackageNameField).getChildComponent()); panel.add(myDestinationFolderComboBox, BorderLayout.CENTER); return panel; }
private boolean applyChosenClassAndExtract(List<PsiVariable> inputVariables, @Nullable Pass<ExtractMethodProcessor> extractPass) throws PrepareFailedException { myStatic = shouldBeStatic(); if (!PsiUtil.isLocalOrAnonymousClass(myTargetClass) && (myTargetClass.getContainingClass() == null || myTargetClass.hasModifierProperty(PsiModifier.STATIC))) { ElementNeedsThis needsThis = new ElementNeedsThis(myTargetClass); for (int i = 0; i < myElements.length && !needsThis.usesMembers(); i++) { PsiElement element = myElements[i]; element.accept(needsThis); } myCanBeStatic = !needsThis.usesMembers(); } else { myCanBeStatic = false; } myInputVariables = new InputVariables(inputVariables, myProject, new LocalSearchScope(myElements), true); if (!checkExitPoints()){ return false; } if (extractPass != null) { extractPass.pass(this); } return true; }
protected void doTest(final Pass<AbstractInplaceIntroducer> pass) { String name = getTestName(true); configureByFile(getBasePath() + name + getExtension()); final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); try { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); getEditor().getSettings().setVariableInplaceRenameEnabled(true); final AbstractInplaceIntroducer introducer = invokeRefactoring(); pass.pass(introducer); TemplateState state = TemplateManagerImpl.getTemplateState(getEditor()); assert state != null; state.gotoEnd(false); checkResultByFile(getBasePath() + name + "_after" + getExtension()); } finally { getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); } }
protected JComponent createTestTreeView() { tree = new TestNGTestTreeView(); final TestTreeStructure structure = new TestTreeStructure(project, rootNode); tree.attachToModel(this); treeBuilder = new TestTreeBuilder(tree, structure); Disposer.register(this, treeBuilder); animator = new Animator(this, treeBuilder); openSourceListener = new OpenSourceSelectionListener(); tree.getSelectionModel().addTreeSelectionListener(openSourceListener); TrackRunningTestUtil.installStopListeners(tree, this, new Pass<AbstractTestProxy>() { @Override public void pass(AbstractTestProxy abstractTestProxy) { myLastSelected = (TestProxy)abstractTestProxy; } }); return tree; }
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable DataContext dataContext) { editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final SelectionModel model = editor.getSelectionModel(); if (model.hasSelection()) { invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd()); } else { final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, editor.getCaretModel().getOffset(), true); final Pass<GrExpression> callback = new Callback(project, editor, file); if (expressions.size() == 1) { callback.pass(expressions.get(0)); } else if (expressions.isEmpty()) { model.selectLineAtCaret(); invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd()); } else { IntroduceTargetChooser.showChooser(editor, expressions, callback, GrIntroduceHandlerBase.GR_EXPRESSION_RENDERER); } } }
protected void performActionOnElementOccurrences(final HaxeIntroduceOperation operation) { final Editor editor = operation.getEditor(); if (editor.getSettings().isVariableInplaceRenameEnabled()) { ensureName(operation); if (operation.isReplaceAll() != null) { performInplaceIntroduce(operation); } else { OccurrencesChooser.simpleChooser(editor).showChooser( operation.getElement(), operation.getOccurrences(), new Pass<OccurrencesChooser.ReplaceChoice>() { @Override public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) { operation.setReplaceAll(replaceChoice == OccurrencesChooser.ReplaceChoice.ALL); performInplaceIntroduce(operation); } }); } } else { performIntroduceWithDialog(operation); } }
public void setTabActions(ActionGroup group) { removeOldActionPanel(); if (group == null) return; myActionPanel = new ActionPanel(myTabs, myInfo, new Pass<MouseEvent>() { @Override public void pass(final MouseEvent event) { final MouseEvent me = SwingUtilities.convertMouseEvent(event.getComponent(), event, TabLabel.this); processMouseEvent(me); } }); toggleShowActions(false); add(myActionPanel, BorderLayout.EAST); myTabs.revalidateAndRepaint(false); }
protected static JCheckBox createSetting(final String cbText, final boolean option, final Pass<JCheckBox> pass) { final JCheckBox uncheckedCb = new JCheckBox(cbText, option); uncheckedCb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pass.pass(uncheckedCb); } }); return uncheckedCb; }
public CreateClassDialog(@NotNull Project project, @NotNull String title, @NotNull String targetClassName, @NotNull String targetPackageName, @NotNull ClassKind kind, boolean classNameEditable, @Nullable Module defaultModule) { super(project, true); myClassNameEditable = classNameEditable; myModule = defaultModule; myClassName = targetClassName; myProject = project; myPackageComponent = new PackageNameReferenceEditorCombo(targetPackageName, myProject, RECENTS_KEY, CodeInsightBundle.message("dialog.create.class.package.chooser.title")); myPackageComponent.setTextFieldPreferredWidth(40); init(); if (!myClassNameEditable) { setTitle(CodeInsightBundle.message("dialog.create.class.name", StringUtil.capitalize(kind.getDescription()), targetClassName)); } else { myInformationLabel.setText(CodeInsightBundle.message("dialog.create.class.label", kind.getDescription())); setTitle(title); } myTfClassName.setText(myClassName); myDestinationCB.setData(myProject, getBaseDir(targetPackageName), new Pass<String>() { @Override public void pass(String s) { setErrorText(s); } }, myPackageComponent.getChildComponent()); }
public void setData(final Project project, final PsiDirectory initialTargetDirectory, final EditorComboBox editorComboBox) { setData(project, initialTargetDirectory, new Pass<String>() { @Override public void pass(String s) { } }, editorComboBox); }
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, final DataContext dataContext) { ExtractMethodHandler.selectAndPass(project, editor, file, new Pass<PsiElement[]>() { public void pass(final PsiElement[] selectedValue) { invokeOnElements(project, editor, file, selectedValue); } }); }
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, DataContext dataContext) { final Pass<PsiElement[]> callback = new Pass<PsiElement[]>() { public void pass(final PsiElement[] selectedValue) { invokeOnElements(project, editor, file, selectedValue); } }; selectAndPass(project, editor, file, callback); }
public static void selectAndPass(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, @NotNull final Pass<PsiElement[]> callback) { editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); if (!editor.getSelectionModel().hasSelection()) { final int offset = editor.getCaretModel().getOffset(); final List<PsiExpression> expressions = IntroduceVariableBase.collectExpressions(file, editor, offset, true); if (expressions.isEmpty()) { editor.getSelectionModel().selectLineAtCaret(); } else if (expressions.size() == 1) { callback.pass(new PsiElement[]{expressions.get(0)}); return; } else { IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiExpression>() { @Override public void pass(PsiExpression psiExpression) { callback.pass(new PsiElement[]{psiExpression}); } }, new PsiExpressionTrimRenderer.RenderFunction()); return; } } PsiDocumentManager.getInstance(project).commitAllDocuments(); callback.pass(getElements(project, editor, file)); }
private static void invokeOnElements(final Project project, final Editor editor, PsiFile file, PsiElement[] elements) { getProcessor(elements, project, file, editor, true, new Pass<ExtractMethodProcessor>(){ @Override public void pass(ExtractMethodProcessor processor) { invokeOnElements(project, editor, processor, true); } }); }
public void testAnchor() throws Exception { doTest(new Pass<AbstractInplaceIntroducer>() { @Override public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { } }); }
public void testAnchor1() throws Exception { doTest(new Pass<AbstractInplaceIntroducer>() { @Override public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { } }); }
public void testBeforeAssignment() throws Exception { doTest(new Pass<AbstractInplaceIntroducer>() { @Override public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { } }); }
public void testTemplateAdjustment() throws Exception { doTest(new Pass<AbstractInplaceIntroducer>() { @Override public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { } }); }
public void testBeforeAssignmentReplaceAll() throws Exception { doTest(new Pass<AbstractInplaceIntroducer>() { @Override public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { inplaceIntroduceFieldPopup.setReplaceAllOccurrences(true); } }); }