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

The following are top voted examples for showing how to use com.intellij.psi.tree.ILazyParseableElementType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: intellij-ce-playground   File: XmlASTFactory.java   Source Code and License 6 votes vote down vote up
@Override
public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) {
  if (type == XML_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == DTD_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == XHTML_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == HTML_FILE) {
    return new HtmlFileElement(text);
  }
  else if (type instanceof ITemplateDataElementType) {
    return new XmlFileElement(type, text);
  }
  return null;
}
 
Example 2
Project: tools-idea   File: XmlASTFactory.java   Source Code and License 6 votes vote down vote up
@Override
public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) {
  if (type == XML_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == DTD_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == XHTML_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == HTML_FILE) {
    return new HtmlFileElement(text);
  }
  else if (type instanceof ITemplateDataElementType) {
    return new XmlFileElement(type, text);
  }
  return null;
}
 
Example 3
Project: consulo-xml   File: XmlASTLazyFactory.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) {
  if (type == XML_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == DTD_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == XHTML_FILE) {
    return new XmlFileElement(type, text);
  }
  else if (type == HTML_FILE) {
    return new HtmlFileElement(text);
  }
  else if (type instanceof TemplateDataElementType) {
    return new XmlFileElement(type, text);
  }
  return null;
}
 
Example 4
Project: lua-for-idea   File: LuaFormattingBlock.java   Source Code and License 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 5
Project: RtplPlugin   File: XmlParsing.java   Source Code and License 5 votes vote down vote up
public void parseTagContent() {
  PsiBuilder.Marker xmlText = null;
  while (token() != XML_END_TAG_START && !eof()) {
    final IElementType tt = token();
    if (tt == XML_START_TAG_START) {
      xmlText = terminateText(xmlText);
      parseTag(false);
    }
    else if (tt == XML_ENTITY_REF_TOKEN) {
      xmlText = terminateText(xmlText);
      parseReference();
    }
    else if (tt == XML_CHAR_ENTITY_REF) {
      xmlText = startText(xmlText);
      parseReference();
    }
    else if (isCommentToken(tt)) {
      xmlText = terminateText(xmlText);
      parseComment();
    }
    else if (tt == XML_BAD_CHARACTER) {
      xmlText = startText(xmlText);
      final PsiBuilder.Marker error = mark();
      advance();
      error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
    }
    else if (tt instanceof CustomParsingType || tt instanceof ILazyParseableElementType) {
      xmlText = terminateText(xmlText);
      advance();
    }
    else {
      xmlText = startText(xmlText);
      advance();
    }
  }

  terminateText(xmlText);
}
 
Example 6
Project: intellij-ce-playground   File: ASTFactory.java   Source Code and License 5 votes vote down vote up
@NotNull
public static LazyParseableElement lazy(@NotNull final ILazyParseableElementType type, CharSequence text) {
  final ASTNode node = type.createNode(text);
  if (node != null) return (LazyParseableElement)node;

  if (type == TokenType.CODE_FRAGMENT) {
    return new CodeFragmentElement(null);
  }
  else if (type == TokenType.DUMMY_HOLDER) {
    return new DummyHolderElement(text);
  }

  final LazyParseableElement customLazy = factory(type).createLazy(type, text);
  return customLazy != null ? customLazy : DefaultFactoryHolder.DEFAULT.createLazy(type, text);
}
 
Example 7
Project: intellij-ce-playground   File: CoreASTFactory.java   Source Code and License 5 votes vote down vote up
@Override
@NotNull
public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) {
  if (type instanceof IFileElementType) {
    return new FileElement(type, text);
  }

  return new LazyParseableElement(type, text);
}
 
Example 8
Project: intellij-ce-playground   File: ParseUtilBase.java   Source Code and License 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 9
Project: intellij-ce-playground   File: GroovyBlock.java   Source Code and License 5 votes vote down vote up
/**
 * @param node Tree node
 * @return true if node is incomplete
 */
public static 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 10
Project: tools-idea   File: LazyParseableElement.java   Source Code and License 5 votes vote down vote up
private void ensureParsed() {
  if (!ourParsingAllowed) {
    LOG.error("Parsing not allowed!!!");
  }
  CharSequence text = myText();
  if (text == null) return;

  if (TreeUtil.getFileElement(this) == null) {
    LOG.error("Chameleons must not be parsed till they're in file tree: " + this);
  }

  ApplicationManager.getApplication().assertReadAccessAllowed();

  ILazyParseableElementType type = (ILazyParseableElementType)getElementType();
  ASTNode parsedNode = type.parseContents(this);

  if (parsedNode == null && text.length() > 0) {
    CharSequence diagText = ApplicationManager.getApplication().isInternal() ? text : "";
    LOG.error("No parse for a non-empty string: " + diagText + "; type=" + LogUtil.objectAndClass(type));
  }

  synchronized (lock) {
    if (myText == null) return;
    if (rawFirstChild() != null) {
      LOG.error("Reentrant parsing?");
    }

    myText = null;

    if (parsedNode == null) return;
    super.rawAddChildrenWithoutNotifications((TreeElement)parsedNode);
  }

  // create PSI all at once, to reduce contention of PsiLock in CompositeElement.getPsi()
  // create PSI outside the 'lock' since this method grabs PSI_LOCK and deadlock is possible when someone else locks in the other order.
  createAllChildrenPsiIfNecessary();
}
 
Example 11
Project: tools-idea   File: CoreASTFactory.java   Source Code and License 5 votes vote down vote up
@Override
@NotNull
public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) {
  if (type instanceof IFileElementType) {
    return new FileElement(type, text);
  }

  return new LazyParseableElement(type, text);
}
 
Example 12
Project: tools-idea   File: ParseUtilBase.java   Source Code and License 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 13
Project: tools-idea   File: GroovyBlock.java   Source Code and License 5 votes vote down vote up
/**
 * @param node Tree node
 * @return true if node is incomplete
 */
public static 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 14
Project: consulo-csharp   File: CSharpDocParsing.java   Source Code and License 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 15
Project: consulo-lua   File: LuaFormattingBlock.java   Source Code and License 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 16
Project: consulo   File: BraceHighlightingHandler.java   Source Code and License 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 17
Project: consulo   File: ParseUtilBase.java   Source Code and License 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 18
Project: intellij-ce-playground   File: ASTFactory.java   Source Code and License 4 votes vote down vote up
@Nullable
public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) {
  return null;
}
 
Example 19
Project: intellij-ce-playground   File: LazyParseableElement.java   Source Code and License 4 votes vote down vote up
private void ensureParsed() {
  if (!ourParsingAllowed) {
    LOG.error("Parsing not allowed!!!");
  }
  CharSequence text = myText();
  if (text == null) return;

  if (TreeUtil.getFileElement(this) == null) {
    LOG.error("Chameleons must not be parsed till they're in file tree: " + this);
  }

  ApplicationManager.getApplication().assertReadAccessAllowed();

  DebugUtil.startPsiModification("lazy-parsing");
  try {
    ILazyParseableElementType type = (ILazyParseableElementType)getElementType();
    ASTNode parsedNode = type.parseContents(this);

    if (parsedNode == null && text.length() > 0) {
      CharSequence diagText = ApplicationManager.getApplication().isInternal() ? text : "";
      LOG.error("No parse for a non-empty string: " + diagText + "; type=" + LogUtil.objectAndClass(type));
    }

    synchronized (lock) {
      if (myText == null) return;
      if (rawFirstChild() != null) {
        LOG.error("Reentrant parsing?");
      }

      myText = null;

      if (parsedNode == null) return;
      super.rawAddChildrenWithoutNotifications((TreeElement)parsedNode);
    }
  }
  finally {
    DebugUtil.finishPsiModification();
  }

  if (!Boolean.TRUE.equals(ourSuppressEagerPsiCreation.get())) {
    // create PSI all at once, to reduce contention of PsiLock in CompositeElement.getPsi()
    // create PSI outside the 'lock' since this method grabs PSI_LOCK and deadlock is possible when someone else locks in the other order.
    createAllChildrenPsiIfNecessary();
  }
}
 
Example 20
Project: intellij-ce-playground   File: XmlParsing.java   Source Code and License 4 votes vote down vote up
public void parseTagContent() {
  PsiBuilder.Marker xmlText = null;
  while (token() != XML_END_TAG_START && !eof()) {
    final IElementType tt = token();
    if (tt == XML_START_TAG_START) {
      xmlText = terminateText(xmlText);
      parseTag(false);
    }
    else if (tt == XML_PI_START) {
      xmlText = terminateText(xmlText);
      parseProcessingInstruction();
    }
    else if (tt == XML_ENTITY_REF_TOKEN) {
      xmlText = terminateText(xmlText);
      parseReference();
    }
    else if (tt == XML_CHAR_ENTITY_REF) {
      xmlText = startText(xmlText);
      parseReference();
    }
    else if (tt == XML_CDATA_START) {
      xmlText = startText(xmlText);
      parseCData();
    }
    else if (isCommentToken(tt)) {
      xmlText = terminateText(xmlText);
      parseComment();
    }
    else if (tt == XML_BAD_CHARACTER) {
      xmlText = startText(xmlText);
      final PsiBuilder.Marker error = mark();
      advance();
      error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
    }
    else if (tt instanceof CustomParsingType || tt instanceof ILazyParseableElementType) {
      xmlText = terminateText(xmlText);
      advance();
    }
    else {
      xmlText = startText(xmlText);
      advance();
    }
  }

  terminateText(xmlText);
}
 
Example 21
Project: tools-idea   File: PsiFileImpl.java   Source Code and License 4 votes vote down vote up
public void setContentElementType(final IElementType contentElementType) {
  LOG.assertTrue(contentElementType instanceof ILazyParseableElementType, contentElementType);
  myContentElementType = contentElementType;
}
 
Example 22
Project: tools-idea   File: PsiFileImpl.java   Source Code and License 4 votes vote down vote up
public TreeElement createContentLeafElement(CharSequence leafText) {
  if (myContentElementType instanceof ILazyParseableElementType) {
    return ASTFactory.lazy((ILazyParseableElementType)myContentElementType, leafText);
  }
  return ASTFactory.leaf(myContentElementType, leafText);
}
 
Example 23
Project: tools-idea   File: XmlParsing.java   Source Code and License 4 votes vote down vote up
public void parseTagContent() {
  PsiBuilder.Marker xmlText = null;
  while (token() != XML_END_TAG_START && !eof()) {
    final IElementType tt = token();
    if (tt == XML_START_TAG_START) {
      xmlText = terminateText(xmlText);
      parseTag(false);
    }
    else if (tt == XML_PI_START) {
      xmlText = terminateText(xmlText);
      parseProcessingInstruction();
    }
    else if (tt == XML_ENTITY_REF_TOKEN) {
      xmlText = terminateText(xmlText);
      parseReference();
    }
    else if (tt == XML_CHAR_ENTITY_REF) {
      xmlText = startText(xmlText);
      parseReference();
    }
    else if (tt == XML_CDATA_START) {
      xmlText = startText(xmlText);
      parseCData();
    }
    else if (isCommentToken(tt)) {
      xmlText = terminateText(xmlText);
      parseComment();
    }
    else if (tt == XML_BAD_CHARACTER) {
      xmlText = startText(xmlText);
      final PsiBuilder.Marker error = mark();
      advance();
      error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
    }
    else if (tt instanceof CustomParsingType || tt instanceof ILazyParseableElementType) {
      xmlText = terminateText(xmlText);
      advance();
    }
    else {
      xmlText = startText(xmlText);
      advance();
    }
  }

  terminateText(xmlText);
}
 
Example 24
Project: intellij-haxe   File: HaxeAstFactory.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) {
  return super.createLazy(type, text);
}
 
Example 25
Project: consulo   File: ASTLazyFactory.java   Source Code and License 4 votes vote down vote up
@Nonnull
LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text);
 
Example 26
Project: consulo   File: ASTFactory.java   Source Code and License 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);
}
 
Example 27
Project: consulo-xml   File: XmlParsing.java   Source Code and License 4 votes vote down vote up
public void parseTagContent() {
  PsiBuilder.Marker xmlText = null;
  while (token() != XML_END_TAG_START && !eof()) {
    final IElementType tt = token();
    if (tt == XML_START_TAG_START) {
      xmlText = terminateText(xmlText);
      parseTag(false);
    }
    else if (tt == XML_PI_START) {
      xmlText = terminateText(xmlText);
      parseProcessingInstruction();
    }
    else if (tt == XML_ENTITY_REF_TOKEN) {
      xmlText = terminateText(xmlText);
      parseReference();
    }
    else if (tt == XML_CHAR_ENTITY_REF) {
      xmlText = startText(xmlText);
      parseReference();
    }
    else if (tt == XML_CDATA_START) {
      xmlText = startText(xmlText);
      parseCData();
    }
    else if (isCommentToken(tt)) {
      xmlText = terminateText(xmlText);
      parseComment();
    }
    else if (tt == XML_BAD_CHARACTER) {
      xmlText = startText(xmlText);
      final PsiBuilder.Marker error = mark();
      advance();
      error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
    }
    else if (tt instanceof CustomParsingType || tt instanceof ILazyParseableElementType) {
      xmlText = terminateText(xmlText);
      advance();
    }
    else {
      xmlText = startText(xmlText);
      advance();
    }
  }

  terminateText(xmlText);
}