diff --git a/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java b/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java index a8f13f093832..81cf1f34a53e 100644 --- a/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/file/PsiJavaDirectoryFactory.java @@ -15,6 +15,7 @@ */ package com.intellij.psi.impl.file; +import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; @@ -46,7 +47,7 @@ public class PsiJavaDirectoryFactory extends PsiDirectoryFactory { } return ""; } - return presentable ? directory.getVirtualFile().getPresentableUrl() : ""; + return presentable ? ProjectUtil.getLocationRelativeToUserHome(directory.getVirtualFile().getPresentableUrl()) : ""; } @Override diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index e207ed7aef03..00297ce6e6db 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -300,11 +300,12 @@ public class InplaceIntroduceConstantPopup { }); } - public void performInplaceIntroduce() { - startIntroduceTemplate(false, null); + public boolean performInplaceIntroduce() { + return startIntroduceTemplate(false, null); } - private void startIntroduceTemplate(final boolean replaceAllOccurrences, @Nullable final PsiType fieldDefaultType) { + private boolean startIntroduceTemplate(final boolean replaceAllOccurrences, @Nullable final PsiType fieldDefaultType) { + final Ref result = new Ref(); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { myTypeSelectorManager.setAllOccurences(replaceAllOccurrences); @@ -325,6 +326,7 @@ public class InplaceIntroduceConstantPopup { IntroduceConstantDialog.createNameSuggestionGenerator(propName, myExpr, JavaCodeStyleManager.getInstance(myProject)) .getSuggestedNameInfo(defaultType).names; final PsiField field = createFieldToStartTemplateOn(names, defaultType); + boolean started = false; if (field != null) { myEditor.getCaretModel().moveToOffset(field.getTextOffset()); myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); @@ -332,10 +334,20 @@ public class InplaceIntroduceConstantPopup { nameSuggestions.add(field.getName()); nameSuggestions.addAll(Arrays.asList(names)); final VariableInplaceRenamer renamer = new FieldInplaceIntroducer(field); - renamer.performInplaceRename(false, nameSuggestions); + started = renamer.performInplaceRename(false, nameSuggestions); + } + result.set(started); + if (!started && field != null) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + field.delete(); + } + }); } } }, IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME); + return result.get(); } private PsiField createFieldToStartTemplateOn(final String[] names, final PsiType psiType) { @@ -343,22 +355,19 @@ public class InplaceIntroduceConstantPopup { return ApplicationManager.getApplication().runWriteAction(new Computable() { @Override public PsiField compute() { - final Ref ref = new Ref(); - final Runnable runnable = new Runnable() { - public void run() { - PsiField field = elementFactory.createFieldFromText(psiType.getCanonicalText() + " " + (myConstantName != null ? myConstantName : names[0]) + " = " + myInitializerText + ";", myParentClass); - PsiUtil.setModifierProperty(field, PsiModifier.FINAL, true); - PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true); - final String visibility = getSelectedVisibility(); - if (visibility != null) { - PsiUtil.setModifierProperty(field, visibility, true); - } - field = BaseExpressionToFieldHandler.ConvertToFieldRunnable.appendField(myExpr, BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, myParentClass, myParentClass, myAnchorElementIfAll, field); - ref.set(field); - } - }; - PostprocessReformattingAspect.getInstance(myProject).postponeFormattingInside(runnable); - return ref.get(); + + PsiField field = elementFactory.createFieldFromText( + psiType.getCanonicalText() + " " + (myConstantName != null ? myConstantName : names[0]) + " = " + myInitializerText + ";", + myParentClass); + PsiUtil.setModifierProperty(field, PsiModifier.FINAL, true); + PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true); + final String visibility = getSelectedVisibility(); + if (visibility != null) { + PsiUtil.setModifierProperty(field, visibility, true); + } + return BaseExpressionToFieldHandler.ConvertToFieldRunnable + .appendField(myExpr, BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, myParentClass, myParentClass, + myAnchorElementIfAll, field); } }); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index d137c9bdffc4..77b1c27dca0a 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -151,11 +151,12 @@ public class InplaceIntroduceFieldPopup { return myOccurrenceMarkers; } - public void startTemplate() { - startTemplate(false, null); + public boolean startTemplate() { + return startTemplate(false, null); } - public void startTemplate(final boolean replaceAllOccurrences, @Nullable final PsiType fieldDefaultType) { + public boolean startTemplate(final boolean replaceAllOccurrences, @Nullable final PsiType fieldDefaultType) { + final Ref result = new Ref(); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { myTypeSelectorManager.setAllOccurences(replaceAllOccurrences); @@ -176,6 +177,7 @@ public class InplaceIntroduceFieldPopup { IntroduceFieldDialog.createGenerator(myStatic, myLocalVariable, myInitializerExpression, myLocalVariable != null) .getSuggestedNameInfo(defaultType); + boolean started = false; final PsiField field = createFieldToStartTemplateOn(suggestedNameInfo.names, defaultType); if (field != null) { myEditor.getCaretModel().moveToOffset(field.getTextOffset()); @@ -184,10 +186,20 @@ public class InplaceIntroduceFieldPopup { nameSuggestions.add(field.getName()); nameSuggestions.addAll(Arrays.asList(suggestedNameInfo.names)); final VariableInplaceRenamer renamer = new FieldInplaceIntroducer(field); - renamer.performInplaceRename(false, nameSuggestions); + started = renamer.performInplaceRename(false, nameSuggestions); + } + result.set(started); + if (!started && field != null) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + field.delete(); + } + }); } } }, IntroduceFieldHandler.REFACTORING_NAME, IntroduceFieldHandler.REFACTORING_NAME); + return result.get(); } private PsiField createFieldToStartTemplateOn(final String[] names, @@ -196,22 +208,14 @@ public class InplaceIntroduceFieldPopup { return ApplicationManager.getApplication().runWriteAction(new Computable() { @Override public PsiField compute() { - final Ref ref = new Ref(); - PostprocessReformattingAspect.getInstance(myProject).postponeFormattingInside(new Runnable() { - @Override - public void run() { - PsiField field = elementFactory.createField(myFieldName != null ? myFieldName : names[0], defaultType); - field = (PsiField)myParentClass.add(field); - PsiUtil.setModifierProperty(field, PsiModifier.FINAL, myIntroduceFieldPanel.isDeclareFinal()); - final String visibility = myIntroduceFieldPanel.getFieldVisibility(); - if (visibility != null) { - PsiUtil.setModifierProperty(field, visibility, true); - } - ref.set(field); - } - }); - - return ref.get(); + PsiField field = elementFactory.createField(myFieldName != null ? myFieldName : names[0], defaultType); + field = (PsiField)myParentClass.add(field); + PsiUtil.setModifierProperty(field, PsiModifier.FINAL, myIntroduceFieldPanel.isDeclareFinal()); + final String visibility = myIntroduceFieldPanel.getFieldVisibility(); + if (visibility != null) { + PsiUtil.setModifierProperty(field, visibility, true); + } + return field; } }); } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java index 2f230c9def78..cf86a545362b 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java @@ -147,10 +147,11 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler { final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, type, containingMethod, expr, occurences); if (editor != null && editor.getSettings().isVariableInplaceRenameEnabled()) { - new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurences, typeSelectorManager, + if (new InplaceIntroduceConstantPopup(project, editor, parentClass, expr, localVariable, occurences, typeSelectorManager, anchorElement, anchorElementIfAll, - expr != null ? createOccurenceManager(expr, parentClass) : null).performInplaceIntroduce(); - return null; + expr != null ? createOccurenceManager(expr, parentClass) : null).performInplaceIntroduce() ){ + return null; + } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java index bc69a59642aa..d617bb670d7b 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java @@ -109,8 +109,9 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { myInplaceIntroduceFieldPopup = new InplaceIntroduceFieldPopup(localVariable, parentClass, declareStatic, currentMethodConstructor, occurences, expr, typeSelectorManager, editor, allowInitInMethod, allowInitInMethodIfAll, anchorElement, anchorElementIfAll, expr != null ? createOccurenceManager(expr, parentClass) : null); - myInplaceIntroduceFieldPopup.startTemplate(); - return null; + if (myInplaceIntroduceFieldPopup.startTemplate()) { + return null; + } } IntroduceFieldDialog dialog = new IntroduceFieldDialog( diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java index 4bc1422a9a7a..7578f7b67c53 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/InplaceIntroduceParameterPopup.java @@ -194,16 +194,17 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { return myReplaceFieldsCb!= null ? (Integer)myReplaceFieldsCb.getSelectedItem() : IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE; } - void inplaceIntroduceParameter() { - startIntroduceTemplate(false); + boolean inplaceIntroduceParameter() { + return startIntroduceTemplate(false); } - private void startIntroduceTemplate(final boolean replaceAllOccurrences) { - startIntroduceTemplate(replaceAllOccurrences, hasFinalModifier()); + private boolean startIntroduceTemplate(final boolean replaceAllOccurrences) { + return startIntroduceTemplate(replaceAllOccurrences, hasFinalModifier()); } - private void startIntroduceTemplate(final boolean replaceAllOccurrences, + private boolean startIntroduceTemplate(final boolean replaceAllOccurrences, final boolean hasFinalModifier) { + final Ref result = new Ref(); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { myTypeSelectorManager.setAllOccurences(replaceAllOccurrences); @@ -213,6 +214,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { final String[] names = IntroduceParameterHandler.createNameSuggestionGenerator(myExpr, propName, myProject) .getSuggestedNameInfo(defaultType).names; final PsiParameter parameter = createParameterToStartTemplateOn(names, defaultType, hasFinalModifier); + boolean started = false; if (parameter != null) { myParameterIndex = myMethod.getParameterList().getParameterIndex(parameter); myEditor.getCaretModel().moveToOffset(parameter.getTextOffset()); @@ -222,10 +224,19 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI { nameSuggestions.addAll(Arrays.asList(names)); final VariableInplaceRenamer renamer = new ParameterInplaceIntroducer(parameter); LOG.assertTrue(parameter.isPhysical()); - renamer.performInplaceRename(false, nameSuggestions); + started = renamer.performInplaceRename(false, nameSuggestions); + } + result.set(started); + if (!started && parameter != null) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + parameter.delete(); + } + }); } } }, IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME); + return result.get(); } @Override diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java index 2e0787fc34f4..215534815684 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -419,21 +419,20 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase implements R NameSuggestionsGenerator nameSuggestionsGenerator = createNameSuggestionGenerator(myExpr, propName, myProject); boolean isInplaceAvailableOnDataContext = myEditor != null && myEditor.getSettings().isVariableInplaceRenameEnabled(); - if (!isInplaceAvailableOnDataContext) { - if (myEditor != null) { - RefactoringUtil.highlightAllOccurences(myProject, occurences, myEditor); - } - new IntroduceParameterDialog(myProject, classMemberRefs, occurences, myLocalVar, myExpr, nameSuggestionsGenerator, - typeSelectorManager, methodToSearchFor, method, parametersToRemove, mustBeFinal).show(); - if (myEditor != null) { - myEditor.getSelectionModel().removeSelection(); - } + if (isInplaceAvailableOnDataContext && new InplaceIntroduceParameterPopup(myProject, myEditor, classMemberRefs, + typeSelectorManager, + myExpr, myLocalVar, method, methodToSearchFor, occurences, + parametersToRemove, + mustBeFinal).inplaceIntroduceParameter()) { + return; } - else { - new InplaceIntroduceParameterPopup(myProject, myEditor, classMemberRefs, - typeSelectorManager, - myExpr, myLocalVar, method, methodToSearchFor, occurences, parametersToRemove, - mustBeFinal).inplaceIntroduceParameter(); + if (myEditor != null) { + RefactoringUtil.highlightAllOccurences(myProject, occurences, myEditor); + } + new IntroduceParameterDialog(myProject, classMemberRefs, occurences, myLocalVar, myExpr, nameSuggestionsGenerator, + typeSelectorManager, methodToSearchFor, method, parametersToRemove, mustBeFinal).show(); + if (myEditor != null) { + myEditor.getSelectionModel().removeSelection(); } } } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java index da8472d0ddbd..c5951cf994a2 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/VariableInplaceIntroducer.java @@ -169,7 +169,9 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer { @Override public boolean performInplaceRename(boolean processTextOccurrences, LinkedHashSet nameSuggestions) { final boolean result = super.performInplaceRename(processTextOccurrences, nameSuggestions); - showBalloon(); + if (result) { + showBalloon(); + } return result; } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 15479826bb09..110978c930df 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -52,6 +52,7 @@ import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider; import com.intellij.openapi.ui.ComboBox; @@ -859,7 +860,7 @@ public final class ProjectViewImpl extends ProjectView implements PersistentStat if (element != null) { PsiFile file = element.getContainingFile(); if (file != null) { - title = file.getVirtualFile().getPresentableUrl(); + title = ProjectUtil.getLocationRelativeToUserHome(file.getVirtualFile().getPresentableUrl()); } else if (element instanceof PsiDirectory) { title = PsiDirectoryFactory.getInstance(myProject).getQualifiedName((PsiDirectory) element, true); @@ -871,7 +872,7 @@ public final class ProjectViewImpl extends ProjectView implements PersistentStat else { title = ""; if (myProject != null) { - title = myProject.getPresentableUrl(); + title = ProjectUtil.getLocationRelativeToUserHome(myProject.getPresentableUrl()); } } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java index 3c5844747f33..45cbf3bc1037 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java @@ -22,6 +22,7 @@ import com.intellij.ide.projectView.ViewSettings; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.util.Iconable; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -79,7 +80,7 @@ public class PsiFileNode extends BasePsiNode{ public String getTitle() { final PsiFile file = getValue(); if (file != null) { - return file.getVirtualFile().getPresentableUrl(); + return ProjectUtil.getLocationRelativeToUserHome(file.getVirtualFile().getPresentableUrl()); } return super.getTitle(); } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java index 95b603c9d879..c0c3c1b40a8d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/PsiDirectoryFactoryImpl.java @@ -16,9 +16,11 @@ package com.intellij.psi.impl.file; +import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.impl.PsiManagerImpl; +import com.intellij.util.PlatformUtils; import org.jetbrains.annotations.NotNull; /** @@ -37,7 +39,7 @@ public class PsiDirectoryFactoryImpl extends PsiDirectoryFactory { @NotNull public String getQualifiedName(@NotNull final PsiDirectory directory, final boolean presentable) { if (presentable) { - return directory.getVirtualFile().getPresentableUrl(); + return ProjectUtil.getLocationRelativeToUserHome(directory.getVirtualFile().getPresentableUrl()); } return ""; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java index afce9857faef..9b228d342609 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java @@ -43,12 +43,12 @@ public class PlatformFrameTitleBuilder extends FrameTitleBuilder { if (file instanceof VirtualFilePathWrapper) { return ((VirtualFilePathWrapper)file).getPresentablePath(); } - String url = file.getPresentableUrl(); + String url = ProjectUtil.getLocationRelativeToUserHome(file.getPresentableUrl()); VirtualFile baseDir = ProjectBaseDirectory.getInstance(project).getBaseDir(); if (baseDir == null) baseDir = project.getBaseDir(); if (baseDir != null) { //noinspection ConstantConditions - final String projectHomeUrl = baseDir.getPresentableUrl(); + final String projectHomeUrl = ProjectUtil.getLocationRelativeToUserHome(baseDir.getPresentableUrl()); if (url.startsWith(projectHomeUrl)) { url = "..." + url.substring(projectHomeUrl.length()); }