Java Code Examples for com.intellij.lang.PsiBuilder#getTreeBuilt()

The following examples show how to use com.intellij.lang.PsiBuilder#getTreeBuilt() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();

	while(!builder.eof())
	{
		PreprocessorParsing.parse(builder);
	}

	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 3
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();
	SharedParsingHelpers.parseType(new CSharpBuilderWrapper(builder, languageVersion), SharedParsingHelpers.VAR_SUPPORT);
	while(!builder.eof())
	{
		builder.error("Unexpected token");
		builder.advanceLexer();
	}
	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 4
Source Project: consulo-csharp   File: CSharpParser.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	builder.setDebugMode(ApplicationProperties.isInSandbox());

	CSharpBuilderWrapper builderWrapper = new CSharpBuilderWrapper(builder, languageVersion);

	PsiBuilder.Marker marker = builderWrapper.mark();

	DeclarationParsing.parseAll(builderWrapper, true, false);

	marker.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 5
Source Project: consulo   File: PrattParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public final ASTNode parse(@Nonnull final IElementType root, @Nonnull final PsiBuilder builder, @Nonnull LanguageVersion languageVersion) {
  final PrattBuilder prattBuilder = PrattBuilderImpl.createBuilder(builder, getRegistry());
  final MutableMarker marker = prattBuilder.mark();
  parse(prattBuilder);
  marker.finish(root);
  return builder.getTreeBuilt();
}
 
Example 6
Source Project: intellij   File: BuildParserDefinition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
  if (debug.getValue()) {
    System.err.println(builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY));
  }
  PsiBuilder.Marker rootMarker = builder.mark();
  ParsingContext context = new ParsingContext(builder);
  context.statementParser.parseFileInput();
  rootMarker.done(root);
  return builder.getTreeBuilt();
}
 
Example 7
Source Project: JetBrains-NASM-Language   File: NASMParser.java    License: MIT License 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 8
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 9
Source Project: mule-intellij-plugins   File: MelParser.java    License: Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 10
Source Project: Intellij-Plugin   File: ConceptParser.java    License: Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
    parseLight(t, b);
    return b.getTreeBuilt();
}
 
Example 11
Source Project: nix-idea   File: NixParser.java    License: Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 12
Source Project: CppTools   File: CppParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
public ASTNode parse(IElementType iElementType, PsiBuilder psiBuilder) {
  final PsiBuilder.Marker rootMarker = psiBuilder.mark();
  final LinkedList<BlockInfo> blocks = new LinkedList<BlockInfo>();
  boolean openBlock = true;

  while (psiBuilder.getTokenType() != null) {
    if (openBlock) {
      final IElementType type = psiBuilder.getTokenType();
      if (type != CppTokenTypes.RBRACE && type != CppTokenTypes.SEMICOLON && type != CppTokenTypes.COMMA &&
        type != CppTokenTypes.LBRACE && (type != CppTokenTypes.PRE_KEYWORD || !psiBuilder.getTokenText().equals("\\"))) {
        openBlock = false;
        blocks.add(new BlockInfo(psiBuilder.mark(), blocks.size() > 0 ? BlockInfo.BlockType.STATEMENT : BlockInfo.BlockType.FUNC));
      }
    }

    final IElementType tokenType = psiBuilder.getTokenType();

    if (tokenType == CppTokenTypes.LBRACE) {
      blocks.add(new BlockInfo(psiBuilder.mark(), BlockInfo.BlockType.BLOCK));
    } else if (tokenType == CppTokenTypes.LPAR || tokenType == CppTokenTypes.LBRACKET) {
      if (blocks.size() > 0) blocks.getLast().addParens(psiBuilder.mark());
    }

    final PsiBuilder.Marker tokenMarker = requiresComposite(tokenType) ? psiBuilder.mark():null;
    psiBuilder.advanceLexer();
    if (tokenMarker != null) tokenMarker.done(tokenType);

    if (tokenType == CppTokenTypes.LBRACE) {
      openBlock = true;
    } else if (tokenType == CppTokenTypes.RPAR || tokenType == CppTokenTypes.RBRACKET) {
      if (blocks.size() > 0) blocks.getLast().doneParens();
    } else if (tokenType == CppTokenTypes.RBRACE && blocks.size() > 0) {
      blocks.removeLast().done();
      if (blocks.size() > 0) blocks.removeLast().done();
      openBlock = true;
    }
    else if (tokenType == CppTokenTypes.SEMICOLON && blocks.size() > 0 && !blocks.getLast().hasParens() && !openBlock) {
      blocks.removeLast().done();
      openBlock = true;
    }
  }

  while(blocks.size() > 0) {
    blocks.removeLast().done();
  }
  rootMarker.done(iElementType);
  return psiBuilder.getTreeBuilt();
}
 
Example 13
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
	ProgressIndicatorProvider.checkCanceled();

	TokenSource source = new PSITokenSource(builder);
	TokenStream tokens = new CommonTokenStream(source);
	parser.setTokenStream(tokens);
	parser.setErrorHandler(new ErrorStrategyAdaptor()); // tweaks missing tokens
	parser.removeErrorListeners();
	parser.addErrorListener(new SyntaxErrorListener()); // trap errors
	ParseTree parseTree = null;
	PsiBuilder.Marker rollbackMarker = builder.mark();
	try {
		parseTree = parse(parser, root);
	}
	finally {
		rollbackMarker.rollbackTo();
	}

	// Now convert ANTLR parser tree to PSI tree by mimicking subtree
	// enter/exit with mark/done calls. I *think* this creates their parse
	// tree (AST as they call it) when you call {@link PsiBuilder#getTreeBuilt}
	ANTLRParseTreeToPSIConverter listener = createListener(parser, root, builder);
	PsiBuilder.Marker rootMarker = builder.mark();
	ParseTreeWalker.DEFAULT.walk(listener, parseTree);
	while (!builder.eof()) {
		ProgressIndicatorProvider.checkCanceled();
		builder.advanceLexer();
	}
	// NOTE: parse tree returned from parse will be the
	// usual ANTLR tree ANTLRParseTreeToPSIConverter will
	// convert that to the analogous jetbrains AST nodes
	// When parsing an entire file, the root IElementType
	// will be a IFileElementType.
	//
	// When trying to rename IDs and so on, you get a
	// dummy root and a type arg identifier IElementType.
	// This results in a weird tree that has for example
	// (ID (expr (primary ID))) with the ID IElementType
	// as a subtree root as well as the appropriate leaf
	// all the way at the bottom.  The dummy ID root is a
	// CompositeElement and created by
	// ParserDefinition.createElement() despite having
	// being TokenIElementType.
	rootMarker.done(root);
	return builder.getTreeBuilt(); // calls the ASTFactory.createComposite() etc...
}
 
Example 14
Source Project: react-templates-plugin   File: RTParser.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
    new RTJSParser(builder).parseRT(root);
    return builder.getTreeBuilt();
}
 
Example 15
public ASTNode parse(IElementType root_, PsiBuilder builder_) {
  parseLight(root_, builder_);
  return builder_.getTreeBuilt();
}
 
Example 16
Source Project: intellij-sdk-docs   File: SimpleParser.java    License: Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 17
Source Project: intellij-thrift   File: ThriftParser.java    License: Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 18
Source Project: react-templates-plugin   File: RTParser.java    License: MIT License 4 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
    new RTJSParser(builder).parseRT(root);
    return builder.getTreeBuilt();
}
 
Example 19
Source Project: Buck-IntelliJ-Plugin   File: BuckParser.java    License: Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 20
Source Project: arma-intellij-plugin   File: SQFParser.java    License: MIT License 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}