moved to analysis
authorAlexey Kudravtsev <cdr@intellij.com>
Fri, 19 Sep 2014 12:45:24 +0000 (16:45 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Sun, 21 Sep 2014 10:22:13 +0000 (14:22 +0400)
16 files changed:
java/java-analysis-impl/src/com/intellij/find/findUsages/JavaClassFindUsagesOptions.java [moved from java/java-impl/src/com/intellij/find/findUsages/JavaClassFindUsagesOptions.java with 100% similarity]
java/java-analysis-impl/src/com/intellij/find/findUsages/JavaFindUsagesOptions.java [moved from java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesOptions.java with 98% similarity]
java/java-analysis-impl/src/com/intellij/find/findUsages/JavaMethodFindUsagesOptions.java [moved from java/java-impl/src/com/intellij/find/findUsages/JavaMethodFindUsagesOptions.java with 100% similarity]
java/java-analysis-impl/src/com/intellij/find/findUsages/JavaPackageFindUsagesOptions.java [moved from java/java-impl/src/com/intellij/find/findUsages/JavaPackageFindUsagesOptions.java with 100% similarity]
java/java-analysis-impl/src/com/intellij/find/findUsages/JavaThrowFindUsagesOptions.java [moved from java/java-impl/src/com/intellij/find/findUsages/JavaThrowFindUsagesOptions.java with 100% similarity]
java/java-analysis-impl/src/com/intellij/find/findUsages/JavaVariableFindUsagesOptions.java [moved from java/java-impl/src/com/intellij/find/findUsages/JavaVariableFindUsagesOptions.java with 63% similarity]
java/java-analysis-impl/src/com/intellij/psi/impl/search/ThrowSearchUtil.java [moved from java/java-impl/src/com/intellij/psi/impl/search/ThrowSearchUtil.java with 100% similarity]
platform/analysis-impl/analysis-impl.iml
platform/analysis-impl/src/com/intellij/find/FindBundle.java [moved from platform/lang-impl/src/com/intellij/find/FindBundle.java with 97% similarity]
platform/analysis-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java [moved from platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java with 90% similarity]
platform/analysis-impl/src/com/intellij/psi/search/PredefinedSearchScopeProvider.java [new file with mode: 0644]
platform/indexing-api/src/com/intellij/find/FindModel.java [moved from platform/lang-api/src/com/intellij/find/FindModel.java with 92% similarity]
platform/indexing-impl/src/com/intellij/find/FindSettings.java [moved from platform/lang-impl/src/com/intellij/find/FindSettings.java with 92% similarity]
platform/lang-impl/src/com/intellij/ide/util/scopeChooser/ScopeChooserCombo.java
platform/lang-impl/src/com/intellij/psi/search/PredefinedSearchScopeProviderImpl.java [new file with mode: 0644]
platform/platform-resources/src/META-INF/LangExtensions.xml

similarity index 98%
rename from java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesOptions.java
rename to java/java-analysis-impl/src/com/intellij/find/findUsages/JavaFindUsagesOptions.java
index b78dfca59fe5c6436029c887f54ced1deeb2ca3a..7accfccd14b937a437872fa7acc525aeb2c19693 100644 (file)
@@ -29,7 +29,7 @@ public abstract class JavaFindUsagesOptions extends FindUsagesOptions {
   public boolean isSkipImportStatements = false;
 
   public JavaFindUsagesOptions(@NotNull Project project) {
-    super(project, null);
+    super(project);
 
     isUsages = true;
   }
similarity index 63%
rename from java/java-impl/src/com/intellij/find/findUsages/JavaVariableFindUsagesOptions.java
rename to java/java-analysis-impl/src/com/intellij/find/findUsages/JavaVariableFindUsagesOptions.java
index c7fc44babc9cbf2820f58d76afbe5b53364376c4..14d865280d3a75908863a7bc2521b67e75429e80 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * 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.find.findUsages;
 
 import com.intellij.openapi.project.Project;
index b4ca0c1a0ef3746be92f258b83c868496d3216d0..97b1b8b47b32a76303ebda36113a565bfcae3a0d 100644 (file)
@@ -15,7 +15,7 @@
     <orderEntry type="module" module-name="resources-en" />
     <orderEntry type="module" module-name="projectModel-impl" />
     <orderEntry type="module" module-name="editor-ui-ex" />
-    <orderEntry type="module" module-name="indexing-api" />
+    <orderEntry type="module" module-name="indexing-impl" />
   </component>
 </module>
 
similarity index 97%
rename from platform/lang-impl/src/com/intellij/find/FindBundle.java
rename to platform/analysis-impl/src/com/intellij/find/FindBundle.java
index 6f18c8c41edfa0b0085e9945fe3835d11e9f7b83..7276de4278a9a7defc74ca0196bb2b726b9add03 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 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.
similarity index 90%
rename from platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java
rename to platform/analysis-impl/src/com/intellij/find/findUsages/FindUsagesOptions.java
index 38d3d161fc91984c2679dc5c7ebbe1515aa67a46..d1a0cab54bb2f66726d3a156f068d68588beb093 100644 (file)
 
 package com.intellij.find.findUsages;
 
-import com.intellij.find.FindBundle;
 import com.intellij.find.FindSettings;
-import com.intellij.ide.util.scopeChooser.ScopeChooserCombo;
 import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.project.Project;
+import com.intellij.psi.search.PredefinedSearchScopeProvider;
 import com.intellij.psi.search.ProjectScope;
 import com.intellij.psi.search.SearchRequestCollector;
 import com.intellij.psi.search.SearchScope;
@@ -45,7 +44,8 @@ public class FindUsagesOptions implements Cloneable {
 
   public FindUsagesOptions(@NotNull Project project, @Nullable final DataContext dataContext) {
     String defaultScopeName = FindSettings.getInstance().getDefaultScopeName();
-    List<SearchScope> predefined = ScopeChooserCombo.getPredefinedScopes(project, dataContext, true, false, false, false);
+    List<SearchScope> predefined = PredefinedSearchScopeProvider.getInstance().getPredefinedScopes(project, dataContext, true, false, false,
+                                                                                                   false);
     SearchScope resultScope = null;
     for (SearchScope scope : predefined) {
       if (scope.getDisplayName().equals(defaultScopeName)) {
@@ -105,6 +105,6 @@ public class FindUsagesOptions implements Cloneable {
 
   @NotNull
   public String generateUsagesString() {
-    return FindBundle.message("find.usages.panel.title.usages");
+    return "Usages";
   }
 }
diff --git a/platform/analysis-impl/src/com/intellij/psi/search/PredefinedSearchScopeProvider.java b/platform/analysis-impl/src/com/intellij/psi/search/PredefinedSearchScopeProvider.java
new file mode 100644 (file)
index 0000000..76881d8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.search;
+
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public abstract class PredefinedSearchScopeProvider {
+  public static PredefinedSearchScopeProvider getInstance() {
+    return ServiceManager.getService(PredefinedSearchScopeProvider.class);
+  }
+
+  public abstract List<SearchScope> getPredefinedScopes(@NotNull final Project project,
+                                                        @Nullable final DataContext dataContext,
+                                                        boolean suggestSearchInLibs,
+                                                        boolean prevSearchFiles,
+                                                        boolean currentSelection,
+                                                        boolean usageView);
+}
similarity index 92%
rename from platform/lang-api/src/com/intellij/find/FindModel.java
rename to platform/indexing-api/src/com/intellij/find/FindModel.java
index d071877968722ff15943a179cf8f19fcec6f0c2e..e687d58dd4a3bbf0f07a08389fd9ca4964ba96c0 100644 (file)
@@ -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.
  */
 package com.intellij.find;
 
-import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.UserDataHolderBase;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.util.PatternUtil;
 import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -34,8 +32,6 @@ import java.util.regex.PatternSyntaxException;
  * operations.
  */
 public class FindModel extends UserDataHolderBase implements Cloneable {
-  private static final Logger LOG = Logger.getInstance("#com.intellij.find.FindModel");
-
   public static void initStringToFindNoMultiline(FindModel findModel, String s) {
     if (!StringUtil.isEmpty(s)) {
       if (!s.contains("\r") && !s.contains("\n")) {
@@ -516,7 +512,6 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
    * @param replaceAll the value of the Replace All flag.
    */
   public void setReplaceAll(boolean replaceAll) {
-    boolean changed = isReplaceAll != replaceAll;
     isReplaceAll = replaceAll;
     notifyObservers();
   }
@@ -662,33 +657,32 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
   }
 
 
+  @Override
   public String toString() {
-    @NonNls StringBuilder buffer = new StringBuilder();
-    buffer.append("--- FIND MODEL ---\n");
-    buffer.append("myStringToFind =").append(myStringToFind).append("\n");
-    buffer.append("myStringToReplace =").append(myStringToReplace).append("\n");
-    buffer.append("isReplaceState =").append(isReplaceState).append("\n");
-    buffer.append("isWholeWordsOnly =").append(isWholeWordsOnly).append("\n");
-    buffer.append("searchContext =").append(searchContext).append("\n");
-    buffer.append("isFromCursor =").append(isFromCursor).append("\n");
-    buffer.append("isForward =").append(isForward).append("\n");
-    buffer.append("isGlobal =").append(isGlobal).append("\n");
-    buffer.append("isRegularExpressions =").append(isRegularExpressions).append("\n");
-    buffer.append("isCaseSensitive =").append(isCaseSensitive).append("\n");
-    buffer.append("isMultipleFiles =").append(isMultipleFiles).append("\n");
-    buffer.append("isPromptOnReplace =").append(isPromptOnReplace).append("\n");
-    buffer.append("isReplaceAll =").append(isReplaceAll).append("\n");
-    buffer.append("isOpenNewTab =").append(isOpenNewTab).append("\n");
-    buffer.append("isOpenInNewTabEnabled =").append(isOpenInNewTabEnabled).append("\n");
-    buffer.append("isOpenNewTabVisible =").append(isOpenNewTabVisible).append("\n");
-    buffer.append("isProjectScope =").append(isProjectScope).append("\n");
-    buffer.append("directoryName =").append(directoryName).append("\n");
-    buffer.append("isWithSubdirectories =").append(isWithSubdirectories).append("\n");
-    buffer.append("fileFilter =").append(fileFilter).append("\n");
-    buffer.append("moduleName =").append(moduleName).append("\n");
-    buffer.append("customScopeName =").append(customScopeName).append("\n");
-    buffer.append("searchInProjectFiles =").append(mySearchInProjectFiles).append("\n");
-    return buffer.toString();
+    return "--- FIND MODEL ---\n" +
+           "myStringToFind =" + myStringToFind + "\n" +
+           "myStringToReplace =" + myStringToReplace + "\n" +
+           "isReplaceState =" + isReplaceState + "\n" +
+           "isWholeWordsOnly =" + isWholeWordsOnly + "\n" +
+           "searchContext =" + searchContext + "\n" +
+           "isFromCursor =" + isFromCursor + "\n" +
+           "isForward =" + isForward + "\n" +
+           "isGlobal =" + isGlobal + "\n" +
+           "isRegularExpressions =" + isRegularExpressions + "\n" +
+           "isCaseSensitive =" + isCaseSensitive + "\n" +
+           "isMultipleFiles =" + isMultipleFiles + "\n" +
+           "isPromptOnReplace =" + isPromptOnReplace + "\n" +
+           "isReplaceAll =" + isReplaceAll + "\n" +
+           "isOpenNewTab =" + isOpenNewTab + "\n" +
+           "isOpenInNewTabEnabled =" + isOpenInNewTabEnabled + "\n" +
+           "isOpenNewTabVisible =" + isOpenNewTabVisible + "\n" +
+           "isProjectScope =" + isProjectScope + "\n" +
+           "directoryName =" + directoryName + "\n" +
+           "isWithSubdirectories =" + isWithSubdirectories + "\n" +
+           "fileFilter =" + fileFilter + "\n" +
+           "moduleName =" + moduleName + "\n" +
+           "customScopeName =" + customScopeName + "\n" +
+           "searchInProjectFiles =" + mySearchInProjectFiles + "\n";
   }
 
   /**
@@ -897,7 +891,8 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
     }
   }
 
-  public @NotNull SearchContext getSearchContext() {
+  @NotNull
+  public SearchContext getSearchContext() {
     return searchContext;
   }
 
similarity index 92%
rename from platform/lang-impl/src/com/intellij/find/FindSettings.java
rename to platform/indexing-impl/src/com/intellij/find/FindSettings.java
index d8c6d73461a1f028766bd84595435d96c0d7bc5f..fec175af35d1b2a7a6bafce411cfbda5ad86bdf0 100644 (file)
@@ -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.
@@ -79,11 +79,11 @@ public abstract class FindSettings{
 
   public abstract void setLocalRegularExpressions(boolean regularExpressions);
 
-  public abstract void addStringToFind(String s);
+  public abstract void addStringToFind(@NotNull String s);
 
-  public abstract void addStringToReplace(String s);
+  public abstract void addStringToReplace(@NotNull String s);
 
-  public abstract void addDirectory(String s);
+  public abstract void addDirectory(@NotNull String s);
 
   @NotNull
   public abstract String[] getRecentFindStrings();
@@ -106,7 +106,7 @@ public abstract class FindSettings{
 
   public abstract void setWithSubdirectories(boolean b);
 
-  public abstract void initModelBySetings(FindModel model);
+  public abstract void initModelBySetings(@NotNull FindModel model);
 
   public abstract String getFileMask();
 
index 98190010159bbd27480accbd560b7cc1fb7d92f3..ed40624a26df108a9db1c1c9a803536818423b29 100644 (file)
 package com.intellij.ide.util.scopeChooser;
 
 import com.intellij.ide.DataManager;
-import com.intellij.ide.IdeBundle;
-import com.intellij.ide.favoritesTreeView.FavoritesManager;
-import com.intellij.ide.projectView.impl.AbstractUrl;
 import com.intellij.openapi.Disposable;
-import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.LangDataKeys;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.SelectionModel;
 import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.module.*;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Condition;
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.TextRange;
-import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.packageDependencies.ChangeListsScopesProvider;
 import com.intellij.packageDependencies.DependencyValidationManager;
-import com.intellij.psi.PsiDocumentManager;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiWhiteSpace;
-import com.intellij.psi.search.*;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.search.GlobalSearchScopesCore;
+import com.intellij.psi.search.PredefinedSearchScopeProvider;
+import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.search.scope.packageSet.NamedScope;
 import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
 import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.util.PsiUtilCore;
 import com.intellij.ui.ComboboxWithBrowseButton;
 import com.intellij.ui.ListCellRendererWrapper;
-import com.intellij.usages.Usage;
-import com.intellij.usages.UsageView;
-import com.intellij.usages.UsageViewManager;
-import com.intellij.usages.rules.PsiElementUsage;
-import com.intellij.util.PlatformUtils;
-import com.intellij.util.TreeItem;
-import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jps.model.java.JavaSourceRootType;
 
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.*;
+import java.util.ArrayList;
 import java.util.List;
 
 public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Disposable {
@@ -231,7 +206,9 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
 
   private void createPredefinedScopeDescriptors(DefaultComboBoxModel model) {
     @SuppressWarnings("deprecation") final DataContext context = DataManager.getInstance().getDataContext();
-    for (SearchScope scope : getPredefinedScopes(myProject, context, mySuggestSearchInLibs, myPrevSearchFiles, myCurrentSelection, myUsageView)) {
+    for (SearchScope scope : PredefinedSearchScopeProvider.getInstance().getPredefinedScopes(myProject, context, mySuggestSearchInLibs,
+                                                                                             myPrevSearchFiles, myCurrentSelection,
+                                                                                             myUsageView)) {
       model.addElement(new ScopeDescriptor(scope));
     }
     for (ScopeDescriptorProvider provider : Extensions.getExtensions(ScopeDescriptorProvider.EP_NAME)) {
@@ -241,224 +218,6 @@ public class ScopeChooserCombo extends ComboboxWithBrowseButton implements Dispo
     }
   }
 
-  public static List<SearchScope> getPredefinedScopes(@NotNull final Project project,
-                                                      @Nullable final DataContext dataContext,
-                                                      boolean suggestSearchInLibs,
-                                                      boolean prevSearchFiles,
-                                                      boolean currentSelection,
-                                                      boolean usageView) {
-    Collection<SearchScope> result = ContainerUtil.newLinkedHashSet();
-    result.add(GlobalSearchScope.projectScope(project));
-    if (suggestSearchInLibs) {
-      result.add(GlobalSearchScope.allScope(project));
-    }
-
-    if (ModuleUtil.isSupportedRootType(project, JavaSourceRootType.TEST_SOURCE)) {
-      result.add(GlobalSearchScopesCore.projectProductionScope(project));
-      result.add(GlobalSearchScopesCore.projectTestScope(project));
-    }
-
-    result.add(GlobalSearchScopes.openFilesScope(project));
-
-    if (dataContext != null) {
-      PsiElement dataContextElement = CommonDataKeys.PSI_FILE.getData(dataContext);
-      if (dataContextElement == null) {
-        dataContextElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
-      }
-      if (dataContextElement != null) {
-        if (!PlatformUtils.isCidr()) { // TODO: have an API to disable module scopes.
-          Module module = ModuleUtilCore.findModuleForPsiElement(dataContextElement);
-          if (module == null) {
-            module = LangDataKeys.MODULE.getData(dataContext);
-          }
-          if (module != null && !(ModuleType.get(module) instanceof InternalModuleType)) {
-            result.add(module.getModuleScope());
-          }
-        }
-        if (dataContextElement.getContainingFile() != null) {
-          result.add(new LocalSearchScope(dataContextElement, IdeBundle.message("scope.current.file")));
-        }
-      }
-    }
-
-    if (currentSelection) {
-      FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
-      final Editor selectedTextEditor = fileEditorManager.getSelectedTextEditor();
-      if (selectedTextEditor != null) {
-        final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(selectedTextEditor.getDocument());
-        if (psiFile != null) {
-          SelectionModel selectionModel = selectedTextEditor.getSelectionModel();
-          if (selectionModel.hasSelection()) {
-            int start = selectionModel.getSelectionStart();
-            final PsiElement startElement = psiFile.findElementAt(start);
-            if (startElement != null) {
-              int end = selectionModel.getSelectionEnd();
-              final PsiElement endElement = psiFile.findElementAt(end);
-              if (endElement != null) {
-                final PsiElement parent = PsiTreeUtil.findCommonParent(startElement, endElement);
-                if (parent != null) {
-                  final List<PsiElement> elements = new ArrayList<PsiElement>();
-                  final PsiElement[] children = parent.getChildren();
-                  TextRange selection = new TextRange(start, end);
-                  for (PsiElement child : children) {
-                    if (!(child instanceof PsiWhiteSpace) && child.getContainingFile() != null && selection.contains(child.getTextOffset())) {
-                      elements.add(child);
-                    }
-                  }
-                  if (!elements.isEmpty()) {
-                    SearchScope local = new LocalSearchScope(PsiUtilCore.toPsiElementArray(elements), IdeBundle.message("scope.selection"));
-                    result.add(local);
-                  }
-                }
-              }
-            }
-          }
-        }
-      }
-    }
-
-    if (usageView) {
-      UsageView selectedUsageView = UsageViewManager.getInstance(project).getSelectedUsageView();
-      if (selectedUsageView != null && !selectedUsageView.isSearchInProgress()) {
-        final Set<Usage> usages = selectedUsageView.getUsages();
-        final List<PsiElement> results = new ArrayList<PsiElement>(usages.size());
-
-        if (prevSearchFiles) {
-          final Set<VirtualFile> files = collectFiles(usages, true);
-          if (!files.isEmpty()) {
-            GlobalSearchScope prev = new GlobalSearchScope(project) {
-              private Set<VirtualFile> myFiles = null;
-              @NotNull
-              @Override
-              public String getDisplayName() {
-                return IdeBundle.message("scope.files.in.previous.search.result");
-              }
-
-              @Override
-              public synchronized boolean contains(@NotNull VirtualFile file) {
-                if (myFiles == null) {
-                  myFiles = collectFiles(usages, false);
-                }
-                return myFiles.contains(file);
-              }
-
-              @Override
-              public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
-                return 0;
-              }
-
-              @Override
-              public boolean isSearchInModuleContent(@NotNull Module aModule) {
-                return true;
-              }
-
-              @Override
-              public boolean isSearchInLibraries() {
-                return true;
-              }
-            };
-            result.add(prev);
-          }
-        }
-        else {
-          for (Usage usage : usages) {
-            if (usage instanceof PsiElementUsage) {
-              final PsiElement element = ((PsiElementUsage)usage).getElement();
-              if (element != null && element.isValid() && element.getContainingFile() != null) {
-                results.add(element);
-              }
-            }
-          }
-
-          if (!results.isEmpty()) {
-            result.add(new LocalSearchScope(PsiUtilCore.toPsiElementArray(results), IdeBundle.message("scope.previous.search.results")));
-          }
-        }
-      }
-    }
-
-    final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
-    if (favoritesManager != null) {
-      for (final String favorite : favoritesManager.getAvailableFavoritesListNames()) {
-        final Collection<TreeItem<Pair<AbstractUrl,String>>> rootUrls = favoritesManager.getFavoritesListRootUrls(favorite);
-        if (rootUrls.isEmpty()) continue;  // ignore unused root
-        result.add(new GlobalSearchScope(project) {
-          @NotNull
-          @Override
-          public String getDisplayName() {
-            return "Favorite \'" + favorite + "\'";
-          }
-
-          @Override
-          public boolean contains(@NotNull final VirtualFile file) {
-            return favoritesManager.contains(favorite, file);
-          }
-
-          @Override
-          public int compare(@NotNull final VirtualFile file1, @NotNull final VirtualFile file2) {
-            return 0;
-          }
-
-          @Override
-          public boolean isSearchInModuleContent(@NotNull final Module aModule) {
-            return true;
-          }
-
-          @Override
-          public boolean isSearchInLibraries() {
-            return true;
-          }
-        });
-      }
-    }
-
-    ContainerUtil.addIfNotNull(result, getSelectedFilesScope(project, dataContext));
-
-    return ContainerUtil.newArrayList(result);
-  }
-
-  @Nullable 
-  private static SearchScope getSelectedFilesScope(final Project project, @Nullable DataContext dataContext) {
-    final VirtualFile[] filesOrDirs = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
-    if (filesOrDirs != null) {
-      final List<VirtualFile> selectedFiles = ContainerUtil.filter(filesOrDirs, new Condition<VirtualFile>() {
-        @Override
-        public boolean value(VirtualFile file) {
-          return !file.isDirectory();
-        }
-      });
-      if (!selectedFiles.isEmpty()) {
-        return new DelegatingGlobalSearchScope(GlobalSearchScope.filesScope(project, selectedFiles)){
-          @NotNull
-          @Override
-          public String getDisplayName() {
-            return "Selected Files";
-          }
-        };
-      }
-    }
-    return null;
-  }
-
-  protected static Set<VirtualFile> collectFiles(Set<Usage> usages, boolean findFirst) {
-    final Set<VirtualFile> files = new HashSet<VirtualFile>();
-    for (Usage usage : usages) {
-      if (usage instanceof PsiElementUsage) {
-        PsiElement psiElement = ((PsiElementUsage)usage).getElement();
-        if (psiElement != null && psiElement.isValid()) {
-          PsiFile psiFile = psiElement.getContainingFile();
-          if (psiFile != null) {
-            VirtualFile file = psiFile.getVirtualFile();
-            if (file != null) {
-              files.add(file);
-              if (findFirst) return files;
-            }
-          }
-        }
-      }
-    }
-    return files;
-  }
 
   @Nullable
   public SearchScope getSelectedScope() {
diff --git a/platform/lang-impl/src/com/intellij/psi/search/PredefinedSearchScopeProviderImpl.java b/platform/lang-impl/src/com/intellij/psi/search/PredefinedSearchScopeProviderImpl.java
new file mode 100644 (file)
index 0000000..7e96f96
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * 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.search;
+
+import com.intellij.ide.IdeBundle;
+import com.intellij.ide.favoritesTreeView.FavoritesManager;
+import com.intellij.ide.projectView.impl.AbstractUrl;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.SelectionModel;
+import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.module.*;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.TextRange;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiDocumentManager;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiWhiteSpace;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.util.PsiUtilCore;
+import com.intellij.usages.Usage;
+import com.intellij.usages.UsageView;
+import com.intellij.usages.UsageViewManager;
+import com.intellij.usages.rules.PsiElementUsage;
+import com.intellij.util.PlatformUtils;
+import com.intellij.util.TreeItem;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jps.model.java.JavaSourceRootType;
+
+import java.util.*;
+
+public class PredefinedSearchScopeProviderImpl extends PredefinedSearchScopeProvider {
+  @NotNull
+  @Override
+  public List<SearchScope> getPredefinedScopes(@NotNull final Project project,
+                                               @Nullable final DataContext dataContext,
+                                               boolean suggestSearchInLibs,
+                                               boolean prevSearchFiles,
+                                               boolean currentSelection,
+                                               boolean usageView) {
+    Collection<SearchScope> result = ContainerUtil.newLinkedHashSet();
+    result.add(GlobalSearchScope.projectScope(project));
+    if (suggestSearchInLibs) {
+      result.add(GlobalSearchScope.allScope(project));
+    }
+
+    if (ModuleUtil.isSupportedRootType(project, JavaSourceRootType.TEST_SOURCE)) {
+      result.add(GlobalSearchScopesCore.projectProductionScope(project));
+      result.add(GlobalSearchScopesCore.projectTestScope(project));
+    }
+
+    result.add(GlobalSearchScopes.openFilesScope(project));
+
+    if (dataContext != null) {
+      PsiElement dataContextElement = CommonDataKeys.PSI_FILE.getData(dataContext);
+      if (dataContextElement == null) {
+        dataContextElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
+      }
+      if (dataContextElement != null) {
+        if (!PlatformUtils.isCidr()) { // TODO: have an API to disable module scopes.
+          Module module = ModuleUtilCore.findModuleForPsiElement(dataContextElement);
+          if (module == null) {
+            module = LangDataKeys.MODULE.getData(dataContext);
+          }
+          if (module != null && !(ModuleType.get(module) instanceof InternalModuleType)) {
+            result.add(module.getModuleScope());
+          }
+        }
+        if (dataContextElement.getContainingFile() != null) {
+          result.add(new LocalSearchScope(dataContextElement, IdeBundle.message("scope.current.file")));
+        }
+      }
+    }
+
+    if (currentSelection) {
+      FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
+      final Editor selectedTextEditor = fileEditorManager.getSelectedTextEditor();
+      if (selectedTextEditor != null) {
+        final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(selectedTextEditor.getDocument());
+        if (psiFile != null) {
+          SelectionModel selectionModel = selectedTextEditor.getSelectionModel();
+          if (selectionModel.hasSelection()) {
+            int start = selectionModel.getSelectionStart();
+            final PsiElement startElement = psiFile.findElementAt(start);
+            if (startElement != null) {
+              int end = selectionModel.getSelectionEnd();
+              final PsiElement endElement = psiFile.findElementAt(end);
+              if (endElement != null) {
+                final PsiElement parent = PsiTreeUtil.findCommonParent(startElement, endElement);
+                if (parent != null) {
+                  final List<PsiElement> elements = new ArrayList<PsiElement>();
+                  final PsiElement[] children = parent.getChildren();
+                  TextRange selection = new TextRange(start, end);
+                  for (PsiElement child : children) {
+                    if (!(child instanceof PsiWhiteSpace) && child.getContainingFile() != null && selection.contains(child.getTextOffset())) {
+                      elements.add(child);
+                    }
+                  }
+                  if (!elements.isEmpty()) {
+                    SearchScope local = new LocalSearchScope(PsiUtilCore.toPsiElementArray(elements), IdeBundle.message("scope.selection"));
+                    result.add(local);
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+
+    if (usageView) {
+      UsageView selectedUsageView = UsageViewManager.getInstance(project).getSelectedUsageView();
+      if (selectedUsageView != null && !selectedUsageView.isSearchInProgress()) {
+        final Set<Usage> usages = selectedUsageView.getUsages();
+        final List<PsiElement> results = new ArrayList<PsiElement>(usages.size());
+
+        if (prevSearchFiles) {
+          final Set<VirtualFile> files = collectFiles(usages, true);
+          if (!files.isEmpty()) {
+            GlobalSearchScope prev = new GlobalSearchScope(project) {
+              private Set<VirtualFile> myFiles = null;
+              @NotNull
+              @Override
+              public String getDisplayName() {
+                return IdeBundle.message("scope.files.in.previous.search.result");
+              }
+
+              @Override
+              public synchronized boolean contains(@NotNull VirtualFile file) {
+                if (myFiles == null) {
+                  myFiles = collectFiles(usages, false);
+                }
+                return myFiles.contains(file);
+              }
+
+              @Override
+              public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
+                return 0;
+              }
+
+              @Override
+              public boolean isSearchInModuleContent(@NotNull Module aModule) {
+                return true;
+              }
+
+              @Override
+              public boolean isSearchInLibraries() {
+                return true;
+              }
+            };
+            result.add(prev);
+          }
+        }
+        else {
+          for (Usage usage : usages) {
+            if (usage instanceof PsiElementUsage) {
+              final PsiElement element = ((PsiElementUsage)usage).getElement();
+              if (element != null && element.isValid() && element.getContainingFile() != null) {
+                results.add(element);
+              }
+            }
+          }
+
+          if (!results.isEmpty()) {
+            result.add(new LocalSearchScope(PsiUtilCore.toPsiElementArray(results), IdeBundle.message("scope.previous.search.results")));
+          }
+        }
+      }
+    }
+
+    final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
+    if (favoritesManager != null) {
+      for (final String favorite : favoritesManager.getAvailableFavoritesListNames()) {
+        final Collection<TreeItem<Pair<AbstractUrl,String>>> rootUrls = favoritesManager.getFavoritesListRootUrls(favorite);
+        if (rootUrls.isEmpty()) continue;  // ignore unused root
+        result.add(new GlobalSearchScope(project) {
+          @NotNull
+          @Override
+          public String getDisplayName() {
+            return "Favorite \'" + favorite + "\'";
+          }
+
+          @Override
+          public boolean contains(@NotNull final VirtualFile file) {
+            return favoritesManager.contains(favorite, file);
+          }
+
+          @Override
+          public int compare(@NotNull final VirtualFile file1, @NotNull final VirtualFile file2) {
+            return 0;
+          }
+
+          @Override
+          public boolean isSearchInModuleContent(@NotNull final Module aModule) {
+            return true;
+          }
+
+          @Override
+          public boolean isSearchInLibraries() {
+            return true;
+          }
+        });
+      }
+    }
+
+    ContainerUtil.addIfNotNull(result, getSelectedFilesScope(project, dataContext));
+
+    return ContainerUtil.newArrayList(result);
+  }
+
+  @Nullable
+  private static SearchScope getSelectedFilesScope(final Project project, @Nullable DataContext dataContext) {
+    final VirtualFile[] filesOrDirs = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
+    if (filesOrDirs != null) {
+      final List<VirtualFile> selectedFiles = ContainerUtil.filter(filesOrDirs, new Condition<VirtualFile>() {
+        @Override
+        public boolean value(VirtualFile file) {
+          return !file.isDirectory();
+        }
+      });
+      if (!selectedFiles.isEmpty()) {
+        return new DelegatingGlobalSearchScope(GlobalSearchScope.filesScope(project, selectedFiles)){
+          @NotNull
+          @Override
+          public String getDisplayName() {
+            return "Selected Files";
+          }
+        };
+      }
+    }
+    return null;
+  }
+
+  protected static Set<VirtualFile> collectFiles(Set<Usage> usages, boolean findFirst) {
+    final Set<VirtualFile> files = new HashSet<VirtualFile>();
+    for (Usage usage : usages) {
+      if (usage instanceof PsiElementUsage) {
+        PsiElement psiElement = ((PsiElementUsage)usage).getElement();
+        if (psiElement != null && psiElement.isValid()) {
+          PsiFile psiFile = psiElement.getContainingFile();
+          if (psiFile != null) {
+            VirtualFile file = psiFile.getVirtualFile();
+            if (file != null) {
+              files.add(file);
+              if (findFirst) return files;
+            }
+          }
+        }
+      }
+    }
+    return files;
+  }
+}
index 4aa4ef8dea9494faeb72ba2c6ac9ad9b2f769f46..6d7cfa2ce4b801edb49dbe8f84474b58404a8b8a 100644 (file)
 
     <applicationService serviceInterface="com.intellij.psi.impl.source.resolve.reference.impl.providers.FileInfoManager"
                         serviceImplementation="com.intellij.psi.impl.source.resolve.reference.impl.providers.FileInfoManager"/>
+    <applicationService serviceInterface="com.intellij.psi.search.PredefinedSearchScopeProvider"
+                        serviceImplementation="com.intellij.psi.search.PredefinedSearchScopeProviderImpl"/>
 
     <applicationService serviceInterface="com.intellij.psi.PsiReferenceService"
                         serviceImplementation="com.intellij.psi.PsiReferenceServiceImpl"/>