本文整理汇总了Java中com.intellij.psi.impl.source.tree.TreeUtil.findParent方法的典型用法代码示例。如果您正苦于以下问题:Java TreeUtil.findParent方法的具体用法?Java TreeUtil.findParent怎么用?Java TreeUtil.findParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.TreeUtil
的用法示例。
在下文中一共展示了TreeUtil.findParent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preprocessOnPaste
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
final Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).commitDocument(document);
int caretOffset = editor.getCaretModel().getOffset();
PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset);
ASTNode node = element.getNode();
if (node != null) {
boolean hasMarkup = text.indexOf('>') >= 0 || text.indexOf('<') >= 0;
if (element.getTextOffset() == caretOffset &&
node.getElementType() == XmlTokenType.XML_END_TAG_START &&
node.getTreePrev().getElementType() == XmlTokenType.XML_TAG_END) {
return hasMarkup ? text : encode(text, element);
} else {
XmlElement parent = PsiTreeUtil.getParentOfType(element, XmlText.class, XmlAttributeValue.class);
if (parent != null) {
if (parent instanceof XmlText && hasMarkup) {
return text;
}
if (TreeUtil.findParent(node, XmlElementType.XML_CDATA) == null &&
TreeUtil.findParent(node, XmlElementType.XML_COMMENT) == null) {
return encode(text, element);
}
}
}
}
return text;
}
示例2: preprocessOnPaste
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
final Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).commitDocument(document);
int caretOffset = editor.getCaretModel().getOffset();
PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset);
ASTNode node = element.getNode();
if (node != null) {
boolean hasMarkup = text.indexOf('>') >= 0 || text.indexOf('<') >= 0;
if (element.getTextOffset() == caretOffset &&
node.getElementType() == XmlElementType.XML_END_TAG_START &&
node.getTreePrev().getElementType() == XmlElementType.XML_TAG_END) {
return hasMarkup ? text : encode(text, element);
} else {
XmlElement parent = PsiTreeUtil.getParentOfType(element, XmlText.class, XmlAttributeValue.class);
if (parent != null) {
if (parent instanceof XmlText && hasMarkup) {
return text;
}
if (TreeUtil.findParent(node, XmlElementType.XML_CDATA) == null &&
TreeUtil.findParent(node, XmlElementType.XML_COMMENT) == null) {
return encode(text, element);
}
}
}
}
return text;
}
示例3: collect
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Override
public void collect(@NotNull TwigFileVariableCollectorParameter parameter, @NotNull Map<String, Set<String>> variables) {
ASTNode macroStatement = TreeUtil.findParent(parameter.getElement().getNode(), TwigElementTypes.MACRO_STATEMENT);
if(macroStatement == null) {
return;
}
PsiElement psiElement = macroStatement.getPsi();
if(psiElement == null) {
return;
}
PsiElement marcoTag = psiElement.getFirstChild();
if(marcoTag == null) {
return;
}
Pair<String, String> pair = TwigUtil.getTwigMacroNameAndParameter(marcoTag);
if(pair == null || pair.getSecond() == null) {
return;
}
// strip braces "(foobar, foo)"
String args = StringUtils.stripStart(pair.getSecond(), "( ");
args = StringUtils.stripEnd(args, ") ");
for (String s : args.split("\\s*,\\s*")) {
variables.put(s, Collections.emptySet());
}
}
示例4: findForeachNode
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
public ASTNode findForeachNode() {
return TreeUtil.findParent(getNode(), VtlElementTypes.DIRECTIVE_FOREACH);
}