@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; }
public static int getCumulativeVersion() { int version = VERSION; for (final FileType fileType : FileTypeRegistry.getInstance().getRegisteredFileTypes()) { 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) { version += ((IStubFileElementType)type).getStubVersion(); } } } BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); if (builder != null) { version += builder.getStubVersion(); } } return version; }
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; } if (IndexingStamp.isFileIndexedStateCurrent(file, INDEX_ID)) { return true; } } } final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); return builder != null && builder.acceptsFile(file); }
/** * Creates the IDEA language object associated with the specified language. * * @param language * The language. * @return The created IDEA language. */ private LanguageBindings createLanguageBindings(final ILanguage language) { final MetaborgIdeaLanguage ideaLanguage = createIdeaLanguage(language); final MetaborgLanguageFileType fileType = createFileType(ideaLanguage); final SpoofaxTokenTypeManager tokenTypeManager = createTokenTypeManager(ideaLanguage); final IFileElementType fileElementType = createFileElementType(ideaLanguage, tokenTypeManager); final ParserDefinition parserDefinition = createParserDefinition(fileType, fileElementType); final SpoofaxSyntaxHighlighterFactory syntaxHighlighterFactory = createSyntaxHighlighterFactory(); final InstanceLanguageExtensionPoint<?> parserDefinitionExtension = new InstanceLanguageExtensionPoint<>(ExtensionIds.ParserDefinition, ideaLanguage, parserDefinition); final InstanceSyntaxHighlighterFactoryExtensionPoint syntaxHighlighterFactoryExtension = new InstanceSyntaxHighlighterFactoryExtensionPoint(ideaLanguage, syntaxHighlighterFactory); final InstanceLanguageExtensionPoint<?> externalAnnotatorExtension = new InstanceLanguageExtensionPoint<>( ExtensionIds.ExternalAnnotator, ideaLanguage, this.metaborgSourceAnnotator); return new LanguageBindings(tokenTypeManager, fileType, parserDefinitionExtension, syntaxHighlighterFactoryExtension, externalAnnotatorExtension); }
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; } final ID indexId = IndexInfrastructure.getStubId(INDEX_ID, file.getFileType()); if (IndexingStamp.isFileIndexed(file, indexId, IndexInfrastructure.getIndexCreationStamp(indexId))) { return true; } } } final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); return builder != null && builder.acceptsFile(file); }
private static Map<FileType, Integer> computeVersionMap() { Map<FileType, Integer> map = new HashMap<FileType, Integer>(); for (final FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) { 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) { map.put(fileType, ((IStubFileElementType)type).getStubVersion()); } } } final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); if (builder != null) { map.put(fileType, builder.getStubVersion()); } } return map; }
/** Builds a new instance of {@link IgnoreFile}. */ public IgnoreFile(@NotNull FileViewProvider viewProvider, @NotNull IgnoreFileType fileType) { super(viewProvider); this.fileType = fileType; this.language = findLanguage(fileType.getLanguage(), viewProvider); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(this.language); if (parserDefinition == null) { throw new RuntimeException( "PsiFileBase: language.getParserDefinition() returned null for: " + this.language ); } this.parserDefinition = parserDefinition; final IFileElementType nodeType = parserDefinition.getFileNodeType(); init(nodeType, nodeType); }
@NotNull private static IElementType createElementType(String id, BiConsumer<PsiBuilder, LanguageVersion> consumer) { return new IFileElementType(id, CSharpLanguage.INSTANCE) { @Override protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) { final Project project = psi.getProject(); final Language languageForParser = getLanguageForParser(psi); final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY); final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion; final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars()); consumer.accept(builder, languageVersion); while(!builder.eof()) { builder.advanceLexer(); } return builder.getTreeBuilt(); } }; }
@Override protected ParseTree parseImpl(ANTLRv4Parser parser, IElementType root, PsiBuilder builder) { int startRule; if (root instanceof IFileElementType) { startRule = ANTLRv4Parser.RULE_grammarSpec; } else if (root == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.TOKEN_REF) || root == ANTLRv4TokenTypes.TOKEN_ELEMENT_TYPES.get(ANTLRv4Lexer.RULE_REF)) { startRule = ANTLRv4Parser.RULE_atom; } else { startRule = Token.INVALID_TYPE; } switch (startRule) { case ANTLRv4Parser.RULE_grammarSpec: return parser.grammarSpec(); case ANTLRv4Parser.RULE_atom: return parser.atom(); default: String ruleName = ANTLRv4Parser.ruleNames[startRule]; throw new UnsupportedOperationException(String.format("cannot start parsing using root element %s", root)); } }
public static boolean canHaveStub(@Nonnull 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); }
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; }
@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; } Language language = ((LanguageFileType)fileType).getLanguage(); final IFileElementType contentType = LanguageParserDefinitions.INSTANCE.forLanguage(language).getFileNodeType(); if (!(contentType instanceof IStubFileElementType)) { LOG.error("File is not of IStubFileElementType: " + contentType + ", " + file); return null; } final FileASTNode node = file.getNode(); if (contentType 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; }
@Override @NotNull public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) { if (type instanceof IFileElementType) { return new FileElement(type, text); } return new LazyParseableElement(type, text); }
@Override @NotNull public CompositeElement createComposite(final IElementType type) { if (type instanceof IFileElementType) { return new FileElement(type, null); } return new CompositeElement(type); }
@Override @Nullable public CompositeElement createComposite(final IElementType type) { if (type instanceof IFileElementType) { return new FileElement(type, null); } return new CompositeElement(type); }
/** * Binds token and PSI elements and related classes. */ protected void bindElements() { bind(IMetaborgPsiElementFactory.class).to(DefaultMetaborgPsiElementFactory.class).in(Singleton.class); install(new FactoryModuleBuilder() .implement(IFileElementType.class, MetaborgFileElementType.class) .build(IFileElementTypeFactory.class)); install(new FactoryModuleBuilder() .implement(ATermAstElementTypeProvider.class, ATermAstElementTypeProvider.class) .build(IATermAstElementTypeProviderFactory.class)); }
@Inject /* package private */ MetaborgParserDefinition( @Assisted final MetaborgLanguageFileType fileType, @Assisted final IFileElementType fileElementType, final IMetaborgPsiElementFactory psiElementFactory, final ICharacterLexerFactory characterLexerFactory, final ILanguageBindingManager bindingManager) { this.fileType = fileType; this.fileElement = fileElementType; this.psiElementFactory = psiElementFactory; this.characterLexerFactory = characterLexerFactory; this.bindingManager = bindingManager; }
@Nullable public CompositeElement createComposite(final IElementType type) { if (type instanceof IFileElementType) { return new FileElement(type, null); } return new CompositeElement(type); }
/** Create a FileElement for root or a parse tree CompositeElement (not * PSI) for the token. This impl is more or less the default. */ @Override public CompositeElement createComposite(IElementType type) { if (type instanceof IFileElementType) { return new FileElement(type, null); } return new CompositeElement(type); }
@Nonnull @Override public CompositeElement createComposite(IElementType type) { if (type instanceof IFileElementType) { return new FileElement(type, null); } if (type instanceof ICompositeElementType) { return (CompositeElement)((ICompositeElementType)type).createCompositeNode(); } return new CompositeElement(type); }
@Override public IFileElementType getFileNodeType() { return FILE; }
@Override public IFileElementType getFileNodeType() { return RmlFileStubElementType.INSTANCE; }
@NotNull @Override public IFileElementType getFileNodeType() { return FILE; }
public IFileElementType getFileNodeType() { return FILE; }
@Override public IFileElementType getFileNodeType() { return File; }