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;
7 import java.util.ArrayList;
8 import java.util.Iterator;
12 * Class describing the match result
14 public final class MatchResultImpl extends MatchResult {
16 private SmartPsiPointer matchRef;
19 private String matchImage;
20 private List<MatchResult> matches;
21 private boolean target;
23 private boolean myScopeMatch;
24 private boolean myMultipleMatch;
25 private MatchResultImpl myContext;
30 public MatchResultImpl(String name, String image, SmartPsiPointer ref, boolean target) {
31 this(name,image,ref,0,-1,target);
34 public MatchResultImpl(String name, String image, SmartPsiPointer ref, int start, int end, boolean target) {
44 public String getMatchImage() {
49 public SmartPsiPointer getMatchRef() {
54 public PsiElement getMatch() {
55 if (matchRef == null) {
58 return matchRef.getElement();
61 public void setMatchRef(SmartPsiPointer matchStart) {
62 matchRef = matchStart;
66 public String getName() {
70 public void setName(String name) {
74 public List<MatchResult> getMatches() {
75 if (matches==null) matches = new ArrayList<MatchResult>();
80 public List<MatchResult> getAllSons() {
85 public boolean hasSons() {
86 return matches!=null && matches.size() > 0;
90 public boolean isScopeMatch() {
95 public boolean isMultipleMatch() {
96 return myMultipleMatch;
100 if (matchRef != null) {
105 if (matches != null) {
106 for (final MatchResult match : matches) {
107 ((MatchResultImpl)match).clear();
116 public void clearMatches() {
120 public void setScopeMatch(final boolean scopeMatch) {
121 myScopeMatch = scopeMatch;
124 public void setMultipleMatch(final boolean multipleMatch) {
125 myMultipleMatch = multipleMatch;
128 public MatchResultImpl findSon(String name) {
130 // @todo this could be performance bottleneck, replace with hash lookup!
131 for (final MatchResult match : matches) {
132 final MatchResultImpl res = (MatchResultImpl)match;
134 if (name.equals(res.getName())) {
142 public MatchResultImpl removeSon(String typedVar) {
143 if (matches == null) return null;
145 // @todo this could be performance bottleneck, replace with hash lookup!
146 for(Iterator<MatchResult> i=matches.iterator();i.hasNext();) {
147 final MatchResultImpl res = (MatchResultImpl)i.next();
148 if (typedVar.equals(res.getName())) {
157 public void addSon(MatchResultImpl result) {
158 getMatches().add(result);
161 public void setMatchImage(String matchImage) {
162 this.matchImage = matchImage;
166 public boolean isTarget() {
170 public void setTarget(boolean target) {
171 this.target = target;
174 public boolean isMatchImageNull() {
175 return matchImage==null;
179 public int getStart() {
183 public void setStart(int start) {
188 public int getEnd() {
192 public void setEnd(int end) {
196 public void setContext(final MatchResultImpl context) {
200 public MatchResultImpl getContext() {
205 public String toString() {
206 return "MatchResultImpl{name='" + name + '\'' + ", matchImage='" + matchImage + '\'' + "}";