From 371ac598970d11948179e5561860808bf0d84ae0 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 26 Jul 2010 15:20:03 +0400 Subject: [PATCH 01/17] Git: git log tree, allow to choose jars in structure filter --- .../src/git4idea/history/browser/GitLogTreeFileSelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/history/browser/GitLogTreeFileSelector.java b/plugins/git4idea/src/git4idea/history/browser/GitLogTreeFileSelector.java index 57d198b7a5db..a213c28ba2bb 100644 --- a/plugins/git4idea/src/git4idea/history/browser/GitLogTreeFileSelector.java +++ b/plugins/git4idea/src/git4idea/history/browser/GitLogTreeFileSelector.java @@ -54,7 +54,7 @@ public class GitLogTreeFileSelector extends DialogWrapper { } private void initUi() { - final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true); + final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, true); descriptor.setRoot(myRoot); myFileSystemTree = FileSystemTreeFactory.SERVICE.getInstance().createFileSystemTree(myProject, descriptor); final JTree tree = myFileSystemTree.getTree(); From 2ffaef856fc976d6b50b26521b2905c25a562397 Mon Sep 17 00:00:00 2001 From: irengrig Date: Tue, 27 Jul 2010 12:01:22 +0400 Subject: [PATCH 02/17] VCS: correctly [automatically] detect vcs --- .../openapi/vcs/actions/AbstractVcsAction.java | 2 +- .../vcs/actions/DescindingFilesFilter.java | 6 +----- .../vcs/impl/ProjectLevelVcsManagerImpl.java | 15 ++++++++++++++- .../vcs/update/AbstractCommonUpdateAction.java | 11 +---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractVcsAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractVcsAction.java index 57a3a3b518af..c27f0fcb87d8 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractVcsAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractVcsAction.java @@ -42,7 +42,7 @@ public abstract class AbstractVcsAction extends AsyncUpdateAction im @NotNull protected static FilePath[] filterDescindingFiles(@NotNull FilePath[] roots, Project project) { - return DescindingFilesFilter.filterDescindingFiles(roots, project, null); + return DescindingFilesFilter.filterDescindingFiles(roots, project); } protected VcsContext prepareDataFromContext(final AnActionEvent e) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/DescindingFilesFilter.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/DescindingFilesFilter.java index 2b7d5308b3c3..6ec2f5069641 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/DescindingFilesFilter.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/DescindingFilesFilter.java @@ -16,15 +16,12 @@ package com.intellij.openapi.vcs.actions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsKey; import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.util.containers.Convertor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.*; @@ -33,8 +30,7 @@ public class DescindingFilesFilter { } @NotNull - public static FilePath[] filterDescindingFiles(@NotNull FilePath[] roots, Project project, - @Nullable final Convertor, Boolean> pathsFilter) { + public static FilePath[] filterDescindingFiles(@NotNull FilePath[] roots, Project project) { final List result = new LinkedList(); ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index c9fe936a8ca9..667053d780e9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -658,9 +658,22 @@ public void addMessageToConsoleWindow(final String message, final TextAttributes return !myHaveLegacyVcsConfiguration && !myMappingsLoaded; } + /** + * Used to guess VCS for automatic mapping through a look into a working copy + */ @Nullable public AbstractVcs findVersioningVcs(VirtualFile file) { - return getVcsFor(file); + final VcsDescriptor[] vcsDescriptors = getAllVcss(); + VcsDescriptor probableVcs = null; + for (VcsDescriptor vcsDescriptor : vcsDescriptors) { + if (vcsDescriptor.probablyUnderVcs(file)) { + if (probableVcs != null) { + return null; + } + probableVcs = vcsDescriptor; + } + } + return probableVcs == null ? null : findVcsByName(probableVcs.getName()); } public CheckoutProvider.Listener getCompositeCheckoutListener() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java index 2e2faf070455..30287ce60626 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java @@ -31,7 +31,6 @@ import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.ui.MessageType; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.actions.AbstractVcsAction; @@ -50,7 +49,6 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.util.containers.Convertor; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.OptionsDialog; import com.intellij.vcsUtil.VcsUtil; @@ -84,14 +82,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { if (project != null) { try { final FilePath[] filePaths = myScopeInfo.getRoots(context, myActionInfo); - final FilePath[] roots = DescindingFilesFilter.filterDescindingFiles(filterRoots(filePaths, context), project, - new Convertor, Boolean>() { - public Boolean convert(Pair pair) { - final AbstractVcs vcs = pair.getSecond(); - final FilePath fp = pair.getFirst(); - return vcs.isVersionedDirectory(fp.getVirtualFile()); - } - }); + final FilePath[] roots = DescindingFilesFilter.filterDescindingFiles(filterRoots(filePaths, context), project); if (roots.length == 0) { return; } From 1b28cabde8f49be107ac605832d72fc52dc510c4 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Tue, 27 Jul 2010 13:31:33 +0400 Subject: [PATCH 03/17] Empty tags are back. --- plugins/git4idea/git4idea.iml | 1 + plugins/groovy/jetgroovy.iml | 2 ++ plugins/maven/facade-api/maven-facade-api.iml | 2 ++ .../maven/facade-impl/maven-facade-impl.iml | 28 +++++++++++++++++++ plugins/relaxng/relaxng.iml | 7 +++++ plugins/svn4idea/svn4idea-tests.iml | 3 ++ plugins/svn4idea/svn4idea.iml | 5 ++++ 7 files changed, 48 insertions(+) diff --git a/plugins/git4idea/git4idea.iml b/plugins/git4idea/git4idea.iml index 5fa1b17970c1..aa21265058b8 100644 --- a/plugins/git4idea/git4idea.iml +++ b/plugins/git4idea/git4idea.iml @@ -16,6 +16,7 @@ + diff --git a/plugins/groovy/jetgroovy.iml b/plugins/groovy/jetgroovy.iml index 75c0ecccfd80..c01f8d1bd815 100644 --- a/plugins/groovy/jetgroovy.iml +++ b/plugins/groovy/jetgroovy.iml @@ -26,6 +26,8 @@ + + diff --git a/plugins/maven/facade-api/maven-facade-api.iml b/plugins/maven/facade-api/maven-facade-api.iml index 56173f227d95..8ba63b8dc7db 100644 --- a/plugins/maven/facade-api/maven-facade-api.iml +++ b/plugins/maven/facade-api/maven-facade-api.iml @@ -14,6 +14,8 @@ + + diff --git a/plugins/maven/facade-impl/maven-facade-impl.iml b/plugins/maven/facade-impl/maven-facade-impl.iml index ae61f67a346f..9240cd8ba91c 100644 --- a/plugins/maven/facade-impl/maven-facade-impl.iml +++ b/plugins/maven/facade-impl/maven-facade-impl.iml @@ -16,6 +16,8 @@ + + @@ -23,6 +25,8 @@ + + @@ -30,6 +34,8 @@ + + @@ -37,6 +43,8 @@ + + @@ -44,6 +52,8 @@ + + @@ -51,6 +61,8 @@ + + @@ -58,6 +70,8 @@ + + @@ -65,6 +79,8 @@ + + @@ -72,6 +88,8 @@ + + @@ -79,6 +97,8 @@ + + @@ -86,6 +106,8 @@ + + @@ -93,6 +115,8 @@ + + @@ -100,6 +124,8 @@ + + @@ -107,6 +133,8 @@ + + diff --git a/plugins/relaxng/relaxng.iml b/plugins/relaxng/relaxng.iml index 6ff34b95fc39..d7d35d40c904 100644 --- a/plugins/relaxng/relaxng.iml +++ b/plugins/relaxng/relaxng.iml @@ -18,6 +18,7 @@ + @@ -28,6 +29,8 @@ + + @@ -35,6 +38,8 @@ + + @@ -42,6 +47,8 @@ + + diff --git a/plugins/svn4idea/svn4idea-tests.iml b/plugins/svn4idea/svn4idea-tests.iml index 5039b6b4a9f5..798757278775 100644 --- a/plugins/svn4idea/svn4idea-tests.iml +++ b/plugins/svn4idea/svn4idea-tests.iml @@ -16,6 +16,7 @@ + @@ -29,6 +30,8 @@ + + diff --git a/plugins/svn4idea/svn4idea.iml b/plugins/svn4idea/svn4idea.iml index e00b72d68d9c..fd765b400568 100644 --- a/plugins/svn4idea/svn4idea.iml +++ b/plugins/svn4idea/svn4idea.iml @@ -22,6 +22,7 @@ + @@ -32,6 +33,8 @@ + + @@ -40,6 +43,8 @@ + + From 9ada5b49244247daef20ea6471d8567425a90736 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 27 Jul 2010 13:52:32 +0400 Subject: [PATCH 04/17] IDEA-56795 Groovy method does not resolve --- .../jetbrains/plugins/groovy/gpp/GppTypeConverter.java | 2 +- .../plugins/groovy/lang/psi/impl/GrMapType.java | 2 ++ .../plugins/groovy/lang/GroovyHighlightingTest.java | 6 +++++- .../highlighting/MapNotAcceptedAsStringParameter.groovy | 7 +++++++ .../method/mapNotAcceptedAsStringParameter/A.groovy | 9 +++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 plugins/groovy/testdata/highlighting/MapNotAcceptedAsStringParameter.groovy create mode 100644 plugins/groovy/testdata/resolve/method/mapNotAcceptedAsStringParameter/A.groovy diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppTypeConverter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppTypeConverter.java index b03125b76fd1..a41d82ebd46e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppTypeConverter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/gpp/GppTypeConverter.java @@ -71,7 +71,7 @@ public class GppTypeConverter extends GrTypeConverter { return true; } - if (hasDefaultConstructor(lType)) { + if (!isMethodCallConversion(context) && hasDefaultConstructor(lType)) { return true; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrMapType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrMapType.java index 3fbe912f1cc7..2d92fec1267d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrMapType.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrMapType.java @@ -109,6 +109,8 @@ public class GrMapType extends GrLiteralClassType { } public String getInternalCanonicalText() { + if (myStringEntries.size() == 0) return "[:]"; + List components = new ArrayList(); for (String s : myStringEntries.keySet()) { components.add("'" + s + "':" + getInternalCanonicalText(myStringEntries.get(s))); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index 6a29d6fb27f8..63a106b42e52 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -68,7 +68,7 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { doTest(); } - private void doTest(LocalInspectionTool... tools) throws Exception { + private void doTest(LocalInspectionTool... tools) { myFixture.enableInspections(tools); myFixture.testHighlighting(true, false, false, getTestName(false) + ".groovy"); } @@ -280,4 +280,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { } public void testNumberDuplicatesInMaps() throws Exception {doTest();} + + public void testMapNotAcceptedAsStringParameter() { + doTest(); + } } \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/MapNotAcceptedAsStringParameter.groovy b/plugins/groovy/testdata/highlighting/MapNotAcceptedAsStringParameter.groovy new file mode 100644 index 000000000000..8126990df539 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/MapNotAcceptedAsStringParameter.groovy @@ -0,0 +1,7 @@ +class A { + void method(String m) {} + + { + method([:]) + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/resolve/method/mapNotAcceptedAsStringParameter/A.groovy b/plugins/groovy/testdata/resolve/method/mapNotAcceptedAsStringParameter/A.groovy new file mode 100644 index 000000000000..502c53f40771 --- /dev/null +++ b/plugins/groovy/testdata/resolve/method/mapNotAcceptedAsStringParameter/A.groovy @@ -0,0 +1,9 @@ +class A { + void method(Map m, Closure e ) {} + void method(String m) {} + +{ +method([:]) +} + +} \ No newline at end of file From 0d493420efe5125d29ecb009ea10a98810ca05f4 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 27 Jul 2010 14:08:28 +0400 Subject: [PATCH 05/17] cosmetics --- .../indexing/FileBasedIndexProjectHandler.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java index 73604f7878d7..ad5e603357b1 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java @@ -51,17 +51,17 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple if (startupManager != null) { startupManager.registerPreStartupActivity(new Runnable() { public void run() { - final RefreshCacheUpdater refreshUpdater = new RefreshCacheUpdater(); - final UnindexedFilesUpdater rootsChangeUpdater = new UnindexedFilesUpdater(project, index); + final RefreshCacheUpdater changedFilesUpdater = new RefreshCacheUpdater(); + final UnindexedFilesUpdater unindexedFilesUpdater = new UnindexedFilesUpdater(project, index); - startupManager.registerCacheUpdater(rootsChangeUpdater); - rootManager.registerRootsChangeUpdater(rootsChangeUpdater); - rootManager.registerRefreshUpdater(refreshUpdater); + startupManager.registerCacheUpdater(unindexedFilesUpdater); + rootManager.registerRootsChangeUpdater(unindexedFilesUpdater); + rootManager.registerRefreshUpdater(changedFilesUpdater); myIndex.registerIndexableSet(FileBasedIndexProjectHandler.this, project); projectManager.addProjectManagerListener(project, new ProjectManagerAdapter() { public void projectClosing(Project project) { - rootManager.unregisterRefreshUpdater(refreshUpdater); - rootManager.unregisterRootsChangeUpdater(rootsChangeUpdater); + rootManager.unregisterRefreshUpdater(changedFilesUpdater); + rootManager.unregisterRootsChangeUpdater(unindexedFilesUpdater); myIndex.removeIndexableSet(FileBasedIndexProjectHandler.this); } }); From bde13841d71cb956459f0147c953822e0e57cf42 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 27 Jul 2010 14:10:11 +0400 Subject: [PATCH 06/17] do not defer dumb mode start to ensure changed files are processed in dumb mode if needed --- .../openapi/roots/impl/ProjectRootManagerImpl.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java index 39d89a5f576e..1034ec9e6e20 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java @@ -35,7 +35,6 @@ import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.impl.ModuleImpl; import com.intellij.openapi.module.impl.scopes.JdkScope; import com.intellij.openapi.module.impl.scopes.LibraryRuntimeClasspathScope; -import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.DumbServiceImpl; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ex.ProjectEx; @@ -619,11 +618,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj return; // in test mode suppress addition to a queue unless project is properly initialized } } - myStartupManager.runWhenProjectIsInitialized(new DumbAwareRunnable() { - public void run() { - DumbServiceImpl.getInstance(myProject).queueCacheUpdate(myRefreshCacheUpdaters); - } - }); + DumbServiceImpl.getInstance(myProject).queueCacheUpdate(myRefreshCacheUpdaters); } private void addRootsToWatch() { From cb91fdde47b181691778aaeb0167124993803a82 Mon Sep 17 00:00:00 2001 From: irengrig Date: Tue, 27 Jul 2010 14:39:18 +0400 Subject: [PATCH 07/17] VCS: fix deadlock (do not invoke read action under inner lock) --- .../intellij/openapi/vcs/changes/ChangeListManagerImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java index 794398d88685..295cea12e625 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java @@ -38,6 +38,7 @@ import com.intellij.openapi.vcs.checkin.CheckinHandler; import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; import com.intellij.openapi.vcs.impl.VcsInitObject; import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl; +import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.EditorNotifications; @@ -1084,7 +1085,9 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec @Nullable private VcsKey findVcs(final String path) { // does not matter directory or not - final AbstractVcs vcs = myVcsManager.getVcsFor(FilePathImpl.create(new File(path), false)); + final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path)); + if (vf == null) return null; + final AbstractVcs vcs = myVcsManager.getVcsFor(vf); return vcs == null ? null : vcs.getKeyInstanceMethod(); } } From 6cee0d855fe6671530cd093f950094811e1a1cc0 Mon Sep 17 00:00:00 2001 From: Maxim Medvedev Date: Tue, 27 Jul 2010 14:57:26 +0400 Subject: [PATCH 08/17] IDEA-56701 'Assignment not used' for variables passed into an anonymous class constructor --- .../unusedDef/UnusedDefInspection.java | 49 ++++++++++++------- .../controlFlow/impl/ControlFlowBuilder.java | 19 ++++--- .../highlighting/IfIncrementElseReturn.groovy | 2 +- .../highlighting/PrefixIncrementCfa.groovy | 2 +- .../highlighting/UnusedVariable.groovy | 2 +- 5 files changed, 47 insertions(+), 27 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java index 6f0aa265a5a9..5468100a25b4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/unusedDef/UnusedDefInspection.java @@ -15,25 +15,35 @@ */ package org.jetbrains.plugins.groovy.codeInspection.unusedDef; -import com.intellij.codeInspection.*; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Processor; -import gnu.trove.*; -import org.jetbrains.annotations.*; +import gnu.trove.TIntHashSet; +import gnu.trove.TIntObjectHashMap; +import gnu.trove.TIntProcedure; +import gnu.trove.TObjectProcedure; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle; import org.jetbrains.plugins.groovy.codeInspection.GroovyLocalInspectionBase; -import org.jetbrains.plugins.groovy.lang.psi.*; +import org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrClassInitializer; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrClassInitializer; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrPostfixExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction; import org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction; import org.jetbrains.plugins.groovy.lang.psi.dataFlow.DFAEngine; @@ -105,22 +115,27 @@ public class UnusedDefInspection extends GroovyLocalInspectionBase { unusedDefs.forEach(new TIntProcedure() { public boolean execute(int num) { - final ReadWriteVariableInstruction instruction = (ReadWriteVariableInstruction) flow[num]; + final ReadWriteVariableInstruction instruction = (ReadWriteVariableInstruction)flow[num]; final PsiElement element = instruction.getElement(); + if (element == null) return true; + PsiElement toHighlight = null; if (isLocalAssignment(element) && isUsedInToplevelFlowOnly(element)) { if (element instanceof GrReferenceExpression) { PsiElement parent = element.getParent(); - PsiElement toHighlight = null; if (parent instanceof GrAssignmentExpression) { - toHighlight = ((GrAssignmentExpression) parent).getLValue(); - } if (parent instanceof GrPostfixExpression) { + toHighlight = ((GrAssignmentExpression)parent).getRValue(); + } + if (parent instanceof GrPostfixExpression) { toHighlight = parent; } - if (toHighlight == null) toHighlight = element; - problemsHolder.registerProblem(toHighlight, GroovyInspectionBundle.message("unused.assignment.tooltip"), ProblemHighlightType.LIKE_UNUSED_SYMBOL); - } else if (element instanceof GrVariable) { - problemsHolder.registerProblem(((GrVariable) element).getNameIdentifierGroovy(), GroovyInspectionBundle.message("unused.assignment.tooltip"), ProblemHighlightType.LIKE_UNUSED_SYMBOL); } + else if (element instanceof GrVariable) { + toHighlight = ((GrVariable)element).getInitializerGroovy(); + if (toHighlight == null) toHighlight = ((GrVariable)element).getNameIdentifierGroovy(); + } + if (toHighlight == null) toHighlight = element; + problemsHolder.registerProblem(toHighlight, GroovyInspectionBundle.message("unused.assignment.tooltip"), + ProblemHighlightType.LIKE_UNUSED_SYMBOL); } return true; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java index 102e34cde437..ea85bc7a40b1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java @@ -39,6 +39,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClaus import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrTraditionalForClause; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.controlFlow.*; @@ -60,7 +61,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } - private class ExceptionInfo { + private static class ExceptionInfo { GrCatchClause myClause; List myThrowers = new ArrayList(); @@ -181,7 +182,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { myHead = instruction; } - void addEdge(InstructionImpl beg, InstructionImpl end) { + static void addEdge(InstructionImpl beg, InstructionImpl end) { if (!beg.mySucc.contains(end)) { beg.mySucc.add(end); } @@ -281,7 +282,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { @Nullable private ExceptionInfo findCatch(PsiType thrownType) { for (int i = myCatchedExceptionInfos.size() - 1; i >= 0; i--) { - final ControlFlowBuilder.ExceptionInfo info = myCatchedExceptionInfos.get(i); + final ExceptionInfo info = myCatchedExceptionInfos.get(i); final GrCatchClause clause = info.myClause; final GrParameter parameter = clause.getParameter(); if (parameter != null) { @@ -363,7 +364,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } } - private boolean isIncOrDecOperand(GrReferenceExpression referenceExpression) { + private static boolean isIncOrDecOperand(GrReferenceExpression referenceExpression) { final PsiElement parent = referenceExpression.getParent(); if (parent instanceof GrPostfixExpression) return true; if (parent instanceof GrUnaryExpression) { @@ -667,6 +668,9 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } public void visitTypeDefinition(GrTypeDefinition typeDefinition) { + if (typeDefinition instanceof GrAnonymousClassDefinition) { + super.visitTypeDefinition(typeDefinition); + } } public void visitVariable(GrVariable variable) { @@ -678,6 +682,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } } + @Nullable private InstructionImpl findInstruction(PsiElement element) { for (int i = myProcessingStack.size() - 1; i >= 0; i--) { InstructionImpl instruction = myProcessingStack.get(i); @@ -686,7 +691,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { return null; } - class CallInstructionImpl extends InstructionImpl implements CallInstruction { + static class CallInstructionImpl extends InstructionImpl implements CallInstruction { private final InstructionImpl myCallee; public String toString() { @@ -712,7 +717,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } } - class PostCallInstructionImpl extends InstructionImpl implements AfterCallInstruction { + static class PostCallInstructionImpl extends InstructionImpl implements AfterCallInstruction { private final CallInstructionImpl myCall; private RetInstruction myReturnInsn; @@ -743,7 +748,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } } - class RetInstruction extends InstructionImpl { + static class RetInstruction extends InstructionImpl { RetInstruction(int num) { super(null, num); } diff --git a/plugins/groovy/testdata/highlighting/IfIncrementElseReturn.groovy b/plugins/groovy/testdata/highlighting/IfIncrementElseReturn.groovy index 04e1d86bc2e5..7067d0b17666 100644 --- a/plugins/groovy/testdata/highlighting/IfIncrementElseReturn.groovy +++ b/plugins/groovy/testdata/highlighting/IfIncrementElseReturn.groovy @@ -10,4 +10,4 @@ int numPermutationsPrinted = 1; } -def x = 2 \ No newline at end of file +def x = 2 \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/PrefixIncrementCfa.groovy b/plugins/groovy/testdata/highlighting/PrefixIncrementCfa.groovy index 711bb7b8c062..2fd6f971ca1f 100644 --- a/plugins/groovy/testdata/highlighting/PrefixIncrementCfa.groovy +++ b/plugins/groovy/testdata/highlighting/PrefixIncrementCfa.groovy @@ -1,5 +1,5 @@ int idx -idx = 2 +idx = 2 idx = 3 if (++idx == 8) { //Assignment is used here idx = 33 diff --git a/plugins/groovy/testdata/highlighting/UnusedVariable.groovy b/plugins/groovy/testdata/highlighting/UnusedVariable.groovy index 0ea69f992bde..bf0f533ac9c8 100644 --- a/plugins/groovy/testdata/highlighting/UnusedVariable.groovy +++ b/plugins/groovy/testdata/highlighting/UnusedVariable.groovy @@ -1 +1 @@ -Class clazz = null \ No newline at end of file +Class clazz = null \ No newline at end of file From 3700b6edc202c4a5c4d7351fdaff141d826a6655 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 13:07:14 +0400 Subject: [PATCH 09/17] rename: check if preprocess is applicable --- .../com/intellij/refactoring/rename/RenameProcessor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java index 2599740ff7a5..f15f07ceb484 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java @@ -118,8 +118,10 @@ public class RenameProcessor extends BaseRefactoringProcessor { final List processors = RenamePsiElementProcessor.allForElement(element); myForceShowPreview = false; for (RenamePsiElementProcessor processor : processors) { - processor.prepareRenaming(element, newName, allRenames); - myForceShowPreview |= processor.forcesShowPreview(); + if (processor.canProcessElement(element)) { + processor.prepareRenaming(element, newName, allRenames); + myForceShowPreview |= processor.forcesShowPreview(); + } } } From 130f4aad40d962d2e7f6359bba2a69ced2caac56 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 13:08:08 +0400 Subject: [PATCH 10/17] disable groovy rename alias for java variables --- .../refactoring/rename/RenameAliasImportedFieldProcessor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java index 77d651727802..05295eaedcef 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/rename/RenameAliasImportedFieldProcessor.java @@ -20,6 +20,7 @@ import com.intellij.psi.PsiReference; import com.intellij.refactoring.rename.RenameJavaVariableProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import java.util.Collection; @@ -29,7 +30,7 @@ import java.util.Collection; public class RenameAliasImportedFieldProcessor extends RenameJavaVariableProcessor{ @Override public boolean canProcessElement(PsiElement element) { - return super.canProcessElement(element) && !(element instanceof GrField && ((GrField)element).isProperty()); + return element instanceof GrVariable && !(element instanceof GrField && ((GrField)element).isProperty()); } @NotNull From b6c253f29cccd6270009c45012a7a9acf44e93bc Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 13:41:52 +0400 Subject: [PATCH 11/17] NPE --- .../daemon/impl/actions/SuppressWarningsFoldingBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java index 1f5e80ebcadb..0c90b896ece3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressWarningsFoldingBuilder.java @@ -86,7 +86,7 @@ public class SuppressWarningsFoldingBuilder extends FoldingBuilderEx { return o.toString(); } } - return memberValue.getText(); + return memberValue != null ? memberValue.getText() : ""; } From 0bbbfef61998427104db5e899f847fa23051b80e Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 15:04:50 +0400 Subject: [PATCH 12/17] introduce over non-valid expression (IDEA-26836) --- .../IntroduceVariableBase.java | 22 ++++++++++++++----- ...expressionWithSpacesInSelection.after.java | 10 +++++++++ .../SubexpressionWithSpacesInSelection.java | 9 ++++++++ .../refactoring/IntroduceVariableTest.java | 4 ++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.after.java create mode 100644 java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.java diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 705c7f0e195a..e5eedc93225f 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -194,12 +194,20 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme return tempExpr; } - public static PsiExpression getSelectedExpression(final Project project, final PsiFile file, final int startOffset, final int endOffset) { + public static PsiExpression getSelectedExpression(final Project project, final PsiFile file, int startOffset, int endOffset) { - final PsiElement elementAtStart = file.findElementAt(startOffset); - if (elementAtStart == null) return null; - final PsiElement elementAtEnd = file.findElementAt(endOffset - 1); - if (elementAtEnd == null) return null; + PsiElement elementAtStart = file.findElementAt(startOffset); + if (elementAtStart == null || elementAtStart instanceof PsiWhiteSpace || elementAtStart instanceof PsiComment) { + elementAtStart = PsiTreeUtil.skipSiblingsForward(elementAtStart, PsiWhiteSpace.class, PsiComment.class); + if (elementAtStart == null) return null; + startOffset = elementAtStart.getTextOffset(); + } + PsiElement elementAtEnd = file.findElementAt(endOffset - 1); + if (elementAtEnd == null || elementAtEnd instanceof PsiWhiteSpace || elementAtEnd instanceof PsiComment) { + elementAtEnd = PsiTreeUtil.skipSiblingsBackward(elementAtEnd, PsiWhiteSpace.class, PsiComment.class); + if (elementAtEnd == null) return null; + endOffset = elementAtEnd.getTextRange().getEndOffset(); + } PsiExpression tempExpr; PsiElement elementAt = PsiTreeUtil.findCommonParent(elementAtStart, elementAtEnd); @@ -295,7 +303,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme tempExpr.putUserData(ElementToWorkOn.PARENT, parent); } else { - PsiErrorElement errorElement = PsiTreeUtil.getNextSiblingOfType(elementAtStart, PsiErrorElement.class); + PsiErrorElement errorElement = elementAtStart instanceof PsiErrorElement + ? (PsiErrorElement)elementAtStart + : PsiTreeUtil.getNextSiblingOfType(elementAtStart, PsiErrorElement.class); if (errorElement == null) { errorElement = PsiTreeUtil.getParentOfType(elementAtStart, PsiErrorElement.class); } diff --git a/java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.after.java b/java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.after.java new file mode 100644 index 000000000000..8d577b12ebd7 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.after.java @@ -0,0 +1,10 @@ +class A { + public void test(boolean a, boolean b) { + final boolean ab = a && + b; + if (true && ab +//some comment + + ); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.java b/java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.java new file mode 100644 index 000000000000..f0475fa0b5e2 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceVariable/SubexpressionWithSpacesInSelection.java @@ -0,0 +1,9 @@ +class A { + public void test(boolean a, boolean b) { + if (true && a && + b +//some comment + + ); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java index 1db6d6e7e100..e2fccd3b84a2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java @@ -198,6 +198,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { public void testAndAndSubexpression() throws Exception { doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean")); } + + public void testSubexpressionWithSpacesInSelection() throws Exception { + doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean")); + } public void testDuplicatesAnonymousClassCreationWithSimilarParameters () throws Exception { doTest(new MockIntroduceVariableHandler("foo1", true, true, false, "Foo")); From 55609df916a317cd0e49c38046417ab6428f85c1 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 15:14:05 +0400 Subject: [PATCH 13/17] rename: describe element to automatic rename (IDEA-21731) --- .../refactoring/rename/AutomaticRenamingDialog.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java b/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java index 7e27933be6f0..01b15258e6e6 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/AutomaticRenamingDialog.java @@ -24,11 +24,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiNamedElement; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.rename.naming.AutomaticRenamer; import com.intellij.refactoring.ui.EnableDisableAction; import com.intellij.refactoring.ui.StringTableCellEditor; +import com.intellij.refactoring.util.RefactoringUIUtil; import com.intellij.ui.BooleanTableCellRenderer; import com.intellij.ui.GuiUtils; import com.intellij.ui.TableUtil; @@ -248,15 +250,7 @@ public class AutomaticRenamingDialog extends DialogWrapper { case CHECK_COLUMN: return Boolean.valueOf(myShouldRename[rowIndex]); case OLD_NAME_COLUMN: - final PsiNamedElement namedElement = myRenames[rowIndex]; - String location = null; - if (namedElement instanceof NavigationItem) { - final ItemPresentation presentation = ((NavigationItem)namedElement).getPresentation(); - if (presentation != null) { - location = presentation.getLocationString(); - } - } - return namedElement.getName() + (location != null ? " " + location : ""); + return "" + RefactoringUIUtil.getDescription(myRenames[rowIndex], true) + ""; case NEW_NAME_COLUMN: return myNewNames[rowIndex]; default: From 5b0a120466c9ef4b1ae514831de8ebcf9cd1d6b1 Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 17:43:08 +0400 Subject: [PATCH 14/17] scopes: listen rename/move element (IDEA-11534) --- .../scope/packageSet/PatternPackageSet.java | 21 ++- .../psi/PsiQualifiedNamedElement.java | 0 .../packageSet/ComplementPackageSet.java | 4 + .../packageSet/FilePatternPackageSet.java | 18 ++- .../packageSet/IntersectionPackageSet.java | 8 + .../packageSet/PatternBasedPackageSet.java | 27 ++++ .../scope/packageSet/UnionPackageSet.java | 8 + .../RefactoringElementListenerComposite.java | 0 ...factoringScopeElementListenerProvider.java | 144 ++++++++++++++++++ .../src/META-INF/LangExtensions.xml | 1 + 10 files changed, 228 insertions(+), 3 deletions(-) rename {java/openapi => platform/lang-api}/src/com/intellij/psi/PsiQualifiedNamedElement.java (100%) create mode 100644 platform/lang-api/src/com/intellij/psi/search/scope/packageSet/PatternBasedPackageSet.java rename {java/openapi => platform/lang-api}/src/com/intellij/refactoring/listeners/RefactoringElementListenerComposite.java (100%) create mode 100644 platform/lang-impl/src/com/intellij/packageDependencies/ui/RefactoringScopeElementListenerProvider.java diff --git a/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java b/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java index 9bb1209cf342..9631b4f90b0a 100644 --- a/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java +++ b/java/openapi/src/com/intellij/psi/search/scope/packageSet/PatternPackageSet.java @@ -18,17 +18,18 @@ package com.intellij.psi.search.scope.packageSet; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.*; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.regex.Pattern; -public class PatternPackageSet implements PackageSet { +public class PatternPackageSet implements PatternBasedPackageSet { @NonNls public static final String SCOPE_TEST = "test"; @NonNls public static final String SCOPE_SOURCE = "src"; @NonNls public static final String SCOPE_LIBRARY = "lib"; @@ -136,4 +137,20 @@ public class PatternPackageSet implements PackageSet { return buf.toString(); } + @Override + public String getModulePattern() { + return myModulePatternText; + } + + @Override + public boolean isOn(String oldQName) { + return Comparing.strEqual(oldQName, myAspectJSyntaxPattern) || //class qname + Comparing.strEqual(oldQName + "..*", myAspectJSyntaxPattern) || //package req + Comparing.strEqual(oldQName + ".*", myAspectJSyntaxPattern); //package + } + + @Override + public String getPattern() { + return myAspectJSyntaxPattern; + } } \ No newline at end of file diff --git a/java/openapi/src/com/intellij/psi/PsiQualifiedNamedElement.java b/platform/lang-api/src/com/intellij/psi/PsiQualifiedNamedElement.java similarity index 100% rename from java/openapi/src/com/intellij/psi/PsiQualifiedNamedElement.java rename to platform/lang-api/src/com/intellij/psi/PsiQualifiedNamedElement.java diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/ComplementPackageSet.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/ComplementPackageSet.java index 010707b85741..f9536b1887f8 100644 --- a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/ComplementPackageSet.java +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/ComplementPackageSet.java @@ -45,4 +45,8 @@ public class ComplementPackageSet implements PackageSet { public int getNodePriority() { return 1; } + + public PackageSet getComplementarySet() { + return myComplementarySet; + } } diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java index 2ad0fe15b41f..b1824bf43a54 100644 --- a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java @@ -26,6 +26,7 @@ import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -34,7 +35,7 @@ import org.jetbrains.annotations.NonNls; import java.util.regex.Pattern; -public class FilePatternPackageSet implements PackageSet { +public class FilePatternPackageSet implements PatternBasedPackageSet { public static final @NonNls String SCOPE_FILE = "file"; private Pattern myModulePattern; private Pattern myModuleGroupPattern; @@ -169,6 +170,21 @@ public class FilePatternPackageSet implements PackageSet { return buf.toString(); } + @Override + public String getPattern() { + return myPathPattern; + } + + @Override + public String getModulePattern() { + return myModulePatternText; + } + + @Override + public boolean isOn(String oldQName) { + return Comparing.strEqual(myPathPattern, oldQName); + } + public static String getRelativePath(final VirtualFile virtualFile, final ProjectFileIndex index, final boolean useFQName) { final Module module = index.getModuleForFile(virtualFile); if (module != null) { diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/IntersectionPackageSet.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/IntersectionPackageSet.java index f9a96d092cfd..11526b528efb 100644 --- a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/IntersectionPackageSet.java +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/IntersectionPackageSet.java @@ -52,4 +52,12 @@ public class IntersectionPackageSet implements PackageSet { return buf.toString(); } + + public PackageSet getFirstSet() { + return myFirstSet; + } + + public PackageSet getSecondSet() { + return mySecondSet; + } } diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/PatternBasedPackageSet.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/PatternBasedPackageSet.java new file mode 100644 index 000000000000..34aaace526fa --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/PatternBasedPackageSet.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2010 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.search.scope.packageSet; + +/** + * User: anna + * Date: Jul 26, 2010 + */ +public interface PatternBasedPackageSet extends PackageSet{ + String getPattern(); + String getModulePattern(); + + boolean isOn(String oldQName); +} diff --git a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/UnionPackageSet.java b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/UnionPackageSet.java index b47609873ccb..8a227836c881 100644 --- a/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/UnionPackageSet.java +++ b/platform/lang-api/src/com/intellij/psi/search/scope/packageSet/UnionPackageSet.java @@ -42,4 +42,12 @@ public class UnionPackageSet implements PackageSet { public String getText() { return myFirstSet.getText() + "||" + mySecondSet.getText(); } + + public PackageSet getFirstSet() { + return myFirstSet; + } + + public PackageSet getSecondSet() { + return mySecondSet; + } } \ No newline at end of file diff --git a/java/openapi/src/com/intellij/refactoring/listeners/RefactoringElementListenerComposite.java b/platform/lang-api/src/com/intellij/refactoring/listeners/RefactoringElementListenerComposite.java similarity index 100% rename from java/openapi/src/com/intellij/refactoring/listeners/RefactoringElementListenerComposite.java rename to platform/lang-api/src/com/intellij/refactoring/listeners/RefactoringElementListenerComposite.java diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/RefactoringScopeElementListenerProvider.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/RefactoringScopeElementListenerProvider.java new file mode 100644 index 000000000000..505ed9dbb175 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/RefactoringScopeElementListenerProvider.java @@ -0,0 +1,144 @@ +/* + * Copyright 2000-2010 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.packageDependencies.ui; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiQualifiedNamedElement; +import com.intellij.psi.search.scope.packageSet.*; +import com.intellij.refactoring.listeners.RefactoringElementListener; +import com.intellij.refactoring.listeners.RefactoringElementListenerComposite; +import com.intellij.refactoring.listeners.RefactoringElementListenerProvider; +import org.jetbrains.annotations.NotNull; + +/** + * User: anna + * Date: Jul 26, 2010 + */ +public class RefactoringScopeElementListenerProvider implements RefactoringElementListenerProvider { + private static final Logger LOG = Logger.getInstance("#" + RefactoringScopeElementListenerProvider.class.getName()); + + @Override + public RefactoringElementListener getListener(PsiElement element) { + final PsiFile containingFile = element.getContainingFile(); + if (!(element instanceof PsiQualifiedNamedElement)) return null; + final String oldName = ((PsiQualifiedNamedElement)element).getQualifiedName(); + RefactoringElementListenerComposite composite = null; + for (final NamedScopesHolder holder : NamedScopeManager.getAllNamedScopeHolders(element.getProject())) { + final NamedScope[] scopes = holder.getEditableScopes(); + for (int i = 0; i < scopes.length; i++) { + final NamedScope scope = scopes[i]; + final PackageSet packageSet = scope.getValue(); + if (packageSet != null && (containingFile == null || packageSet.contains(containingFile, holder))) { + composite = traverse(new OldScopeDescriptor(oldName, scope, i, holder), composite, packageSet); + } + } + } + return composite; + } + + private static RefactoringElementListenerComposite traverse(OldScopeDescriptor scopeDescriptor, + RefactoringElementListenerComposite composite, + PackageSet packageSet) { + if (packageSet instanceof PatternBasedPackageSet) { + composite = checkPatternPackageSet(scopeDescriptor, composite, ((PatternBasedPackageSet)packageSet), + scopeDescriptor.getScope().getValue().getText()); + } + else if (packageSet instanceof ComplementPackageSet) { + composite = traverse(scopeDescriptor, composite, ((ComplementPackageSet)packageSet).getComplementarySet()); + } + else if (packageSet instanceof UnionPackageSet) { + composite = traverse(scopeDescriptor, composite, ((UnionPackageSet)packageSet).getFirstSet()); + composite = traverse(scopeDescriptor, composite, ((UnionPackageSet)packageSet).getSecondSet()); + } + else if (packageSet instanceof IntersectionPackageSet) { + composite = traverse(scopeDescriptor, composite, ((IntersectionPackageSet)packageSet).getFirstSet()); + composite = traverse(scopeDescriptor, composite, ((IntersectionPackageSet)packageSet).getSecondSet()); + } + return composite; + } + + private static RefactoringElementListenerComposite checkPatternPackageSet(final OldScopeDescriptor descriptor, + RefactoringElementListenerComposite composite, + final PatternBasedPackageSet pattern, + final String text) { + if (pattern.isOn(descriptor.getOldQName())) { + if (composite == null) { + composite = new RefactoringElementListenerComposite(); + } + composite.addListener(new RefactoringElementListener() { + @Override + public void elementMoved(@NotNull PsiElement newElement) { + setName(newElement); + } + + @Override + public void elementRenamed(@NotNull PsiElement newElement) { + setName(newElement); + } + + private void setName(@NotNull PsiElement newElement) { + LOG.assertTrue(newElement instanceof PsiQualifiedNamedElement); + try { + final String newPattern = text.replace(descriptor.getOldQName(), ((PsiQualifiedNamedElement)newElement).getQualifiedName()); + final PackageSet newSet = PackageSetFactory.getInstance().compile(newPattern); + NamedScope newScope = new NamedScope(descriptor.getScope().getName(), newSet); + final NamedScope[] currentScopes = descriptor.getHolder().getEditableScopes(); + currentScopes[descriptor.getIdx()] = newScope; + descriptor.getHolder().setScopes(currentScopes); + } + catch (ParsingException ignore) { + } + } + }); + } + return composite; + } + + private static class OldScopeDescriptor { + private final String myOldQName; + private final NamedScopesHolder myHolder; + private final int myIdx; + private final NamedScope myScope; + + private OldScopeDescriptor(final String oldQName, + final NamedScope scope, + final int idx, + final NamedScopesHolder holder) { + myOldQName = oldQName; + myHolder = holder; + myIdx = idx; + myScope = scope; + } + + public String getOldQName() { + return myOldQName; + } + + public NamedScopesHolder getHolder() { + return myHolder; + } + + public int getIdx() { + return myIdx; + } + + public NamedScope getScope() { + return myScope; + } + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 21b6000930ab..49b97ae80a36 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -296,6 +296,7 @@ + From eea315f19b1abd81358f5e893443b9d14b164c2c Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 26 Jul 2010 19:24:40 +0400 Subject: [PATCH 15/17] inline constant: do not override qualifier --- .../inline/InlineConstantFieldProcessor.java | 10 ++++++++-- ...lifiedConstantExpressionReplacedWithAnotherOne.java | 10 ++++++++++ ...ConstantExpressionReplacedWithAnotherOne.java.after | 9 +++++++++ .../refactoring/inline/InlineConstantFieldTest.java | 4 ++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java create mode 100644 java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java.after diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java index 0cc343e57b59..f33755c9c1ef 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java @@ -165,9 +165,15 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor { PsiExpression qExpression = ((PsiReferenceExpression)expr).getQualifierExpression(); if (qExpression != null) { if (initializer1 instanceof PsiMethodCallExpression) { - ((PsiMethodCallExpression)initializer1).getMethodExpression().setQualifierExpression(qExpression); + PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)initializer1).getMethodExpression(); + if (methodExpression.getQualifierExpression() == null) { + methodExpression.setQualifierExpression(qExpression); + } } else if (initializer1 instanceof PsiReferenceExpression) { - ((PsiReferenceExpression)initializer1).setQualifierExpression(qExpression); + PsiReferenceExpression referenceExpression = (PsiReferenceExpression)initializer1; + if (referenceExpression.getQualifierExpression() == null) { + referenceExpression.setQualifierExpression(qExpression); + } } } } diff --git a/java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java b/java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java new file mode 100644 index 000000000000..69dad46d8976 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java @@ -0,0 +1,10 @@ +class QTest { + final int myI = Source.CONST; + public static void main(String[] args) { + System.out.println(new QTest().myI); + } +} + +class Source { + int CONST = 0; +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java.after b/java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java.after new file mode 100644 index 000000000000..c9d9be20793b --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineConstantField/QualifiedConstantExpressionReplacedWithAnotherOne.java.after @@ -0,0 +1,9 @@ +class QTest { + public static void main(String[] args) { + System.out.println(Source.CONST); + } +} + +class Source { + int CONST = 0; +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java index 9257fd73d8b4..a27675020e98 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineConstantFieldTest.java @@ -25,6 +25,10 @@ public class InlineConstantFieldTest extends LightCodeInsightTestCase { doTest(); } + public void testQualifiedConstantExpressionReplacedWithAnotherOne() throws Exception { + doTest(); + } + @Override protected Sdk getProjectJDK() { return JavaSdkImpl.getMockJdk17("java 1.5"); From 63c5c051078e4cf69178370238c21c9850c4f6a4 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 27 Jul 2010 14:44:53 +0400 Subject: [PATCH 16/17] imls --- java/compiler/impl/compiler-impl.iml | 2 ++ plugins/cvs/cvs-core/cvs-core.iml | 1 + 2 files changed, 3 insertions(+) diff --git a/java/compiler/impl/compiler-impl.iml b/java/compiler/impl/compiler-impl.iml index 381f3496886b..4f7473c9ff2a 100644 --- a/java/compiler/impl/compiler-impl.iml +++ b/java/compiler/impl/compiler-impl.iml @@ -23,6 +23,8 @@ + + diff --git a/plugins/cvs/cvs-core/cvs-core.iml b/plugins/cvs/cvs-core/cvs-core.iml index f170b4099106..53189febbd11 100644 --- a/plugins/cvs/cvs-core/cvs-core.iml +++ b/plugins/cvs/cvs-core/cvs-core.iml @@ -15,6 +15,7 @@ + From 97639c3c42351922a880fddf827ce31065c030d3 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 27 Jul 2010 15:30:22 +0400 Subject: [PATCH 17/17] CIDR-debugger: resolving struct fields --- .../src/com/intellij/psi/util/PsiTreeUtil.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java b/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java index f20559eef3fd..f5c174dea4b5 100644 --- a/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java +++ b/platform/lang-api/src/com/intellij/psi/util/PsiTreeUtil.java @@ -180,12 +180,22 @@ public class PsiTreeUtil { } @Nullable public static T findChildOfType(@NotNull final PsiElement element, @NotNull final Class aClass, final boolean strict) { + return findChildOfAnyType(element, strict, aClass); + } + + @Nullable public static T findChildOfAnyType(@NotNull final PsiElement element, @NotNull final Class... classes) { + return findChildOfAnyType(element, true, classes); + } + + @Nullable public static T findChildOfAnyType(@NotNull final PsiElement element, final boolean strict, @NotNull final Class... classes) { PsiElementProcessor.FindElement processor = new PsiElementProcessor.FindElement() { @Override public boolean execute(PsiElement each) { if (strict && each == element) return true; - if (instanceOf(aClass, each)) { - return setFound(each); + for (Class eachClass : classes) { + if (instanceOf(eachClass, each)) { + return setFound(each); + } } return true; }