mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
@@ -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
|
||||
|
||||
+29
-20
@@ -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<Boolean> result = new Ref<Boolean>();
|
||||
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<PsiField>() {
|
||||
@Override
|
||||
public PsiField compute() {
|
||||
final Ref<PsiField> ref = new Ref<PsiField>();
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+24
-20
@@ -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<Boolean> result = new Ref<Boolean>();
|
||||
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<PsiField>() {
|
||||
@Override
|
||||
public PsiField compute() {
|
||||
final Ref<PsiField> ref = new Ref<PsiField>();
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+4
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-2
@@ -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(
|
||||
|
||||
+17
-6
@@ -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<Boolean> result = new Ref<Boolean>();
|
||||
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
|
||||
|
||||
+13
-14
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -169,7 +169,9 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
@Override
|
||||
public boolean performInplaceRename(boolean processTextOccurrences, LinkedHashSet<String> nameSuggestions) {
|
||||
final boolean result = super.performInplaceRename(processTextOccurrences, nameSuggestions);
|
||||
showBalloon();
|
||||
if (result) {
|
||||
showBalloon();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PsiFile>{
|
||||
public String getTitle() {
|
||||
final PsiFile file = getValue();
|
||||
if (file != null) {
|
||||
return file.getVirtualFile().getPresentableUrl();
|
||||
return ProjectUtil.getLocationRelativeToUserHome(file.getVirtualFile().getPresentableUrl());
|
||||
}
|
||||
return super.getTitle();
|
||||
}
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
+2
-2
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user