List of usage examples for com.intellij.openapi.ui Messages getWarningIcon
@NotNull public static Icon getWarningIcon()
From source file:com.intellij.plugins.haxe.ide.refactoring.memberPushDown.PushDownProcessor.java
License:Apache License
@Override protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) { final UsageInfo[] usagesIn = refUsages.get(); final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos); pushDownConflicts.checkSourceClassConflicts(); if (usagesIn.length == 0) { if (myClass.isEnum() || myClass.hasModifierProperty(PsiModifier.FINAL)) { if (Messages.showOkCancelDialog( (myClass.isEnum()// ww w .ja v a 2s . c om ? "Enum " + myClass.getQualifiedName() + " doesn't have constants to inline to. " : "Final class " + myClass.getQualifiedName() + "does not have inheritors. ") + "Pushing members down will result in them being deleted. " + "Would you like to proceed?", JavaPushDownHandler.REFACTORING_NAME, Messages.getWarningIcon()) != Messages.OK) { return false; } } else { String noInheritors = myClass.isInterface() ? RefactoringBundle.message("interface.0.does.not.have.inheritors", myClass.getQualifiedName()) : RefactoringBundle.message("class.0.does.not.have.inheritors", myClass.getQualifiedName()); final String message = noInheritors + "\n" + RefactoringBundle.message("push.down.will.delete.members"); final int answer = Messages.showYesNoCancelDialog(message, JavaPushDownHandler.REFACTORING_NAME, Messages.getWarningIcon()); if (answer == Messages.YES) { myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass); if (myCreateClassDlg != null) { pushDownConflicts.checkTargetClassConflicts(null, false, myCreateClassDlg.getTargetDirectory()); return showConflicts(pushDownConflicts.getConflicts(), usagesIn); } else { return false; } } else if (answer != Messages.NO) return false; } } Runnable runnable = new Runnable() { @Override public void run() { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { for (UsageInfo usage : usagesIn) { final PsiElement element = usage.getElement(); if (element instanceof PsiClass) { pushDownConflicts.checkTargetClassConflicts((PsiClass) element, usagesIn.length > 1, element); } } } }); } }; if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) { return false; } for (UsageInfo info : usagesIn) { final PsiElement element = info.getElement(); if (element instanceof PsiFunctionalExpression) { pushDownConflicts.getConflicts().putValue(element, RefactoringBundle.message("functional.interface.broken")); } } final PsiAnnotation annotation = AnnotationUtil.findAnnotation(myClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE); if (annotation != null && isMoved(LambdaUtil.getFunctionalInterfaceMethod(myClass))) { pushDownConflicts.getConflicts().putValue(annotation, RefactoringBundle.message("functional.interface.broken")); } return showConflicts(pushDownConflicts.getConflicts(), usagesIn); }
From source file:com.intellij.profile.codeInspection.ui.header.InspectionToolsConfigurable.java
License:Apache License
public InspectionToolsConfigurable(@NotNull final InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) { myWholePanel = new JPanel(new BorderLayout()); final JPanel toolbar = new JPanel(new GridBagLayout()); toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); myPanel = new JPanel(); myWholePanel.add(toolbar, BorderLayout.PAGE_START); myWholePanel.add(myPanel, BorderLayout.CENTER); myProfiles = new ProfilesConfigurableComboBox(new ListCellRendererWrapper<Profile>() { @Override/*from w w w .ja va 2s .c o m*/ public void customize(final JList list, final Profile value, final int index, final boolean selected, final boolean hasFocus) { final SingleInspectionProfilePanel singleInspectionProfilePanel = myPanels.get(value); final boolean isShared = singleInspectionProfilePanel.isProfileShared(); setIcon(isShared ? AllIcons.General.ProjectSettings : AllIcons.General.Settings); setText(singleInspectionProfilePanel.getCurrentProfileName()); } }) { @Override public void onProfileChosen(InspectionProfileImpl inspectionProfile) { myLayout.show(myPanel, getCardName(inspectionProfile)); myAuxiliaryRightPanel.showDescription(inspectionProfile.getDescription()); } }; JPanel profilesHolder = new JPanel(); profilesHolder.setLayout(new CardLayout()); JComponent manageButton = new ManageButton(new ManageButtonBuilder() { @Override public boolean isSharedToTeamMembers() { SingleInspectionProfilePanel panel = getSelectedPanel(); return panel != null && panel.isProfileShared(); } @Override public void setShareToTeamMembers(boolean shared) { final SingleInspectionProfilePanel selectedPanel = getSelectedPanel(); LOG.assertTrue(selectedPanel != null, "No settings selectedPanel for: " + getSelectedObject()); final String name = getSelectedPanel().getCurrentProfileName(); for (SingleInspectionProfilePanel p : myPanels.values()) { if (p != selectedPanel && Comparing.equal(p.getCurrentProfileName(), name)) { final boolean curShared = p.isProfileShared(); if (curShared == shared) { Messages.showErrorDialog( (shared ? "Shared" : "Application level") + " profile with same name exists.", "Inspections Settings"); return; } } } selectedPanel.setProfileShared(shared); myProfiles.repaint(); } @Override public void copy() { final InspectionProfileImpl newProfile = copyToNewProfile(getSelectedObject(), getProject()); if (newProfile != null) { final InspectionProfileImpl modifiableModel = (InspectionProfileImpl) newProfile .getModifiableModel(); modifiableModel.setModified(true); modifiableModel.setProjectLevel(false); addProfile(modifiableModel); rename(modifiableModel); } } @Override public boolean canRename() { final InspectionProfileImpl profile = getSelectedObject(); return !profile.isProfileLocked(); } @Override public void rename() { rename(getSelectedObject()); } private void rename(@NotNull final InspectionProfileImpl inspectionProfile) { final String initialName = getSelectedPanel().getCurrentProfileName(); myProfiles.showEditCard(initialName, new SaveInputComponentValidator() { @Override public void doSave(@NotNull String text) { if (!text.equals(initialName)) { getProfilePanel(inspectionProfile).setCurrentProfileName(text); } myProfiles.showComboBoxCard(); } @Override public boolean checkValid(@NotNull String text) { final SingleInspectionProfilePanel singleInspectionProfilePanel = myPanels .get(inspectionProfile); if (singleInspectionProfilePanel == null) { return false; } final boolean isValid = text.equals(initialName) || !hasName(text, singleInspectionProfilePanel.isProfileShared()); if (isValid) { myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription()); } else { myAuxiliaryRightPanel .showError("Name is already in use. Please change name to unique."); } return isValid; } @Override public void cancel() { myProfiles.showComboBoxCard(); myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription()); } }); } @Override public boolean canDelete() { return isDeleteEnabled(myProfiles.getSelectedProfile()); } @Override public void delete() { final InspectionProfileImpl selectedProfile = myProfiles.getSelectedProfile(); myProfiles.getModel().removeElement(selectedProfile); myDeletedProfiles.add(selectedProfile); } @Override public boolean canEditDescription() { return true; } @Override public void editDescription() { myAuxiliaryRightPanel.editDescription(getSelectedObject().getDescription()); } @Override public boolean hasDescription() { return !StringUtil.isEmpty(getSelectedObject().getDescription()); } @Override public void export() { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor(); descriptor.setDescription("Choose directory to store profile file"); FileChooser.chooseFile(descriptor, getProject(), myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { final Element element = new Element("inspections"); try { final SingleInspectionProfilePanel panel = getSelectedPanel(); LOG.assertTrue(panel != null); final InspectionProfileImpl profile = getSelectedObject(); LOG.assertTrue(true); profile.writeExternal(element); final String filePath = FileUtil.toSystemDependentName(file.getPath()) + File.separator + FileUtil.sanitizeFileName(profile.getName()) + ".xml"; if (new File(filePath).isFile()) { if (Messages.showOkCancelDialog(myWholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) { return; } } JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator()); } catch (WriteExternalException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } @Override public void doImport() { final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileSelectable(VirtualFile file) { return file.getFileType().equals(InternalStdFileTypes.XML); } }; descriptor.setDescription("Choose profile file"); FileChooser.chooseFile(descriptor, getProject(), myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { if (file == null) return; InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), myProfileManager); try { Element rootElement = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(file)) .getRootElement(); if (Comparing.strEqual(rootElement.getName(), "component")) {//import right from .idea/inspectProfiles/xxx.xml rootElement = rootElement.getChildren().get(0); } final Set<String> levels = new HashSet<String>(); for (Object o : rootElement.getChildren("inspection_tool")) { final Element inspectElement = (Element) o; levels.add(inspectElement.getAttributeValue("level")); for (Object s : inspectElement.getChildren("scope")) { levels.add(((Element) s).getAttributeValue("level")); } } for (Iterator<String> iterator = levels.iterator(); iterator.hasNext();) { String level = iterator.next(); if (myProfileManager.getOwnSeverityRegistrar().getSeverity(level) != null) { iterator.remove(); } } if (!levels.isEmpty()) { if (Messages.showYesNoDialog(myWholePanel, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == Messages.YES) { for (String level : levels) { final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES .getDefaultAttributes(); HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl( new HighlightSeverity(level, 50), TextAttributesKey.createTextAttributesKey(level)); myProfileManager.getOwnSeverityRegistrar().registerSeverity( new SeverityRegistrar.SeverityBasedTextAttributes( textAttributes.clone(), info), textAttributes.getErrorStripeColor()); } } } profile.readExternal(rootElement); profile.setProjectLevel(false); profile.initInspectionTools(getProject()); if (getProfilePanel(profile) != null) { if (Messages.showOkCancelDialog(myWholePanel, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) { return; } } final ModifiableModel model = profile.getModifiableModel(); model.setModified(true); addProfile((InspectionProfileImpl) model); //TODO myDeletedProfiles ? really need this myDeletedProfiles.remove(profile); } catch (InvalidDataException e1) { LOG.error(e1); } catch (JDOMException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } }).build(); myAuxiliaryRightPanel = new AuxiliaryRightPanel(new AuxiliaryRightPanel.DescriptionSaveListener() { @Override public void saveDescription(@NotNull String description) { final InspectionProfileImpl inspectionProfile = getSelectedObject(); if (!Comparing.strEqual(description, inspectionProfile.getDescription())) { inspectionProfile.setDescription(description); inspectionProfile.setModified(true); } myAuxiliaryRightPanel.showDescription(description); } @Override public void cancel() { myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription()); } }); toolbar.add(new JLabel(HEADER_TITLE), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); toolbar.add(myProfiles.getHintLabel(), new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 6, 6, 0), 0, 0)); toolbar.add(myProfiles, new GridBagConstraints(1, 1, 1, 1, 0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 6, 0, 0), 0, 0)); toolbar.add(manageButton, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 10, 0, 0), 0, 0)); toolbar.add(myAuxiliaryRightPanel.getHintLabel(), new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 15, 6, 0), 0, 0)); toolbar.add(myAuxiliaryRightPanel, new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 15, 0, 0), 0, 0)); ((InspectionManagerEx) InspectionManager.getInstance(projectProfileManager.getProject())) .buildInspectionSearchIndexIfNecessary(); myProjectProfileManager = projectProfileManager; myProfileManager = profileManager; }
From source file:com.intellij.profile.codeInspection.ui.InspectionToolsConfigurable.java
License:Apache License
public InspectionToolsConfigurable(@NotNull final InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) { ((InspectionManagerEx) InspectionManager.getInstance(projectProfileManager.getProject())) .buildInspectionSearchIndexIfNecessary(); myAddButton.addActionListener(new ActionListener() { @Override//from w w w .j a v a2 s . c o m public void actionPerformed(ActionEvent e) { final Set<String> existingProfileNames = myPanels.keySet(); final ModifiableModel model = SingleInspectionProfilePanel.createNewProfile(-1, getSelectedObject(), myWholePanel, "", existingProfileNames, projectProfileManager.getProject()); if (model != null) { addProfile((InspectionProfileImpl) model); myDeletedProfiles.remove(getProfilePrefix(model) + model.getName()); myDeleteButton.setEnabled(true); } } }); myDeleteButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final InspectionProfileImpl selectedProfile = (InspectionProfileImpl) myProfiles.getSelectedItem(); ((DefaultComboBoxModel) myProfiles.getModel()).removeElement(selectedProfile); myDeletedProfiles.add(getProfilePrefix(selectedProfile) + selectedProfile.getName()); myDeleteButton.setEnabled(isDeleteEnabled(selectedProfile)); } }); final Project project = projectProfileManager.getProject(); myImportButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileSelectable(VirtualFile file) { return file.getFileType().equals(StdFileTypes.XML); } }; descriptor.setDescription("Choose profile file"); FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { if (file == null) return; InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), myProfileManager); try { Element rootElement = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(file)) .getRootElement(); if (Comparing.strEqual(rootElement.getName(), "component")) {//import right from .idea/inspectProfiles/xxx.xml rootElement = rootElement.getChildren().get(0); } final Set<String> levels = new HashSet<String>(); for (Object o : rootElement.getChildren("inspection_tool")) { final Element inspectElement = (Element) o; levels.add(inspectElement.getAttributeValue("level")); for (Object s : inspectElement.getChildren("scope")) { levels.add(((Element) s).getAttributeValue("level")); } } for (Iterator<String> iterator = levels.iterator(); iterator.hasNext();) { String level = iterator.next(); if (myProfileManager.getOwnSeverityRegistrar().getSeverity(level) != null) { iterator.remove(); } } if (!levels.isEmpty()) { if (Messages.showYesNoDialog(myWholePanel, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == Messages.YES) { for (String level : levels) { final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES .getDefaultAttributes(); HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl( new HighlightSeverity(level, 50), com.intellij.openapi.editor.colors.TextAttributesKey .createTextAttributesKey(level)); myProfileManager.getOwnSeverityRegistrar().registerSeverity( new SeverityRegistrar.SeverityBasedTextAttributes( textAttributes.clone(), info), textAttributes.getErrorStripeColor()); } } } profile.readExternal(rootElement); profile.setLocal(true); profile.initInspectionTools(project); if (getProfilePanel(profile) != null) { if (Messages.showOkCancelDialog(myWholePanel, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) return; } final ModifiableModel model = profile.getModifiableModel(); model.setModified(true); addProfile((InspectionProfileImpl) model); myDeletedProfiles.remove(getProfilePrefix(profile) + profile.getName()); myDeleteButton.setEnabled(true); } catch (InvalidDataException e1) { LOG.error(e1); } catch (JDOMException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } }); myExportButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor(); descriptor.setDescription("Choose directory to store profile file"); FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { final Element element = new Element("inspections"); try { final SingleInspectionProfilePanel panel = getSelectedPanel(); LOG.assertTrue(panel != null); final InspectionProfileImpl profile = (InspectionProfileImpl) panel .getSelectedProfile(); profile.writeExternal(element); final String filePath = FileUtil.toSystemDependentName(file.getPath()) + File.separator + FileUtil.sanitizeFileName(profile.getName()) + ".xml"; if (new File(filePath).isFile()) { if (Messages.showOkCancelDialog(myWholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) return; } JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator()); } catch (WriteExternalException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } }); myCopyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Set<String> existingProfileNames = myPanels.keySet(); final InspectionProfileImpl model = (InspectionProfileImpl) SingleInspectionProfilePanel .createNewProfile(0, getSelectedObject(), myWholePanel, "", existingProfileNames, project); if (model != null) { final InspectionProfileImpl modifiableModel = (InspectionProfileImpl) model .getModifiableModel(); modifiableModel.setModified(true); addProfile(modifiableModel); myDeletedProfiles.remove(getProfilePrefix(model) + model.getName()); myDeleteButton.setEnabled(true); } } }); myProjectProfileManager = projectProfileManager; myProfileManager = profileManager; myJBScrollPane.setBorder(null); }
From source file:com.intellij.refactoring.changeSignature.JavaChangeSignatureDialog.java
License:Apache License
@Override protected String validateAndCommitData() { PsiManager manager = PsiManager.getInstance(myProject); PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); String name = getMethodName(); if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(name)) { return RefactoringMessageUtil.getIncorrectIdentifierMessage(name); }// w w w . j ava 2 s .c o m if (myMethod.canChangeReturnType() == MethodDescriptor.ReadWriteOption.ReadWrite) { try { ((PsiTypeCodeFragment) myReturnTypeCodeFragment).getType(); } catch (PsiTypeCodeFragment.TypeSyntaxException e) { myReturnTypeField.requestFocus(); return RefactoringBundle.message("changeSignature.wrong.return.type", myReturnTypeCodeFragment.getText()); } catch (PsiTypeCodeFragment.NoTypeException e) { myReturnTypeField.requestFocus(); return RefactoringBundle.message("changeSignature.no.return.type"); } } List<ParameterTableModelItemBase<ParameterInfoImpl>> parameterInfos = myParametersTableModel.getItems(); final int newParametersNumber = parameterInfos.size(); for (int i = 0; i < newParametersNumber; i++) { final ParameterTableModelItemBase<ParameterInfoImpl> item = parameterInfos.get(i); if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(item.parameter.getName())) { return RefactoringMessageUtil.getIncorrectIdentifierMessage(item.parameter.getName()); } final PsiType type; try { type = ((PsiTypeCodeFragment) parameterInfos.get(i).typeCodeFragment).getType(); } catch (PsiTypeCodeFragment.TypeSyntaxException e) { return RefactoringBundle.message("changeSignature.wrong.type.for.parameter", item.typeCodeFragment.getText(), item.parameter.getName()); } catch (PsiTypeCodeFragment.NoTypeException e) { return RefactoringBundle.message("changeSignature.no.type.for.parameter", item.parameter.getName()); } item.parameter.setType(type); if (type instanceof PsiEllipsisType && i != newParametersNumber - 1) { return RefactoringBundle.message("changeSignature.vararg.not.last"); } if (item.parameter.oldParameterIndex < 0) { item.parameter.defaultValue = ApplicationManager.getApplication() .runWriteAction(new Computable<String>() { @Override public String compute() { return JavaCodeStyleManager.getInstance(myProject) .qualifyClassReferences(item.defaultValueCodeFragment).getText(); } }); String def = item.parameter.defaultValue; def = def.trim(); if (!(type instanceof PsiEllipsisType)) { try { if (!StringUtil.isEmpty(def)) { factory.createExpressionFromText(def, null); } } catch (IncorrectOperationException e) { return e.getMessage(); } } } } ThrownExceptionInfo[] exceptionInfos = myExceptionsModel.getThrownExceptions(); PsiTypeCodeFragment[] typeCodeFragments = myExceptionsModel.getTypeCodeFragments(); for (int i = 0; i < exceptionInfos.length; i++) { ThrownExceptionInfo exceptionInfo = exceptionInfos[i]; PsiTypeCodeFragment typeCodeFragment = typeCodeFragments[i]; try { PsiType type = typeCodeFragment.getType(); if (!(type instanceof PsiClassType)) { return RefactoringBundle.message("changeSignature.wrong.type.for.exception", typeCodeFragment.getText()); } PsiClassType throwable = JavaPsiFacade.getInstance(myProject).getElementFactory() .createTypeByFQClassName("java.lang.Throwable", type.getResolveScope()); if (!throwable.isAssignableFrom(type)) { return RefactoringBundle.message("changeSignature.not.throwable.type", typeCodeFragment.getText()); } exceptionInfo.setType((PsiClassType) type); } catch (PsiTypeCodeFragment.TypeSyntaxException e) { return RefactoringBundle.message("changeSignature.wrong.type.for.exception", typeCodeFragment.getText()); } catch (PsiTypeCodeFragment.NoTypeException e) { return RefactoringBundle.message("changeSignature.no.type.for.exception"); } } // warnings try { if (myMethod.canChangeReturnType() == MethodDescriptor.ReadWriteOption.ReadWrite) { if (!RefactoringUtil.isResolvableType(((PsiTypeCodeFragment) myReturnTypeCodeFragment).getType())) { if (Messages.showOkCancelDialog(myProject, RefactoringBundle.message("changeSignature.cannot.resolve.return.type", myReturnTypeCodeFragment.getText()), RefactoringBundle.message("changeSignature.refactoring.name"), Messages.getWarningIcon()) != 0) { return EXIT_SILENTLY; } } } for (ParameterTableModelItemBase<ParameterInfoImpl> item : parameterInfos) { if (!RefactoringUtil.isResolvableType(((PsiTypeCodeFragment) item.typeCodeFragment).getType())) { if (Messages.showOkCancelDialog(myProject, RefactoringBundle.message("changeSignature.cannot.resolve.parameter.type", item.typeCodeFragment.getText(), item.parameter.getName()), RefactoringBundle.message("changeSignature.refactoring" + ".name"), Messages.getWarningIcon()) != 0) { return EXIT_SILENTLY; } } } } catch (PsiTypeCodeFragment.IncorrectTypeException ignored) { } return null; }
From source file:com.intellij.refactoring.extractMethod.AbstractExtractMethodDialog.java
License:Apache License
@Override protected void doOKAction() { final String error = myValidator.check(getMethodName()); if (error != null) { if (ApplicationManager.getApplication().isUnitTestMode()) { Messages.showInfoMessage(error, RefactoringBundle.message("error.title")); return; }/*from w w w .j a v a2 s. c o m*/ if (Messages.showOkCancelDialog(error + ". " + RefactoringBundle.message("do.you.wish.to.continue"), RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) != 0) { return; } } super.doOKAction(); }
From source file:com.intellij.refactoring.introduceField.IntroduceConstantDialog.java
License:Apache License
protected void doOKAction() { final String targetClassName = getTargetClassName(); PsiClass newClass = myParentClass;/* ww w . j a va2s . c o m*/ if (!"".equals(targetClassName) && !Comparing.strEqual(targetClassName, myParentClass.getQualifiedName())) { newClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassName, GlobalSearchScope.projectScope(myProject)); if (newClass == null) { if (Messages.showOkCancelDialog(myProject, RefactoringBundle.message("class.does.not.exist.in.the.project"), IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != OK_EXIT_CODE) { return; } myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(targetClassName, myParentClass); } else { myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(newClass); } } String fieldName = getEnteredName(); String errorString = null; if ("".equals(fieldName)) { errorString = RefactoringBundle.message("no.field.name.specified"); } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) { errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName); } else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) { errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass), myParentClass.getQualifiedName(), newClass.getQualifiedName()); } if (errorString != null) { CommonRefactoringUtil.showErrorMessage(IntroduceFieldHandler.REFACTORING_NAME, errorString, HelpID.INTRODUCE_FIELD, myProject); return; } if (newClass != null) { PsiField oldField = newClass.findFieldByName(fieldName, true); if (oldField != null) { int answer = Messages.showYesNoDialog(myProject, RefactoringBundle.message("field.exists", fieldName, oldField.getContainingClass().getQualifiedName()), IntroduceFieldHandler.REFACTORING_NAME, Messages.getWarningIcon()); if (answer != 0) { return; } } } JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getFieldVisibility(); RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, targetClassName); super.doOKAction(); }
From source file:com.intellij.refactoring.introduceField.IntroduceFieldDialog.java
License:Apache License
protected void doOKAction() { String fieldName = getEnteredName(); String errorString = null;//from w ww. jav a 2s. co m if ("".equals(fieldName)) { errorString = RefactoringBundle.message("no.field.name.specified"); } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) { errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName); } if (errorString != null) { CommonRefactoringUtil.showErrorMessage(IntroduceFieldHandler.REFACTORING_NAME, errorString, HelpID.INTRODUCE_FIELD, myProject); return; } PsiField oldField = myParentClass.findFieldByName(fieldName, true); if (oldField != null) { int answer = Messages.showYesNoDialog(myProject, RefactoringBundle.message("field.exists", fieldName, oldField.getContainingClass().getQualifiedName()), IntroduceFieldHandler.REFACTORING_NAME, Messages.getWarningIcon()); if (answer != 0) { return; } } myCentralPanel.saveFinalState(); ourLastInitializerPlace = myCentralPanel.getInitializerPlace(); JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY = getFieldVisibility(); myNameSuggestionsManager.nameSelected(); myTypeSelectorManager.typeSelected(getFieldType()); super.doOKAction(); }
From source file:com.intellij.refactoring.makeStatic.MakeParameterizedStaticDialog.java
License:Apache License
protected boolean validateData() { int ret = 0;//from w w w .j a v a 2 s. c o m if (isMakeClassParameter()) { final PsiMethod methodWithParameter = checkParameterDoesNotExist(); if (methodWithParameter != null) { String who = methodWithParameter == myMember ? RefactoringBundle.message("this.method") : DescriptiveNameUtil.getDescriptiveName(methodWithParameter); String message = RefactoringBundle.message("0.already.has.parameter.named.1.use.this.name.anyway", who, getClassParameterName()); ret = Messages.showYesNoDialog(myProject, message, RefactoringBundle.message("warning.title"), Messages.getWarningIcon()); myClassParameterNameInputField.requestFocusInWindow(); } } return ret == 0; }
From source file:com.intellij.refactoring.memberPushDown.PushDownProcessor.java
License:Apache License
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) { final UsageInfo[] usagesIn = refUsages.get(); final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos); pushDownConflicts.checkSourceClassConflicts(); if (usagesIn.length == 0) { if (myClass.isEnum() || myClass.hasModifierProperty(PsiModifier.FINAL)) { if (Messages.showOkCancelDialog( (myClass.isEnum()/*from ww w. j av a2s . c o m*/ ? "Enum " + myClass.getQualifiedName() + " doesn't have constants to inline to. " : "Final class " + myClass.getQualifiedName() + "does not have inheritors. ") + "Pushing members down will result in them being deleted. " + "Would you like to proceed?", JavaPushDownHandler.REFACTORING_NAME, Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE) { return false; } } else { String noInheritors = myClass.isInterface() ? RefactoringBundle.message("interface.0.does.not.have.inheritors", myClass.getQualifiedName()) : RefactoringBundle.message("class.0.does.not.have.inheritors", myClass.getQualifiedName()); final String message = noInheritors + "\n" + RefactoringBundle.message("push.down.will.delete.members"); final int answer = Messages.showYesNoCancelDialog(message, JavaPushDownHandler.REFACTORING_NAME, Messages.getWarningIcon()); if (answer == DialogWrapper.OK_EXIT_CODE) { myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass); if (myCreateClassDlg != null) { pushDownConflicts.checkTargetClassConflicts(null, false, myCreateClassDlg.getTargetDirectory()); return showConflicts(pushDownConflicts.getConflicts(), usagesIn); } else { return false; } } else if (answer != 1) return false; } } Runnable runnable = new Runnable() { public void run() { for (UsageInfo usage : usagesIn) { final PsiElement element = usage.getElement(); if (element instanceof PsiClass) { pushDownConflicts.checkTargetClassConflicts((PsiClass) element, usagesIn.length > 1, element); } } } }; if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) { return false; } return showConflicts(pushDownConflicts.getConflicts(), usagesIn); }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.JavaMoveClassesOrPackagesHandler.java
License:Apache License
private static void moveDirectoriesLibrariesSafe(Project project, PsiElement targetContainer, MoveCallback callback, PsiDirectory[] directories, String prompt) { final PsiJavaPackage aPackage = JavaDirectoryService.getInstance().getPackage(directories[0]); LOG.assertTrue(aPackage != null);/*from ww w . j a v a 2s .c om*/ final PsiDirectory[] projectDirectories = aPackage.getDirectories(GlobalSearchScope.projectScope(project)); if (projectDirectories.length > 1) { int ret = Messages.showYesNoCancelDialog(project, prompt + " or all directories in project?", RefactoringBundle.message("warning.title"), RefactoringBundle.message("move.current.directory"), RefactoringBundle.message("move.directories"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon()); if (ret == 0) { moveAsDirectory(project, targetContainer, callback, directories); } else if (ret == 1) { moveAsDirectory(project, targetContainer, callback, projectDirectories); } } else if (Messages.showOkCancelDialog(project, prompt + "?", RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) { moveAsDirectory(project, targetContainer, callback, directories); } }