private void saveRefactoringSettings() { final JavaRefactoringSettings refactoringSettings = JavaRefactoringSettings.getInstance(); final boolean searchInComments = isSearchInComments(); final boolean searchForTextOccurences = isSearchInNonJavaFiles(); refactoringSettings.MOVE_SEARCH_IN_COMMENTS = searchInComments; refactoringSettings.MOVE_SEARCH_FOR_TEXT = searchForTextOccurences; refactoringSettings.MOVE_PREVIEW_USAGES = isPreviewUsages(); }
private void saveSettings() { final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); settings.INTRODUCE_PARAMETER_CREATE_FINALS = myDeclareFinalCheckBox.isSelected(); if (myGetterPanel.isVisible()) { settings.INTRODUCE_PARAMETER_REPLACE_FIELDS_WITH_GETTERS = getReplaceFieldsWithGetter(); } if (myForceReturnCheckBox.isEnabled() && mySignaturePanel.isVisible()) { GroovyApplicationSettings.getInstance().FORCE_RETURN = myForceReturnCheckBox.isSelected(); } }
protected void saveSettings(JavaRefactoringSettings settings) { if (myCbDeleteLocalVariable != null) { settings.INTRODUCE_PARAMETER_DELETE_LOCAL_VARIABLE = myCbDeleteLocalVariable.isSelectedWhenSelectable(); } if (myCbUseInitializer != null) { settings.INTRODUCE_PARAMETER_USE_INITIALIZER = myCbUseInitializer.isSelectedWhenSelectable(); } }
@Override public void setToSearchForTextOccurrences(PsiElement element, boolean enabled) { if (element instanceof PsiClass) { JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_CLASS = enabled; } else if (element instanceof PsiMethod) { JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD = enabled; } else if (element instanceof PsiVariable) { JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_VARIABLE = enabled; } else if (element instanceof PsiPackage) { JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_PACKAGE = enabled; } }
@Override public boolean isToSearchForTextOccurrences(PsiElement element) { if (element instanceof PsiClass) { return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_CLASS; } else if (element instanceof PsiMethod) { return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD; } else if (element instanceof PsiVariable) { return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_VARIABLE; } else if (element instanceof PsiPackage) { return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_PACKAGE; } return false; }
@Override protected void saveSettings(@NotNull PsiVariable psiVariable) { super.saveSettings(psiVariable); JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY = myIntroduceFieldPanel.getFieldVisibility(); myIntroduceFieldPanel.saveFinalState(); }
@Override protected boolean performRefactoring() { JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_MOVE_TO_ANOTHER_CLASS = myPanel.isMoveToAnotherClass(); if (myPanel.isMoveToAnotherClass()) { try { myEditor.putUserData(INTRODUCE_RESTART, true); myEditor.putUserData(ACTIVE_INTRODUCE, this); final GrIntroduceConstantHandler constantHandler = new GrIntroduceConstantHandler(); final PsiLocalVariable localVariable = (PsiLocalVariable) getLocalVariable(); constantHandler.getContextAndInvoke( myProject, myEditor, ((GrExpression) myExpr), (GrVariable) localVariable, null); } finally { myEditor.putUserData(INTRODUCE_RESTART, false); myEditor.putUserData(ACTIVE_INTRODUCE, null); releaseResources(); if (myLocalMarker != null) { myLocalMarker.dispose(); } if (myExprMarker != null) { myExprMarker.dispose(); } } return false; } return super.performRefactoring(); }
private boolean hasFinalModifier() { final Boolean createFinals = JavaRefactoringSettings.getInstance().INTRODUCE_PARAMETER_CREATE_FINALS; return createFinals == null ? CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS : createFinals.booleanValue(); }
protected void doOKAction() { if (!myValidator.isOK(this)) return; myNameSuggestionsManager.nameSelected(); myTypeSelectorManager.typeSelected(getSelectedType()); if (myCbFinal.isEnabled()) { JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS = myCbFinal.isSelected(); } super.doOKAction(); }
private String getSelectedVisibility() { if (myParentClass != null && myParentClass.isInterface()) { return PsiModifier.PUBLIC; } String initialVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY; if (initialVisibility == null) { initialVisibility = PsiModifier.PUBLIC; } return initialVisibility; }
protected void doOKAction() { final String path = FileUtil.toSystemIndependentName(myDestDirectoryField.getText()); final Project project = myDirectory.getProject(); PsiDirectory directory = ApplicationManager.getApplication() .runWriteAction( new Computable<PsiDirectory>() { public PsiDirectory compute() { try { return DirectoryUtil.mkdirs(PsiManager.getInstance(project), path); } catch (IncorrectOperationException e) { LOG.error(e); return null; } } }); if (directory == null) { Messages.showErrorDialog( project, RefactoringBundle.message("cannot.find.or.create.destination.directory"), RefactoringBundle.message("cannot.move")); return; } super.doOKAction(); final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory); if (aPackage == null) { Messages.showErrorDialog( project, RefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"), RefactoringBundle.message("cannot.move")); return; } final JavaRefactoringSettings refactoringSettings = JavaRefactoringSettings.getInstance(); final boolean searchInComments = isSearchInComments(); final boolean searchForTextOccurences = isSearchInNonJavaFiles(); refactoringSettings.MOVE_SEARCH_IN_COMMENTS = searchInComments; refactoringSettings.MOVE_SEARCH_FOR_TEXT = searchForTextOccurences; performRefactoring(project, directory, aPackage, searchInComments, searchForTextOccurences); }
protected void doAction() { final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); settings.INTRODUCE_PARAMETER_REPLACE_FIELDS_WITH_GETTERS = myPanel.getReplaceFieldsWithGetters(); if (myCbDeclareFinal != null && myCbDeclareFinal.isEnabled()) { settings.INTRODUCE_PARAMETER_CREATE_FINALS = Boolean.valueOf(myCbDeclareFinal.isSelected()); } myPanel.saveSettings(settings); myNameSuggestionsManager.nameSelected(); boolean isDeleteLocalVariable = false; PsiExpression parameterInitializer = myExpression; if (myLocalVar != null) { if (myPanel.isUseInitializer()) { parameterInitializer = myLocalVar.getInitializer(); } isDeleteLocalVariable = myPanel.isDeleteLocalVariable(); } final IntroduceParameterProcessor processor = new IntroduceParameterProcessor( myProject, myMethodToReplaceIn, myMethodToSearchFor, parameterInitializer, myExpression, myLocalVar, isDeleteLocalVariable, getParameterName(), myPanel.isReplaceAllOccurences(), myPanel.getReplaceFieldsWithGetters(), isDeclareFinal(), myPanel.isGenerateDelegate(), getSelectedType(), myPanel.getParametersToRemove()); invokeRefactoring(processor); myParameterNameField.requestFocusInWindow(); }
protected JPanel createReplaceFieldsWithGettersPanel() { JPanel radioButtonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.insets = new Insets(4, 8, 4, 8); gbConstraints.weighty = 1; gbConstraints.weightx = 1; gbConstraints.gridy = 0; gbConstraints.gridwidth = GridBagConstraints.REMAINDER; gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.anchor = GridBagConstraints.WEST; radioButtonPanel.add( new JLabel( RefactoringBundle.message("replace.fields.used.in.expressions.with.their.getters")), gbConstraints); myReplaceFieldsWithGettersNoneRadio = new JRadioButton(); myReplaceFieldsWithGettersNoneRadio.setText(RefactoringBundle.message("do.not.replace")); myReplaceFieldsWithGettersInaccessibleRadio = new JRadioButton(); myReplaceFieldsWithGettersInaccessibleRadio.setText( RefactoringBundle.message("replace.fields.inaccessible.in.usage.context")); myReplaceFieldsWithGettersAllRadio = new JRadioButton(); myReplaceFieldsWithGettersAllRadio.setText(RefactoringBundle.message("replace.all.fields")); gbConstraints.gridy++; radioButtonPanel.add(myReplaceFieldsWithGettersNoneRadio, gbConstraints); gbConstraints.gridy++; radioButtonPanel.add(myReplaceFieldsWithGettersInaccessibleRadio, gbConstraints); gbConstraints.gridy++; radioButtonPanel.add(myReplaceFieldsWithGettersAllRadio, gbConstraints); final int currentSetting = JavaRefactoringSettings.getInstance().INTRODUCE_PARAMETER_REPLACE_FIELDS_WITH_GETTERS; myReplaceFieldsWithGettersButtonGroup.add(myReplaceFieldsWithGettersNoneRadio); myReplaceFieldsWithGettersButtonGroup.add(myReplaceFieldsWithGettersInaccessibleRadio); myReplaceFieldsWithGettersButtonGroup.add(myReplaceFieldsWithGettersAllRadio); if (currentSetting == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL) { myReplaceFieldsWithGettersAllRadio.setSelected(true); } else if (currentSetting == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE) { myReplaceFieldsWithGettersInaccessibleRadio.setSelected(true); } else if (currentSetting == IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE) { myReplaceFieldsWithGettersNoneRadio.setSelected(true); } return radioButtonPanel; }
@Override protected void addCustomElementsToCentralPanel(JPanel panel) { myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("javadoc.for.abstracts")); myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC); boolean hasJavadoc = false; for (MemberInfo info : myMemberInfos) { final PsiMember member = info.getMember(); if (myMemberInfoModel.isAbstractEnabled(info) && member instanceof PsiDocCommentOwner) { info.setToAbstract(myMemberInfoModel.isAbstractWhenDisabled(info)); if (((PsiDocCommentOwner) member).getDocComment() != null) { hasJavadoc = true; break; } } } UIUtil.setEnabled(myJavaDocPanel, hasJavadoc, true); panel.add(myJavaDocPanel, BorderLayout.EAST); }
protected void doAction() { if (!myCallback.checkConflicts(this)) return; JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy(); final PsiClass superClass = getSuperClass(); String name = superClass.getQualifiedName(); if (name != null) { StatisticsManager.getInstance() .incUseCount( new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name)); } List<MemberInfo> infos = getSelectedMemberInfos(); invokeRefactoring( new PullUpProcessor( myClass, superClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy()))); close(OK_EXIT_CODE); }
@Override protected boolean performRefactoring() { JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_MOVE_TO_ANOTHER_CLASS = myMoveToAnotherClassCb.isSelected(); if (myMoveToAnotherClassCb.isSelected()) { myEditor.putUserData(INTRODUCE_RESTART, true); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { myEditor.putUserData(ACTIVE_INTRODUCE, InplaceIntroduceConstantPopup.this); try { final IntroduceConstantHandler constantHandler = new IntroduceConstantHandler(); final PsiLocalVariable localVariable = (PsiLocalVariable) getLocalVariable(); if (localVariable != null) { constantHandler.invokeImpl(myProject, localVariable, myEditor); } else { constantHandler.invokeImpl(myProject, myExpr, myEditor); } } finally { myEditor.putUserData(INTRODUCE_RESTART, false); myEditor.putUserData(ACTIVE_INTRODUCE, null); releaseResources(); if (myLocalMarker != null) { myLocalMarker.dispose(); } if (myExprMarker != null) { myExprMarker.dispose(); } } } }); return false; } return super.performRefactoring(); }
private JPanel createLeftPanel() { final JPanel left = new JPanel(new GridBagLayout()); myMoveToAnotherClassCb = new JCheckBox( "Move to another class", JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_MOVE_TO_ANOTHER_CLASS); myMoveToAnotherClassCb.setMnemonic('m'); myMoveToAnotherClassCb.setFocusable(false); left.add( myMoveToAnotherClassCb, new GridBagConstraints( 0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); return left; }
@Override protected void saveSettings(@NotNull PsiVariable psiVariable) { myPanel.saveSettings(JavaRefactoringSettings.getInstance()); }
public MoveClassesOrPackagesToNewDirectoryDialog( @NotNull final PsiDirectory directory, PsiElement[] elementsToMove, boolean canShowPreserveSourceRoots, final MoveCallback moveCallback) { super(false); setTitle(MoveHandler.REFACTORING_NAME); myDirectory = directory; myElementsToMove = elementsToMove; myMoveCallback = moveCallback; myDestDirectoryField.setText( FileUtil.toSystemDependentName(directory.getVirtualFile().getPath())); final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false); myDestDirectoryField .getButton() .addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final VirtualFile[] files = FileChooser.chooseFiles( myDirectory.getProject(), descriptor, directory.getVirtualFile()); if (files.length == 1) { myDestDirectoryField.setText(FileUtil.toSystemDependentName(files[0].getPath())); } } }); if (elementsToMove.length == 1) { PsiElement firstElement = elementsToMove[0]; myNameLabel.setText( RefactoringBundle.message( "move.single.class.or.package.name.label", UsageViewUtil.getType(firstElement), UsageViewUtil.getLongName(firstElement))); } else if (elementsToMove.length > 1) { myNameLabel.setText( elementsToMove[0] instanceof PsiClass ? RefactoringBundle.message("move.specified.classes") : RefactoringBundle.message("move.specified.packages")); } final JavaRefactoringSettings refactoringSettings = JavaRefactoringSettings.getInstance(); mySearchInCommentsAndStringsCheckBox.setSelected(refactoringSettings.MOVE_SEARCH_IN_COMMENTS); mySearchForTextOccurrencesCheckBox.setSelected(refactoringSettings.MOVE_SEARCH_FOR_TEXT); myDestDirectoryField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { public void textChanged(DocumentEvent event) { setOKActionEnabled(myDestDirectoryField.getText().length() > 0); } }); if (canShowPreserveSourceRoots) { final Set<VirtualFile> sourceRoots = new HashSet<VirtualFile>(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(directory.getProject()).getFileIndex(); for (PsiElement element : elementsToMove) { if (element instanceof PsiPackage) { for (PsiDirectory psiDirectory : ((PsiPackage) element).getDirectories()) { sourceRoots.add(fileIndex.getSourceRootForFile(psiDirectory.getVirtualFile())); } } else if (element instanceof PsiClass) { final PsiDirectory psiDirectory = element.getContainingFile().getContainingDirectory(); LOG.assertTrue(psiDirectory != null); if (psiDirectory != null) { sourceRoots.add(psiDirectory.getVirtualFile()); } } } myPreserveSourceRoot.setVisible(sourceRoots.size() > 1); } init(); }
protected JComponent createNorthPanel() { GridBagConstraints gbConstraints = new GridBagConstraints(); JPanel panel = new JPanel(new GridBagLayout()); gbConstraints.anchor = GridBagConstraints.WEST; gbConstraints.fill = GridBagConstraints.NONE; gbConstraints.gridx = 0; gbConstraints.insets = new Insets(4, 4, 4, 0); gbConstraints.gridwidth = 1; gbConstraints.weightx = 0; gbConstraints.weighty = 0; gbConstraints.gridy = 0; JLabel type = new JLabel(RefactoringBundle.message("parameter.of.type")); panel.add(type, gbConstraints); gbConstraints.insets = new Insets(4, 4, 4, 8); gbConstraints.gridx++; gbConstraints.weightx = 1; gbConstraints.fill = GridBagConstraints.BOTH; myTypeSelector = myTypeSelectorManager.getTypeSelector(); panel.add(myTypeSelector.getComponent(), gbConstraints); gbConstraints.insets = new Insets(4, 4, 4, 8); gbConstraints.gridwidth = 1; gbConstraints.weightx = 0; gbConstraints.gridx = 0; gbConstraints.gridy = 1; gbConstraints.fill = GridBagConstraints.NONE; myParameterNameField = new NameSuggestionsField(myProject); final JLabel nameLabel = new JLabel(RefactoringBundle.message("name.prompt")); nameLabel.setLabelFor(myParameterNameField.getComponent()); panel.add(nameLabel, gbConstraints); /* if (myNameSuggestions.length > 1) { myParameterNameField = createComboBoxForName(); } else { myParameterNameField = createTextFieldForName(); } */ gbConstraints.gridx++; gbConstraints.insets = new Insets(4, 4, 4, 8); gbConstraints.weightx = 1; gbConstraints.fill = GridBagConstraints.BOTH; panel.add(myParameterNameField.getComponent(), gbConstraints); myParameterNameChangedListener = new NameSuggestionsField.DataChanged() { public void dataChanged() { validateButtons(); } }; myParameterNameField.addDataChangedListener(myParameterNameChangedListener); myNameSuggestionsManager = new NameSuggestionsManager( myTypeSelector, myParameterNameField, myNameSuggestionsGenerator); myNameSuggestionsManager.setLabelsFor(type, nameLabel); gbConstraints.gridx = 0; gbConstraints.insets = new Insets(4, 0, 4, 8); gbConstraints.gridwidth = 2; if (myOccurenceNumber > 1 && !myPanel.myIsInvokedOnDeclaration) { gbConstraints.gridy++; myPanel.createOccurrencesCb(gbConstraints, panel, myOccurenceNumber); } if (myPanel.myCbReplaceAllOccurences != null) { gbConstraints.insets = new Insets(0, 16, 4, 8); } JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); myPanel.createLocalVariablePanel(gbConstraints, panel, settings); myPanel.createRemoveParamsPanel(gbConstraints, panel); gbConstraints.insets = new Insets(4, 0, 4, 8); gbConstraints.gridy++; myCbDeclareFinal = new NonFocusableCheckBox(RefactoringBundle.message("declare.final")); final Boolean settingsFinals = settings.INTRODUCE_PARAMETER_CREATE_FINALS; myCbDeclareFinal.setSelected( settingsFinals == null ? CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS : settingsFinals.booleanValue()); panel.add(myCbDeclareFinal, gbConstraints); if (myMustBeFinal) { myCbDeclareFinal.setSelected(true); myCbDeclareFinal.setEnabled(false); } else if (myHasWriteAccess && myPanel.isReplaceAllOccurences()) { myCbDeclareFinal.setSelected(false); myCbDeclareFinal.setEnabled(false); } gbConstraints.gridy++; myPanel.createDelegateCb(gbConstraints, panel); return panel; }
protected JComponent createCenterPanel() { JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.weightx = 1; gbConstraints.weighty = 0; gbConstraints.gridwidth = 1; gbConstraints.gridx = 0; gbConstraints.gridy = 0; gbConstraints.insets = JBUI.emptyInsets(); if (myOccurrencesCount > 1) { myCbReplaceAll = new NonFocusableCheckBox(); myCbReplaceAll.setText( RefactoringBundle.message("replace.all.occurences", myOccurrencesCount)); panel.add(myCbReplaceAll, gbConstraints); myReplaceAllListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { updateControls(); } }; myCbReplaceAll.addItemListener(myReplaceAllListener); if (myAnyLValueOccurences) { myCbReplaceWrite = new StateRestoringCheckBox(); myCbReplaceWrite.setText(RefactoringBundle.message("replace.write.access.occurrences")); gbConstraints.insets = JBUI.insetsLeft(8); gbConstraints.gridy++; panel.add(myCbReplaceWrite, gbConstraints); myCbReplaceWrite.addItemListener(myReplaceAllListener); } } myCbFinal = new NonFocusableCheckBox(); myCbFinal.setText(RefactoringBundle.message("declare.final")); final Boolean createFinals = JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS; myCbFinalState = createFinals == null ? CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_LOCALS : createFinals.booleanValue(); gbConstraints.insets = JBUI.emptyInsets(); gbConstraints.gridy++; panel.add(myCbFinal, gbConstraints); myFinalListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (myCbFinal.isEnabled()) { myCbFinalState = myCbFinal.isSelected(); } } }; myCbFinal.addItemListener(myFinalListener); updateControls(); return panel; }
@Override protected void saveSettings(@NotNull PsiVariable psiVariable) { super.saveSettings(psiVariable); JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getSelectedVisibility(); }
@Override protected void setDocCommentPolicySetting(int policy) { JavaRefactoringSettings.getInstance().EXTRACT_SUPERCLASS_JAVADOC = policy; }
@Nullable public UsageInfo[] preprocessUsages(final Project project, final UsageInfo[] usages) { final ArrayList<UsageInfo> result = new ArrayList<>(); final ArrayList<UsageInfo> overridingMethods = new ArrayList<>(); final ArrayList<SafeDeleteParameterCallHierarchyUsageInfo> delegatingParams = new ArrayList<>(); final ArrayList<SafeDeleteMethodCalleeUsageInfo> calleesSafeToDelete = new ArrayList<>(); for (UsageInfo usage : usages) { if (usage.isNonCodeUsage) { result.add(usage); } else if (usage instanceof SafeDeleteMethodCalleeUsageInfo) { calleesSafeToDelete.add((SafeDeleteMethodCalleeUsageInfo) usage); } else if (usage instanceof SafeDeleteOverridingMethodUsageInfo) { overridingMethods.add(usage); } else if (usage instanceof SafeDeleteParameterCallHierarchyUsageInfo) { delegatingParams.add((SafeDeleteParameterCallHierarchyUsageInfo) usage); } else if (usage instanceof SafeDeleteAnnotation) { result.add( new SafeDeleteAnnotation( (PsiAnnotation) usage.getElement(), ((SafeDeleteAnnotation) usage).getReferencedElement(), true)); } else { result.add(usage); } } if (!overridingMethods.isEmpty()) { if (ApplicationManager.getApplication().isUnitTestMode()) { result.addAll(overridingMethods); } else { OverridingMethodsDialog dialog = new OverridingMethodsDialog(project, overridingMethods); if (!dialog.showAndGet()) { return null; } final ArrayList<UsageInfo> selected = dialog.getSelected(); final Set<UsageInfo> unselected = new HashSet<>(overridingMethods); unselected.removeAll(selected); if (!unselected.isEmpty()) { final List<PsiMethod> unselectedMethods = ContainerUtil.map( unselected, info -> ((SafeDeleteOverridingMethodUsageInfo) info).getOverridingMethod()); for (Iterator<UsageInfo> iterator = result.iterator(); iterator.hasNext(); ) { final UsageInfo info = iterator.next(); if (info instanceof SafeDeleteOverrideAnnotation && !allSuperMethodsSelectedToDelete( unselectedMethods, ((SafeDeleteOverrideAnnotation) info).getMethod())) { iterator.remove(); } } } result.addAll(selected); } } if (!delegatingParams.isEmpty()) { final SafeDeleteParameterCallHierarchyUsageInfo parameterHierarchyUsageInfo = delegatingParams.get(0); if (ApplicationManager.getApplication().isUnitTestMode()) { result.addAll(delegatingParams); } else { final PsiMethod method = parameterHierarchyUsageInfo.getCalledMethod(); final PsiParameter parameter = parameterHierarchyUsageInfo.getReferencedElement(); final int parameterIndex = method.getParameterList().getParameterIndex(parameter); final JavaCallerChooser chooser = new SafeDeleteJavaCallerChooser(method, project, result) { @Override protected ArrayList<SafeDeleteParameterCallHierarchyUsageInfo> getTopLevelItems() { return delegatingParams; } @Override protected int getParameterIdx() { return parameterIndex; } }; TreeUtil.expand(chooser.getTree(), 2); if (!chooser.showAndGet()) { return null; } } } if (!calleesSafeToDelete.isEmpty()) { if (ApplicationManager.getApplication().isUnitTestMode()) { result.addAll(calleesSafeToDelete); } else { final PsiMethod method = calleesSafeToDelete.get(0).getCallerMethod(); final ArrayList<UsageInfo> list = new ArrayList<>(); JavaCallerChooser chooser = new SafeDeleteJavaCalleeChooser(method, project, list) { @Override protected ArrayList<SafeDeleteMethodCalleeUsageInfo> getTopLevelItems() { return calleesSafeToDelete; } }; TreeUtil.expand(chooser.getTree(), 2); if (!chooser.showAndGet()) { return null; } result.addAll(list); final List<PsiElement> methodsToDelete = new ArrayList<>(); for (UsageInfo info : list) { methodsToDelete.add(info.getElement()); } methodsToDelete.add(method); final Condition<PsiElement> insideDeletedCondition = getUsageInsideDeletedFilter( methodsToDelete.toArray(new PsiElement[methodsToDelete.size()])); for (UsageInfo info : list) { SafeDeleteProcessor.addNonCodeUsages( info.getElement(), result, insideDeletedCondition, JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD, JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD); } } } return result.toArray(new UsageInfo[result.size()]); }
@Override protected void init() { super.init(); JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance(); initReplaceFieldsWithGetters(settings); myDeclareFinalCheckBox.setSelected(hasFinalModifier()); myDelegateViaOverloadingMethodCheckBox.setVisible(myInfo.getToSearchFor() != null); setTitle(RefactoringBundle.message("introduce.parameter.title")); myTable.init(myInfo); final GrParameter[] parameters = myInfo.getToReplaceIn().getParameters(); toRemoveCBs.forEachEntry( new TObjectIntProcedure<JCheckBox>() { @Override public boolean execute(JCheckBox checkbox, int index) { checkbox.setSelected(true); final GrParameter param = parameters[index]; final ParameterInfo pinfo = findParamByOldName(param.getName()); if (pinfo != null) { pinfo.setPassAsParameter(false); } return true; } }); updateSignature(); if (myCanIntroduceSimpleParameter) { mySignaturePanel.setVisible(false); // action to hide signature panel if we have variants to introduce simple parameter myTypeComboBox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { mySignaturePanel.setVisible(myTypeComboBox.isClosureSelected()); pack(); } }); } final PsiType closureReturnType = inferClosureReturnType(); if (PsiType.VOID.equals(closureReturnType)) { myForceReturnCheckBox.setEnabled(false); myForceReturnCheckBox.setSelected(false); } else { myForceReturnCheckBox.setSelected(isForceReturn()); } if (myInfo.getToReplaceIn() instanceof GrClosableBlock) { myDelegateViaOverloadingMethodCheckBox.setEnabled(false); myDelegateViaOverloadingMethodCheckBox.setToolTipText( "Delegating is not allowed in closure context"); } pack(); }
public void setEnabled(final boolean enabled) { JavaRefactoringSettings.getInstance().setRenameVariables(enabled); }
@Override protected int getDocCommentPolicySetting() { return JavaRefactoringSettings.getInstance().EXTRACT_SUPERCLASS_JAVADOC; }
public boolean isToSearchForTextOccurrences(final PsiElement element) { if (element instanceof PsiField) { return JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_FIELD; } return JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_VARIABLE; }
public boolean isEnabled() { return JavaRefactoringSettings.getInstance().isToRenameVariables(); }
public void setToSearchForTextOccurrences(final PsiElement element, final boolean enabled) { if (element instanceof PsiField) { JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_FIELD = enabled; } JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_VARIABLE = enabled; }