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); } }
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(); }
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; } }); }
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; } }); }
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; }
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); } }); }
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); } }); }
@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); }
@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); }
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)); }
@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(); } } ); }
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; }
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); } }); }
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(); }
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; } }); }
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; } }); }
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(); }
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()); }
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; }
@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); } } }
@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; } }); }
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; }
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(); } }); } }
public AbstractFileTreeTable(@NotNull Project project, @NotNull Class<T> valueClass, @NotNull String valueTitle, @NotNull VirtualFileFilter filter, boolean showProjectNode) { this(project, valueClass, valueTitle, filter, showProjectNode, true); }
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"); } }; }
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()); }
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; }
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); }
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()); }
public void testFindClass() { getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.ALL); PsiClass aClass = myJavaFacade.findClass("pack.MyClass", GlobalSearchScope.allScope(myProject)); assertNotNull(aClass); checkValid(aClass); getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE); }
@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); } } }
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; }
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"); } }; }
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); } }
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; }
@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); } } }
@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; } }); }
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; }