@Override public Lexer getIndexingLexer(@NotNull final PsiFile file) { if (JspPsiUtil.isInJspFile(file)) { return EditorHighlighterCache.getLexerBasedOnLexerHighlighter(file.getText(), file.getVirtualFile(), file.getProject()); } return null; }
@Override public Lexer getIndexingLexer(final PsiFile file) { if (JspPsiUtil.isInJspFile(file)) { EditorHighlighter highlighter = null; final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); final EditorHighlighter cachedEditorHighlighter; boolean alreadyInitializedHighlighter = false; if ((cachedEditorHighlighter = EditorHighlighterCache.getEditorHighlighterForCachesBuilding(document)) != null && PlatformIdTableBuilding.checkCanUseCachedEditorHighlighter(file.getText(), cachedEditorHighlighter)) { highlighter = cachedEditorHighlighter; alreadyInitializedHighlighter = true; } else { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file.getProject(), virtualFile); } } if (highlighter != null) { return new LexerEditorHighlighterLexer(highlighter, alreadyInitializedHighlighter); } } return null; }
private boolean indexUnsavedDocument(@NotNull final Document document, @NotNull final ID<?, ?> requestedIndexId, final Project project, @Nullable GlobalSearchScope filter, @Nullable VirtualFile restrictedFile) { final VirtualFile vFile = myFileDocumentManager.getFile(document); if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { return true; } if (restrictedFile != null) { if (!Comparing.equal(vFile, restrictedFile)) { return false; } } else if (filter != null && !filter.accept(vFile)) { return false; } final PsiFile dominantContentFile = findDominantPsiForDocument(document, project); final DocumentContent content; if (dominantContentFile != null && dominantContentFile.getViewProvider().getModificationStamp() != document.getModificationStamp()) { content = new PsiContent(document, dominantContentFile); } else { content = new AuthenticContent(document); } final long currentDocStamp = content.getModificationStamp(); final long previousDocStamp = myLastIndexedDocStamps.getAndSet(document, requestedIndexId, currentDocStamp); if (currentDocStamp != previousDocStamp) { final String contentText = content.getText(); if (!isTooLarge(vFile, contentText.length()) && getInputFilter(requestedIndexId).acceptInput(vFile)) { // Reasonably attempt to use same file content when calculating indices as we can evaluate them several at once and store in file content WeakReference<FileContentImpl> previousContentRef = document.getUserData(ourFileContentKey); FileContentImpl previousContent = previousContentRef != null ? previousContentRef.get() : null; final FileContentImpl newFc; if (previousContent != null && previousContent.getStamp() == currentDocStamp) { newFc = previousContent; } else { newFc = new FileContentImpl(vFile, contentText, vFile.getCharset(), currentDocStamp); document.putUserData(ourFileContentKey, new WeakReference<FileContentImpl>(newFc)); } initFileContent(newFc, project, dominantContentFile); if (content instanceof AuthenticContent) { newFc.putUserData(EDITOR_HIGHLIGHTER, EditorHighlighterCache.getEditorHighlighterForCachesBuilding(document)); } final int inputId = Math.abs(getFileId(vFile)); try { getIndex(requestedIndexId).update(inputId, newFc).compute(); } catch (ProcessCanceledException pce) { myLastIndexedDocStamps.getAndSet(document, requestedIndexId, previousDocStamp); throw pce; } finally { cleanFileContent(newFc, dominantContentFile); } } } return true; }