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

The following examples show how to use com.intellij.psi.util.PsiTreeUtil#getDeepestFirst() . 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
Source File: FluidTypeResolver.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
/**
 * 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
Source File: TokenVocabResolver.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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
Source File: Trees.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: MyPsiUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
}