1 package com.intellij.structuralsearch.impl.matcher;
3 import com.intellij.psi.PsiElement;
4 import com.intellij.structuralsearch.MatchResult;
5 import com.intellij.structuralsearch.plugin.util.SmartPsiPointer;
6 import org.jetbrains.annotations.NonNls;
8 import java.util.ArrayList;
9 import java.util.Iterator;
10 import java.util.List;
13 * Class describing the match result
15 public final class MatchResultImpl extends MatchResult {
17 private SmartPsiPointer matchRef;
20 private String matchImage;
21 private List<MatchResult> matches;
22 private boolean target;
24 private boolean myScopeMatch;
25 private boolean myMultipleMatch;
26 @NonNls private static final String NULL = "null";
27 private MatchResultImpl myContext;
32 public MatchResultImpl(String name, String image, SmartPsiPointer ref, boolean target) {
33 this(name,image,ref,0,-1,target);
36 public MatchResultImpl(String name, String image, SmartPsiPointer ref, int start, int end, boolean target) {
45 public String getMatchImage() {
46 if (matchImage==null) {
52 public void setParent(MatchResult parent) {
55 public SmartPsiPointer getMatchRef() {
59 public PsiElement getMatch() {
60 return matchRef.getElement();
63 public void setMatchRef(SmartPsiPointer matchStart) {
64 matchRef = matchStart;
67 public String getName() {
71 public void setName(String name) {
75 public List<MatchResult> getMatches() {
76 if (matches==null) matches = new ArrayList<MatchResult>();
80 public List<MatchResult> getAllSons() {
84 public boolean hasSons() {
88 public boolean isScopeMatch() {
92 public boolean isMultipleMatch() {
93 return myMultipleMatch;
97 if (matchRef != null) {
102 if (matches != null) {
103 for (final MatchResult match : matches) {
104 ((MatchResultImpl)match).clear();
113 public void clearMatches() {
117 public void setScopeMatch(final boolean scopeMatch) {
118 myScopeMatch = scopeMatch;
121 public void setMultipleMatch(final boolean multipleMatch) {
122 myMultipleMatch = multipleMatch;
125 public MatchResultImpl findSon(String name) {
127 // @todo this could be performance bottleneck, replace with hash lookup!
128 for (final MatchResult match : matches) {
129 final MatchResultImpl res = (MatchResultImpl)match;
131 if (name.equals(res.getName())) {
139 public MatchResultImpl removeSon(String typedVar) {
140 if (matches == null) return null;
142 // @todo this could be performance bottleneck, replace with hash lookup!
143 for(Iterator<MatchResult> i=matches.iterator();i.hasNext();) {
144 final MatchResultImpl res = (MatchResultImpl)i.next();
145 if (typedVar.equals(res.getName())) {
154 public void addSon(MatchResultImpl result) {
155 getMatches().add(result);
158 public void setMatchImage(String matchImage) {
159 this.matchImage = matchImage;
162 public boolean isTarget() {
166 public void setTarget(boolean target) {
167 this.target = target;
170 public boolean isMatchImageNull() {
171 return matchImage==null;
174 public int getStart() {
178 public void setStart(int start) {
182 public int getEnd() {
186 public void setEnd(int end) {
190 public void setContext(final MatchResultImpl context) {
194 public MatchResultImpl getContext() {
199 public String toString() {
200 return "MatchResultImpl{name='" + name + '\'' + ", matchImage='" + matchImage + '\'' + "}";