Java 类com.intellij.openapi.vfs.VirtualFileFilter 实例源码

项目:intellij-ce-playground    文件:LightDaemonAnalyzerTestCase.java   
private void checkHighlighting(ExpectedHighlightingData data, String filePath) {
  data.init();

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  getFile().getText(); //to load text
  myJavaFilesFilter.allowTreeAccessForFile(getVFile());
  getJavaFacade().setAssertOnFileLoadingFilter(myJavaFilesFilter, myTestRootDisposable); // check repository work

  try {
    Collection<HighlightInfo> infos = doHighlighting();

    data.checkResult(infos, getEditor().getDocument().getText(), filePath);
  }
  finally {
    getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
  }
}
项目:intellij-ce-playground    文件:Src15RepositoryUseTest.java   
public void testAnnotationIndex() throws Exception {
  getJavaFacade().setAssertOnFileLoadingFilter(new VirtualFileFilter() {
    @Override
    public boolean accept(final VirtualFile file) {
      return !"package-info.java".equals(file.getName());
    }
  }, myTestRootDisposable);

  final PsiClass annotationTypeClass = findClass("annotations.AnnotationType");
  assertTrue(annotationTypeClass.isAnnotationType());

  final Collection<PsiMember> all = AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();

  assertEquals(2, all.size());
  Set<String> correctNames = new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
  for (PsiMember member : all) {
    assertTrue(correctNames.contains(member.getName()));
  }

  final Collection<PsiPackage> packages =
    AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
  assertEquals(1, packages.size());
  assertEquals("annotated", packages.iterator().next().getQualifiedName());

  tearDownLoadingFilter();
}
项目:intellij-ce-playground    文件:AnalysisScope.java   
protected boolean accept(@NotNull final PsiDirectory dir, @NotNull final Processor<VirtualFile> processor) {
  final Project project = dir.getProject();
  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  //we should analyze generated source files only if the action is explicitly invoked for a directory located under generated roots
  final boolean processGeneratedFiles = isInGeneratedSources(dir.getVirtualFile(), project);
  return VfsUtilCore.iterateChildrenRecursively(dir.getVirtualFile(), VirtualFileFilter.ALL, new ContentIterator() {
    @Override
    @SuppressWarnings({"SimplifiableIfStatement"})
    public boolean processFile(@NotNull final VirtualFile fileOrDir) {
      if (!myIncludeTestSource && index.isInTestSourceContent(fileOrDir)) return true;
      if (!processGeneratedFiles && isInGeneratedSources(fileOrDir, project)) return true;
      if (!fileOrDir.isDirectory()) {
        return processor.process(fileOrDir);
      }
      return true;
    }
  });
}
项目:intellij-ce-playground    文件:ReformatCodeAction.java   
public static void registerScopeFilter(@NotNull AbstractLayoutCodeProcessor processor, @Nullable final SearchScope scope) {
  if (scope == null) {
    return;
  }

  processor.addFileFilter(new VirtualFileFilter() {
    @Override
    public boolean accept(@NotNull VirtualFile file) {
      if (scope instanceof LocalSearchScope) {
        return ((LocalSearchScope)scope).isInScope(file);
      }
      if (scope instanceof GlobalSearchScope) {
        return ((GlobalSearchScope)scope).contains(file);
      }

      return false;
    }
  });
}
项目:intellij-ce-playground    文件:PyMultiFileResolveTestCase.java   
protected PsiElement doResolve(PsiFile psiFile) {
  final PsiPolyVariantReference ref = PyResolveTestCase.findReferenceByMarker(psiFile);
  final PsiManagerImpl psiManager = (PsiManagerImpl)myFixture.getPsiManager();
  psiManager.setAssertOnFileLoadingFilter(new VirtualFileFilter() {
    @Override
    public boolean accept(VirtualFile file) {
      FileType fileType = file.getFileType();
      return fileType == PythonFileType.INSTANCE;
    }
  }, myTestRootDisposable);
  final ResolveResult[] resolveResults = ref.multiResolve(false);
  psiManager.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
  if (resolveResults.length == 0) {
    return null;
  }
  return resolveResults[0].isValidResult() ? resolveResults[0].getElement() : null;
}
项目:intellij-ce-playground    文件:AndroidConversionTest.java   
public void testConvert() throws IOException {
  final String testDataPath = AndroidTestCase.getTestDataPath() + "/conversion/proguardOptions";
  final File testData = new File(testDataPath, "before");
  final File tempDir = FileUtil.createTempDirectory("project", null);
  FileUtil.copyDir(testData, tempDir);
  ProjectConversionTestUtil.convert(tempDir.getAbsolutePath());
  final File expectedDataDir = new File(testDataPath, "after");
  PlatformTestUtil.assertDirectoriesEqual(
    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(expectedDataDir),
    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir),
    new VirtualFileFilter() {
      @Override
      public boolean accept(VirtualFile file) {
        return !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP);
      }
    });
}
项目:intellij-ce-playground    文件:AppEngineFacetConverterTest.java   
public void testConvert() throws IOException {
  String testDataPath = "plugins/google-app-engine/testData/conversion/appEngineFacet/";
  File testData = PathManagerEx.findFileUnderProjectHome(testDataPath + "before", getClass());
  File tempDir = FileUtil.createTempDirectory("app-engine-project", null);
  FileUtil.copyDir(testData, tempDir);
  ProjectConversionTestUtil.convert(tempDir.getAbsolutePath());
  File expectedDataDir = PathManagerEx.findFileUnderProjectHome(testDataPath + "after", getClass());
  PlatformTestUtil.assertDirectoriesEqual(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(expectedDataDir),
                                          LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir),
                                          new VirtualFileFilter() {
                                            @Override
                                            public boolean accept(VirtualFile file) {
                                              return !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP);
                                            }
                                          });
}
项目:intellij    文件:FileLookupData.java   
@Nullable
public static FileLookupData nonLocalFileLookup(
    String originalLabel,
    @Nullable BuildFile containingFile,
    QuoteType quoteType,
    PathFormat pathFormat) {
  if (originalLabel.indexOf(':') != -1) {
    // it's a package-local reference
    return null;
  }
  // handle the single '/' case by calling twice.
  String relativePath = StringUtil.trimStart(StringUtil.trimStart(originalLabel, "/"), "/");
  if (relativePath.startsWith("/")) {
    return null;
  }
  boolean onlyDirectories = pathFormat != PathFormat.NonLocalWithoutInitialBackslashes;
  VirtualFileFilter filter = vf -> !onlyDirectories || vf.isDirectory();
  return new FileLookupData(
      originalLabel, containingFile, null, relativePath, pathFormat, quoteType, filter);
}
项目:intellij    文件:FileLookupData.java   
@Nullable
public static FileLookupData packageLocalFileLookup(
    String originalLabel,
    StringLiteral element,
    @Nullable BuildFile basePackage,
    @Nullable VirtualFileFilter fileFilter) {
  if (basePackage == null) {
    return null;
  }
  Label packageLabel = basePackage.getPackageLabel();
  if (packageLabel == null) {
    return null;
  }
  String basePackagePath = packageLabel.blazePackage().relativePath();
  String filePath = basePackagePath + "/" + LabelUtils.getRuleComponent(originalLabel);
  return new FileLookupData(
      originalLabel,
      basePackage,
      basePackagePath,
      filePath,
      PathFormat.PackageLocal,
      element.getQuoteType(),
      fileFilter);
}
项目:intellij    文件:FileLookupData.java   
private FileLookupData(
    String originalLabel,
    @Nullable BuildFile containingFile,
    @Nullable String containingPackage,
    String filePathFragment,
    PathFormat pathFormat,
    QuoteType quoteType,
    @Nullable VirtualFileFilter fileFilter) {

  this.originalLabel = originalLabel;
  this.containingFile = containingFile;
  this.containingPackage = containingPackage;
  this.fileFilter = fileFilter;
  this.filePathFragment = filePathFragment;
  this.pathFormat = pathFormat;
  this.quoteType = quoteType;

  assert (pathFormat != PathFormat.PackageLocal
      || (containingPackage != null && containingFile != null));
}
项目:polygene-java    文件:PolygeneFacetType.java   
@Override
public final void registerDetectors( FacetDetectorRegistry<PolygeneFacetConfiguration> registry )
{
    registry.registerOnTheFlyDetector(
        StdFileTypes.JAVA, VirtualFileFilter.ALL, new HasPolygeneImportPackageCondition(),
        new FacetDetector<PsiFile, PolygeneFacetConfiguration>( "PolygeneFacetDetector" )
        {
            @Override
            public PolygeneFacetConfiguration detectFacet( PsiFile source,
                                                       Collection<PolygeneFacetConfiguration> existingConfigurations )
            {
                if( !existingConfigurations.isEmpty() )
                {
                    return existingConfigurations.iterator().next();
                }

                return createDefaultConfiguration();
            }
        }
    );
}
项目:google-cloud-intellij    文件:AppEngineCodeInsightTestCase.java   
protected CodeInsightTestFixture createCodeInsightFixture(final String relativeTestDataPath)
    throws Exception {
  final String testDataPath = new File(getTestDataPath(), relativeTestDataPath).getAbsolutePath();
  final CodeInsightTestFixture codeInsightFixture =
      JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(myProjectFixture);
  codeInsightFixture.setTestDataPath(testDataPath);
  final TempDirTestFixture tempDir = codeInsightFixture.getTempDirFixture();
  myModuleBuilder.addSourceContentRoot(tempDir.getTempDirPath());
  codeInsightFixture.setUp();
  final VirtualFile dir = LocalFileSystem.getInstance().refreshAndFindFileByPath(testDataPath);
  Assert.assertNotNull("Test data directory not found: " + testDataPath, dir);
  VfsUtil.processFilesRecursively(dir, new CommonProcessors.CollectProcessor<VirtualFile>());
  dir.refresh(false, true);
  tempDir.copyAll(
      testDataPath,
      "",
      new VirtualFileFilter() {
        @Override
        public boolean accept(VirtualFile file) {
          return !file.getName().contains("_after");
        }
      });
  return codeInsightFixture;
}
项目:google-cloud-intellij    文件:BaseConverterTest.java   
protected void testConvert(String testDataPath) throws IOException {
  // setup test data
  File testDataRoot = new File(AppEngineCodeInsightTestCase.getTestDataPath(), testDataPath);
  File testData = new File(testDataRoot, BEFORE_PATH);
  File tempDir = FileUtil.createTempDirectory(testDataPath, null);
  FileUtil.copyDir(testData, tempDir);
  File expectedDataDir = new File(testDataRoot, AFTER_PATH);

  // run the conversion operation
  ProjectConversionTestUtil.convert(tempDir.getAbsolutePath());

  PlatformTestUtil.assertDirectoriesEqual(
      LocalFileSystem.getInstance().refreshAndFindFileByIoFile(expectedDataDir),
      LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir),
      new VirtualFileFilter() {
        @Override
        public boolean accept(VirtualFile file) {
          // ignore any generated backup files
          return !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP);
        }
      });
}
项目:tools-idea    文件:Src15RepositoryUseTest.java   
public void testAnnotationIndex() throws Exception {
  getJavaFacade().setAssertOnFileLoadingFilter(new VirtualFileFilter() {
    @Override
    public boolean accept(final VirtualFile file) {
      return !"package-info.java".equals(file.getName());
    }
  });

  final PsiClass annotationTypeClass = findClass("annotations.AnnotationType");
  assertTrue(annotationTypeClass.isAnnotationType());

  final Collection<PsiMember> all = AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();

  assertEquals(2, all.size());
  Set<String> correctNames = new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
  for (PsiMember member : all) {
    assertTrue(correctNames.contains(member.getName()));
  }

  final Collection<PsiPackage> packages =
    AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
  assertEquals(1, packages.size());
  assertEquals("annotated", packages.iterator().next().getQualifiedName());

  tearDownLoadingFilter();
}
项目:tools-idea    文件:AnalysisScope.java   
protected void accept(@NotNull final PsiDirectory dir, @NotNull final PsiElementVisitor visitor, final boolean needReadAction) {
  final Project project = dir.getProject();
  final PsiManager psiManager = PsiManager.getInstance(project);
  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  VfsUtilCore.iterateChildrenRecursively(dir.getVirtualFile(), VirtualFileFilter.ALL, new ContentIterator() {
    @Override
    @SuppressWarnings({"SimplifiableIfStatement"})
    public boolean processFile(@NotNull final VirtualFile fileOrDir) {
      if (!myIncludeTestSource && index.isInTestSourceContent(fileOrDir)) return true;
      if (!fileOrDir.isDirectory()) {
        return AnalysisScope.processFile(fileOrDir, visitor, psiManager, needReadAction);
      }
      return true;
    }
  });
}
项目:tools-idea    文件:AppEngineFacetConverterTest.java   
public void testConvert() throws IOException {
  String testDataPath = "plugins/google-app-engine/testData/conversion/appEngineFacet/";
  File testData = PathManagerEx.findFileUnderProjectHome(testDataPath + "before", getClass());
  File tempDir = FileUtil.createTempDirectory("app-engine-project", null);
  FileUtil.copyDir(testData, tempDir);
  ProjectConversionTestUtil.convert(tempDir.getAbsolutePath());
  File expectedDataDir = PathManagerEx.findFileUnderProjectHome(testDataPath + "after", getClass());
  PlatformTestUtil.assertDirectoriesEqual(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(expectedDataDir),
                                          LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir),
                                          new VirtualFileFilter() {
                                            @Override
                                            public boolean accept(VirtualFile file) {
                                              return !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP);
                                            }
                                          });
}
项目:consulo    文件:AnalysisScope.java   
protected boolean accept(@Nonnull final PsiDirectory dir, @Nonnull final Processor<VirtualFile> processor) {
  final Project project = dir.getProject();
  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  //we should analyze generated source files only if the action is explicitly invoked for a directory located under generated roots
  final boolean processGeneratedFiles = isInGeneratedSources(dir.getVirtualFile(), project);
  return VfsUtilCore.iterateChildrenRecursively(dir.getVirtualFile(), VirtualFileFilter.ALL, new ContentIterator() {
    @Override
    @SuppressWarnings({"SimplifiableIfStatement"})
    public boolean processFile(@Nonnull final VirtualFile fileOrDir) {
      if (!myIncludeTestSource && index.isInTestSourceContent(fileOrDir)) return true;
      if (!processGeneratedFiles && isInGeneratedSources(fileOrDir, project)) return true;
      if (!fileOrDir.isDirectory()) {
        return processor.process(fileOrDir);
      }
      return true;
    }
  });
}
项目:consulo-java    文件:Src15RepositoryUseTest.java   
public void testAnnotationIndex() throws Exception {
  getJavaFacade().setAssertOnFileLoadingFilter(new VirtualFileFilter() {
    @Override
    public boolean accept(final VirtualFile file) {
      return !"package-info.java".equals(file.getName());
    }
  }, null);

  final PsiClass annotationTypeClass = findClass("annotations.AnnotationType");
  assertTrue(annotationTypeClass.isAnnotationType());

  final Collection<PsiMember> all = AnnotatedMembersSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();

  assertEquals(2, all.size());
  Set<String> correctNames = new HashSet<String>(Arrays.asList("AnnotatedClass", "correctMethod"));
  for (PsiMember member : all) {
    assertTrue(correctNames.contains(member.getName()));
  }

  final Collection<PsiJavaPackage> packages =
    AnnotatedPackagesSearch.search(annotationTypeClass, GlobalSearchScope.moduleScope(myModule)).findAll();
  assertEquals(1, packages.size());
  assertEquals("annotated", packages.iterator().next().getQualifiedName());

  tearDownLoadingFilter();
}
项目:intellij-ce-playground    文件:ModifyAnnotationsTest.java   
public void testReplaceAnnotation() throws Exception {
  //be sure not to load tree
  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.ALL, myTestRootDisposable);
  PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(myProject));
  assertNotNull(aClass);
  final PsiAnnotation[] annotations = aClass.getModifierList().getAnnotations();
  assertEquals(1, annotations.length);
  assertEquals("A", annotations[0].getNameReferenceElement().getReferenceName());
  final PsiAnnotation newAnnotation = myJavaFacade.getElementFactory().createAnnotationFromText("@B", null);
  //here the tree is going to be loaded
  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      WriteCommandAction.runWriteCommandAction(null, new Runnable() {
        @Override
        public void run() {
          try {
            annotations[0].replace(newAnnotation);
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
      });
    }
  }, null, null);

  assertEquals("@B", aClass.getModifierList().getText());
}
项目:intellij-ce-playground    文件:PlatformTestUtil.java   
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, @Nullable VirtualFileFilter filter) {
  HashMap<String, VirtualFile> map = new HashMap<String, VirtualFile>();
  for (VirtualFile file : files) {
    if (filter != null && !filter.accept(file)) continue;
    map.put(file.getName(), file);
  }
  return map;
}
项目:intellij-ce-playground    文件:PlatformTestUtil.java   
@SuppressWarnings("UnsafeVfsRecursion")
public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, @Nullable VirtualFileFilter fileFilter) throws IOException {
  FileDocumentManager.getInstance().saveAllDocuments();

  VirtualFile[] childrenAfter = dirAfter.getChildren();

  if (dirAfter.isInLocalFileSystem() && dirAfter.getFileSystem() != TempFileSystem.getInstance()) {
    File[] ioAfter = new File(dirAfter.getPath()).listFiles();
    shallowCompare(childrenAfter, ioAfter);
  }

  VirtualFile[] childrenBefore = dirBefore.getChildren();
  if (dirBefore.isInLocalFileSystem() && dirBefore.getFileSystem() != TempFileSystem.getInstance()) {
    File[] ioBefore = new File(dirBefore.getPath()).listFiles();
    shallowCompare(childrenBefore, ioBefore);
  }

  HashMap<String, VirtualFile> mapAfter = buildNameToFileMap(childrenAfter, fileFilter);
  HashMap<String, VirtualFile> mapBefore = buildNameToFileMap(childrenBefore, fileFilter);

  Set<String> keySetAfter = mapAfter.keySet();
  Set<String> keySetBefore = mapBefore.keySet();
  assertEquals(dirAfter.getPath(), keySetAfter, keySetBefore);

  for (String name : keySetAfter) {
    VirtualFile fileAfter = mapAfter.get(name);
    VirtualFile fileBefore = mapBefore.get(name);
    if (fileAfter.isDirectory()) {
      assertDirectoriesEqual(fileAfter, fileBefore, fileFilter);
    }
    else {
      assertFilesEqual(fileAfter, fileBefore);
    }
  }
}
项目:intellij-ce-playground    文件:PsiManagerImpl.java   
@TestOnly
public void setAssertOnFileLoadingFilter(@NotNull VirtualFileFilter filter, @NotNull Disposable parentDisposable) {
  // Find something to ensure there's no changed files waiting to be processed in repository indices.
  myAssertOnFileLoadingFilter = filter;
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      myAssertOnFileLoadingFilter = VirtualFileFilter.NONE;
    }
  });
}
项目:intellij-ce-playground    文件:AbstractLayoutCodeProcessor.java   
private boolean acceptedByFilters(@NotNull PsiFile file) {
  VirtualFile vFile = file.getVirtualFile();
  if (vFile == null) {
    return false;
  }

  for (VirtualFileFilter filter : myFilters) {
    if (!filter.accept(file.getVirtualFile())) {
      return false;
    }
  }

  return true;
}
项目:intellij-ce-playground    文件:ReformatCodeAction.java   
public static void registerFileMaskFilter(@NotNull AbstractLayoutCodeProcessor processor, @Nullable String fileTypeMask) {
  if (fileTypeMask == null)
    return;

  final Pattern pattern = getFileTypeMaskPattern(fileTypeMask);
  if (pattern != null) {
    processor.addFileFilter(new VirtualFileFilter() {
      @Override
      public boolean accept(@NotNull VirtualFile file) {
        return pattern.matcher(file.getName()).matches();
      }
    });
  }
}
项目:intellij-ce-playground    文件:AbstractFileTreeTable.java   
public AbstractFileTreeTable(@NotNull Project project,
                             @NotNull Class<T> valueClass,
                             @NotNull String valueTitle,
                             @NotNull VirtualFileFilter filter,
                             boolean showProjectNode) {
  this(project, valueClass, valueTitle, filter, showProjectNode, true);
}
项目:intellij-ce-playground    文件:XmlIndex.java   
protected static VirtualFileFilter createFilter(@NotNull final Module module) {

    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    return new VirtualFileFilter() {
      @Override
      public boolean accept(final VirtualFile file) {
        Module moduleForFile = fileIndex.getModuleForFile(file);
        if (moduleForFile != null) { // in module content
          return module.equals(moduleForFile);
        }
        if (fileIndex.isInLibraryClasses(file)) {
          List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(file);
          if (orderEntries.isEmpty()) {
            return false;
          }
          for (OrderEntry orderEntry : orderEntries) {
            Module ownerModule = orderEntry.getOwnerModule();
            if (ownerModule.equals(module)) {
              return true;
            }
          }
        }
        final VirtualFile parent = file.getParent();
        assert parent != null;
        return parent.getName().equals("standardSchemas");
      }
    };
  }
项目:intellij-ce-playground    文件:DomStubUsingTest.java   
public void testFileLoading() throws Exception {
  XmlFile file = prepareFile("foo.xml");
  ((PsiManagerImpl)getPsiManager()).setAssertOnFileLoadingFilter(VirtualFileFilter.ALL, myTestRootDisposable);
  DomFileElement<Foo> element = DomManager.getDomManager(getProject()).getFileElement(file, Foo.class);
  assertNotNull(element);
  GenericDomValue<String> id = element.getRootElement().getId();
  assertEquals("foo", id.getValue());
}
项目:intellij    文件:LabelReference.java   
private BuildLookupElement[] getSkylarkExtensionLookups(String labelString) {
  if (!skylarkExtensionReference(myElement)) {
    return BuildLookupElement.EMPTY_ARRAY;
  }
  String packagePrefix = LabelUtils.getPackagePathComponent(labelString);
  BuildFile parentFile = myElement.getContainingFile();
  if (parentFile == null) {
    return BuildLookupElement.EMPTY_ARRAY;
  }
  BlazePackage containingPackage = BlazePackage.getContainingPackage(parentFile);
  if (containingPackage == null) {
    return BuildLookupElement.EMPTY_ARRAY;
  }
  BuildFile referencedBuildFile =
      LabelUtils.getReferencedBuildFile(containingPackage.buildFile, packagePrefix);

  // Directories before the colon are already covered.
  // We're only concerned with package-local directories.
  boolean hasColon = labelString.indexOf(':') != -1;
  VirtualFileFilter filter =
      file ->
          ("bzl".equals(file.getExtension()) && !file.getPath().equals(parentFile.getFilePath()))
              || (hasColon && file.isDirectory());
  FileLookupData lookupData =
      FileLookupData.packageLocalFileLookup(labelString, myElement, referencedBuildFile, filter);

  return lookupData != null
      ? getReferenceManager().resolvePackageLookupElements(lookupData)
      : BuildLookupElement.EMPTY_ARRAY;
}
项目:tools-idea    文件:LightDaemonAnalyzerTestCase.java   
private void checkHighlighting(ExpectedHighlightingData data, String filePath) {
  data.init();

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  getFile().getText(); //to load text
  myJavaFilesFilter.allowTreeAccessForFile(getVFile());
  getJavaFacade().setAssertOnFileLoadingFilter(myJavaFilesFilter); // check repository work

  Collection<HighlightInfo> infos = doHighlighting();

  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);

  data.checkResult(infos, getEditor().getDocument().getText(), filePath);
}
项目:tools-idea    文件:ModifyAnnotationsTest.java   
public void testReplaceAnnotation() throws Exception {
  //be sure not to load tree
  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.ALL);
  PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(myProject));
  assertNotNull(aClass);
  final PsiAnnotation[] annotations = aClass.getModifierList().getAnnotations();
  assertEquals(1, annotations.length);
  assertEquals("A", annotations[0].getNameReferenceElement().getReferenceName());
  final PsiAnnotation newAnnotation = myJavaFacade.getElementFactory().createAnnotationFromText("@B", null);
  //here the tree is going to be loaded
  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          try {
            annotations[0].replace(newAnnotation);
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
      });
    }
  }, null, null);

  assertEquals("@B", aClass.getModifierList().getText());
}
项目:tools-idea    文件:ClsRepositoryUseTest.java   
public void testFindClass() {
  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.ALL);

  PsiClass aClass = myJavaFacade.findClass("pack.MyClass", GlobalSearchScope.allScope(myProject));
  assertNotNull(aClass);
  checkValid(aClass);

  getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
}
项目:tools-idea    文件:PlatformTestUtil.java   
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, @Nullable VirtualFileFilter filter) {
  HashMap<String, VirtualFile> map = new HashMap<String, VirtualFile>();
  for (VirtualFile file : files) {
    if (filter != null && !filter.accept(file)) continue;
    map.put(file.getName(), file);
  }
  return map;
}
项目:tools-idea    文件:PlatformTestUtil.java   
@SuppressWarnings("UnsafeVfsRecursion")
public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, @Nullable VirtualFileFilter fileFilter) throws IOException {
  FileDocumentManager.getInstance().saveAllDocuments();

  VirtualFile[] childrenAfter = dirAfter.getChildren();
  if (dirAfter.isInLocalFileSystem()) {
    File[] ioAfter = new File(dirAfter.getPath()).listFiles();
    shallowCompare(childrenAfter, ioAfter);
  }

  VirtualFile[] childrenBefore = dirBefore.getChildren();
  if (dirBefore.isInLocalFileSystem()) {
    File[] ioBefore = new File(dirBefore.getPath()).listFiles();
    shallowCompare(childrenBefore, ioBefore);
  }

  HashMap<String, VirtualFile> mapAfter = buildNameToFileMap(childrenAfter, fileFilter);
  HashMap<String, VirtualFile> mapBefore = buildNameToFileMap(childrenBefore, fileFilter);

  Set<String> keySetAfter = mapAfter.keySet();
  Set<String> keySetBefore = mapBefore.keySet();
  assertEquals(dirAfter.getPath(), keySetAfter, keySetBefore);

  for (String name : keySetAfter) {
    VirtualFile fileAfter = mapAfter.get(name);
    VirtualFile fileBefore = mapBefore.get(name);
    if (fileAfter.isDirectory()) {
      assertDirectoriesEqual(fileAfter, fileBefore, fileFilter);
    }
    else {
      assertFilesEqual(fileAfter, fileBefore);
    }
  }
}
项目:tools-idea    文件:CodeInsightTestFixtureImpl.java   
private long collectAndCheckHighlightings(final ExpectedHighlightingData data) {
    final Project project = getProject();
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    FileElement hardRefToFileElement = ((PsiFileImpl)myFile).calcTreeElement();//to load text

    //to initialize caches
    if (!DumbService.isDumb(project)) {
      CacheManager.SERVICE.getInstance(project).getFilesWithWord(XXX, UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(project), true);
    }

    List<HighlightInfo> infos;
    final long start = System.currentTimeMillis();
    try {
      ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(myJavaFilesFilter);

//    ProfilingUtil.startCPUProfiling();
      infos = doHighlighting();
      removeDuplicatedRangesForInjected(infos);
//    ProfilingUtil.captureCPUSnapshot("testing");
    }
    finally {
      ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
    }
    final long elapsed = System.currentTimeMillis() - start;

    data.checkResult(infos, myEditor.getDocument().getText());
    hardRefToFileElement.hashCode(); // use it so gc won't collect it
    return elapsed;
  }
项目:tools-idea    文件:XmlIndex.java   
protected static VirtualFileFilter createFilter(@NotNull final Module module) {

    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    return new VirtualFileFilter() {
      public boolean accept(final VirtualFile file) {
        Module moduleForFile = fileIndex.getModuleForFile(file);
        if (moduleForFile != null) { // in module content
          return module.equals(moduleForFile);
        }
        if (fileIndex.isInLibraryClasses(file)) {
          List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(file);
          if (orderEntries.isEmpty()) {
            return false;
          }
          for (OrderEntry orderEntry : orderEntries) {
            Module ownerModule = orderEntry.getOwnerModule();
            if (ownerModule.equals(module)) {
              return true;
            }
          }
        }
        final VirtualFile parent = file.getParent();
        assert parent != null;
        return parent.getName().equals("standardSchemas");
      }
    };
  }
项目:tools-idea    文件:DomStubUsingTest.java   
public void testFileLoading() throws Exception {
  XmlFile file = prepareFile("foo.xml");
  ((PsiManagerImpl)getPsiManager()).setAssertOnFileLoadingFilter(VirtualFileFilter.ALL);
  try {
    DomManager.getDomManager(getProject()).getFileElement(file, Foo.class);
  }
  finally {
    ((PsiManagerImpl)getPsiManager()).setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
  }
}
项目:consulo    文件:PlatformTestUtil.java   
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, @javax.annotation.Nullable VirtualFileFilter filter) {
  HashMap<String, VirtualFile> map = new HashMap<String, VirtualFile>();
  for (VirtualFile file : files) {
    if (filter != null && !filter.accept(file)) continue;
    map.put(file.getName(), file);
  }
  return map;
}
项目:consulo    文件:PlatformTestUtil.java   
@SuppressWarnings("UnsafeVfsRecursion")
public static void assertDirectoriesEqual(VirtualFile dirAfter, VirtualFile dirBefore, @javax.annotation.Nullable VirtualFileFilter fileFilter) throws IOException {
  FileDocumentManager.getInstance().saveAllDocuments();

  VirtualFile[] childrenAfter = dirAfter.getChildren();
  if (dirAfter.isInLocalFileSystem()) {
    File[] ioAfter = new File(dirAfter.getPath()).listFiles();
    shallowCompare(childrenAfter, ioAfter);
  }

  VirtualFile[] childrenBefore = dirBefore.getChildren();
  if (dirBefore.isInLocalFileSystem()) {
    File[] ioBefore = new File(dirBefore.getPath()).listFiles();
    shallowCompare(childrenBefore, ioBefore);
  }

  HashMap<String, VirtualFile> mapAfter = buildNameToFileMap(childrenAfter, fileFilter);
  HashMap<String, VirtualFile> mapBefore = buildNameToFileMap(childrenBefore, fileFilter);

  Set<String> keySetAfter = mapAfter.keySet();
  Set<String> keySetBefore = mapBefore.keySet();
  assertEquals(dirAfter.getPath(), keySetAfter, keySetBefore);

  for (String name : keySetAfter) {
    VirtualFile fileAfter = mapAfter.get(name);
    VirtualFile fileBefore = mapBefore.get(name);
    if (fileAfter.isDirectory()) {
      assertDirectoriesEqual(fileAfter, fileBefore, fileFilter);
    }
    else {
      assertFilesEqual(fileAfter, fileBefore);
    }
  }
}
项目:consulo    文件:PsiManagerImpl.java   
@Override
@TestOnly
public void setAssertOnFileLoadingFilter(@Nonnull VirtualFileFilter filter, @Nonnull Disposable parentDisposable) {
  // Find something to ensure there's no changed files waiting to be processed in repository indices.
  myAssertOnFileLoadingFilter = filter;
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      myAssertOnFileLoadingFilter = VirtualFileFilter.NONE;
    }
  });
}
项目:consulo    文件:AbstractLayoutCodeProcessor.java   
private boolean acceptedByFilters(@Nonnull PsiFile file) {
  VirtualFile vFile = file.getVirtualFile();
  if (vFile == null) {
    return false;
  }

  for (VirtualFileFilter filter : myFilters) {
    if (!filter.accept(file.getVirtualFile())) {
      return false;
    }
  }

  return true;
}