Search in sources :

Example 1 with IFileElementType

use of com.intellij.psi.tree.IFileElementType in project intellij-community by JetBrains.

the class LightStubBuilder method buildStubTree.

@Override
public StubElement buildStubTree(@NotNull PsiFile file) {
    LighterAST tree = FORCED_AST.get();
    if (tree == null) {
        FileType fileType = file.getFileType();
        if (!(fileType instanceof LanguageFileType)) {
            LOG.error("File is not of LanguageFileType: " + fileType + ", " + file);
            return null;
        }
        assert file instanceof PsiFileImpl;
        final IFileElementType contentType = ((PsiFileImpl) file).getElementTypeForStubBuilder();
        if (contentType == null) {
            LOG.error("File is not of IStubFileElementType: " + file);
            return null;
        }
        final FileASTNode node = file.getNode();
        if (node.getElementType() instanceof ILightStubFileElementType) {
            tree = node.getLighterAST();
        } else {
            tree = new TreeBackedLighterAST(node);
        }
    } else {
        FORCED_AST.set(null);
    }
    if (tree == null)
        return null;
    final StubElement rootStub = createStubForFile(file, tree);
    buildStubTree(tree, tree.getRoot(), rootStub);
    return rootStub;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) ILightStubFileElementType(com.intellij.psi.tree.ILightStubFileElementType)

Example 2 with IFileElementType

use of com.intellij.psi.tree.IFileElementType in project intellij-community by JetBrains.

the class ChameleonSyntaxHighlightingPass method collectInformationWithProgress.

@Override
public void collectInformationWithProgress(@NotNull ProgressIndicator progress) {
    SyntaxTraverser<PsiElement> s = psiTraverser(myFile).filter(o -> {
        IElementType type = PsiUtilCore.getElementType(o);
        return type instanceof ILazyParseableElementType && !(type instanceof IFileElementType);
    });
    List<PsiElement> lazyOutside = ContainerUtil.newArrayListWithCapacity(100);
    List<PsiElement> lazyInside = ContainerUtil.newArrayListWithCapacity(100);
    List<HighlightInfo> outside = ContainerUtil.newArrayListWithCapacity(100);
    List<HighlightInfo> inside = ContainerUtil.newArrayListWithCapacity(100);
    for (PsiElement e : s) {
        (e.getTextRange().intersects(myPriorityRange) ? lazyInside : lazyOutside).add(e);
    }
    for (PsiElement e : lazyInside) {
        collectHighlights(e, inside, outside, myPriorityRange);
    }
    myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, inside, myPriorityRange, myRestrictRange, getId());
    for (PsiElement e : lazyOutside) {
        collectHighlights(e, inside, outside, myPriorityRange);
    }
    myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, outside, myPriorityRange, myRestrictRange, getId());
    myHighlights.addAll(inside);
    myHighlights.addAll(outside);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IFileElementType(com.intellij.psi.tree.IFileElementType) ILazyParseableElementType(com.intellij.psi.tree.ILazyParseableElementType) PsiElement(com.intellij.psi.PsiElement)

Example 3 with IFileElementType

use of com.intellij.psi.tree.IFileElementType in project intellij-community by JetBrains.

the class CoreStubTreeLoader method canHaveStub.

@Override
public boolean canHaveStub(VirtualFile file) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof LanguageFileType) {
        Language l = ((LanguageFileType) fileType).getLanguage();
        ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition == null)
            return false;
        final IFileElementType elementType = parserDefinition.getFileNodeType();
        return elementType instanceof IStubFileElementType && ((IStubFileElementType) elementType).shouldBuildStubFor(file);
    } else if (fileType.isBinary()) {
        final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
        return builder != null && builder.acceptsFile(file);
    }
    return false;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType)

Example 4 with IFileElementType

use of com.intellij.psi.tree.IFileElementType in project intellij-community by JetBrains.

the class StubUpdatingIndex method canHaveStub.

public static boolean canHaveStub(@NotNull VirtualFile file) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof LanguageFileType) {
        final Language l = ((LanguageFileType) fileType).getLanguage();
        final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition == null) {
            return false;
        }
        final IFileElementType elementType = parserDefinition.getFileNodeType();
        if (elementType instanceof IStubFileElementType) {
            if (((IStubFileElementType) elementType).shouldBuildStubFor(file)) {
                return true;
            }
            FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
            if (file instanceof NewVirtualFile && fileBasedIndex instanceof FileBasedIndexImpl && ((FileBasedIndexImpl) fileBasedIndex).getIndex(INDEX_ID).isIndexedStateForFile(((NewVirtualFile) file).getId(), file)) {
                return true;
            }
        }
    }
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Example 5 with IFileElementType

use of com.intellij.psi.tree.IFileElementType in project intellij-community by JetBrains.

the class StubVersionMap method getVersionOwner.

private static Object getVersionOwner(FileType fileType) {
    Object owner = null;
    if (fileType instanceof LanguageFileType) {
        Language l = ((LanguageFileType) fileType).getLanguage();
        ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition != null) {
            final IFileElementType type = parserDefinition.getFileNodeType();
            if (type instanceof IStubFileElementType) {
                owner = type;
            }
        }
    }
    BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
        owner = builder;
    }
    return owner;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language)

Aggregations

IFileElementType (com.intellij.psi.tree.IFileElementType)5 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)4 Language (com.intellij.lang.Language)3 ParserDefinition (com.intellij.lang.ParserDefinition)3 FileType (com.intellij.openapi.fileTypes.FileType)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)1 IElementType (com.intellij.psi.tree.IElementType)1 ILazyParseableElementType (com.intellij.psi.tree.ILazyParseableElementType)1 ILightStubFileElementType (com.intellij.psi.tree.ILightStubFileElementType)1