Merge branch origin/master
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import org.jetbrains.jps.gant.JpsGantTool
|
||||
import org.jetbrains.jps.gant.TeamCityBuildInfoPrinter
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
@@ -627,6 +628,23 @@ binding.setVariable("zipSources", { String home, String targetDir ->
|
||||
notifyArtifactBuilt(sources)
|
||||
})
|
||||
|
||||
binding.setVariable("zipSourcesOfModules", { String home, String targetFilePath, Collection<String> modules ->
|
||||
projectBuilder.stage("zip sources of ${modules.size()} modules to $targetFilePath")
|
||||
|
||||
ant.mkdir(dir: new File(targetFilePath).getParent())
|
||||
ant.delete(file: targetFilePath)
|
||||
ant.zip(destfile: targetFilePath) {
|
||||
modules.each {
|
||||
JpsModule module = findModule(it)
|
||||
module.getSourceRoots(JavaSourceRootType.SOURCE).flatten().collect {it.file}.each { File srcRoot ->
|
||||
zipfileset(prefix: module.name, dir: srcRoot.absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notifyArtifactBuilt(targetFilePath)
|
||||
})
|
||||
|
||||
/**
|
||||
* E.g.
|
||||
*
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class EnterAction extends AnAction {
|
||||
if (selection.length > 0) {
|
||||
if (selection.length == 1 && selection[0].isDirectory()) {
|
||||
presentation.setVisible(true);
|
||||
} else if (selection.length > 0) {
|
||||
} else {
|
||||
boolean notImages = false;
|
||||
ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
|
||||
for (VirtualFile file : selection) {
|
||||
@@ -65,9 +65,6 @@ public final class EnterAction extends AnAction {
|
||||
}
|
||||
presentation.setEnabled(!notImages);
|
||||
presentation.setVisible(false);
|
||||
} else {
|
||||
presentation.setVisible(false);
|
||||
presentation.setEnabled(false);
|
||||
}
|
||||
} else {
|
||||
presentation.setVisible(false);
|
||||
|
||||
@@ -8,6 +8,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a group of frameworks. in the frameworks tree ("Additional Libraries and Frameworks"
|
||||
* in the New Project dialog or the tree displayed in the "Add Framework Support" dialog).
|
||||
* Frameworks in a group can have a common version number.
|
||||
*
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FrameworkGroup<V extends FrameworkVersion> implements FrameworkOrGroup {
|
||||
@@ -26,6 +30,10 @@ public abstract class FrameworkGroup<V extends FrameworkVersion> implements Fram
|
||||
@NotNull
|
||||
public abstract Icon getIcon();
|
||||
|
||||
/**
|
||||
* Returns the list of known versions of the framework group. The list is shown to the user
|
||||
* and allows them to choose the version used in their project.
|
||||
*/
|
||||
@NotNull
|
||||
public List<V> getGroupVersions() {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -20,8 +20,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Represents a single node (framework or group) in the frameworks tree ("Additional Libraries and Frameworks"
|
||||
* in the New Project dialog or the tree displayed in the "Add Framework Support" dialog).
|
||||
*
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 09.10.13
|
||||
* @since 09.10.13
|
||||
*/
|
||||
public interface FrameworkOrGroup {
|
||||
@NotNull
|
||||
|
||||
@@ -17,17 +17,12 @@ package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint;
|
||||
import com.intellij.openapi.roots.FileIndexFacade;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.RecursionManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -47,10 +42,10 @@ public class ContractInference {
|
||||
|
||||
@NotNull
|
||||
public static List<MethodContract> inferContracts(@NotNull final PsiMethod method) {
|
||||
if (isLibraryCode(method)) {
|
||||
if (!InferenceFromSourceUtil.shouldInferFromSource(method)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
return CachedValuesManager.getCachedValue(method, new CachedValueProvider<List<MethodContract>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -66,12 +61,6 @@ public class ContractInference {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static boolean isLibraryCode(@NotNull PsiMethod method) {
|
||||
if (method instanceof PsiCompiledElement) return true;
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method);
|
||||
return virtualFile != null && FileIndexFacade.getInstance(method.getProject()).isInLibrarySource(virtualFile);
|
||||
}
|
||||
}
|
||||
|
||||
class ContractInferenceInterpreter {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.openapi.roots.FileIndexFacade;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class InferenceFromSourceUtil {
|
||||
static boolean shouldInferFromSource(@NotNull PsiMethod method) {
|
||||
if (isLibraryCode(method) ||
|
||||
method.hasModifierProperty(PsiModifier.ABSTRACT) ||
|
||||
PsiUtil.canBeOverriden(method) ||
|
||||
method.getBody() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) return true;
|
||||
|
||||
return !isUnusedInAnonymousClass(method);
|
||||
}
|
||||
|
||||
private static boolean isUnusedInAnonymousClass(@NotNull PsiMethod method) {
|
||||
PsiClass containingClass = method.getContainingClass();
|
||||
return containingClass instanceof PsiAnonymousClass &&
|
||||
MethodReferencesSearch.search(method, new LocalSearchScope(containingClass), false).findFirst() == null;
|
||||
}
|
||||
|
||||
private static boolean isLibraryCode(@NotNull PsiMethod method) {
|
||||
if (method instanceof PsiCompiledElement) return true;
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method);
|
||||
return virtualFile != null && FileIndexFacade.getInstance(method.getProject()).isInLibrarySource(virtualFile);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
public class NullityInference {
|
||||
|
||||
public static Nullness inferNullity(final PsiMethod method) {
|
||||
if (ContractInference.isLibraryCode(method)) {
|
||||
if (!InferenceFromSourceUtil.shouldInferFromSource(method)) {
|
||||
return Nullness.UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,10 @@ import java.util.List;
|
||||
public class PurityInference {
|
||||
|
||||
public static boolean inferPurity(@NotNull final PsiMethod method) {
|
||||
if (ContractInference.isLibraryCode(method) || method.getReturnType() == PsiType.VOID || method.getBody() == null || method.isConstructor()) {
|
||||
if (!InferenceFromSourceUtil.shouldInferFromSource(method) ||
|
||||
method.getReturnType() == PsiType.VOID ||
|
||||
method.getBody() == null ||
|
||||
method.isConstructor()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -50,7 +51,24 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
private static final Function<PsiElement, String> ourTooltipProvider = new Function<PsiElement, String>() {
|
||||
@Override
|
||||
public String fun(PsiElement nameIdentifier) {
|
||||
return XmlStringUtil.wrapInHtml(JavaDocInfoGenerator.generateSignature(nameIdentifier.getParent()));
|
||||
PsiModifierListOwner owner = (PsiModifierListOwner)nameIdentifier.getParent();
|
||||
|
||||
boolean hasInferred = false;
|
||||
boolean hasExternal = false;
|
||||
for (PsiAnnotation annotation : findSignatureNonCodeAnnotations(owner)) {
|
||||
hasExternal |= AnnotationUtil.isExternalAnnotation(annotation);
|
||||
hasInferred |= AnnotationUtil.isInferredAnnotation(annotation);
|
||||
}
|
||||
|
||||
String header;
|
||||
if (hasInferred && hasExternal) {
|
||||
header = "External and <i>inferred</i>";
|
||||
} else if (hasInferred) {
|
||||
header = "<i>Inferred</i>";
|
||||
} else {
|
||||
header = "External";
|
||||
}
|
||||
return XmlStringUtil.wrapInHtml(header + " annotations available. Full signature:<p>\n" + JavaDocInfoGenerator.generateSignature(owner));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,7 +83,7 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
PsiElement nameIdentifier = ((PsiNameIdentifierOwner)owner).getNameIdentifier();
|
||||
if (nameIdentifier == null || !nameIdentifier.getTextRange().equals(element.getTextRange())) return null;
|
||||
|
||||
if (!shouldShowSignature((PsiModifierListOwner)owner)) {
|
||||
if (findSignatureNonCodeAnnotations((PsiModifierListOwner)owner).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,38 +94,35 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
GutterIconRenderer.Alignment.RIGHT);
|
||||
}
|
||||
|
||||
private static boolean shouldShowSignature(PsiModifierListOwner owner) {
|
||||
if (hasNonCodeAnnotations(owner)) {
|
||||
return true;
|
||||
}
|
||||
private static List<PsiAnnotation> findSignatureNonCodeAnnotations(PsiModifierListOwner owner) {
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList(findOwnNonCodeAnnotations(owner));
|
||||
|
||||
if (owner instanceof PsiMethod) {
|
||||
for (PsiParameter parameter : ((PsiMethod)owner).getParameterList().getParameters()) {
|
||||
if (hasNonCodeAnnotations(parameter)) {
|
||||
return true;
|
||||
}
|
||||
result.addAll(findOwnNonCodeAnnotations(parameter));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean hasNonCodeAnnotations(@NotNull PsiModifierListOwner element) {
|
||||
private static List<PsiAnnotation> findOwnNonCodeAnnotations(@NotNull PsiModifierListOwner element) {
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList();
|
||||
Project project = element.getProject();
|
||||
PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element);
|
||||
if (externalAnnotations != null) {
|
||||
for (PsiAnnotation annotation : externalAnnotations) {
|
||||
if (isVisibleAnnotation(annotation)) {
|
||||
return true;
|
||||
result.add(annotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PsiAnnotation annotation : InferredAnnotationsManager.getInstance(project).findInferredAnnotations(element)) {
|
||||
if (isVisibleAnnotation(annotation)) {
|
||||
return true;
|
||||
result.add(annotation);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isVisibleAnnotation(@NotNull PsiAnnotation annotation) {
|
||||
|
||||
@@ -78,4 +78,14 @@ public class ConvertToInstanceMethodDialog extends MoveInstanceMethodDialogBase
|
||||
}.installOn(variableChooser);
|
||||
return variableChooser;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMovePropertySuffix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCbTitle() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.refactoring.convertToInstanceMethod;
|
||||
import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.history.LocalHistory;
|
||||
import com.intellij.history.LocalHistoryAction;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -231,6 +232,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
if (!myTargetClass.isInterface()) {
|
||||
PsiMethod method = addMethodToClass(myTargetClass);
|
||||
fixVisibility(method, usages);
|
||||
EditorHelper.openInEditor(method);
|
||||
}
|
||||
else {
|
||||
final PsiMethod interfaceMethod = addMethodToClass(myTargetClass);
|
||||
@@ -240,6 +242,8 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
modifierList.setModifierProperty(PsiModifier.PROTECTED, false);
|
||||
RefactoringUtil.makeMethodAbstract(myTargetClass, interfaceMethod);
|
||||
|
||||
EditorHelper.openInEditor(interfaceMethod);
|
||||
|
||||
for (final PsiClass psiClass : inheritors) {
|
||||
final PsiMethod newMethod = addMethodToClass(psiClass);
|
||||
PsiUtil.setModifierProperty(newMethod, myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY) ? myNewVisibility
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.refactoring.move;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public abstract class MoveDialogBase extends RefactoringDialog {
|
||||
|
||||
private JCheckBox myOpenEditorCb;
|
||||
|
||||
protected abstract String getMovePropertySuffix();
|
||||
protected abstract String getCbTitle();
|
||||
|
||||
protected JCheckBox initOpenInEditorCb() {
|
||||
myOpenEditorCb = new JCheckBox(getCbTitle(), PropertiesComponent.getInstance().getBoolean("Move" + getMovePropertySuffix() +".OpenInEditor",
|
||||
isEnabledByDefault()));
|
||||
return myOpenEditorCb;
|
||||
}
|
||||
|
||||
protected boolean isEnabledByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void saveOpenInEditorOption() {
|
||||
if (myOpenEditorCb != null) {
|
||||
PropertiesComponent.getInstance().setValue("Move" + getMovePropertySuffix() +".OpenInEditor", String.valueOf(myOpenEditorCb.isSelected()));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isOpenInEditor() {
|
||||
return myOpenEditorCb != null && myOpenEditorCb.isSelected();
|
||||
}
|
||||
|
||||
protected MoveDialogBase(@NotNull Project project, boolean canBeParent) {
|
||||
super(project, canBeParent);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.move.moveClassesOrPackages;
|
||||
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -39,6 +40,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -60,6 +62,7 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
private final boolean mySearchInNonJavaFiles;
|
||||
private NonCodeUsageInfo[] myNonCodeUsages;
|
||||
private final MoveCallback myMoveCallback;
|
||||
private boolean myOpenInEditor;
|
||||
|
||||
public MoveClassToInnerProcessor(Project project,
|
||||
final PsiClass[] classesToMove,
|
||||
@@ -167,6 +170,13 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
|
||||
if (myOpenInEditor && !oldToNewElementsMapping.isEmpty()) {
|
||||
final PsiElement item = ContainerUtil.getFirstItem(oldToNewElementsMapping.values());
|
||||
if (item != null) {
|
||||
EditorHelper.openInEditor(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
@@ -324,6 +334,10 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
});
|
||||
}
|
||||
|
||||
public void setOpenInEditor(boolean openInEditor) {
|
||||
myOpenInEditor = openInEditor;
|
||||
}
|
||||
|
||||
private static class ConflictsCollector {
|
||||
private final PsiClass myClassToMove;
|
||||
private final MultiMap<PsiElement, String> myConflicts;
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="ce694" binding="myTargetPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="ce694" binding="myTargetPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -135,6 +135,14 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="58f9b" binding="myOpenInEditorPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="fdc31">
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.refactoring.*;
|
||||
import com.intellij.refactoring.move.MoveCallback;
|
||||
import com.intellij.refactoring.move.MoveClassesOrPackagesCallback;
|
||||
import com.intellij.refactoring.move.MoveDialogBase;
|
||||
import com.intellij.refactoring.move.MoveHandler;
|
||||
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesUtil;
|
||||
import com.intellij.refactoring.ui.ClassNameReferenceEditor;
|
||||
@@ -64,7 +65,7 @@ import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
public class MoveClassesOrPackagesDialog extends MoveDialogBase {
|
||||
@NonNls private static final String RECENTS_KEY = "MoveClassesOrPackagesDialog.RECENTS_KEY";
|
||||
private final PsiElement[] myElementsToMove;
|
||||
private final MoveCallback myMoveCallback;
|
||||
@@ -90,6 +91,7 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
private ComboboxWithBrowseButton myDestinationFolderCB;
|
||||
private JPanel myTargetPanel;
|
||||
private JLabel myTargetDestinationLabel;
|
||||
private JPanel myOpenInEditorPanel;
|
||||
private boolean myHavePackages;
|
||||
private boolean myTargetDirectoryFixed;
|
||||
private boolean mySuggestToMoveToAnotherRoot;
|
||||
@@ -138,6 +140,13 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
myInnerClassChooser.requestFocus();
|
||||
}
|
||||
});
|
||||
|
||||
for (PsiElement element : elementsToMove) {
|
||||
if (element.getContainingFile() != null) {
|
||||
myOpenInEditorPanel.add(initOpenInEditorCb(), BorderLayout.EAST);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateControlsEnabled() {
|
||||
@@ -376,6 +385,7 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
}
|
||||
|
||||
protected void doAction() {
|
||||
saveOpenInEditorOption();
|
||||
if (isMoveToPackage()) {
|
||||
invokeMoveToPackage();
|
||||
}
|
||||
@@ -419,6 +429,7 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
|
||||
MoveClassesOrPackagesProcessor processor = createMoveToPackageProcessor(destination, myElementsToMove, myMoveCallback);
|
||||
if (processor.verifyValidPackageName()) {
|
||||
processor.setOpenInEditor(isOpenInEditor());
|
||||
invokeRefactoring(processor);
|
||||
}
|
||||
}
|
||||
@@ -476,7 +487,9 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
for (int i = 0; i < myElementsToMove.length; i++) {
|
||||
classesToMove[i] = (PsiClass)myElementsToMove[i];
|
||||
}
|
||||
invokeRefactoring(createMoveToInnerProcessor(targetClass, classesToMove, myMoveCallback));
|
||||
final MoveClassToInnerProcessor processor = createMoveToInnerProcessor(targetClass, classesToMove, myMoveCallback);
|
||||
processor.setOpenInEditor(isOpenInEditor());
|
||||
invokeRefactoring(processor);
|
||||
}
|
||||
|
||||
//for scala plugin
|
||||
@@ -510,4 +523,14 @@ public class MoveClassesOrPackagesDialog extends RefactoringDialog {
|
||||
private List<VirtualFile> getSourceRoots() {
|
||||
return JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMovePropertySuffix() {
|
||||
return "Class";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCbTitle() {
|
||||
return "Open moved in editor";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.move.moveClassesOrPackages;
|
||||
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -71,6 +72,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
private final MoveCallback myMoveCallback;
|
||||
protected @NotNull final MoveDestination myMoveDestination;
|
||||
protected NonCodeUsageInfo[] myNonCodeUsages;
|
||||
private boolean myOpenInEditor;
|
||||
|
||||
public MoveClassesOrPackagesProcessor(Project project,
|
||||
PsiElement[] elements,
|
||||
@@ -203,6 +205,10 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
return myMoveDestination.getTargetPackage();
|
||||
}
|
||||
|
||||
public void setOpenInEditor(boolean openInEditor) {
|
||||
myOpenInEditor = openInEditor;
|
||||
}
|
||||
|
||||
protected static class ConflictsUsageInfo extends UsageInfo {
|
||||
private final Collection<String> myConflicts;
|
||||
|
||||
@@ -540,6 +546,15 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
myNonCodeUsages = CommonMoveUtil.retargetUsages(usages, oldToNewElementsMapping);
|
||||
|
||||
if (myOpenInEditor) {
|
||||
for (PsiElement element : myElementsToMove) {
|
||||
if (element.getContainingFile() != null) {
|
||||
EditorHelper.openInEditor(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
myNonCodeUsages = new NonCodeUsageInfo[0];
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.*;
|
||||
import com.intellij.refactoring.move.MoveCallback;
|
||||
import com.intellij.refactoring.move.MoveDialogBase;
|
||||
import com.intellij.refactoring.move.MoveHandler;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
@@ -43,6 +44,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashSet;
|
||||
@@ -51,7 +53,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class MoveClassesOrPackagesToNewDirectoryDialog extends RefactoringDialog {
|
||||
public class MoveClassesOrPackagesToNewDirectoryDialog extends MoveDialogBase {
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesToNewDirectoryDialog");
|
||||
|
||||
private final PsiDirectory myDirectory;
|
||||
@@ -124,6 +126,12 @@ public class MoveClassesOrPackagesToNewDirectoryDialog extends RefactoringDialog
|
||||
myPreserveSourceRoot.setSelected(sameModule);
|
||||
}
|
||||
init();
|
||||
for (PsiElement element : elementsToMove) {
|
||||
if (element.getContainingFile() != null) {
|
||||
myOpenInEditor.add(initOpenInEditorCb(), BorderLayout.WEST);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TextFieldWithBrowseButton myDestDirectoryField;
|
||||
@@ -132,6 +140,7 @@ public class MoveClassesOrPackagesToNewDirectoryDialog extends RefactoringDialog
|
||||
private JPanel myRootPanel;
|
||||
private JLabel myNameLabel;
|
||||
private JCheckBox myPreserveSourceRoot;
|
||||
private JPanel myOpenInEditor;
|
||||
|
||||
private boolean isSearchInNonJavaFiles() {
|
||||
return mySearchForTextOccurrencesCheckBox.isSelected();
|
||||
@@ -179,6 +188,7 @@ public class MoveClassesOrPackagesToNewDirectoryDialog extends RefactoringDialog
|
||||
final boolean searchForTextOccurences = isSearchInNonJavaFiles();
|
||||
refactoringSettings.MOVE_SEARCH_IN_COMMENTS = searchInComments;
|
||||
refactoringSettings.MOVE_SEARCH_FOR_TEXT = searchForTextOccurences;
|
||||
saveOpenInEditorOption();
|
||||
invokeRefactoring(createRefactoringProcessor(project, directory, aPackage, searchInComments, searchForTextOccurences));
|
||||
}
|
||||
|
||||
@@ -218,12 +228,28 @@ public class MoveClassesOrPackagesToNewDirectoryDialog extends RefactoringDialog
|
||||
|
||||
MoveClassesOrPackagesProcessor processor = createMoveClassesOrPackagesProcessor(myDirectory.getProject(), myElementsToMove, destination,
|
||||
searchInComments, searchForTextOccurences, myMoveCallback);
|
||||
|
||||
|
||||
processor.setOpenInEditor(isOpenInEditor());
|
||||
if (processor.verifyValidPackageName()) {
|
||||
return processor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMovePropertySuffix() {
|
||||
return "ClassWithTarget";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCbTitle() {
|
||||
return "Open moved classes in editor";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledByDefault() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesToNewDirectoryDialog">
|
||||
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="5" left="5" bottom="5" right="5"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="666" height="148"/>
|
||||
<xy x="20" y="20" width="666" height="168"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -69,9 +69,17 @@
|
||||
</component>
|
||||
<vspacer id="c1dce">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="60268" binding="myOpenInEditor" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<inspectionSuppressions>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.refactoring.move.moveInner.MoveInnerDialog">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="10" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -23,7 +23,7 @@
|
||||
</hspacer>
|
||||
<vspacer id="34c3">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="8093b" class="com.intellij.ui.EditorTextField" binding="myClassNameField">
|
||||
@@ -89,6 +89,14 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="f9ba1" binding="myOpenInEditorPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.move.moveInner;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.help.HelpManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -37,6 +38,7 @@ import com.intellij.refactoring.HelpID;
|
||||
import com.intellij.refactoring.JavaRefactoringSettings;
|
||||
import com.intellij.refactoring.PackageWrapper;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.move.MoveDialogBase;
|
||||
import com.intellij.refactoring.move.MoveInstanceMembersUtil;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesUtil;
|
||||
import com.intellij.refactoring.ui.NameSuggestionsField;
|
||||
@@ -52,13 +54,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MoveInnerDialog extends RefactoringDialog {
|
||||
public class MoveInnerDialog extends MoveDialogBase {
|
||||
private final Project myProject;
|
||||
private final PsiClass myInnerClass;
|
||||
private final PsiElement myTargetContainer;
|
||||
@@ -74,11 +77,22 @@ public class MoveInnerDialog extends RefactoringDialog {
|
||||
private JLabel myPackageNameLabel;
|
||||
private JLabel myClassNameLabel;
|
||||
private JLabel myParameterNameLabel;
|
||||
private JPanel myOpenInEditorPanel;
|
||||
private SuggestedNameInfo mySuggestedNameInfo;
|
||||
private final PsiClass myOuterClass;
|
||||
|
||||
@NonNls private static final String RECENTS_KEY = "MoveInnerDialog.RECENTS_KEY";
|
||||
|
||||
@Override
|
||||
protected String getMovePropertySuffix() {
|
||||
return "Inner";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCbTitle() {
|
||||
return "Open moved member in editor";
|
||||
}
|
||||
|
||||
public MoveInnerDialog(Project project, PsiClass innerClass, MoveInnerProcessor processor, final PsiElement targetContainer) {
|
||||
super(project, true);
|
||||
myProject = project;
|
||||
@@ -91,6 +105,7 @@ public class MoveInnerDialog extends RefactoringDialog {
|
||||
myPackageNameLabel.setLabelFor(myPackageNameField.getChildComponent());
|
||||
myClassNameLabel.setLabelFor(myClassNameField);
|
||||
myParameterNameLabel.setLabelFor(myParameterField);
|
||||
myOpenInEditorPanel.add(initOpenInEditorCb(), BorderLayout.EAST);
|
||||
}
|
||||
|
||||
public boolean isSearchInComments() {
|
||||
@@ -297,6 +312,10 @@ public class MoveInnerDialog extends RefactoringDialog {
|
||||
if (target == null) return;
|
||||
myProcessor.setup(getInnerClass(), className, isPassOuterClass(), parameterName,
|
||||
isSearchInComments(), isSearchInNonJavaFiles(), target);
|
||||
|
||||
final boolean openInEditor = isOpenInEditor();
|
||||
saveOpenInEditorOption();
|
||||
myProcessor.setOpenInEditor(openInEditor);
|
||||
invokeRefactoring(myProcessor);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.refactoring.move.moveInner;
|
||||
|
||||
import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.codeInsight.CodeInsightUtilCore;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.lang.findUsages.DescriptiveNameUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
@@ -70,6 +71,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
private boolean mySearchInComments;
|
||||
private boolean mySearchInNonJavaFiles;
|
||||
private NonCodeUsageInfo[] myNonCodeUsages;
|
||||
private boolean myOpenInEditor;
|
||||
|
||||
public MoveInnerProcessor(Project project, MoveCallback moveCallback) {
|
||||
super(project);
|
||||
@@ -267,9 +269,9 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
ChangeContextUtil.decodeContextInfo(newClass, null, null);
|
||||
}
|
||||
|
||||
PsiFile targetFile = newClass.getContainingFile();
|
||||
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, targetFile.getVirtualFile(), newClass.getTextOffset());
|
||||
FileEditorManager.getInstance(myProject).openTextEditor(descriptor, true);
|
||||
if (myOpenInEditor) {
|
||||
EditorHelper.openInEditor(newClass);
|
||||
}
|
||||
|
||||
if (myMoveCallback != null) {
|
||||
myMoveCallback.refactoringCompleted();
|
||||
@@ -530,4 +532,8 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
|
||||
public String getParameterName() {
|
||||
return myParameterNameOuterClass;
|
||||
}
|
||||
|
||||
public void setOpenInEditor(boolean openInEditor) {
|
||||
myOpenInEditor = openInEditor;
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,8 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
|
||||
mainPanel.add(parametersPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0), 0,0));
|
||||
}
|
||||
|
||||
mainPanel.add(initOpenInEditorCb(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0), 0,0));
|
||||
|
||||
separator.setLabelFor(myList);
|
||||
validateTextFields(myList.getSelectedIndex());
|
||||
|
||||
@@ -148,8 +150,10 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
|
||||
final MoveInstanceMethodProcessor processor = new MoveInstanceMethodProcessor(myMethod.getProject(),
|
||||
myMethod, targetVariable,
|
||||
myVisibilityPanel.getVisibility(),
|
||||
isOpenInEditor(),
|
||||
parameterNames);
|
||||
if (!verifyTargetClass(processor.getTargetClass())) return;
|
||||
saveOpenInEditorOption();
|
||||
invokeRefactoring(processor);
|
||||
}
|
||||
|
||||
@@ -167,4 +171,14 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
|
||||
protected void doHelpAction() {
|
||||
HelpManager.getInstance().invokeHelp(HelpID.MOVE_INSTANCE_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMovePropertySuffix() {
|
||||
return "Instance";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCbTitle() {
|
||||
return "Open moved method in editor";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiVariable;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.move.MoveDialogBase;
|
||||
import com.intellij.refactoring.ui.JavaVisibilityPanel;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
@@ -38,7 +39,7 @@ import java.awt.*;
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public abstract class MoveInstanceMethodDialogBase extends RefactoringDialog {
|
||||
public abstract class MoveInstanceMethodDialogBase extends MoveDialogBase {
|
||||
protected final PsiMethod myMethod;
|
||||
protected final PsiVariable[] myVariables;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.refactoring.move.moveInstanceMethod;
|
||||
|
||||
import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.codeInsight.generation.OverrideImplementUtil;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -62,16 +63,27 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
private PsiVariable myTargetVariable;
|
||||
private PsiClass myTargetClass;
|
||||
private final String myNewVisibility;
|
||||
private final boolean myOpenInEditor;
|
||||
private final Map<PsiClass, String> myOldClassParameterNames;
|
||||
|
||||
public MoveInstanceMethodProcessor(final Project project,
|
||||
final PsiMethod method,
|
||||
final PsiVariable targetVariable,
|
||||
final String newVisibility,
|
||||
final Map<PsiClass, String> oldClassParameterNames) {
|
||||
this(project, method, targetVariable, newVisibility, false, oldClassParameterNames);
|
||||
}
|
||||
|
||||
public MoveInstanceMethodProcessor(final Project project,
|
||||
final PsiMethod method,
|
||||
final PsiVariable targetVariable,
|
||||
final String newVisibility,
|
||||
boolean openInEditor,
|
||||
final Map<PsiClass, String> oldClassParameterNames) {
|
||||
super(project);
|
||||
myMethod = method;
|
||||
myTargetVariable = targetVariable;
|
||||
myOpenInEditor = openInEditor;
|
||||
myOldClassParameterNames = oldClassParameterNames;
|
||||
LOG.assertTrue(myTargetVariable instanceof PsiParameter || myTargetVariable instanceof PsiField);
|
||||
LOG.assertTrue(myTargetVariable.getType() instanceof PsiClassType);
|
||||
@@ -247,6 +259,10 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
reference.bindToElement(method);
|
||||
}
|
||||
VisibilityUtil.fixVisibility(UsageViewUtil.toElements(usages), method, myNewVisibility);
|
||||
|
||||
if (myOpenInEditor) {
|
||||
EditorHelper.openInEditor(method);
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.move.moveMembers;
|
||||
|
||||
import com.intellij.ide.util.ClassFilter;
|
||||
import com.intellij.ide.util.PackageUtil;
|
||||
import com.intellij.ide.util.TreeClassChooser;
|
||||
import com.intellij.ide.util.TreeClassChooserFactory;
|
||||
import com.intellij.ide.util.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
@@ -38,6 +35,7 @@ import com.intellij.refactoring.JavaRefactoringSettings;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.classMembers.MemberInfoChange;
|
||||
import com.intellij.refactoring.move.MoveCallback;
|
||||
import com.intellij.refactoring.move.MoveDialogBase;
|
||||
import com.intellij.refactoring.ui.JavaVisibilityPanel;
|
||||
import com.intellij.refactoring.ui.MemberSelectionPanel;
|
||||
import com.intellij.refactoring.ui.MemberSelectionTable;
|
||||
@@ -61,7 +59,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MoveMembersDialog extends RefactoringDialog implements MoveMembersOptions {
|
||||
public class MoveMembersDialog extends MoveDialogBase implements MoveMembersOptions {
|
||||
@NonNls private static final String RECENTS_KEY = "MoveMembersDialog.RECENTS_KEY";
|
||||
private MyMemberInfoModel myMemberInfoModel;
|
||||
|
||||
@@ -76,6 +74,16 @@ public class MoveMembersDialog extends RefactoringDialog implements MoveMembersO
|
||||
JavaVisibilityPanel myVisibilityPanel;
|
||||
private final JCheckBox myIntroduceEnumConstants = new JCheckBox(RefactoringBundle.message("move.enum.constant.cb"), true);
|
||||
|
||||
@Override
|
||||
protected String getMovePropertySuffix() {
|
||||
return "Member";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCbTitle() {
|
||||
return "Open moved members in editor";
|
||||
}
|
||||
|
||||
public MoveMembersDialog(Project project,
|
||||
PsiClass sourceClass,
|
||||
final PsiClass initialTargetClass,
|
||||
@@ -195,6 +203,7 @@ public class MoveMembersDialog extends RefactoringDialog implements MoveMembersO
|
||||
myVisibilityPanel = new JavaVisibilityPanel(true, true);
|
||||
myVisibilityPanel.setVisibility(null);
|
||||
panel.add(myVisibilityPanel, BorderLayout.EAST);
|
||||
panel.add(initOpenInEditorCb(), BorderLayout.SOUTH);
|
||||
|
||||
return panel;
|
||||
}
|
||||
@@ -246,8 +255,9 @@ public class MoveMembersDialog extends RefactoringDialog implements MoveMembersO
|
||||
public String getTargetClassName() {
|
||||
return MoveMembersDialog.this.getTargetClassName();
|
||||
}
|
||||
}));
|
||||
}, isOpenInEditor()));
|
||||
|
||||
saveOpenInEditorOption();
|
||||
JavaRefactoringSettings.getInstance().MOVE_PREVIEW_USAGES = isPreviewUsages();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.move.moveMembers;
|
||||
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -56,6 +57,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
private PsiClass myTargetClass;
|
||||
private final Set<PsiMember> myMembersToMove = new LinkedHashSet<PsiMember>();
|
||||
private final MoveCallback myMoveCallback;
|
||||
private final boolean myOpenInEditor;
|
||||
private String myNewVisibility; // "null" means "as is"
|
||||
private String myCommandName = MoveMembersImpl.REFACTORING_NAME;
|
||||
private MoveMembersOptions myOptions;
|
||||
@@ -65,8 +67,13 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
public MoveMembersProcessor(Project project, @Nullable MoveCallback moveCallback, MoveMembersOptions options) {
|
||||
this(project, moveCallback, options, false);
|
||||
}
|
||||
|
||||
public MoveMembersProcessor(Project project, @Nullable MoveCallback moveCallback, MoveMembersOptions options, boolean openInEditor) {
|
||||
super(project);
|
||||
myMoveCallback = moveCallback;
|
||||
myOpenInEditor = openInEditor;
|
||||
setOptions(options);
|
||||
}
|
||||
|
||||
@@ -231,6 +238,13 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
|
||||
if (myMoveCallback != null) {
|
||||
myMoveCallback.refactoringCompleted();
|
||||
}
|
||||
|
||||
if (myOpenInEditor && !movedMembers.isEmpty()) {
|
||||
final PsiMember item = ContainerUtil.getFirstItem(movedMembers.values());
|
||||
if (item != null) {
|
||||
EditorHelper.openInEditor(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.augment;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -29,6 +30,7 @@ import java.util.List;
|
||||
|
||||
|
||||
public abstract class PsiAugmentProvider {
|
||||
private static final Logger LOG = Logger.getInstance("#" + PsiAugmentProvider.class.getName());
|
||||
public static final ExtensionPointName<PsiAugmentProvider> EP_NAME = ExtensionPointName.create("com.intellij.lang.psiAugmentProvider");
|
||||
|
||||
@NotNull
|
||||
@@ -64,9 +66,14 @@ public abstract class PsiAugmentProvider {
|
||||
@Nullable
|
||||
public static PsiType getInferredType(PsiTypeElement typeElement) {
|
||||
for (PsiAugmentProvider provider : Extensions.getExtensions(EP_NAME)) {
|
||||
final PsiType type = provider.inferType(typeElement);
|
||||
if (type != null) {
|
||||
return type;
|
||||
try {
|
||||
final PsiType type = provider.inferType(typeElement);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error("provider: " + provider, e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -16,16 +16,11 @@
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ReadActionProcessor;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.FileIndexFacade;
|
||||
import com.intellij.openapi.roots.PackageIndex;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.file.impl.JavaFileManager;
|
||||
@@ -34,19 +29,15 @@ import com.intellij.psi.impl.source.JavaDummyHolder;
|
||||
import com.intellij.psi.impl.source.JavaDummyHolderFactory;
|
||||
import com.intellij.psi.impl.source.resolve.FileContextUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StubTreeLoader;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.reference.SoftReference;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.*;
|
||||
@@ -94,7 +85,7 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
public PsiClass findClass(@NotNull final String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
ProgressIndicatorProvider.checkCanceled(); // We hope this method is being called often enough to cancel daemon processes smoothly
|
||||
|
||||
if (DumbService.getInstance(getProject()).isDumb()) {
|
||||
if (shouldUseSlowResolve()) {
|
||||
PsiClass[] classes = findClassesInDumbMode(qualifiedName, scope);
|
||||
if (classes.length != 0) {
|
||||
return classes[0];
|
||||
@@ -134,7 +125,7 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
if (DumbService.getInstance(getProject()).isDumb()) {
|
||||
if (shouldUseSlowResolve()) {
|
||||
return findClassesInDumbMode(qualifiedName, scope);
|
||||
}
|
||||
|
||||
@@ -147,6 +138,11 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
return classes.toArray(new PsiClass[classes.size()]);
|
||||
}
|
||||
|
||||
private boolean shouldUseSlowResolve() {
|
||||
DumbService dumbService = DumbService.getInstance(getProject());
|
||||
return dumbService.isDumb() && dumbService.isAlternativeResolveEnabled();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiElementFinder[] finders() {
|
||||
PsiElementFinder[] answer = myElementFinders;
|
||||
@@ -161,7 +157,6 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
@NotNull
|
||||
private PsiElementFinder[] calcFinders() {
|
||||
List<PsiElementFinder> elementFinders = new ArrayList<PsiElementFinder>();
|
||||
elementFinders.add(new PsiElementFinderImpl());
|
||||
ContainerUtil.addAll(elementFinders, myProject.getExtensions(PsiElementFinder.EP_NAME));
|
||||
return elementFinders.toArray(new PsiElementFinder[elementFinders.size()]);
|
||||
}
|
||||
@@ -274,146 +269,6 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx {
|
||||
return result.values().toArray(new PsiPackage[result.size()]);
|
||||
}
|
||||
|
||||
public PsiClass[] findClassByShortName(String name, PsiPackage psiPackage, GlobalSearchScope scope) {
|
||||
List<PsiClass> result = null;
|
||||
for (PsiElementFinder finder : filteredFinders()) {
|
||||
PsiClass[] classes = finder.getClasses(name, psiPackage, scope);
|
||||
if (classes.length == 0) continue;
|
||||
if (result == null) result = new ArrayList<PsiClass>();
|
||||
ContainerUtil.addAll(result, classes);
|
||||
}
|
||||
|
||||
return result == null ? PsiClass.EMPTY_ARRAY : result.toArray(new PsiClass[result.size()]);
|
||||
}
|
||||
|
||||
private class PsiElementFinderImpl extends PsiElementFinder implements DumbAware {
|
||||
@Override
|
||||
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
return myFileManager.findClass(qualifiedName, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
return myFileManager.findClasses(qualifiedName, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiPackage findPackage(@NotNull String qualifiedName) {
|
||||
return myFileManager.findPackage(qualifiedName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
final Map<String, PsiPackage> packagesMap = new HashMap<String, PsiPackage>();
|
||||
final String qualifiedName = psiPackage.getQualifiedName();
|
||||
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
|
||||
PsiDirectory[] subDirs = dir.getSubdirectories();
|
||||
for (PsiDirectory subDir : subDirs) {
|
||||
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(subDir);
|
||||
if (aPackage != null) {
|
||||
final String subQualifiedName = aPackage.getQualifiedName();
|
||||
if (subQualifiedName.startsWith(qualifiedName) && !packagesMap.containsKey(subQualifiedName)) {
|
||||
packagesMap.put(aPackage.getQualifiedName(), aPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
packagesMap.remove(qualifiedName); // avoid SOE caused by returning a package as a subpackage of itself
|
||||
return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] getClasses(@NotNull PsiPackage psiPackage, @NotNull final GlobalSearchScope scope) {
|
||||
return getClasses(null, psiPackage, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] getClasses(@Nullable String shortName, @NotNull PsiPackage psiPackage, @NotNull final GlobalSearchScope scope) {
|
||||
List<PsiClass> list = null;
|
||||
String packageName = psiPackage.getQualifiedName();
|
||||
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
|
||||
PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(dir);
|
||||
if (classes.length == 0) continue;
|
||||
if (list == null) list = new ArrayList<PsiClass>();
|
||||
for (PsiClass aClass : classes) {
|
||||
// class file can be located in wrong place inside file system
|
||||
String qualifiedName = aClass.getQualifiedName();
|
||||
if (qualifiedName != null) qualifiedName = StringUtil.getPackageName(qualifiedName);
|
||||
if (Comparing.strEqual(qualifiedName, packageName)) {
|
||||
if (shortName == null || shortName.equals(aClass.getName())) list.add(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list == null) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if (list.size() > 1) {
|
||||
ContainerUtil.quickSort(list, new Comparator<PsiClass>() {
|
||||
@Override
|
||||
public int compare(PsiClass o1, PsiClass o2) {
|
||||
VirtualFile file1 = PsiUtilCore.getVirtualFile(o1);
|
||||
VirtualFile file2 = PsiUtilCore.getVirtualFile(o2);
|
||||
return file1 == null ? file2 == null ? 0 : -1 : file2 == null ? 1 : scope.compare(file2, file1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list.toArray(new PsiClass[list.size()]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
Set<String> names = null;
|
||||
FileIndexFacade facade = FileIndexFacade.getInstance(myProject);
|
||||
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
|
||||
for (PsiFile file : dir.getFiles()) {
|
||||
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
if (vFile != null &&
|
||||
!(file instanceof PsiCompiledElement) &&
|
||||
!facade.isInSourceContent(vFile) &&
|
||||
(!scope.isForceSearchingInLibrarySources() ||
|
||||
!StubTreeLoader.getInstance().canHaveStub(vFile))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<String> inFile = file instanceof PsiClassOwnerEx ? ((PsiClassOwnerEx)file).getClassNames() : getClassNames(((PsiClassOwner)file).getClasses());
|
||||
|
||||
if (inFile.isEmpty()) continue;
|
||||
if (names == null) names = new HashSet<String>();
|
||||
names.addAll(inFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return names == null ? Collections.<String>emptySet() : names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processPackageDirectories(@NotNull PsiPackage psiPackage,
|
||||
@NotNull final GlobalSearchScope scope,
|
||||
@NotNull final Processor<PsiDirectory> consumer,
|
||||
boolean includeLibrarySources) {
|
||||
final PsiManager psiManager = PsiManager.getInstance(getProject());
|
||||
return PackageIndex.getInstance(getProject()).getDirsByPackageName(psiPackage.getQualifiedName(), includeLibrarySources)
|
||||
.forEach(new ReadActionProcessor<VirtualFile>() {
|
||||
@Override
|
||||
public boolean processInReadAction(final VirtualFile dir) {
|
||||
if (!scope.contains(dir)) return true;
|
||||
PsiDirectory psiDir = psiManager.findDirectory(dir);
|
||||
return psiDir == null || consumer.process(psiDir);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfPackagePrefix(@NotNull String packageName) {
|
||||
final Collection<String> packagePrefixes = myFileManager.getNonTrivialPackagePrefixes();
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.openapi.application.ReadActionProcessor;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.FileIndexFacade;
|
||||
import com.intellij.openapi.roots.PackageIndex;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.file.impl.JavaFileManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StubTreeLoader;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by kosyakov on 05.12.14.
|
||||
*/
|
||||
public class PsiElementFinderImpl extends PsiElementFinder implements DumbAware {
|
||||
|
||||
private final Project myProject;
|
||||
private final JavaFileManager myFileManager;
|
||||
|
||||
public PsiElementFinderImpl(Project project, JavaFileManager javaFileManager) {
|
||||
this.myProject = project;
|
||||
this.myFileManager = javaFileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
return myFileManager.findClass(qualifiedName, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
return myFileManager.findClasses(qualifiedName, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiPackage findPackage(@NotNull String qualifiedName) {
|
||||
return myFileManager.findPackage(qualifiedName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
final Map<String, PsiPackage> packagesMap = new HashMap<String, PsiPackage>();
|
||||
final String qualifiedName = psiPackage.getQualifiedName();
|
||||
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
|
||||
PsiDirectory[] subDirs = dir.getSubdirectories();
|
||||
for (PsiDirectory subDir : subDirs) {
|
||||
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(subDir);
|
||||
if (aPackage != null) {
|
||||
final String subQualifiedName = aPackage.getQualifiedName();
|
||||
if (subQualifiedName.startsWith(qualifiedName) && !packagesMap.containsKey(subQualifiedName)) {
|
||||
packagesMap.put(aPackage.getQualifiedName(), aPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
packagesMap.remove(qualifiedName); // avoid SOE caused by returning a package as a subpackage of itself
|
||||
return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] getClasses(@NotNull PsiPackage psiPackage, @NotNull final GlobalSearchScope scope) {
|
||||
return getClasses(null, psiPackage, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiClass[] getClasses(@Nullable String shortName, @NotNull PsiPackage psiPackage, @NotNull final GlobalSearchScope scope) {
|
||||
List<PsiClass> list = null;
|
||||
String packageName = psiPackage.getQualifiedName();
|
||||
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
|
||||
PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(dir);
|
||||
if (classes.length == 0) continue;
|
||||
if (list == null) list = new ArrayList<PsiClass>();
|
||||
for (PsiClass aClass : classes) {
|
||||
// class file can be located in wrong place inside file system
|
||||
String qualifiedName = aClass.getQualifiedName();
|
||||
if (qualifiedName != null) qualifiedName = StringUtil.getPackageName(qualifiedName);
|
||||
if (Comparing.strEqual(qualifiedName, packageName)) {
|
||||
if (shortName == null || shortName.equals(aClass.getName())) list.add(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list == null) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
if (list.size() > 1) {
|
||||
ContainerUtil.quickSort(list, new Comparator<PsiClass>() {
|
||||
@Override
|
||||
public int compare(PsiClass o1, PsiClass o2) {
|
||||
VirtualFile file1 = PsiUtilCore.getVirtualFile(o1);
|
||||
VirtualFile file2 = PsiUtilCore.getVirtualFile(o2);
|
||||
return file1 == null ? file2 == null ? 0 : -1 : file2 == null ? 1 : scope.compare(file2, file1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return list.toArray(new PsiClass[list.size()]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
Set<String> names = null;
|
||||
FileIndexFacade facade = FileIndexFacade.getInstance(myProject);
|
||||
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
|
||||
for (PsiFile file : dir.getFiles()) {
|
||||
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
if (vFile != null &&
|
||||
!(file instanceof PsiCompiledElement) &&
|
||||
!facade.isInSourceContent(vFile) &&
|
||||
(!scope.isForceSearchingInLibrarySources() || !StubTreeLoader.getInstance().canHaveStub(vFile))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<String> inFile =
|
||||
file instanceof PsiClassOwnerEx ? ((PsiClassOwnerEx)file).getClassNames() : getClassNames(((PsiClassOwner)file).getClasses());
|
||||
|
||||
if (inFile.isEmpty()) continue;
|
||||
if (names == null) names = new HashSet<String>();
|
||||
names.addAll(inFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return names == null ? Collections.<String>emptySet() : names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processPackageDirectories(@NotNull PsiPackage psiPackage,
|
||||
@NotNull final GlobalSearchScope scope,
|
||||
@NotNull final Processor<PsiDirectory> consumer,
|
||||
boolean includeLibrarySources) {
|
||||
final PsiManager psiManager = PsiManager.getInstance(myProject);
|
||||
return PackageIndex.getInstance(myProject).getDirsByPackageName(psiPackage.getQualifiedName(), includeLibrarySources)
|
||||
.forEach(new ReadActionProcessor<VirtualFile>() {
|
||||
@Override
|
||||
public boolean processInReadAction(final VirtualFile dir) {
|
||||
if (!scope.contains(dir)) return true;
|
||||
PsiDirectory psiDir = psiManager.findDirectory(dir);
|
||||
return psiDir == null || consumer.process(psiDir);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.javadoc;
|
||||
|
||||
import com.intellij.psi.JavaDocTokenType;
|
||||
import com.intellij.psi.JavaElementVisitor;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.psi.javadoc.PsiDocToken;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
@@ -42,6 +45,15 @@ public class PsiDocTokenImpl extends LeafPsiElement implements PsiDocToken{
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferences() {
|
||||
if (getTokenType() == JavaDocTokenType.DOC_COMMENT_DATA) {
|
||||
return ReferenceProvidersRegistry.getReferencesFromProviders(this, PsiDocToken.class);
|
||||
}
|
||||
return super.getReferences();
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "PsiDocToken:" + getTokenType().toString();
|
||||
}
|
||||
|
||||
@@ -61,6 +61,9 @@ public class JavaTreeGenerator implements TreeGenerator {
|
||||
final LanguageLevel level = PsiUtil.getLanguageLevel(original);
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(original.getManager(), new JavaDummyElement(text, MOD_LIST, level), null);
|
||||
final TreeElement modifierListElement = holder.getTreeElement().getFirstChildNode();
|
||||
if (modifierListElement == null) {
|
||||
throw new AssertionError("No modifier list for \"" + text + '\"');
|
||||
}
|
||||
return markGeneratedIfNeeded(original, modifierListElement);
|
||||
}
|
||||
|
||||
@@ -148,7 +151,7 @@ public class JavaTreeGenerator implements TreeGenerator {
|
||||
return Factory.createSingleLeafElement(type, text, 0, text.length(), table, manager, CodeEditUtil.isNodeGenerated(original.getNode()));
|
||||
}
|
||||
|
||||
private static TreeElement markGeneratedIfNeeded(PsiElement original, TreeElement copy) {
|
||||
private static TreeElement markGeneratedIfNeeded(@NotNull PsiElement original, @NotNull TreeElement copy) {
|
||||
if (CodeEditUtil.isNodeGenerated(original.getNode())) {
|
||||
copy.acceptTree(new GeneratedMarkerVisitor());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,8 +97,9 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements
|
||||
@NotNull
|
||||
public PsiExpressionList getArgumentList() {
|
||||
PsiExpressionList list = (PsiExpressionList)findChildByRoleAsPsiElement(ChildRole.ARGUMENT_LIST);
|
||||
if (list != null) return list;
|
||||
LOG.error("Invalid PSI. Children:" + DebugUtil.psiToString(this, false));
|
||||
if (list == null) {
|
||||
LOG.error("Invalid PSI for'" + getText() + ". Parent:" + DebugUtil.psiToString(getParent(), false));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* <a href="http://www.unicode.org/unicode/standard/standard.html">
|
||||
* <i>The Unicode Standard</i></a>
|
||||
*/
|
||||
class LinksInJavaDoc {
|
||||
// Since Java 7 classloading is parallel on parallel capable classloader (http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html)
|
||||
// Parallel classloading avoids deadlocks like https://youtrack.jetbrains.com/issue/IDEA-131621,
|
||||
// Use mailto:webmaster@jetbrains.com to report abuse
|
||||
}
|
||||
@@ -4,10 +4,17 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
|
||||
import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection;
|
||||
import com.intellij.openapi.paths.WebReference;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/javaDoc";
|
||||
@@ -107,6 +114,35 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLinksInJavaDoc() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final List<WebReference> refs = new ArrayList<WebReference>();
|
||||
myFile.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
for(PsiReference ref:element.getReferences()) {
|
||||
if (ref instanceof WebReference) refs.add((WebReference)ref);
|
||||
}
|
||||
|
||||
super.visitElement(element);
|
||||
}
|
||||
});
|
||||
|
||||
String[] targets = {"http://www.unicode.org/unicode/standard/standard.html",
|
||||
"http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html",
|
||||
"https://youtrack.jetbrains.com/issue/IDEA-131621",
|
||||
"mailto:webmaster@jetbrains.com"
|
||||
};
|
||||
assertTrue(refs.size() == targets.length);
|
||||
int i = 0;
|
||||
|
||||
for(WebReference ref:refs) {
|
||||
assertEquals(ref.getCanonicalText(), targets[i++]);
|
||||
assertTrue(ref.isSoft());
|
||||
assertNotNull(ref.resolve());
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest() throws Exception {
|
||||
super.doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package com.intellij.codeInspection
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.ContractInference
|
||||
import com.intellij.psi.PsiAnonymousClass
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
/**
|
||||
@@ -448,6 +450,27 @@ public static boolean isBlank(String s) {
|
||||
assert c == ['null -> true']
|
||||
}
|
||||
|
||||
public void "test no inference for unused anonymous class methods where annotations won't be used anyway"() {
|
||||
def method = PsiTreeUtil.findChildOfType(myFixture.addClass("""
|
||||
class Foo {{
|
||||
new Object() {
|
||||
Object foo() { return null;}
|
||||
};
|
||||
}}"""), PsiAnonymousClass).methods[0]
|
||||
assert ContractInference.inferContracts(method).collect { it as String } == []
|
||||
}
|
||||
|
||||
public void "test inference for used anonymous class methods"() {
|
||||
def method = PsiTreeUtil.findChildOfType(myFixture.addClass("""
|
||||
class Foo {{
|
||||
new Object() {
|
||||
Object foo() { return null;}
|
||||
Object bar() { return foo();}
|
||||
};
|
||||
}}"""), PsiAnonymousClass).methods[0]
|
||||
assert ContractInference.inferContracts(method).collect { it as String } == [' -> null']
|
||||
}
|
||||
|
||||
private String inferContract(String method) {
|
||||
return assertOneElement(inferContracts(method))
|
||||
}
|
||||
|
||||
@@ -132,14 +132,16 @@ public class BytecodeAnalysisIntegrationTest extends JavaCodeInsightFixtureTestC
|
||||
public void testInferredAnnoGutter() {
|
||||
setUpLibraries();
|
||||
openDecompiledClass("org.apache.velocity.util.ExceptionUtils");
|
||||
checkHasGutter("<html><i>@Contract("null,_,_->null")</i> \n" +
|
||||
checkHasGutter("<html><i>Inferred</i> annotations available. Full signature:<p>\n" +
|
||||
"<i>@Contract("null,_,_->null")</i> \n" +
|
||||
"public static Throwable <b>createWithCause</b>(");
|
||||
}
|
||||
|
||||
public void testExternalAnnoGutter() {
|
||||
setUpExternalUpAnnotations();
|
||||
openDecompiledClass("java.lang.Boolean");
|
||||
checkHasGutter("<html>@org.jetbrains.annotations.Contract("null->false") \n" +
|
||||
checkHasGutter("<html>External and <i>inferred</i> annotations available. Full signature:<p>\n" +
|
||||
"@org.jetbrains.annotations.Contract("null->false") \n" +
|
||||
"private static boolean <b>toBoolean</b>(@org.jetbrains.annotations.Nullable String var0)</html>");
|
||||
}
|
||||
|
||||
|
||||
@@ -193,8 +193,7 @@ public class JavacMain {
|
||||
|
||||
private static boolean canUseOptimizedFileManager(JavaCompilingTool compilingTool) {
|
||||
// since java 9 internal API's used by the optimizedFileManager have changed
|
||||
return compilingTool instanceof JavacCompilerTool &&
|
||||
(JAVA_VERSION.contains("1.6") || JAVA_VERSION.contains("1.7") || JAVA_VERSION.contains("1.8"));
|
||||
return compilingTool instanceof JavacCompilerTool && !SystemInfo.isJavaVersionAtLeast("1.9");
|
||||
}
|
||||
|
||||
private static void handleCancelException(DiagnosticOutputConsumer diagnosticConsumer) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiBundle;
|
||||
@@ -27,6 +28,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.search.scope.packageSet.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -88,6 +90,12 @@ public class GlobalSearchScopesCore {
|
||||
return mySet.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return super.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
|
||||
return 0;
|
||||
@@ -255,6 +263,18 @@ public class GlobalSearchScopesCore {
|
||||
}
|
||||
return super.uniteWith(scope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return super.getProject();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Directory '" + myDirectory.getName() + "'";
|
||||
}
|
||||
}
|
||||
|
||||
static class DirectoriesScope extends GlobalSearchScope {
|
||||
@@ -265,6 +285,9 @@ public class GlobalSearchScopesCore {
|
||||
super(project);
|
||||
myWithSubdirectories = withSubdirectories;
|
||||
myDirectories = directories;
|
||||
if (directories.length < 2) {
|
||||
throw new IllegalArgumentException("Expected >1 directories, but got: " + Arrays.asList(directories));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -353,5 +376,27 @@ public class GlobalSearchScopesCore {
|
||||
}
|
||||
return super.uniteWith(scope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return super.getProject();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
if (myDirectories.length == 1) {
|
||||
VirtualFile root = myDirectories[0];
|
||||
return "Directory '" + root.getName() + "'";
|
||||
}
|
||||
return "Directories " + StringUtil.join(myDirectories, new Function<VirtualFile, String>() {
|
||||
@Override
|
||||
public String fun(VirtualFile file) {
|
||||
return "'" + file.getName() + "'";
|
||||
}
|
||||
}, ", ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* A service managing IDEA's 'dumb' mode: when indices are updated in background and the functionality is very much limited.
|
||||
* Only the explicitly allowed functionality is available. Usually it's allowed by implementing {@link com.intellij.openapi.project.DumbAware} interface.
|
||||
* Only the explicitly allowed functionality is available. Usually it's allowed by implementing {@link DumbAware} interface.
|
||||
*
|
||||
* If you want to register a toolwindow, which will be enabled during the dumb mode, please use {@link com.intellij.openapi.wm.ToolWindowManager}'s
|
||||
* registration methods which have 'canWorkInDumMode' parameter.
|
||||
@@ -45,7 +45,7 @@ public abstract class DumbService {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.project.DumbService");
|
||||
|
||||
/**
|
||||
* @see com.intellij.openapi.project.Project#getMessageBus()
|
||||
* @see Project#getMessageBus()
|
||||
*/
|
||||
public static final Topic<DumbModeListener> DUMB_MODE = new Topic<DumbModeListener>("dumb mode", DumbModeListener.class);
|
||||
|
||||
@@ -210,6 +210,26 @@ public abstract class DumbService {
|
||||
return o instanceof DumbAware;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables alternative resolve strategies for the current thread.<p/>
|
||||
*
|
||||
* Normally reference resolution uses index, and hence is not available in dumb mode. In some cases, alternative ways
|
||||
* of performing resolve are available, although much slower. It's impractical to always use these ways because it'll
|
||||
* lead to overloaded CPU (especially given there's also indexing in progress). But for some explicit user actions
|
||||
* (e.g. explicit Goto Declaration) turning these slower methods is beneficial.<p/>
|
||||
*
|
||||
* A typical usage would involve try-finally, where the alternative resolution is first enabled, then an action is performed,
|
||||
* and then alternative resolution is turned off in the finally block.
|
||||
*/
|
||||
public abstract void setAlternativeResolveEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* @return whether alternative resolution is enabled for the current thread.
|
||||
*
|
||||
* @see #setAlternativeResolveEnabled(boolean)
|
||||
*/
|
||||
public abstract boolean isAlternativeResolveEnabled();
|
||||
|
||||
/**
|
||||
* @see #DUMB_MODE
|
||||
*/
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package com.intellij.psi.search;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -42,7 +44,7 @@ public class NonClasspathDirectoriesScope extends GlobalSearchScope {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GlobalSearchScope compose(List<VirtualFile> roots) {
|
||||
public static GlobalSearchScope compose(@NotNull List<VirtualFile> roots) {
|
||||
if (roots.isEmpty()) {
|
||||
return EMPTY_SCOPE;
|
||||
}
|
||||
@@ -88,4 +90,19 @@ public class NonClasspathDirectoriesScope extends GlobalSearchScope {
|
||||
result = 31 * result + myRoots.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
if (myRoots.size() == 1) {
|
||||
VirtualFile root = myRoots.iterator().next();
|
||||
return "Directory '" + root.getName() + "'";
|
||||
}
|
||||
return "Directories " + StringUtil.join(myRoots, new Function<VirtualFile, String>() {
|
||||
@Override
|
||||
public String fun(VirtualFile file) {
|
||||
return "'" + file.getName() + "'";
|
||||
}
|
||||
}, ", ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,15 @@ public class MockDumbService extends DumbService {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlternativeResolveEnabled(boolean enabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlternativeResolveEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void smartInvokeLater(@NotNull final Runnable runnable) {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -83,7 +83,17 @@ public interface DocumentEx extends Document {
|
||||
@NotNull
|
||||
List<RangeMarker> getGuardedBlocks();
|
||||
|
||||
|
||||
/**
|
||||
* Get all range markers
|
||||
* and hand them to the {@code processor} in their {@link RangeMarker#getStartOffset()} order
|
||||
*/
|
||||
boolean processRangeMarkers(@NotNull Processor<RangeMarker> processor);
|
||||
|
||||
/**
|
||||
* Get range markers which {@link com.intellij.openapi.util.TextRange#intersects(int, int)} the specified range
|
||||
* and hand them to the {@code processor} in their {@link RangeMarker#getStartOffset()} order
|
||||
*/
|
||||
boolean processRangeMarkersOverlappingWith(int start, int end, @NotNull Processor<RangeMarker> processor);
|
||||
}
|
||||
|
||||
|
||||
@@ -332,11 +332,11 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
}
|
||||
}
|
||||
|
||||
public ReadonlyFragmentModificationHandler getReadonlyFragmentModificationHandler() {
|
||||
ReadonlyFragmentModificationHandler getReadonlyFragmentModificationHandler() {
|
||||
return myReadonlyFragmentModificationHandler;
|
||||
}
|
||||
|
||||
public void setReadonlyFragmentModificationHandler(final ReadonlyFragmentModificationHandler readonlyFragmentModificationHandler) {
|
||||
void setReadonlyFragmentModificationHandler(final ReadonlyFragmentModificationHandler readonlyFragmentModificationHandler) {
|
||||
myReadonlyFragmentModificationHandler = readonlyFragmentModificationHandler;
|
||||
}
|
||||
|
||||
@@ -364,13 +364,13 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public int getRangeMarkersSize() {
|
||||
int getRangeMarkersSize() {
|
||||
return myRangeMarkers.size() + myPersistentRangeMarkers.size();
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public int getRangeMarkersNodeSize() {
|
||||
return myRangeMarkers.nodeSize()+myPersistentRangeMarkers.size();
|
||||
int getRangeMarkersNodeSize() {
|
||||
return myRangeMarkers.nodeSize()+myPersistentRangeMarkers.nodeSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -693,7 +693,7 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
getLineSet().clearModificationFlags();
|
||||
}
|
||||
|
||||
public void clearLineModificationFlagsExcept(@NotNull int[] caretLines) {
|
||||
void clearLineModificationFlagsExcept(@NotNull int[] caretLines) {
|
||||
IntArrayList modifiedLines = new IntArrayList(caretLines.length);
|
||||
LineSet lineSet = getLineSet();
|
||||
for (int line : caretLines) {
|
||||
@@ -716,8 +716,8 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
assertNotNestedModification();
|
||||
boolean enableRecursiveModifications = Registry.is("enable.recursive.document.changes"); // temporary property, to remove in IDEA 16
|
||||
myChangeInProgress = true;
|
||||
final DocumentEvent event;
|
||||
try {
|
||||
final DocumentEvent event;
|
||||
try {
|
||||
event = doBeforeChangedUpdate(offset, oldString, newString, wholeTextReplaced);
|
||||
}
|
||||
@@ -742,11 +742,9 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (app != null) {
|
||||
FileDocumentManager manager = FileDocumentManager.getInstance();
|
||||
if (manager != null) {
|
||||
VirtualFile file = manager.getFile(this);
|
||||
if (file != null && !file.isValid()) {
|
||||
LOG.error("File of this document has been deleted.");
|
||||
}
|
||||
VirtualFile file = manager.getFile(this);
|
||||
if (file != null && !file.isValid()) {
|
||||
LOG.error("File of this document has been deleted.");
|
||||
}
|
||||
}
|
||||
assertInsideCommand();
|
||||
@@ -878,9 +876,9 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
private final Ref<DocumentListener[]> myCachedDocumentListenersRef;
|
||||
private final List<DocumentListener> myDocumentListeners;
|
||||
|
||||
public DocumentListenerDisposable(@NotNull DocumentListener listener,
|
||||
@NotNull Ref<DocumentListener[]> cachedDocumentListenersRef,
|
||||
@NotNull List<DocumentListener> documentListeners) {
|
||||
private DocumentListenerDisposable(@NotNull DocumentListener listener,
|
||||
@NotNull Ref<DocumentListener[]> cachedDocumentListenersRef,
|
||||
@NotNull List<DocumentListener> documentListeners) {
|
||||
myListener = listener;
|
||||
myCachedDocumentListenersRef = cachedDocumentListenersRef;
|
||||
myDocumentListeners = documentListeners;
|
||||
@@ -1085,7 +1083,7 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
return "DocumentImpl[" + FileDocumentManager.getInstance().getFile(this) + "]";
|
||||
}
|
||||
|
||||
public void requestTabTracking() {
|
||||
void requestTabTracking() {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
if (myTabTrackingRequestors++ == 0) {
|
||||
myMightContainTabs = false;
|
||||
@@ -1093,14 +1091,14 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
}
|
||||
}
|
||||
|
||||
public void giveUpTabTracking() {
|
||||
void giveUpTabTracking() {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
if (--myTabTrackingRequestors == 0) {
|
||||
myMightContainTabs = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mightContainTabs() {
|
||||
boolean mightContainTabs() {
|
||||
return myMightContainTabs;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.progress.util;
|
||||
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
@@ -28,6 +29,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class TooManyUsagesStatus {
|
||||
private static final Key<TooManyUsagesStatus> KEY = Key.create("TooManyUsagesStatus");
|
||||
private static final NullStatus NULL_STATUS = new NullStatus();
|
||||
private final ProgressIndicator myIndicator;
|
||||
|
||||
private TooManyUsagesStatus(@NotNull ProgressIndicator indicator) {
|
||||
myIndicator = indicator;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TooManyUsagesStatus getFrom(@Nullable ProgressIndicator indicator) {
|
||||
@@ -38,7 +44,7 @@ public class TooManyUsagesStatus {
|
||||
public static TooManyUsagesStatus createFor(@NotNull ProgressIndicator indicator) {
|
||||
TooManyUsagesStatus data = null;
|
||||
if (indicator instanceof UserDataHolder) {
|
||||
data = new TooManyUsagesStatus();
|
||||
data = new TooManyUsagesStatus(indicator);
|
||||
((UserDataHolder)indicator).putUserData(KEY, data);
|
||||
}
|
||||
return data;
|
||||
@@ -65,8 +71,12 @@ public class TooManyUsagesStatus {
|
||||
public void pauseProcessingIfTooManyUsages() {
|
||||
if (tooManyUsagesStatus.get() == Status.WARNING_DIALOG_SHOWN) {
|
||||
//assert ApplicationManager.getApplication().isDispatchThread() || !ApplicationManager.getApplication().isReadAccessAllowed();
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
waitWhileUserClick.await(1, TimeUnit.SECONDS);
|
||||
while (System.currentTimeMillis() < start + 1000) {
|
||||
if (waitWhileUserClick.await(10, TimeUnit.MILLISECONDS)) break;
|
||||
if (myIndicator.isCanceled()) break;
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ignored) {
|
||||
}
|
||||
@@ -74,6 +84,10 @@ public class TooManyUsagesStatus {
|
||||
}
|
||||
|
||||
private static class NullStatus extends TooManyUsagesStatus {
|
||||
private NullStatus() {
|
||||
super(new EmptyProgressIndicator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean switchTooManyUsagesStatus() {
|
||||
return false;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.source.tree.MarkersHolderFileViewProvider;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.reference.SoftReference;
|
||||
import com.intellij.util.containers.UnsafeWeakList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -143,6 +144,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
|
||||
@NotNull
|
||||
public <E extends PsiElement> SmartPsiElementPointer<E> createSmartPsiElementPointer(@NotNull E element, PsiFile containingFile) {
|
||||
if (containingFile != null && !containingFile.isValid() || containingFile == null && !element.isValid()) {
|
||||
PsiUtilCore.ensureValid(element);
|
||||
LOG.error("Invalid element:" + element);
|
||||
}
|
||||
SmartPointerEx<E> pointer = getCachedPointer(element);
|
||||
|
||||
|
Before Width: | Height: | Size: 528 B After Width: | Height: | Size: 130 B |
|
After Width: | Height: | Size: 253 B |
|
After Width: | Height: | Size: 245 B |
|
After Width: | Height: | Size: 133 B |
|
Before Width: | Height: | Size: 687 B After Width: | Height: | Size: 384 B |
|
After Width: | Height: | Size: 516 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1022 B |
|
After Width: | Height: | Size: 843 B |
|
Before Width: | Height: | Size: 754 B After Width: | Height: | Size: 474 B |
|
After Width: | Height: | Size: 598 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 593 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 506 B |
|
Before Width: | Height: | Size: 482 B After Width: | Height: | Size: 252 B |
|
After Width: | Height: | Size: 419 B |
|
After Width: | Height: | Size: 406 B |
|
After Width: | Height: | Size: 255 B |
|
Before Width: | Height: | Size: 503 B After Width: | Height: | Size: 503 B |
|
Before Width: | Height: | Size: 735 B After Width: | Height: | Size: 531 B |
|
After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 552 B After Width: | Height: | Size: 552 B |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 641 B After Width: | Height: | Size: 378 B |
|
After Width: | Height: | Size: 655 B |
|
Before Width: | Height: | Size: 797 B After Width: | Height: | Size: 558 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 682 B After Width: | Height: | Size: 244 B |
|
After Width: | Height: | Size: 523 B |
|
Before Width: | Height: | Size: 162 B After Width: | Height: | Size: 116 B |
|
After Width: | Height: | Size: 138 B |
|
After Width: | Height: | Size: 141 B |
|
After Width: | Height: | Size: 120 B |
|
Before Width: | Height: | Size: 686 B After Width: | Height: | Size: 266 B |
|
After Width: | Height: | Size: 393 B |
|
After Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 343 B |
|
After Width: | Height: | Size: 528 B |
|
After Width: | Height: | Size: 529 B |
|
After Width: | Height: | Size: 336 B |
|
After Width: | Height: | Size: 263 B |
|
Before Width: | Height: | Size: 759 B After Width: | Height: | Size: 513 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 141 B After Width: | Height: | Size: 234 B |
|
After Width: | Height: | Size: 453 B |
|
After Width: | Height: | Size: 456 B |
|
After Width: | Height: | Size: 232 B |
|
Before Width: | Height: | Size: 788 B After Width: | Height: | Size: 554 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 797 B After Width: | Height: | Size: 537 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 711 B After Width: | Height: | Size: 305 B |