mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
public class X {
|
||||
}
|
||||
|
||||
class MyClass1 {}
|
||||
|
||||
/**
|
||||
* {@link #MyClass1Impl()}
|
||||
*/
|
||||
class MyClass1Impl extends MyClass1 {
|
||||
MyClass1Impl() {
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
public class X {
|
||||
}
|
||||
|
||||
class MyClass {}
|
||||
|
||||
/**
|
||||
* {@link #MyClassImpl()}
|
||||
*/
|
||||
class MyClassImpl extends MyClass {
|
||||
MyClassImpl() {
|
||||
}
|
||||
}
|
||||
@@ -54,12 +54,16 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testAutomaticRenameVars() throws Exception {
|
||||
doRenameClass("XX", "Y");
|
||||
}
|
||||
|
||||
private void doRenameClass(final String className, final String newName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("XX", GlobalSearchScope.allScope(getProject()));
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class XX not found", aClass);
|
||||
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, aClass, "Y", true, true) {
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, aClass, newName, true, true) {
|
||||
@Override
|
||||
protected boolean showAutomaticRenamingDialog(AutomaticRenamer automaticVariableRenamer) {
|
||||
for (PsiNamedElement element : automaticVariableRenamer.getElements()) {
|
||||
@@ -78,6 +82,10 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
public void testAutomaticRenameInheritors() throws Exception {
|
||||
doRenameClass("MyClass", "MyClass1");
|
||||
}
|
||||
|
||||
public void testAutomaticRenameVarsCollision() throws Exception {
|
||||
doTest("XX", "Y");
|
||||
}
|
||||
|
||||
@@ -8,99 +8,21 @@
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.projectView.impl.ModuleGroup;
|
||||
import com.intellij.ide.projectView.impl.nodes.LibraryGroupElement;
|
||||
import com.intellij.ide.projectView.impl.nodes.NamedLibraryElement;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.ide.projectView.impl.GroupByTypeComparator;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.SmartPsiElementPointer;
|
||||
|
||||
import java.util.Comparator;
|
||||
public class FavoritesComparator extends GroupByTypeComparator {
|
||||
|
||||
public class FavoritesComparator implements Comparator<NodeDescriptor> {
|
||||
private final FavoriteNodeProvider[] myNodeProviders;
|
||||
private final boolean mySortByType;
|
||||
|
||||
public FavoritesComparator(final boolean sortByType, final Project project) {
|
||||
mySortByType = sortByType;
|
||||
myNodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project);
|
||||
}
|
||||
|
||||
private int getWeight(NodeDescriptor descriptor) {
|
||||
FavoritesTreeNodeDescriptor favoritesTreeNodeDescriptor = (FavoritesTreeNodeDescriptor)descriptor;
|
||||
Object value = favoritesTreeNodeDescriptor.getElement().getValue();
|
||||
if (value instanceof SmartPsiElementPointer){
|
||||
value = ((SmartPsiElementPointer)value).getElement();
|
||||
}
|
||||
if (value instanceof ModuleGroup){
|
||||
return 0;
|
||||
}
|
||||
if (value instanceof Module){
|
||||
return 1;
|
||||
}
|
||||
if (value instanceof PsiDirectory){
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (value instanceof PsiFile){
|
||||
return 6;
|
||||
}
|
||||
if (value instanceof PsiElement){
|
||||
return 7;
|
||||
}
|
||||
if (value instanceof LibraryGroupElement){
|
||||
return 8;
|
||||
}
|
||||
if (value instanceof NamedLibraryElement){
|
||||
return 9;
|
||||
}
|
||||
for(FavoriteNodeProvider provider: myNodeProviders) {
|
||||
int weight = provider.getElementWeight(value, mySortByType);
|
||||
if (weight != -1) return weight;
|
||||
}
|
||||
return 9;
|
||||
public FavoritesComparator(ProjectView projectView, String paneId) {
|
||||
super(projectView, paneId);
|
||||
}
|
||||
|
||||
public int compare(NodeDescriptor nd1, NodeDescriptor nd2) {
|
||||
if (nd1 instanceof FavoritesTreeNodeDescriptor && nd2 instanceof FavoritesTreeNodeDescriptor){
|
||||
FavoritesTreeNodeDescriptor fd1 = (FavoritesTreeNodeDescriptor)nd1;
|
||||
FavoritesTreeNodeDescriptor fd2 = (FavoritesTreeNodeDescriptor)nd2;
|
||||
int weight1 = getWeight(fd1);
|
||||
int weight2 = getWeight(fd2);
|
||||
if (weight1 != weight2) {
|
||||
if (mySortByType) {
|
||||
if (weight1 < 10) {
|
||||
if (weight2 > 10) {//class kind
|
||||
weight2 = 3;
|
||||
}
|
||||
}
|
||||
else if (weight2 < 10) {
|
||||
if (weight1 > 10) {
|
||||
weight1 = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
return weight1 - weight2;
|
||||
}
|
||||
String s1 = fd1.toString();
|
||||
String s2 = fd2.toString();
|
||||
if (s1 == null) return s2 == null ? 0 : -1;
|
||||
if (s2 == null) return +1;
|
||||
if (!s1.equals(s2)) {
|
||||
return s1.compareToIgnoreCase(s2);
|
||||
}
|
||||
else {
|
||||
s1 = fd1.getLocation();
|
||||
s2 = fd2.getLocation();
|
||||
if (s1 == null) return s2 == null ? 0 : -1;
|
||||
if (s2 == null) return +1;
|
||||
return s1.compareToIgnoreCase(s2);
|
||||
}
|
||||
return super.compare(fd1.getElement(), fd2.getElement());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class FavoritesProjectViewPane extends AbstractProjectViewPane {
|
||||
|
||||
public void installComparator() {
|
||||
final ProjectView projectView = ProjectView.getInstance(myProject);
|
||||
getTreeBuilder().setNodeDescriptorComparator(new FavoritesComparator(projectView.isSortByType(ID), myProject));
|
||||
getTreeBuilder().setNodeDescriptorComparator(new FavoritesComparator(projectView, ID));
|
||||
}
|
||||
|
||||
public JComponent createComponent() {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class GroupByTypeComparator implements Comparator<NodeDescriptor> {
|
||||
return AlphaComparator.INSTANCE.compare(descriptor1, descriptor2);
|
||||
}
|
||||
|
||||
private boolean isSortByType() {
|
||||
protected boolean isSortByType() {
|
||||
if (myProjectView != null) {
|
||||
return myProjectView.isSortByType(myPaneId);
|
||||
}
|
||||
|
||||
@@ -99,16 +99,16 @@ public class RenameProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
public void doRun() {
|
||||
prepareRenaming();
|
||||
prepareRenaming(myPrimaryElement, myNewName, myAllRenames);
|
||||
|
||||
super.doRun();
|
||||
}
|
||||
|
||||
public void prepareRenaming() {
|
||||
final List<RenamePsiElementProcessor> processors = RenamePsiElementProcessor.allForElement(myPrimaryElement);
|
||||
public void prepareRenaming(final PsiElement element, final String newName, final LinkedHashMap<PsiElement, String> allRenames) {
|
||||
final List<RenamePsiElementProcessor> processors = RenamePsiElementProcessor.allForElement(element);
|
||||
myForceShowPreview = false;
|
||||
for (RenamePsiElementProcessor processor : processors) {
|
||||
processor.prepareRenaming(myPrimaryElement, myNewName, myAllRenames);
|
||||
processor.prepareRenaming(element, newName, allRenames);
|
||||
myForceShowPreview |= processor.forcesShowPreview();
|
||||
}
|
||||
}
|
||||
@@ -145,15 +145,33 @@ public class RenameProcessor extends BaseRefactoringProcessor {
|
||||
final List<UsageInfo> variableUsages = new ArrayList<UsageInfo>();
|
||||
if (!myRenamers.isEmpty()) {
|
||||
if (!findRenamedVariables(variableUsages)) return false;
|
||||
final LinkedHashMap<PsiElement, String> renames = new LinkedHashMap<PsiElement, String>();
|
||||
for (final AutomaticRenamer renamer : myRenamers) {
|
||||
final List<? extends PsiNamedElement> variables = renamer.getElements();
|
||||
for (final PsiNamedElement variable : variables) {
|
||||
final String newName = renamer.getNewName(variable);
|
||||
if (newName != null) {
|
||||
addElement(variable, newName);
|
||||
prepareRenaming(variable, newName, renames);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!renames.isEmpty()) {
|
||||
myAllRenames.putAll(renames);
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
for (Map.Entry<PsiElement, String> entry : renames.entrySet()) {
|
||||
final UsageInfo[] usages =
|
||||
RenameUtil.findUsages(entry.getKey(), entry.getValue(), mySearchInComments, mySearchTextOccurrences, myAllRenames);
|
||||
Collections.addAll(variableUsages, usages);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!ProgressManager.getInstance()
|
||||
.runProcessWithProgressSynchronously(runnable, RefactoringBundle.message("searching.for.variables"), true, myProject)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!variableUsages.isEmpty()) {
|
||||
@@ -349,7 +367,7 @@ public class RenameProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
protected void prepareTestRun() {
|
||||
if (!PsiElementRenameHandler.canRename(myProject, null, myPrimaryElement)) return;
|
||||
prepareRenaming();
|
||||
prepareRenaming(myPrimaryElement, myNewName, myAllRenames);
|
||||
}
|
||||
|
||||
public Collection<String> getNewNames() {
|
||||
|
||||
Reference in New Issue
Block a user