Search in sources :

Example 1 with FileContent

use of com.intellij.util.indexing.FileContent in project intellij-community by JetBrains.

the class FrameworkDetectionProcessor method collectSuitableFiles.

private void collectSuitableFiles(@NotNull VirtualFile file) {
    try {
        VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
                // Since this code is invoked from New Project Wizard it's very possible that VFS isn't loaded to memory yet, so we need to do it
                // manually, otherwise refresh will do nothing
                myProgressIndicator.checkCanceled();
                return true;
            }
        });
        file.refresh(false, true);
        VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

            @Override
            public boolean visitFile(@NotNull VirtualFile file) {
                myProgressIndicator.checkCanceled();
                if (!myProcessedFiles.add(file)) {
                    return false;
                }
                if (!file.isDirectory()) {
                    final FileType fileType = file.getFileType();
                    if (myDetectorsByFileType.containsKey(fileType)) {
                        myProgressIndicator.setText2(file.getPresentableUrl());
                        try {
                            final FileContent fileContent = new FileContentImpl(file, file.contentsToByteArray(false));
                            for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) {
                                if (detector.myFilePattern.accepts(fileContent)) {
                                    detector.mySuitableFiles.add(file);
                                }
                            }
                        } catch (IOException e) {
                            LOG.info(e);
                        }
                    }
                }
                return true;
            }
        });
    } catch (ProcessCanceledException ignored) {
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileContent(com.intellij.util.indexing.FileContent) FileType(com.intellij.openapi.fileTypes.FileType) FileContentImpl(com.intellij.util.indexing.FileContentImpl) IOException(java.io.IOException) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with FileContent

use of com.intellij.util.indexing.FileContent in project intellij-community by JetBrains.

the class PlatformIdTableBuilding method getTodoIndexer.

@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
    final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
    if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
        SubstitutedFileType sft = (SubstitutedFileType) fileType;
        extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
    } else {
        extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
    }
    if (extIndexer != null) {
        return extIndexer;
    }
    if (fileType instanceof LanguageFileType) {
        final Language lang = ((LanguageFileType) fileType).getLanguage();
        final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
        final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
        if (commentTokens != null) {
            return new TokenSetTodoIndexer(commentTokens, virtualFile);
        }
    }
    if (fileType instanceof CustomSyntaxTableFileType) {
        return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
    }
    return null;
}
Also used : FileContent(com.intellij.util.indexing.FileContent) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) SubstitutedFileType(com.intellij.util.indexing.SubstitutedFileType) Language(com.intellij.lang.Language) TokenSet(com.intellij.psi.tree.TokenSet) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with FileContent

use of com.intellij.util.indexing.FileContent in project intellij-plugins by JetBrains.

the class FacetDetectionTest method testDetectNoFacet.

@Test
public void testDetectNoFacet() {
    ElementPattern<FileContent> filter = new OsmorcFrameworkDetector().createSuitableFilePattern();
    VirtualFile manifestFile = myTempDirFixture.getFile("t1/src/META-INF/MANIFEST.MF");
    assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(false));
}
Also used : FileContent(com.intellij.util.indexing.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Test(org.junit.Test)

Example 4 with FileContent

use of com.intellij.util.indexing.FileContent in project intellij-plugins by JetBrains.

the class FacetDetectionTest method testDetectBundlorFacet.

@Test
public void testDetectBundlorFacet() {
    ModuleManager moduleManager = ModuleManager.getInstance(myFixture.getProject());
    Module t2 = moduleManager.findModuleByName("t2");
    assertNotNull(t2);
    OsmorcFrameworkDetector detector = new OsmorcFrameworkDetector();
    ElementPattern<FileContent> filter = detector.createSuitableFilePattern();
    VirtualFile manifestFile = myTempDirFixture.getFile("t2/src/META-INF/template.mf");
    assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(true));
    OsmorcFacetConfiguration facetConfiguration = detector.createConfiguration(Collections.singletonList(manifestFile));
    assertNotNull(facetConfiguration);
    assertThat(facetConfiguration.getManifestLocation(), equalTo(manifestFile.getPath()));
    assertThat(facetConfiguration.isUseProjectDefaultManifestFileLocation(), equalTo(false));
    OsmorcFacet facet = OsmorcFacetType.getInstance().createFacet(t2, "OSGi", facetConfiguration, null);
    ModifiableRootModel model = ModuleRootManager.getInstance(t2).getModifiableModel();
    try {
        detector.setupFacet(facet, model);
        assertThat(facetConfiguration.getManifestLocation(), equalTo(""));
        assertThat(facetConfiguration.getBundlorFileLocation(), equalTo("src/META-INF/template.mf"));
        assertThat(facetConfiguration.isUseBundlorFile(), equalTo(true));
    } finally {
        model.dispose();
    }
}
Also used : FileContent(com.intellij.util.indexing.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 5 with FileContent

use of com.intellij.util.indexing.FileContent in project intellij-plugins by JetBrains.

the class FacetDetectionTest method testDetectFacet.

@Test
public void testDetectFacet() {
    Module t0 = ModuleManager.getInstance(myFixture.getProject()).findModuleByName("t0");
    assertNotNull(t0);
    OsmorcFrameworkDetector detector = new OsmorcFrameworkDetector();
    ElementPattern<FileContent> filter = detector.createSuitableFilePattern();
    VirtualFile manifestFile = myTempDirFixture.getFile("t0/src/META-INF/MANIFEST.MF");
    assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(true));
    OsmorcFacetConfiguration facetConfiguration = detector.createConfiguration(Collections.singletonList(manifestFile));
    assertNotNull(facetConfiguration);
    assertThat(facetConfiguration.getManifestLocation(), equalTo(manifestFile.getPath()));
    assertThat(facetConfiguration.isUseProjectDefaultManifestFileLocation(), equalTo(false));
    OsmorcFacet facet = OsmorcFacetType.getInstance().createFacet(t0, "OSGi", facetConfiguration, null);
    ModifiableRootModel model = ModuleRootManager.getInstance(t0).getModifiableModel();
    try {
        detector.setupFacet(facet, model);
        assertThat(facetConfiguration.getManifestLocation(), equalTo("src/META-INF/MANIFEST.MF"));
    } finally {
        model.dispose();
    }
}
Also used : FileContent(com.intellij.util.indexing.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Aggregations

FileContent (com.intellij.util.indexing.FileContent)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Test (org.junit.Test)3 Module (com.intellij.openapi.module.Module)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 FileContentImpl (com.intellij.util.indexing.FileContentImpl)2 IOException (java.io.IOException)2 Language (com.intellij.lang.Language)1 ParserDefinition (com.intellij.lang.ParserDefinition)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)1 TodoIndexEntry (com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)1 TokenSet (com.intellij.psi.tree.TokenSet)1 SubstitutedFileType (com.intellij.util.indexing.SubstitutedFileType)1 Nullable (org.jetbrains.annotations.Nullable)1