1 11 package org.eclipse.jdt.core.search; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.internal.core.JavaElement; 16 17 31 public class SearchMatch { 32 33 38 public static final int A_ACCURATE = 0; 39 40 47 public static final int A_INACCURATE = 1; 48 49 private Object element; 50 private int length; 51 private int offset; 52 53 private int accuracy; 54 private SearchParticipant participant; 55 private IResource resource; 56 57 private boolean insideDocComment = false; 58 59 private final static int ALL_GENERIC_FLAVORS = SearchPattern.R_FULL_MATCH | 61 SearchPattern.R_EQUIVALENT_MATCH | 62 SearchPattern.R_ERASURE_MATCH; 63 private int rule = ALL_GENERIC_FLAVORS; 64 65 private boolean raw = false; 67 private boolean implicit = false; 68 69 83 public SearchMatch( 84 IJavaElement element, 85 int accuracy, 86 int offset, 87 int length, 88 SearchParticipant participant, 89 IResource resource) { 90 this.element = element; 91 this.offset = offset; 92 this.length = length; 93 this.accuracy = accuracy & A_INACCURATE; 94 if (accuracy > A_INACCURATE) { 95 int genericFlavors = accuracy & ALL_GENERIC_FLAVORS; 96 if (genericFlavors > 0) { 97 this.rule &= ~ALL_GENERIC_FLAVORS; } 99 this.rule |= accuracy & ~A_INACCURATE; } 101 this.participant = participant; 102 this.resource = resource; 103 } 104 105 110 public final int getAccuracy() { 111 return this.accuracy; 112 } 113 114 121 public final Object getElement() { 122 return this.element; 123 } 124 125 130 public final int getLength() { 131 return this.length; 132 } 133 134 139 public final int getOffset() { 140 return this.offset; 141 } 142 143 148 public final SearchParticipant getParticipant() { 149 return this.participant; 150 } 151 152 157 public final IResource getResource() { 158 return this.resource; 159 } 160 161 168 public final int getRule() { 169 return this.rule; 170 } 171 172 180 public final boolean isEquivalent() { 181 return isErasure() && (this.rule & SearchPattern.R_EQUIVALENT_MATCH) != 0; 182 } 183 184 193 public final boolean isErasure() { 194 return (this.rule & SearchPattern.R_ERASURE_MATCH) != 0; 195 } 196 197 205 public final boolean isExact() { 206 return isEquivalent() && (this.rule & SearchPattern.R_FULL_MATCH) != 0; 207 } 208 209 219 public final boolean isImplicit() { 220 return this.implicit; 221 } 222 223 230 public final boolean isRaw() { 231 return this.raw; 232 } 233 234 241 public final boolean isInsideDocComment() { 242 return this.insideDocComment; 244 } 245 246 251 public final void setAccuracy (int accuracy) { 252 this.accuracy = accuracy; 253 } 254 255 261 public final void setElement (Object element) { 262 this.element = element; 263 } 264 265 272 public final void setInsideDocComment (boolean insideDoc) { 273 this.insideDocComment = insideDoc; 274 } 275 276 285 public final void setImplicit(boolean implicit) { 286 this.implicit = implicit; 287 } 288 289 294 public final void setLength(int length) { 295 this.length = length; 296 } 297 298 303 public final void setOffset(int offset) { 304 this.offset = offset; 305 } 306 307 312 public final void setParticipant (SearchParticipant participant) { 313 this.participant = participant; 314 } 315 316 321 public final void setResource (IResource resource) { 322 this.resource = resource; 323 } 324 325 332 public final void setRule(int rule) { 333 this.rule = rule; 334 } 335 336 343 public final void setRaw(boolean raw) { 344 this.raw = raw; 345 } 346 347 350 public String toString() { 351 StringBuffer buffer = new StringBuffer (); 352 buffer.append("Search match"); buffer.append("\n accuracy="); buffer.append(this.accuracy == A_ACCURATE ? "ACCURATE" : "INACCURATE"); buffer.append("\n rule="); if ((this.rule & SearchPattern.R_FULL_MATCH) != 0) { 357 buffer.append("EXACT"); } else if ((this.rule & SearchPattern.R_EQUIVALENT_MATCH) != 0) { 359 buffer.append("EQUIVALENT"); } else if ((this.rule & SearchPattern.R_ERASURE_MATCH) != 0) { 361 buffer.append("ERASURE"); } 363 buffer.append("\n raw="); buffer.append(this.raw); 365 buffer.append("\n offset="); buffer.append(this.offset); 367 buffer.append("\n length="); buffer.append(this.length); 369 if (this.element != null) { 370 buffer.append("\n element="); buffer.append(((JavaElement)getElement()).toStringWithAncestors()); 372 } 373 buffer.append("\n"); return buffer.toString(); 375 } 376 } 377 | Popular Tags |