@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; }
@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; }
/** * @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)); }
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); }
@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); }
@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); }
@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)); } }
/** * @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)); }
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(); }
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); }
@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(); }
@Nullable public LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text) { return null; }
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(); } }
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); }
public void setContentElementType(final IElementType contentElementType) { LOG.assertTrue(contentElementType instanceof ILazyParseableElementType, contentElementType); myContentElementType = contentElementType; }
public TreeElement createContentLeafElement(CharSequence leafText) { if (myContentElementType instanceof ILazyParseableElementType) { return ASTFactory.lazy((ILazyParseableElementType)myContentElementType, leafText); } return ASTFactory.leaf(myContentElementType, leafText); }
@Nullable @Override public LazyParseableElement createLazy(ILazyParseableElementType type, CharSequence text) { return super.createLazy(type, text); }
@Nonnull LazyParseableElement createLazy(final ILazyParseableElementType type, final CharSequence text);
@Nonnull public static LazyParseableElement lazy(@Nonnull final ILazyParseableElementType type, final CharSequence text) { return ASTLazyFactory.EP.getValue(type).createLazy(type, text); }