本文整理汇总了Java中com.intellij.psi.xml.XmlTag.getNode方法的典型用法代码示例。如果您正苦于以下问题:Java XmlTag.getNode方法的具体用法?Java XmlTag.getNode怎么用?Java XmlTag.getNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.xml.XmlTag
的用法示例。
在下文中一共展示了XmlTag.getNode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEndTagNameElement
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
public static XmlToken getEndTagNameElement(@NotNull XmlTag tag) {
final ASTNode node = tag.getNode();
if (node == null) return null;
ASTNode current = node.getLastChildNode();
ASTNode prev = current;
while (current != null) {
final IElementType elementType = prev.getElementType();
if ((elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) &&
current.getElementType() == XmlTokenType.XML_END_TAG_START) {
return (XmlToken)prev.getPsi();
}
prev = current;
current = current.getTreePrev();
}
return null;
}
示例2: isAvailable
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!XsltSupport.isXsltFile(file)) return false;
final int offset = editor.getCaretModel().getOffset();
final PsiElement element = file.findElementAt(offset);
if (element == null) return false;
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag == null || tag.getParentTag() == null) return false;
if (!tag.getLocalName().equals("if") || !XsltSupport.isXsltTag(tag)) return false;
if (tag.getAttributeValue("test") == null) return false;
final ASTNode node = tag.getNode();
if (node == null) return false;
final ASTNode child = XmlChildRole.START_TAG_NAME_FINDER.findChild(node);
return child != null && child.getTextRange().contains(offset);
}
示例3: isAvailableAt
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
protected static boolean isAvailableAt(PsiElement element, XmlTag tag, int offset) {
final ASTNode node = tag.getNode();
if (node != null) {
final ASTNode child = XmlChildRole.START_TAG_NAME_FINDER.findChild(node);
if (child != null && child.getTextRange().contains(offset)) {
return true;
}
}
// final XmlAttribute att = PsiTreeUtil.getParentOfType(element, XmlAttribute.class);
// if (att != null && "name".equals(att.getName()) && att.getValueElement() != null) {
// return att.getValueElement().getTextRange().contains(offset);
// }
return false;
}
示例4: getStartTagNameElement
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
public static XmlToken getStartTagNameElement(@NotNull XmlTag tag) {
final ASTNode node = tag.getNode();
if (node == null) return null;
ASTNode current = node.getFirstChildNode();
IElementType elementType;
while (current != null
&& (elementType = current.getElementType()) != XmlTokenType.XML_NAME
&& elementType != XmlTokenType.XML_TAG_NAME) {
current = current.getTreeNext();
}
return current == null ? null : (XmlToken)current.getPsi();
}
示例5: replaceByTagContent
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void replaceByTagContent(Project project, XmlTag tagToReplace, XmlTag tagToInline)
throws AndroidRefactoringErrorException {
final ASTNode node = tagToInline.getNode();
if (node == null) {
throw new AndroidRefactoringErrorException();
}
final ASTNode startTagEnd = XmlChildRole.START_TAG_END_FINDER.findChild(node);
final ASTNode closingTagStart = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(node);
if (startTagEnd == null || closingTagStart == null) {
throw new AndroidRefactoringErrorException();
}
final int contentStart = startTagEnd.getTextRange().getEndOffset();
final int contentEnd = closingTagStart.getTextRange().getStartOffset();
if (contentStart < 0 || contentEnd < 0 || contentStart >= contentEnd) {
throw new AndroidRefactoringErrorException();
}
final PsiFile file = tagToInline.getContainingFile();
if(file == null) {
throw new AndroidRefactoringErrorException();
}
final String textToInline = file.getText().
substring(contentStart, contentEnd).trim();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final Document document = documentManager.getDocument(tagToReplace.getContainingFile());
if (document == null) {
throw new AndroidRefactoringErrorException();
}
final TextRange range = tagToReplace.getTextRange();
document.replaceString(range.getStartOffset(), range.getEndOffset(), textToInline);
documentManager.commitDocument(document);
}
示例6: getTagRanges
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
private static Pair<TextRange, TextRange> getTagRanges(XmlTag tag) {
final ASTNode tagNode = tag.getNode();
return Pair.create(getStartTagRange(tagNode), getEndTagRange(tagNode));
}
示例7: isAvailable
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!XsltSupport.isXsltFile(file)) return false;
final int offset = editor.getCaretModel().getOffset();
final PsiElement element = file.findElementAt(offset);
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
if (tag == null) {
return false;
}
if (!XsltSupport.isXsltTag(tag)) {
return false;
} else if (!"attribute".equals(tag.getLocalName())) {
return false;
} else if (tag.getAttribute("name") == null) {
return false;
} else if (findParent(tag) == null) {
// we cannot "inline" anything that isn't clearly the child of either an xsl:element or a literal result element
return false;
}
final ASTNode node = tag.getNode();
if (node == null) return false;
final ASTNode nameNode = XmlChildRole.START_TAG_NAME_FINDER.findChild(node);
if (nameNode == null || !nameNode.getTextRange().contains(offset)) {
return false;
}
final XmlTag[] texts = tag.findSubTags("text", XsltSupport.XSLT_NS);
final XmlTag[] exprs = tag.findSubTags("value-of", XsltSupport.XSLT_NS);
final PsiElement[] children = tag.getChildren();
for (PsiElement child : children) {
if (child instanceof XmlText) {
final XmlText text = (XmlText)child;
if (text.getText().trim().length() == 0) {
if (texts.length == 0 && exprs.length == 0) {
return false;
}
}
} else if (child instanceof XmlTag) {
final XmlTag t = (XmlTag)child;
if (XsltSupport.isXsltTag(t)) {
if ("text".equals(t.getLocalName())) {
} else if ("value-of".equals(t.getLocalName())) {
if (t.getAttribute("select") == null) {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
}
return true;
}