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

The following examples show how to use com.intellij.psi.tree.ILazyParseableElementType. 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
Source Project: reasonml-idea-plugin   Source File: OclParser.java    License: 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 Project: BashSupport   Source File: BashBlock.java    License: 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 Project: consulo-csharp   Source File: CSharpFileStubElementType.java    License: 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 Project: consulo-csharp   Source File: CSharpDocParsing.java    License: 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 Project: consulo   Source File: BraceHighlightingHandler.java    License: 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 Project: consulo   Source File: ParseUtilBase.java    License: 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 Project: intellij-haxe   Source File: HaxeAstFactory.java    License: 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 Project: consulo   Source File: ASTLazyFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
LazyParseableElement createLazy(@Nonnull ILazyParseableElementType type, @Nullable CharSequence text);
 
Example 9
Source Project: consulo   Source File: ASTFactory.java    License: 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);
}