Java 类com.intellij.psi.search.DelegatingGlobalSearchScope 实例源码

项目:intellij-ce-playground    文件:MavenClasspathsAndSearchScopesTest.java   
private void assertSearchScope(GlobalSearchScope searchScope, String... expectedPaths) {
  Collection<VirtualFile> roots;
  if (searchScope instanceof DelegatingGlobalSearchScope) {
    searchScope = ReflectionUtil.getField(DelegatingGlobalSearchScope.class, searchScope, GlobalSearchScope.class, "myBaseScope");
  }
  if (searchScope instanceof ModuleWithDependenciesScope) {
    roots = ((ModuleWithDependenciesScope)searchScope).getRoots();
  }
  else {
    roots = ((LibraryRuntimeClasspathScope)searchScope).getRoots();
  }
  final List<VirtualFile> entries = new ArrayList<VirtualFile>(roots);
  entries.removeAll(Arrays.asList(ProjectRootManager.getInstance(myProject).orderEntries().sdkOnly().classes().getRoots()));

  List<String> actualPaths = new ArrayList<String>();
  for (VirtualFile each : entries) {
    actualPaths.add(each.getPresentableUrl());
  }

  assertPaths(expectedPaths, actualPaths);
}
项目:consulo-java    文件:DefaultDebugEnvironment.java   
private static GlobalSearchScope createSearchScope(@NotNull Project project, @Nullable RunProfile runProfile)
{
    GlobalSearchScope scope = SearchScopeProvider.createSearchScope(project, runProfile);
    if(scope.equals(GlobalSearchScope.allScope(project)))
    {
        // prefer sources over class files
        return new DelegatingGlobalSearchScope(scope)
        {
            final ProjectFileIndex myProjectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            final Comparator<VirtualFile> myScopeComparator = Comparator.comparing(myProjectFileIndex::isInSource).thenComparing(myProjectFileIndex::isInLibrarySource).thenComparing
                    (super::compare);

            @Override
            public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2)
            {
                return myScopeComparator.compare(file1, file2);
            }
        };
    }
    return scope;
}
项目:intellij-ce-playground    文件:ExternalModuleBuildGlobalSearchScope.java   
public ExternalModuleBuildGlobalSearchScope(@NotNull final Project project,
                                            @NotNull GlobalSearchScope baseScope,
                                            @NotNull String externalModulePath) {
  super(new DelegatingGlobalSearchScope(baseScope) {
    @Nullable
    @Override
    public Project getProject() {
      return project;
    }
  });
  this.externalModulePath = externalModulePath;
}
项目:intellij-ce-playground    文件:JavaFxScopeEnlarger.java   
@Nullable
@Override
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
  PsiClass containingClass = null;
  if (element instanceof PsiField) {
    containingClass = ((PsiField)element).getContainingClass();
  }
  else if (element instanceof PsiParameter) {
    final PsiElement declarationScope = ((PsiParameter)element).getDeclarationScope();
    if (declarationScope instanceof PsiMethod && PropertyUtil.isSimplePropertySetter((PsiMethod)declarationScope)) {
      containingClass = ((PsiMethod)declarationScope).getContainingClass();
    }
  }

  if (containingClass != null) {
    if (element instanceof PsiField && 
        !((PsiField)element).hasModifierProperty(PsiModifier.PUBLIC) && 
        AnnotationUtil.isAnnotated((PsiField)element, JavaFxCommonClassNames.JAVAFX_FXML_ANNOTATION, false) || element instanceof PsiParameter) {
      final Project project = element.getProject();
      final String qualifiedName = containingClass.getQualifiedName();
      if (qualifiedName != null && !JavaFxControllerClassIndex.findFxmlWithController(project, qualifiedName).isEmpty()) {
        final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
        return new DelegatingGlobalSearchScope(projectScope){
          @Override
          public boolean contains(@NotNull VirtualFile file) {
            return super.contains(file) && JavaFxFileTypeFactory.isFxml(file);
          }
        };
      }
    }
  } 

  return null;
}
项目:tools-idea    文件:JavaFxScopeEnlarger.java   
@Nullable
@Override
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
  PsiClass containingClass = null;
  if (element instanceof PsiField) {
    containingClass = ((PsiField)element).getContainingClass();
  }
  else if (element instanceof PsiParameter) {
    final PsiElement declarationScope = ((PsiParameter)element).getDeclarationScope();
    if (declarationScope instanceof PsiMethod && PropertyUtil.isSimplePropertySetter((PsiMethod)declarationScope)) {
      containingClass = ((PsiMethod)declarationScope).getContainingClass();
    }
  }

  if (containingClass != null) {
    if (element instanceof PsiField && ((PsiField)element).hasModifierProperty(PsiModifier.PRIVATE) || element instanceof PsiParameter) {
      final Project project = element.getProject();
      final String qualifiedName = containingClass.getQualifiedName();
      if (qualifiedName != null && !JavaFxControllerClassIndex.findFxmlWithController(project, qualifiedName).isEmpty()) {
        final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
        return new DelegatingGlobalSearchScope(projectScope){
          @Override
          public boolean contains(VirtualFile file) {
            return super.contains(file) && JavaFxFileTypeFactory.isFxml(file);
          }
        };
      }
    }
  } 

  return null;
}
项目:consulo-javafx    文件:JavaFxScopeEnlarger.java   
@Nullable
@Override
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
  PsiClass containingClass = null;
  if (element instanceof PsiField) {
    containingClass = ((PsiField)element).getContainingClass();
  }
  else if (element instanceof PsiParameter) {
    final PsiElement declarationScope = ((PsiParameter)element).getDeclarationScope();
    if (declarationScope instanceof PsiMethod && PropertyUtil.isSimplePropertySetter((PsiMethod)declarationScope)) {
      containingClass = ((PsiMethod)declarationScope).getContainingClass();
    }
  }

  if (containingClass != null) {
    if (element instanceof PsiField && ((PsiField)element).hasModifierProperty(PsiModifier.PRIVATE) || element instanceof PsiParameter) {
      final Project project = element.getProject();
      final String qualifiedName = containingClass.getQualifiedName();
      if (qualifiedName != null && !JavaFxControllerClassIndex.findFxmlWithController(project, qualifiedName).isEmpty()) {
        final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
        return new DelegatingGlobalSearchScope(projectScope){
          @Override
          public boolean contains(VirtualFile file) {
            return super.contains(file) && JavaFxFileTypeFactory.isFxml(file);
          }
        };
      }
    }
  } 

  return null;
}
项目:consulo    文件:ExternalModuleBuildGlobalSearchScope.java   
public ExternalModuleBuildGlobalSearchScope(@Nonnull final Project project, @Nonnull GlobalSearchScope baseScope, @Nonnull String externalModulePath) {
  super(new DelegatingGlobalSearchScope(baseScope) {
    @Nullable
    @Override
    public Project getProject() {
      return project;
    }
  });
  this.externalModulePath = externalModulePath;
}
项目:intellij-ce-playground    文件:LibraryScopeCache.java   
@NotNull
private GlobalSearchScope calcLibraryScope(@NotNull List<OrderEntry> orderEntries) {
  List<Module> modulesLibraryUsedIn = new ArrayList<Module>();

  LibraryOrderEntry lib = null;
  for (OrderEntry entry : orderEntries) {
    if (entry instanceof JdkOrderEntry) {
      return getScopeForSdk((JdkOrderEntry)entry);
    }

    if (entry instanceof LibraryOrderEntry) {
      lib = (LibraryOrderEntry)entry;
      modulesLibraryUsedIn.add(entry.getOwnerModule());
    }
    else if (entry instanceof ModuleOrderEntry) {
      modulesLibraryUsedIn.add(entry.getOwnerModule());
    }
  }

  Comparator<Module> comparator = new Comparator<Module>() {
    @Override
    public int compare(@NotNull Module o1, @NotNull Module o2) {
      return o1.getName().compareTo(o2.getName());
    }
  };
  Collections.sort(modulesLibraryUsedIn, comparator);
  List<Module> uniquesList = ContainerUtil.removeDuplicatesFromSorted(modulesLibraryUsedIn, comparator);
  Module[] uniques = uniquesList.toArray(new Module[uniquesList.size()]);

  GlobalSearchScope allCandidates = getScopeForLibraryUsedIn(uniques);
  if (lib != null) {
    final LibraryRuntimeClasspathScope preferred = new LibraryRuntimeClasspathScope(myProject, lib);
    // prefer current library
    return new DelegatingGlobalSearchScope(allCandidates, preferred) {
      @Override
      public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
        boolean c1 = preferred.contains(file1);
        boolean c2 = preferred.contains(file2);
        if (c1 && !c2) return 1;
        if (c2 && !c1) return -1;

        return super.compare(file1, file2);
      }
    };
  }
  return allCandidates;
}
项目:tools-idea    文件:ResolveScopeManagerImpl.java   
private GlobalSearchScope getInherentResolveScope(VirtualFile vFile) {
  ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
  Module module = projectFileIndex.getModuleForFile(vFile);
  if (module != null) {
    boolean includeTests = projectFileIndex.isInTestSourceContent(vFile);
                           // TODO: dmitrylomov: removed this line to see what fails.
                           //!(vFile.getFileType() == StdFileTypes.JAVA && projectFileIndex.isContentSourceFile(vFile));
    return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
  }
  else {
    // resolve references in libraries in context of all modules which contain it
    List<Module> modulesLibraryUsedIn = new ArrayList<Module>();
    List<OrderEntry> orderEntries = projectFileIndex.getOrderEntriesForFile(vFile);

    LibraryOrderEntry lib = null;
    for (OrderEntry entry : orderEntries) {
      if (entry instanceof JdkOrderEntry) {
        return LibraryScopeCache.getInstance(myProject).getScopeForSdk((JdkOrderEntry)entry);
      }

      if (entry instanceof LibraryOrderEntry) {
        lib = (LibraryOrderEntry)entry;
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof ModuleOrderEntry) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
    }

    GlobalSearchScope allCandidates = LibraryScopeCache.getInstance(myProject).getScopeForLibraryUsedIn(modulesLibraryUsedIn);
    if (lib != null) {
      final LibraryRuntimeClasspathScope preferred = new LibraryRuntimeClasspathScope(myProject, lib);
      // prefer current library
      return new DelegatingGlobalSearchScope(allCandidates, preferred) {
        @Override
        public int compare(VirtualFile file1, VirtualFile file2) {
          boolean c1 = preferred.contains(file1);
          boolean c2 = preferred.contains(file2);
          if (c1 && !c2) return 1;
          if (c2 && !c1) return -1;

          return super.compare(file1, file2);
        }
      };
    }
    return allCandidates;
  }
}
项目:consulo    文件:ResolveScopeManagerImpl.java   
@Nonnull
private GlobalSearchScope getInherentResolveScope(VirtualFile vFile) {
  ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
  Module module = projectFileIndex.getModuleForFile(vFile);
  if (module != null) {
    boolean includeTests = projectFileIndex.isInTestSourceContent(vFile);
    return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
  }
  else {
    // resolve references in libraries in context of all modules which contain it
    List<Module> modulesLibraryUsedIn = new ArrayList<>();
    List<OrderEntry> orderEntries = projectFileIndex.getOrderEntriesForFile(vFile);

    LibraryOrderEntry lib = null;
    for (OrderEntry entry : orderEntries) {
      if (entry instanceof ModuleExtensionWithSdkOrderEntry) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof LibraryOrderEntry) {
        lib = (LibraryOrderEntry)entry;
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof ModuleOrderEntry) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof OrderEntryWithTracking) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
    }

    GlobalSearchScope allCandidates = LibraryScopeCache.getInstance(myProject).getScopeForLibraryUsedIn(modulesLibraryUsedIn);
    if (lib != null) {
      final LibraryRuntimeClasspathScope preferred = new LibraryRuntimeClasspathScope(myProject, lib);
      // prefer current library
      return new DelegatingGlobalSearchScope(allCandidates, preferred) {
        @Override
        public int compare(@Nonnull VirtualFile file1, @Nonnull VirtualFile file2) {
          boolean c1 = preferred.contains(file1);
          boolean c2 = preferred.contains(file2);
          if (c1 && !c2) return 1;
          if (c2 && !c1) return -1;

          return super.compare(file1, file2);
        }
      };
    }
    return allCandidates;
  }
}