下面列出了com.intellij.psi.util.PsiTreeUtil#getDeepestFirst ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Get the "for IN" variable identifier as separated string
* <p>
* {% for car in "cars" %}
* {% for car in "cars"|length %}
* {% for car in "cars.test" %}
*/
@NotNull
public static Collection<String> getForTagIdentifierAsString(XmlTag forTag) {
XmlAttribute each = forTag.getAttribute("each");
if (each == null || each.getValueElement() == null) {
return ContainerUtil.emptyList();
}
PsiElement fluidElement = FluidUtil.retrieveFluidElementAtPosition(each.getValueElement());
if (fluidElement == null) {
return Collections.emptyList();
}
PsiElement deepestFirst = PsiTreeUtil.getDeepestFirst(fluidElement);
return FluidTypeResolver.formatPsiTypeName(deepestFirst);
}
/**
* If this reference is the value of a {@code tokenVocab} option, returns the corresponding
* grammar file.
*/
@Nullable
public static PsiFile resolveTokenVocabFile(GrammarElementRefNode reference) {
PsiElement optionValue = PsiTreeUtil.findFirstParent(reference, TokenVocabResolver::isOptionValue);
if (optionValue != null) {
PsiElement option = optionValue.getParent();
if (option != null) {
PsiElement optionName = PsiTreeUtil.getDeepestFirst(option);
if (optionName.getText().equals("tokenVocab")) {
return findRelativeFile(reference.getText(), reference.getContainingFile());
}
}
}
return null;
}
public static PsiElement createLeafFromText(Project project, Language language, PsiElement context,
String text, IElementType type)
{
PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
PsiElement el = factory.createElementFromText(text, language, type, context);
if ( el==null ) return null;
return PsiTreeUtil.getDeepestFirst(el); // forces parsing of file!!
// start rule depends on root passed in
}
public static PsiElement createLeafFromText(Project project, PsiElement context,
String text, IElementType type)
{
PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
PsiElement el = factory.createElementFromText(text,
ANTLRv4Language.INSTANCE,
type,
context);
return PsiTreeUtil.getDeepestFirst(el); // forces parsing of file!!
// start rule depends on root passed in
}