Java Code Examples for com.intellij.psi.util.PsiTreeUtil#getDeepestFirst()

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#getDeepestFirst() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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);
}
 
Example 2
/**
 * 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;
}
 
Example 3
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
}
 
Example 4
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
}