com.intellij.psi.tree.ILazyParseableElementType Java Examples

The following examples show how to use com.intellij.psi.tree.ILazyParseableElementType. 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: OclParser.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public static ASTNode parseOcamlNode(@NotNull ILazyParseableElementType root, @NotNull ASTNode chameleon) {
    PsiElement parentElement = chameleon.getTreeParent().getPsi();
    Project project = parentElement.getProject();

    PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new OclLexer(), root.getLanguage(), chameleon.getText());
    //builder.setDebugMode(true);
    OclParser parser = new OclParser();

    return parser.parse(root, builder).getFirstChildNode();
}
 
Example #2
Source File: BashBlock.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
/**
 * @param node Tree node
 * @return true if node is incomplete
 */
public boolean isIncomplete(@NotNull final ASTNode node) {
    if (node.getElementType() instanceof ILazyParseableElementType) {
        return false;
    }
    ASTNode lastChild = node.getLastChildNode();
    while (lastChild != null &&
            !(lastChild.getElementType() instanceof ILazyParseableElementType) &&
            (lastChild.getPsi() instanceof PsiWhiteSpace || lastChild.getPsi() instanceof PsiComment)) {
        lastChild = lastChild.getTreePrev();
    }
    return lastChild != null && (lastChild.getPsi() instanceof PsiErrorElement || isIncomplete(lastChild));
}
 
Example #3
Source File: CSharpFileStubElementType.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder()
{
	return new DefaultStubBuilder()
	{
		@Nonnull
		@Override
		protected StubElement createStubForFile(@Nonnull PsiFile file)
		{
			if(file instanceof CSharpFileImpl)
			{
				return new CSharpFileStub((CSharpFileImpl) file);
			}
			return super.createStubForFile(file);
		}

		@Override
		public boolean skipChildProcessingWhenBuildingStubs(@Nonnull ASTNode parent, @Nonnull ASTNode node)
		{
			// skip any lazy parseable elements, like preprocessors or code blocks etc
			if(node.getElementType() instanceof ILazyParseableElementType)
			{
				return true;
			}
			return false;
		}
	};
}
 
Example #4
Source File: CSharpDocParsing.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public void parseTagContent()
{
	PsiBuilder.Marker xmlText = null;
	while(token() != CSharpDocTokenType.XML_END_TAG_START && !eof())
	{
		final IElementType tt = token();
		if(tt == CSharpDocTokenType.XML_START_TAG_START)
		{
			xmlText = terminateText(xmlText);
			parseTag();
		}
		else if(isCommentToken(tt))
		{
			xmlText = terminateText(xmlText);
			parseComment();
		}
		else if(tt instanceof CustomParsingType || tt instanceof ILazyParseableElementType)
		{
			xmlText = terminateText(xmlText);
			advance();
		}
		else
		{
			xmlText = startText(xmlText);
			advance();
		}
	}

	terminateText(xmlText);
}
 
Example #5
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static EditorHighlighter getLazyParsableHighlighterIfAny(Project project, Editor editor, PsiFile psiFile) {
  if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
    return ((EditorEx)editor).getHighlighter();
  }
  PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset());
  for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) {
    if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType)) continue;
    Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode());
    if (language == null) continue;
    TextRange range = e.getTextRange();
    final int offset = range.getStartOffset();
    SyntaxHighlighter syntaxHighlighter =
            SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile());
    LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) {
      @Nonnull
      @Override
      public HighlighterIterator createIterator(int startOffset) {
        return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) {
          @Override
          public int getStart() {
            return super.getStart() + offset;
          }

          @Override
          public int getEnd() {
            return super.getEnd() + offset;
          }
        };
      }
    };
    highlighter.setText(editor.getDocument().getText(range));
    return highlighter;
  }
  return ((EditorEx)editor).getHighlighter();
}
 
Example #6
Source File: ParseUtilBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TreeElement createTokenElement(Lexer lexer, CharTable table) {
  IElementType tokenType = lexer.getTokenType();
  if (tokenType == null) {
    return null;
  }
  else if (tokenType instanceof ILazyParseableElementType) {
    return ASTFactory.lazy((ILazyParseableElementType)tokenType, LexerUtil.internToken(lexer, table));
  }
  else {
    return ASTFactory.leaf(tokenType, LexerUtil.internToken(lexer, table));
  }
}
 
Example #7
Source File: HaxeAstFactory.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) {
  return super.createLazy(type, text);
}
 
Example #8
Source File: ASTLazyFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
LazyParseableElement createLazy(@Nonnull ILazyParseableElementType type, @Nullable CharSequence text);
 
Example #9
Source File: ASTFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static LazyParseableElement lazy(@Nonnull final ILazyParseableElementType type, final CharSequence text) {
  return ASTLazyFactory.EP.getValue(type).createLazy(type, text);
}