[intellij-sh] Improve resolving by replace getPrevSibling to direct children iteration

GitOrigin-RevId: 3a1067621348ce96c51719c5a376a3f67a33e999
This commit is contained in:
Mikhail Mazurkevich
2020-02-19 16:53:23 +00:00
committed by intellij-monorepo-bot
parent 5477b0b411
commit 48148fda69
4 changed files with 15 additions and 13 deletions
@@ -13,7 +13,7 @@ public class ShFunctionDeclarationProcessor implements PsiScopeProcessor {
private final String myFunctionName;
private ShFunctionName myResult;
public ShFunctionDeclarationProcessor(String name) {
public ShFunctionDeclarationProcessor(@NotNull String name) {
myFunctionName = name;
}
@@ -22,9 +22,13 @@ public class ResolveUtil {
public static boolean processFunctionDeclarations(@Nullable PsiElement element, @NotNull TextRange lastParentTextRange,
@NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
if (element == null) return true;
for (PsiElement e = element; e != null; e = e.getPrevSibling()) {
if (violateTextRangeRestrictions(e.getTextRange(), lastParentTextRange)) continue;
if (!processor.execute(e, state) || (!violateRestrictions(e) && !processFunctionDeclarations(e.getLastChild(), lastParentTextRange,
if (!processor.execute(element, state)) return false;
PsiElement[] children = element.getChildren();
if (children.length == 0) return true;
for (int i = children.length - 1; i >= 0; i--) {
PsiElement child = children[i];
if (violateTextRangeRestrictions(child.getTextRange(), lastParentTextRange)) continue;
if (!processor.execute(child, state) || (!violateRestrictions(child) && !processFunctionDeclarations(child.getLastChild(), lastParentTextRange,
processor, state))) {
return false;
}
@@ -37,13 +41,11 @@ public class ResolveUtil {
@NotNull ResolveState substitutor,
@Nullable PsiElement lastParent,
@NotNull PsiElement place) {
PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling();
while (run != null) {
if (run instanceof ShCompositeElement && !run.processDeclarations(processor, substitutor, element, place)) {
return false;
}
run = run.getPrevSibling();
PsiElement[] children = element.getChildren();
if (children.length == 0) return true;
for (int i = children.length - 1; i >= 0; i--) {
PsiElement child = children[i];
if (!child.processDeclarations(processor, substitutor, element, place)) return false;
}
return true;
}
@@ -32,7 +32,7 @@ public class ShFile extends PsiFileBase {
@NotNull ResolveState state,
PsiElement lastParent,
@NotNull PsiElement place) {
return ResolveUtil.processFunctionDeclarations(this.getLastChild(), place.getTextRange(), processor, state);
return ResolveUtil.processFunctionDeclarations(this, place.getTextRange(), processor, state);
}
@Nullable
@@ -35,7 +35,7 @@ public abstract class ShLazyParseablePsiElement extends LazyParseablePsiElement
@NotNull ResolveState state,
PsiElement lastParent,
@NotNull PsiElement place) {
return ResolveUtil.processFunctionDeclarations(this.getLastChild(), place.getTextRange(), processor, state);
return ResolveUtil.processFunctionDeclarations(this, place.getTextRange(), processor, state);
}
@Override