Java Code Examples for com.intellij.psi.util.PsiTreeUtil#getStubOrPsiParent()
The following examples show how to use
com.intellij.psi.util.PsiTreeUtil#getStubOrPsiParent() .
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: BashPsiUtils.java From BashSupport with Apache License 2.0 | 6 votes |
/** * Returns the broadest scope of the variable definition. * * @param startElement The element to check * @return The containing block or null */ @Nullable public static BashFunctionDef findBroadestFunctionScope(PsiElement startElement) { BashFunctionDef lastValidScope = null; PsiElement element = PsiTreeUtil.getStubOrPsiParent(startElement); while (element != null) { if (element instanceof BashFunctionDef) { lastValidScope = (BashFunctionDef) element; } element = PsiTreeUtil.getStubOrPsiParent(element); if (element == null) { return lastValidScope; } } return null; }
Example 2
Source File: BashPsiUtils.java From BashSupport with Apache License 2.0 | 6 votes |
/** * This tree walkup method does continue even if a valid definition has been found on an more-inner level. * Bash is different in regard to the definitions, the most outer definitions count, not the most inner / the first one found. * * @param processor * @param entrance * @param maxScope * @param state * @return */ public static boolean varResolveTreeWalkUp(@NotNull final PsiScopeProcessor processor, @NotNull final BashVar entrance, @Nullable final PsiElement maxScope, @NotNull final ResolveState state) { PsiElement prevParent = entrance; PsiElement scope = entrance; boolean hasResult = false; while (scope != null) { hasResult |= !scope.processDeclarations(processor, state, prevParent, entrance); if (scope == maxScope) { break; } prevParent = scope; scope = PsiTreeUtil.getStubOrPsiParent(prevParent); } return !hasResult; }
Example 3
Source File: BashPsiUtils.java From BashSupport with Apache License 2.0 | 6 votes |
@Nullable public static <T extends PsiElement> T findStubParent(@Nullable PsiElement start, Class<T> parentType) { if (start == null) { return null; } Class<? extends PsiElement> breakPoint = PsiFile.class; for (PsiElement current = start; current != null; current = PsiTreeUtil.getStubOrPsiParent(current)) { if (parentType.isInstance(current)) { return (T) current; } if (breakPoint.isInstance(current)) { return null; } } return null; }
Example 4
Source File: BashPsiUtils.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Returns the narrowest scope of the variable definition. * * @param varDef The element to check * @return The containing block or null */ public static BashFunctionDef findNextVarDefFunctionDefScope(PsiElement varDef) { PsiElement element = PsiTreeUtil.getStubOrPsiParent(varDef); while (element != null) { if (element instanceof BashFunctionDef) { return (BashFunctionDef) element; } element = PsiTreeUtil.getStubOrPsiParent(element); } return null; }
Example 5
Source File: BashPsiUtils.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Returns the next logical block which contains this element. * * @param element The element to check * @return The containing block or null */ public static PsiElement findEnclosingBlock(PsiElement element) { while (element != null) { element = PsiTreeUtil.getStubOrPsiParent(element); if (isValidContainer(element)) { return element; } } return null; }