SSR: fix php searching

This commit is contained in:
Bas Leijdekkers
2018-03-20 16:18:57 +01:00
parent 7beaa6dace
commit 0656f7b3e3
2 changed files with 16 additions and 6 deletions
@@ -1,10 +1,9 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.dupLocator.iterators;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* Node iterator interface
*/
public abstract class NodeIterator implements Cloneable {
public abstract boolean hasNext();
public abstract PsiElement current();
@@ -19,12 +18,17 @@ public abstract class NodeIterator implements Cloneable {
}
}
public void rewindTo(@NotNull PsiElement element) {
while (current() != element) {
rewind();
}
}
public NodeIterator clone() {
try {
return (NodeIterator) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
return null;
throw new RuntimeException();
}
}
}
@@ -46,6 +46,7 @@ public abstract class MatchingHandler {
public boolean matchSequentially(NodeIterator patternNodes, NodeIterator matchNodes, MatchContext context) {
final MatchingStrategy strategy = context.getPattern().getStrategy();
final PsiElement currentPatternNode = patternNodes.current();
final PsiElement currentMatchNode = matchNodes.current();
skipIfNecessary(matchNodes, currentPatternNode, strategy);
skipComments(matchNodes, currentPatternNode);
@@ -69,7 +70,12 @@ public abstract class MatchingHandler {
if (patternNodes.hasNext()) {
final MatchingHandler nextHandler = context.getPattern().getHandler(patternNodes.current());
return nextHandler.matchSequentially(patternNodes, matchNodes, context);
if (nextHandler.matchSequentially(patternNodes, matchNodes, context)) {
return true;
} else {
patternNodes.rewindTo(currentPatternNode);
matchNodes.rewindTo(currentMatchNode);
}
} else {
// match was found
return handler.isMatchSequentiallySucceeded(matchNodes);