Java Code Examples for com.intellij.psi.tree.IFileElementType

The following examples show how to use com.intellij.psi.tree.IFileElementType. These examples are extracted from open source projects. 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 Project: consulo-csharp   Source File: CSharpFileFactory.java    License: 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 2
Source Project: idea-gitignore   Source File: IgnoreFile.java    License: 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 3
@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 4
Source Project: consulo   Source File: CoreStubTreeLoader.java    License: 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 5
Source Project: consulo   Source File: StubUpdatingIndex.java    License: 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 Project: consulo   Source File: StubVersionMap.java    License: 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 7
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 8
/** 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 9
Source Project: consulo   Source File: DefaultASTCompositeFactory.java    License: 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 Project: intellij-jsonnet   Source File: JsonnetParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 11
Source Project: reasonml-idea-plugin   Source File: RmlParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return RmlFileStubElementType.INSTANCE;
}
 
Example 12
Source Project: reasonml-idea-plugin   Source File: OclYaccParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 13
Source Project: reasonml-idea-plugin   Source File: OclMlgParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 14
Source Project: reasonml-idea-plugin   Source File: OclP4ParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 15
Source Project: reasonml-idea-plugin   Source File: OclMllParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 16
Source Project: reasonml-idea-plugin   Source File: OclParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return OclFileStubElementType.INSTANCE;
}
 
Example 17
Source Project: reasonml-idea-plugin   Source File: DuneParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 18
Source Project: idea-php-typo3-plugin   Source File: FluidParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 19
Source Project: idea-php-typo3-plugin   Source File: TypoScriptParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
  return FILE;
}
 
Example 20
@Override
public IFileElementType getFileNodeType() {
    return TSV_FILE;
}
 
Example 21
@Override
public IFileElementType getFileNodeType() {
    return PSV_FILE;
}
 
Example 22
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 23
public IFileElementType getFileNodeType()
{
    return FILE;
}
 
Example 24
Source Project: mule-intellij-plugins   Source File: MelParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 25
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 26
Source Project: nix-idea   Source File: NixParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}
 
Example 27
@Override
public IFileElementType getFileNodeType() {
    return FusionFileStub.TYPE;
}
 
Example 28
Source Project: arma-intellij-plugin   Source File: SQFParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
	return FILE;
}
 
Example 29
Source Project: arma-intellij-plugin   Source File: HeaderParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
	return FILE;
}
 
Example 30
Source Project: elm-plugin   Source File: ElmParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public IFileElementType getFileNodeType() {
    return FILE;
}