SSR: cleanup MatchResultImpl & related

This commit is contained in:
Bas Leijdekkers
2015-11-06 20:55:35 +01:00
parent 7312c98275
commit c2ef9b756d
6 changed files with 25 additions and 26 deletions
@@ -531,7 +531,7 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
handleMethodParameter(buf, info, matchMap);
replacementString = buf.toString();
}
else if (match.getAllSons().size() > 0 && !match.isScopeMatch()) {
else if (match.hasSons() && !match.isScopeMatch()) {
// compound matches
StringBuilder buf = new StringBuilder();
MatchResult r = null;
@@ -10,8 +10,8 @@ import java.util.List;
* Class describing the match result
*/
public abstract class MatchResult {
@NonNls public static final String LINE_MATCH = "line";
@NonNls public static final String MULTI_LINE_MATCH = "context";
@NonNls public static final String LINE_MATCH = "__line__";
@NonNls public static final String MULTI_LINE_MATCH = "__multi_line__";
public abstract String getMatchImage();
@@ -26,4 +26,5 @@ public abstract class MatchResult {
public abstract boolean hasSons();
public abstract boolean isScopeMatch();
public abstract boolean isMultipleMatch();
public abstract boolean isTarget();
}
@@ -221,7 +221,7 @@ public abstract class StructuralSearchProfile {
if (info.getName().equals(match.getName())) {
String replacementString = match.getMatchImage();
boolean forceAddingNewLine = false;
if (match.getAllSons().size() > 0 && !match.isScopeMatch()) {
if (match.hasSons() && !match.isScopeMatch()) {
// compound matches
StringBuilder buf = new StringBuilder();
@@ -246,17 +246,15 @@ public class GlobalMatchingVisitor extends AbstractMatchingVisitor {
matchContext.getSink().newMatch(result);
}
private boolean doDispatch(final MatchResultImpl result, MatchResultImpl context) {
private boolean doDispatch(final MatchResult result, MatchResultImpl context) {
boolean ret = false;
for (MatchResult _r : result.getAllSons()) {
final MatchResultImpl r = (MatchResultImpl)_r;
for (MatchResult r : result.getAllSons()) {
if ((r.isScopeMatch() && !r.isTarget()) || r.isMultipleMatch()) {
ret |= doDispatch(r, context);
}
else if (r.isTarget()) {
r.setContext(context);
((MatchResultImpl)r).setContext(context);
matchContext.getSink().newMatch(r);
ret = true;
}
@@ -273,19 +271,15 @@ public class GlobalMatchingVisitor extends AbstractMatchingVisitor {
result.setMatchImage(match.getText());
}
else {
MatchResultImpl sonresult;
for (final PsiElement matchStatement : matchedNodes) {
result.getMatches().add(
sonresult = new MatchResultImpl(
result.getMatches().add(new MatchResultImpl(
MatchResult.LINE_MATCH,
matchStatement.getText(),
new SmartPsiPointer(matchStatement),
true
)
);
sonresult.setParent(result);
}
result.setMatchRef(
@@ -3,7 +3,6 @@ package com.intellij.structuralsearch.impl.matcher;
import com.intellij.psi.PsiElement;
import com.intellij.structuralsearch.MatchResult;
import com.intellij.structuralsearch.plugin.util.SmartPsiPointer;
import org.jetbrains.annotations.NonNls;
import java.util.ArrayList;
import java.util.Iterator;
@@ -23,7 +22,6 @@ public final class MatchResultImpl extends MatchResult {
private boolean myScopeMatch;
private boolean myMultipleMatch;
@NonNls private static final String NULL = "null";
private MatchResultImpl myContext;
MatchResultImpl() {
@@ -42,21 +40,21 @@ public final class MatchResultImpl extends MatchResult {
this.end = end;
}
@Override
public String getMatchImage() {
if (matchImage==null) {
matchImage = NULL;
}
return matchImage;
}
public void setParent(MatchResult parent) {
}
@Override
public SmartPsiPointer getMatchRef() {
return matchRef;
}
@Override
public PsiElement getMatch() {
if (matchRef == null) {
return null;
}
return matchRef.getElement();
}
@@ -64,6 +62,7 @@ public final class MatchResultImpl extends MatchResult {
matchRef = matchStart;
}
@Override
public String getName() {
return name;
}
@@ -77,18 +76,22 @@ public final class MatchResultImpl extends MatchResult {
return matches;
}
@Override
public List<MatchResult> getAllSons() {
return getMatches();
}
@Override
public boolean hasSons() {
return matches!=null;
return matches!=null && matches.size() > 0;
}
@Override
public boolean isScopeMatch() {
return myScopeMatch;
}
@Override
public boolean isMultipleMatch() {
return myMultipleMatch;
}
@@ -159,6 +162,7 @@ public final class MatchResultImpl extends MatchResult {
this.matchImage = matchImage;
}
@Override
public boolean isTarget() {
return target;
}
@@ -171,6 +175,7 @@ public final class MatchResultImpl extends MatchResult {
return matchImage==null;
}
@Override
public int getStart() {
return start;
}
@@ -179,6 +184,7 @@ public final class MatchResultImpl extends MatchResult {
this.start = start;
}
@Override
public int getEnd() {
return end;
}
@@ -167,7 +167,7 @@ public class SubstitutionHandler extends MatchingHandler {
if (!substitution.isMultipleMatch()) {
// adding intermediate node to contain all multiple matches
MatchResultImpl sonresult = new MatchResultImpl(
final MatchResultImpl sonresult = new MatchResultImpl(
substitution.getName(),
substitution.getMatchImage(),
substitution.getMatchRef(),
@@ -176,7 +176,6 @@ public class SubstitutionHandler extends MatchingHandler {
target
);
sonresult.setParent(substitution);
substitution.setMatchRef(
new SmartPsiPointer(match == null ? null : match)
);
@@ -193,7 +192,6 @@ public class SubstitutionHandler extends MatchingHandler {
substitution.addSon( sonresult);
}
result.setParent(substitution);
substitution.addSon( result );
}
}