com.intellij.psi.tree.IFileElementType Java Examples

The following examples show how to use com.intellij.psi.tree.IFileElementType. 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: IgnoreFile.java    From idea-gitignore with MIT License 6 votes vote down vote up
/** 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);
}
 
Example #2
Source File: ANTLRv4GrammarParser.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected ParseTree parse(Parser parser, IElementType root) {
	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 ((ANTLRv4Parser) parser).grammarSpec();

	case ANTLRv4Parser.RULE_atom:
		return ((ANTLRv4Parser) parser).atom();

	default:
		String ruleName = ANTLRv4Parser.ruleNames[startRule];
		throw new UnsupportedOperationException(String.format("cannot start parsing using root element %s", root));
	}
}
 
Example #3
Source File: CSharpFileFactory.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static IElementType createElementType(String id, BiConsumer<PsiBuilder, LanguageVersion> consumer)
{
	return new IFileElementType(id, CSharpLanguage.INSTANCE)
	{
		@Override
		protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull 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();
		}
	};
}
 
Example #4
Source File: StubVersionMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: StubUpdatingIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean canHaveStub(@Nonnull ProjectLocator projectLocator, @Nullable Project project, @Nonnull VirtualFile file) {
  FileType fileType = SubstitutedFileType.substituteFileType(file, file.getFileType(), project == null ? projectLocator.guessProjectForFile(file) : project);
  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);
}
 
Example #6
Source File: CoreStubTreeLoader.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: ANTLRv4ASTFactory.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 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);
  }
 
Example #8
Source File: CypherParser.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
public void parseLight(IElementType t, PsiBuilder b) {
  boolean r;
  b = adapt_builder_(t, b, this, null);
  Marker m = enter_section_(b, 0, _COLLAPSE_, null);
  if (t instanceof IFileElementType) {
    r = parse_root_(t, b, 0);
  }
  else {
    r = false;
  }
  exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
}
 
Example #9
Source File: DefaultASTCompositeFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public CompositeElement createComposite(@Nonnull IElementType type) {
  if (type instanceof IFileElementType) {
    return new FileElement(type, null);
  }
  if (type instanceof ICompositeElementType) {
    return (CompositeElement)((ICompositeElementType)type).createCompositeNode();
  }
  return new CompositeElement(type);
}
 
Example #10
Source File: Identikit.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isForPsiFile() {
  if (myElementTypeId < 0) return false;
  IElementType elementType = IElementType.find(myElementTypeId);
  return elementType instanceof IFileElementType;
}
 
Example #11
Source File: PlainTextParserDefinition.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public IFileElementType getFileNodeType() {
  return PLAIN_FILE_ELEMENT_TYPE;
}
 
Example #12
Source File: SyntaxTraverser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isAlwaysLeaf(@Nonnull T node) {
  return super.isAlwaysLeaf(node) && !(api.typeOf(node) instanceof IFileElementType);
}
 
Example #13
Source File: SandParsingDefinition.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public IFileElementType getFileNodeType() {
  return FILE;
}
 
Example #14
Source File: CppParserDefinition.java    From CppTools with Apache License 2.0 4 votes vote down vote up
public IFileElementType getFileNodeType() {
  return CppSupportLoader.CPP_FILE;
}
 
Example #15
Source File: HaxeParserDefinition.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public IFileElementType getFileNodeType() {
  return HaxeTokenTypeSets.HAXE_FILE;
}
 
Example #16
Source File: MakefileParserDefinition.java    From CppTools with Apache License 2.0 4 votes vote down vote up
public IFileElementType getFileNodeType() {
  return MakefileTokenTypes.MAKE_FILE;
}
 
Example #17
Source File: PsiFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @return the element type of the file node, but possibly in an efficient node that doesn't instantiate the node.
 */
@Nullable
default IFileElementType getFileElementType() {
  return ObjectUtil.tryCast(PsiUtilCore.getElementType(getNode()), IFileElementType.class);
}
 
Example #18
Source File: JsonnetParserDefinition.java    From intellij-jsonnet with Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example #19
Source File: DustParserDefinition.java    From Intellij-Dust with MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
  return FILE;
}
 
Example #20
Source File: CSharpDocParserDefinition.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public IFileElementType getFileNodeType()
{
	throw new UnsupportedOperationException();
}
 
Example #21
Source File: CSharpParserDefinition.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public IFileElementType getFileNodeType()
{
	return CSharpStubElements.FILE;
}
 
Example #22
Source File: CSharpPreprocessorParserDefinition.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public IFileElementType getFileNodeType()
{
	return ourFileElementType;
}
 
Example #23
Source File: GLSLParserDefinition.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
public IFileElementType getFileNodeType() {
    return GLSLElementTypes.FILE;
}
 
Example #24
Source File: LatteParserDefinition.java    From intellij-latte with MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
	return FILE;
}
 
Example #25
Source File: ConceptParserDefinition.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example #26
Source File: SpecParserDefinition.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example #27
Source File: CabalParserDefinition.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
  return FILE;
}
 
Example #28
Source File: HamletParserDefinition.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example #29
Source File: HaskellParserDefinition.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
/**
 * Use a the file stub element type so the contents of these files will be indexed.
 */
@Override
public IFileElementType getFileNodeType() {
    return HaskellFileStubElementType.INSTANCE;
}
 
Example #30
Source File: YangParserDefinition.java    From intellij-yang with Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}