com.intellij.util.indexing.FileContent Java Examples
The following examples show how to use
com.intellij.util.indexing.FileContent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoreStubTreeLoader.java From consulo with Apache License 2.0 | 6 votes |
@Override public ObjectStubTree readOrBuild(Project project, VirtualFile vFile, @Nullable PsiFile psiFile) { if (!canHaveStub(vFile)) { return null; } try { final FileContent fc = new FileContentImpl(vFile, vFile.contentsToByteArray()); fc.putUserData(IndexingDataKeys.PROJECT, project); final Stub element = StubTreeBuilder.buildStubTree(fc); if (element instanceof PsiFileStub) { return new StubTree((PsiFileStub)element); } } catch (IOException e) { throw new RuntimeException(e); } return null; }
Example #2
Source File: PlainTextIndexer.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public Map<IdIndexEntry, Integer> map(@Nonnull final FileContent inputData) { final IdDataConsumer consumer = new IdDataConsumer(); final CharSequence chars = inputData.getContentAsText(); IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() { @Override public void run(final CharSequence chars11, @Nullable char[] charsArray, final int start, final int end) { if (charsArray != null) { consumer.addOccurrence(charsArray, start, end, (int)UsageSearchContext.IN_PLAIN_TEXT); } else { consumer.addOccurrence(chars11, start, end, (int)UsageSearchContext.IN_PLAIN_TEXT); } } }, chars, 0, chars.length()); return consumer.getResult(); }
Example #3
Source File: PlatformIdTableBuilding.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public Map<TodoIndexEntry, Integer> map(FileContent inputData) { Map<TodoIndexEntry, Integer> result = ContainerUtil.newTroveMap(); for (DataIndexer<TodoIndexEntry, Integer, FileContent> indexer : indexers) { for (Map.Entry<TodoIndexEntry, Integer> entry : indexer.map(inputData).entrySet()) { TodoIndexEntry key = entry.getKey(); if (result.containsKey(key)) { result.put(key, result.get(key) + entry.getValue()); } else { result.put(key, entry.getValue()); } } } return result; }
Example #4
Source File: SpecIndexer.java From intellij-swagger with MIT License | 6 votes |
@NotNull @Override public Map<String, Set<String>> map(@NotNull FileContent inputData) { final Map<String, Set<String>> indexMap = new HashMap<>(); if (inputData.getFileType().isBinary()) { return indexMap; } final PsiFile file = inputData.getPsiFile(); if (shouldIndex(file)) { final VirtualFile specDirectory = inputData.getFile().getParent(); final Set<String> referencedFiles = getReferencedFiles(file, specDirectory); indexMap.put( MAIN_SPEC_FILES, ImmutableSet.of(file.getName() + DELIMITER + mainSpecFileType.toString())); indexMap.put(PARTIAL_SPEC_FILES, referencedFiles); } return indexMap; }
Example #5
Source File: AnnotationUtil.java From idea-php-annotation-plugin with MIT License | 6 votes |
public static boolean isValidForIndex(@NotNull FileContent inputData) { String fileName = inputData.getPsiFile().getName(); if(fileName.startsWith(".") || fileName.contains("Test")) { return false; } // we check for project path, on no match we are properly inside external library paths VirtualFile baseDir = inputData.getProject().getBaseDir(); if (baseDir == null) { return true; } String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/'); if(relativePath == null) { return true; } // is Test file in path name return !(relativePath.contains("\\Test\\") || relativePath.contains("\\Fixtures\\")); }
Example #6
Source File: IndexUtil.java From idea-php-drupal-symfony2-bridge with MIT License | 6 votes |
public static boolean isValidForIndex(@NotNull FileContent inputData, @NotNull PsiFile psiFile) { String fileName = psiFile.getName(); if(fileName.startsWith(".") || fileName.endsWith("Test")) { return false; } VirtualFile baseDir = inputData.getProject().getBaseDir(); if(baseDir == null) { return false; } // is Test file in path name String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/'); if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) { return false; } return true; }
Example #7
Source File: BsConfigJson.java From reasonml-idea-plugin with MIT License | 5 votes |
public static boolean isBsConfigJson(@NotNull VirtualFile virtualFile) { if (virtualFile.getFileType() instanceof JsonFileType) { try { FileContent fileContent = FileContentImpl.createByFile(virtualFile); return createFilePattern().accepts(fileContent); } catch (IOException e) { return false; } } return false; }
Example #8
Source File: BaseFilterLexerUtil.java From consulo with Apache License 2.0 | 5 votes |
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) { ScanContent data = content.getUserData(scanContentKey); if (data != null) { content.putUserData(scanContentKey, null); return data; } final boolean needTodo = content.getFile().getFileSystem() instanceof LocalFileSystem; final boolean needIdIndex = IdTableBuilding.getFileTypeIndexer(content.getFileType()) instanceof LexerBasedIdIndexer; final IdDataConsumer consumer = needIdIndex? new IdDataConsumer():null; final OccurrenceConsumer todoOccurrenceConsumer = new OccurrenceConsumer(consumer, needTodo); final Lexer filterLexer = indexer.createLexer(todoOccurrenceConsumer); filterLexer.start(content.getContentAsText()); while (filterLexer.getTokenType() != null) filterLexer.advance(); Map<TodoIndexEntry,Integer> todoMap = null; if (needTodo) { for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) { final int count = todoOccurrenceConsumer.getOccurrenceCount(indexPattern); if (count > 0) { if (todoMap == null) todoMap = new THashMap<TodoIndexEntry, Integer>(); todoMap.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count); } } } data = new ScanContent( consumer != null? consumer.getResult():Collections.<IdIndexEntry, Integer>emptyMap(), todoMap != null ? todoMap: Collections.<TodoIndexEntry,Integer>emptyMap() ); if (needIdIndex && needTodo) content.putUserData(scanContentKey, data); return data; }
Example #9
Source File: FileContentPattern.java From consulo with Apache License 2.0 | 5 votes |
public FileContentPattern xmlWithRootTagNamespace(final ElementPattern<String> namespacePattern) { return with(new PatternCondition<FileContent>("xmlWithRootTagNamespace") { @Override public boolean accepts(@Nonnull final FileContent fileContent, final ProcessingContext context) { try { String rootTagNamespace = parseHeaderWithException(fileContent).getRootTagNamespace(); return rootTagNamespace != null && namespacePattern.accepts(rootTagNamespace, context); } catch (IOException e) { return false; } } }); }
Example #10
Source File: FileContentPattern.java From consulo with Apache License 2.0 | 5 votes |
public FileContentPattern xmlWithRootTag(@Nonnull final String rootTag) { return with(new PatternCondition<FileContent>("withRootTag") { @Override public boolean accepts(@Nonnull FileContent fileContent, ProcessingContext context) { try { return rootTag.equals(parseHeaderWithException(fileContent).getRootTagLocalName()); } catch (IOException e) { return false; } } }); }
Example #11
Source File: FileContentPattern.java From consulo with Apache License 2.0 | 5 votes |
public FileContentPattern inDirectory(final @Nonnull String name) { return with(new PatternCondition<FileContent>("inDirectory") { @Override public boolean accepts(@Nonnull FileContent fileContent, ProcessingContext context) { return name.equals(fileContent.getFile().getParent().getName()); } }); }
Example #12
Source File: FileContentPattern.java From consulo with Apache License 2.0 | 5 votes |
public FileContentPattern withName(final StringPattern namePattern) { return with(new PatternCondition<FileContent>("withName") { @Override public boolean accepts(@Nonnull FileContent fileContent, ProcessingContext context) { return namePattern.accepts(fileContent.getFileName()); } }); }
Example #13
Source File: FileContentPattern.java From consulo with Apache License 2.0 | 5 votes |
public FileContentPattern withName(@Nonnull final String name) { return with(new PatternCondition<FileContent>("withName") { @Override public boolean accepts(@Nonnull FileContent fileContent, ProcessingContext context) { return name.equals(fileContent.getFileName()); } }); }
Example #14
Source File: IdTableBuilding.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public Map<IdIndexEntry, Integer> map(final FileContent inputData) { final CharSequence chars = inputData.getContentAsText(); final char[] charsArray = CharArrayUtil.fromSequenceWithoutCopying(chars); final IdDataConsumer consumer = new IdDataConsumer(); myScanner.processWords(chars, new Processor<WordOccurrence>() { @Override public boolean process(final WordOccurrence t) { if (charsArray != null && t.getBaseText() == chars) { consumer.addOccurrence(charsArray, t.getStart(), t.getEnd(), convertToMask(t.getKind())); } else { consumer.addOccurrence(t.getBaseText(), t.getStart(), t.getEnd(), convertToMask(t.getKind())); } return true; } private int convertToMask(final WordOccurrence.Kind kind) { if (kind == null) return UsageSearchContext.ANY; if (kind == WordOccurrence.Kind.CODE) return UsageSearchContext.IN_CODE; if (kind == WordOccurrence.Kind.COMMENTS) return UsageSearchContext.IN_COMMENTS; if (kind == WordOccurrence.Kind.LITERALS) return UsageSearchContext.IN_STRINGS; if (kind == WordOccurrence.Kind.FOREIGN_LANGUAGE) return UsageSearchContext.IN_FOREIGN_LANGUAGES; return 0; } }); return consumer.getResult(); }
Example #15
Source File: PlatformIdTableBuilding.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, Project project, 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(), project, virtualFile), getTodoIndexer(sft.getFileType(), project, 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); LanguageVersion languageVersion = LanguageVersionUtil.findLanguageVersion(lang, project, virtualFile); final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens(languageVersion) : null; if (commentTokens != null) { return new TokenSetTodoIndexer(commentTokens, languageVersion, virtualFile, project); } } if (fileType instanceof CustomSyntaxTableFileType) { return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, null, virtualFile, project); } return null; }
Example #16
Source File: IgnoreFilesIndex.java From idea-gitignore with MIT License | 5 votes |
/** * Maps indexed files content to the {@link IgnoreEntryOccurrence}. * * @param inputData indexed file data * @return {@link IgnoreEntryOccurrence} data mapped with {@link IgnoreFileTypeKey} */ @NotNull @Override public Map<IgnoreFileTypeKey, IgnoreEntryOccurrence> map(@NotNull final FileContent inputData) { PsiFile inputDataPsi; try { inputDataPsi = inputData.getPsiFile(); } catch (Exception e) { // if there is some stale indices (e.g. for mobi.hsz.idea.gitignore.lang.kind.GitLanguage) // inputData.getPsiFile() could throw exception that should be avoided return Collections.emptyMap(); } if (!(inputDataPsi instanceof IgnoreFile)) { return Collections.emptyMap(); } final ArrayList<Pair<String, Boolean>> items = new ArrayList<>(); inputDataPsi.acceptChildren(new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) { final String regex = Glob.getRegex(entry.getValue(), entry.getSyntax(), false); items.add(Pair.create(regex, entry.isNegated())); } }); return Collections.singletonMap( new IgnoreFileTypeKey((IgnoreFileType) inputData.getFileType()), new IgnoreEntryOccurrence(inputData.getFile().getUrl(), items) ); }
Example #17
Source File: NodeTypesYamlFileIndex.java From intellij-neos with GNU General Public License v3.0 | 5 votes |
private static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) { if (inputData.getFile().getLength() > MAX_FILE_BYTE_SIZE) { return false; } return psiFile.getName().startsWith("NodeTypes."); }
Example #18
Source File: NodeTypesYamlFileIndex.java From intellij-neos with GNU General Public License v3.0 | 5 votes |
@NotNull private Map<String, Void> doIndex(FileContent fileContent) { Map<String, Void> result = new HashMap<>(); YAMLUtil.getTopLevelKeys((YAMLFile)fileContent.getPsiFile()) .forEach(yamlKeyValue -> result.put(yamlKeyValue.getKeyText(), null)); return result; }
Example #19
Source File: NodeTypesYamlFileIndex.java From intellij-neos with GNU General Public License v3.0 | 5 votes |
@NotNull @Override public Map<String, Void> map(@NotNull FileContent fileContent) { PsiFile psiFile = fileContent.getPsiFile(); if (NeosProjectService.isEnabledForIndex(psiFile.getProject()) && isValidForIndex(fileContent, psiFile)) { return doIndex(fileContent); } return Collections.emptyMap(); }
Example #20
Source File: EsyPackageJson.java From reasonml-idea-plugin with MIT License | 5 votes |
public static boolean isEsyPackageJson(@NotNull VirtualFile virtualFile) { if (virtualFile.getFileType() instanceof JsonFileType) { try { FileContent fileContent = FileContentImpl.createByFile(virtualFile); return createFilePattern().accepts(fileContent); } catch (IOException e) { return false; } } return false; }
Example #21
Source File: MuleFrameworkDetector.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@NotNull @Override public ElementPattern<FileContent> createSuitableFilePattern() { return FileContentPattern.fileContent().andOr( FileContentPattern.fileContent().withName("mule-app.properties"), FileContentPattern.fileContent().withName("mule-domain-config.xml")); // new FileContent() // return FileContentPattern.fileContent().oneOf(FileContentPattern.fileContent().withName("mule-app.properties")., FileContentPattern.fileContent().withName("mule-domain-config.xml")); //.withName("mule-app.properties")..withName("mule-domain-config.xml"); }
Example #22
Source File: DuplicatesProfile.java From consulo with Apache License 2.0 | 4 votes |
public boolean acceptsContentForIndexing(FileContent fileContent) { return true; }
Example #23
Source File: PantsAddressesIndex.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
@NotNull @Override public DataIndexer<String, Void, FileContent> getIndexer() { return indexer; }
Example #24
Source File: LexerBasedIdIndexer.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public final Map<IdIndexEntry,Integer> map(final FileContent inputData) { return BaseFilterLexerUtil.scanContent(inputData, this).idMap; }
Example #25
Source File: QuarkusFrameworkDetector.java From intellij-quarkus with Eclipse Public License 2.0 | 4 votes |
@NotNull @Override public ElementPattern<FileContent> createSuitableFilePattern() { return FileContentPattern.fileContent().withName("DUMMY_WILL_NEVER_DETECT"); }
Example #26
Source File: LexerBasedTodoIndexer.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public Map<TodoIndexEntry, Integer> map(final FileContent inputData) { return BaseFilterLexerUtil.scanContent(inputData, this).todoMap; }
Example #27
Source File: FileIncludeProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public abstract FileIncludeInfo[] getIncludeInfos(FileContent content);
Example #28
Source File: StubTreeBuilder.java From consulo with Apache License 2.0 | 4 votes |
@Nullable public static Stub buildStubTree(final FileContent inputData) { Stub data = inputData.getUserData(stubElementKey); if (data != null) return data; //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (inputData) { data = inputData.getUserData(stubElementKey); if (data != null) return data; final FileType fileType = inputData.getFileType(); final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); if (builder != null) { data = builder.buildStubTree(inputData); if (data instanceof PsiFileStubImpl && !((PsiFileStubImpl)data).rootsAreSet()) { ((PsiFileStubImpl)data).setStubRoots(new PsiFileStub[]{(PsiFileStubImpl)data}); } } else { CharSequence contentAsText = inputData.getContentAsText(); PsiDependentFileContent fileContent = (PsiDependentFileContent)inputData; PsiFile psi = fileContent.getPsiFile(); final FileViewProvider viewProvider = psi.getViewProvider(); psi = viewProvider.getStubBindingRoot(); psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText); // if we load AST, it should be easily gc-able. See PsiFileImpl.createTreeElementPointer() psi.getManager().startBatchFilesProcessingMode(); try { IStubFileElementType stubFileElementType = ((PsiFileImpl)psi).getElementTypeForStubBuilder(); if (stubFileElementType != null) { final StubBuilder stubBuilder = stubFileElementType.getBuilder(); if (stubBuilder instanceof LightStubBuilder) { LightStubBuilder.FORCED_AST.set(fileContent.getLighterAST()); } data = stubBuilder.buildStubTree(psi); final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = getStubbedRoots(viewProvider); final List<PsiFileStub> stubs = new ArrayList<>(stubbedRoots.size()); stubs.add((PsiFileStub)data); for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) { final PsiFile secondaryPsi = stubbedRoot.second; if (psi == secondaryPsi) continue; final StubBuilder stubbedRootBuilder = stubbedRoot.first.getBuilder(); if (stubbedRootBuilder instanceof LightStubBuilder) { LightStubBuilder.FORCED_AST.set(new TreeBackedLighterAST(secondaryPsi.getNode())); } final StubElement element = stubbedRootBuilder.buildStubTree(secondaryPsi); if (element instanceof PsiFileStub) { stubs.add((PsiFileStub)element); } ensureNormalizedOrder(element); } final PsiFileStub[] stubsArray = stubs.toArray(PsiFileStub.EMPTY_ARRAY); for (PsiFileStub stub : stubsArray) { if (stub instanceof PsiFileStubImpl) { ((PsiFileStubImpl)stub).setStubRoots(stubsArray); } } } } finally { psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, null); psi.getManager().finishBatchFilesProcessingMode(); } } ensureNormalizedOrder(data); inputData.putUserData(stubElementKey, data); return data; } }
Example #29
Source File: BsConfigJson.java From reasonml-idea-plugin with MIT License | 4 votes |
private static ElementPattern<FileContent> createFilePattern() { return FileContentPattern.fileContent() .withName(BsConfigJsonFileType.getDefaultFilename()); }
Example #30
Source File: FileContentPattern.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static XmlFileHeader parseHeaderWithException(FileContent fileContent) throws IOException { //noinspection IOResourceOpenedButNotSafelyClosed return NanoXmlUtil.parseHeaderWithException(CharArrayUtil.readerFromCharSequence(fileContent.getContentAsText())); }