1 /******************************************************************************* 2 * Copyright (c) 2000, 2017 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.core.tests.model; 15 16 import java.io.File; 17 import java.io.IOException; 18 import java.util.ArrayList; 19 import java.util.Arrays; 20 import java.util.Collections; 21 import java.util.Comparator; 22 import java.util.List; 23 import java.util.Vector; 24 25 import org.eclipse.core.resources.*; 26 import org.eclipse.core.runtime.*; 27 import org.eclipse.jdt.core.*; 28 import org.eclipse.jdt.core.compiler.CharOperation; 29 import org.eclipse.jdt.core.search.*; 30 import org.eclipse.jdt.internal.compiler.ExtraFlags; 31 import org.eclipse.jdt.internal.compiler.env.AccessRestriction; 32 import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit; 33 import org.eclipse.jdt.internal.compiler.util.Util; 34 import org.eclipse.jdt.internal.core.LambdaExpression; 35 import org.eclipse.jdt.internal.core.Member; 36 import org.eclipse.jdt.internal.core.PackageFragment; 37 import org.eclipse.jdt.internal.core.SourceRefElement; 38 import org.eclipse.jdt.internal.core.search.BasicSearchEngine; 39 import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor; 40 import org.eclipse.jdt.internal.core.search.IRestrictedAccessMethodRequestor; 41 import org.eclipse.jdt.internal.core.search.matching.PatternLocator; 42 43 /** 44 * Abstract class for Java Search tests. 45 */ 46 @SuppressWarnings({"rawtypes", "unchecked"}) 47 public class AbstractJavaSearchTests extends ModifyingResourceTests implements IJavaSearchConstants { 48 49 public static List JAVA_SEARCH_SUITES = null; 50 protected static IJavaProject JAVA_PROJECT; 51 protected static boolean COPY_DIRS = true; 52 protected final static int EXACT_RULE = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; 53 protected final static int EQUIVALENT_RULE = EXACT_RULE | SearchPattern.R_EQUIVALENT_MATCH; 54 protected final static int ERASURE_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH; 55 protected final static int RAW_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH | SearchPattern.R_EQUIVALENT_MATCH; 56 57 // ICompilationUnit[] workingCopies; 58 // boolean discard; 59 60 /** 61 * Flags for the default search result collector 62 */ 63 static protected final int SHOW_ACCURACY = 0x0001; 64 static protected final int SHOW_SELECTION = 0x0002; 65 static protected final int SHOW_RULE = 0x0004; 66 static protected final int SHOW_INSIDE_DOC = 0x0008; 67 static protected final int SHOW_POTENTIAL = 0x0010; 68 static protected final int SHOW_PROJECT = 0x0020; 69 static protected final int SHOW_SYNTHETIC = 0x0040; 70 static protected final int SHOW_OFFSET = 0x0080; 71 static protected final int SHOW_ACCESS = 0x0100; 72 static protected final int SHOW_MATCH_KIND = 0x0200; 73 static protected final int SHOW_JAR_FILE = 0x0400; 74 75 public static class ConstructorDeclarationsCollector implements IRestrictedAccessConstructorRequestor { 76 Vector results = new Vector(); 77 acceptConstructor( int modifiers, char[] simpleTypeName, int parameterCount, char[] signature, char[][] parameterTypes, char[][] parameterNames, int typeModifiers, char[] packageName, int extraFlags, String path, AccessRestriction access)78 public void acceptConstructor( 79 int modifiers, 80 char[] simpleTypeName, 81 int parameterCount, 82 char[] signature, 83 char[][] parameterTypes, 84 char[][] parameterNames, 85 int typeModifiers, 86 char[] packageName, 87 int extraFlags, 88 String path, 89 AccessRestriction access) { 90 StringBuffer buffer = new StringBuffer(); 91 92 boolean isMemberType = (extraFlags & ExtraFlags.IsMemberType) != 0; 93 94 buffer.append(packageName == null ? CharOperation.NO_CHAR : packageName); 95 if (isMemberType) { 96 buffer.append('.'); 97 buffer.append('?'); // enclosing type names are not stored in the indexes 98 buffer.append('?'); 99 buffer.append('?'); 100 } 101 buffer.append('.'); 102 buffer.append(simpleTypeName); 103 buffer.append('#'); 104 buffer.append(simpleTypeName); 105 buffer.append('('); 106 107 parameterTypes = signature == null ? parameterTypes : Signature.getParameterTypes(signature); 108 109 for (int i = 0; i < parameterCount; i++) { 110 if (i != 0) buffer.append(','); 111 112 if (parameterTypes != null) { 113 char[] parameterType; 114 if (signature != null) { 115 parameterType = Signature.toCharArray(parameterTypes[i]); 116 CharOperation.replace(parameterType, '/', '.'); 117 } else { 118 parameterType = parameterTypes[i]; 119 } 120 buffer.append(parameterType); 121 } else { 122 buffer.append('?'); // parameter type names are not stored in the indexes 123 buffer.append('?'); 124 buffer.append('?'); 125 } 126 buffer.append(' '); 127 if (parameterNames != null) { 128 buffer.append(parameterNames[i]); 129 } else { 130 buffer.append("arg"+i); 131 } 132 } 133 buffer.append(')'); 134 135 if (parameterCount < 0) { 136 buffer.append('*'); 137 } 138 139 this.results.addElement(buffer.toString()); 140 } 141 142 @Override toString()143 public String toString(){ 144 int length = this.results.size(); 145 String[] strings = new String[length]; 146 this.results.toArray(strings); 147 org.eclipse.jdt.internal.core.util.Util.sort(strings); 148 StringBuffer buffer = new StringBuffer(100); 149 for (int i = 0; i < length; i++){ 150 buffer.append(strings[i]); 151 if (i != length-1) { 152 buffer.append('\n'); 153 } 154 } 155 return buffer.toString(); 156 } size()157 public int size() { 158 return this.results.size(); 159 } 160 } 161 checkAndAddtoBuffer(StringBuffer buffer, char[] precond, char c)162 static void checkAndAddtoBuffer(StringBuffer buffer, char[] precond, char c) { 163 if (precond == null || precond.length == 0) return; 164 buffer.append(precond); 165 buffer.append(c); 166 } 167 public static class MethodDeclarationsCollector implements IRestrictedAccessMethodRequestor { 168 Vector results = new Vector(); 169 170 @Override acceptMethod( char[] methodName, int parameterCount, char[] declaringQualifier, char[] simpleTypeName, int typeModifiers, char[] packageName, char[] signature, char[][] parameterTypes, char[][] parameterNames, char[] returnType, int modifiers, String path, AccessRestriction access, int methodIndex)171 public void acceptMethod( 172 char[] methodName, 173 int parameterCount, 174 char[] declaringQualifier, 175 char[] simpleTypeName, 176 int typeModifiers, 177 char[] packageName, 178 char[] signature, 179 char[][] parameterTypes, 180 char[][] parameterNames, 181 char[] returnType, 182 int modifiers, 183 String path, 184 AccessRestriction access, 185 int methodIndex) { 186 187 StringBuffer buffer = new StringBuffer(); 188 char c = '.'; 189 char[] noname = new String("<NONAME>").toCharArray(); 190 buffer.append(path); 191 buffer.append(' '); 192 buffer.append(returnType == null ? CharOperation.NO_CHAR: returnType); 193 buffer.append(' '); 194 checkAndAddtoBuffer(buffer, packageName, c); 195 checkAndAddtoBuffer(buffer, declaringQualifier, c); 196 checkAndAddtoBuffer(buffer, simpleTypeName == null ? noname : simpleTypeName, c); 197 buffer.append(methodName); 198 buffer.append('('); 199 parameterTypes = signature == null ? parameterTypes : Signature.getParameterTypes(signature); 200 201 for (int i = 0; i < parameterCount; i++) { 202 if (parameterTypes != null) { 203 char[] parameterType; 204 if (parameterTypes.length != parameterCount) { 205 System.out.println("Error"); 206 } 207 if (signature != null) { 208 parameterType = Signature.toCharArray(Signature.getTypeErasure(parameterTypes[i])); 209 CharOperation.replace(parameterType, '/', '.'); 210 } else { 211 parameterType = this.getTypeErasure(parameterTypes[i]); 212 } 213 buffer.append(parameterType); 214 } else { 215 buffer.append('?'); // parameter type names are not stored in the indexes 216 buffer.append('?'); 217 buffer.append('?'); 218 } 219 buffer.append(' '); 220 if (parameterNames != null) { 221 buffer.append(parameterNames[i]); 222 } else { 223 buffer.append("arg"+i); 224 } 225 if (parameterCount > 1 && i < parameterCount - 1) buffer.append(','); 226 } 227 buffer.append(')'); 228 this.results.addElement(buffer.toString()); 229 } getTypeErasure(char[] typeName)230 private char[] getTypeErasure(char[] typeName) { 231 int index; 232 if ((index = CharOperation.indexOf('<', typeName)) == -1) return typeName; 233 234 int length = typeName.length; 235 char[] typeErasurename = new char[length - 2]; 236 237 System.arraycopy(typeName, 0, typeErasurename, 0, index); 238 239 int depth = 1; 240 for (int i = index + 1; i < length; i++) { 241 switch (typeName[i]) { 242 case '<': 243 depth++; 244 break; 245 case '>': 246 depth--; 247 break; 248 default: 249 if (depth == 0) { 250 typeErasurename[index++] = typeName[i]; 251 } 252 break; 253 } 254 } 255 256 System.arraycopy(typeErasurename, 0, typeErasurename = new char[index], 0, index); 257 return typeErasurename; 258 } 259 @Override toString()260 public String toString(){ 261 int length = this.results.size(); 262 String[] strings = new String[length]; 263 this.results.toArray(strings); 264 org.eclipse.jdt.internal.core.util.Util.sort(strings); 265 StringBuffer buffer = new StringBuffer(100); 266 for (int i = 0; i < length; i++){ 267 buffer.append(strings[i]); 268 if (i != length-1) { 269 buffer.append('\n'); 270 } 271 } 272 return buffer.toString(); 273 } size()274 public int size() { 275 return this.results.size(); 276 } 277 } 278 /** 279 * Collects results as a string. 280 */ 281 public static class JavaSearchResultCollector extends SearchRequestor { 282 int flags = SHOW_POTENTIAL; // default 283 protected SearchMatch match; 284 public StringBuffer results = new StringBuffer(), line; 285 public int showFlavors = 0; 286 public int count = 0; 287 List lines = new ArrayList(); 288 boolean sorted; JavaSearchResultCollector()289 public JavaSearchResultCollector() { 290 this(false); 291 } JavaSearchResultCollector(boolean sorted)292 public JavaSearchResultCollector(boolean sorted) { 293 this.sorted = sorted; 294 } acceptSearchMatch(SearchMatch searchMatch)295 public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { 296 this.count++; 297 this.match = searchMatch; 298 writeLine(); 299 if (this.line != null && (this.match.getAccuracy() == SearchMatch.A_ACCURATE || (this.flags & SHOW_POTENTIAL) != 0)) { 300 this.lines.add(this.line); 301 } 302 } addLine(String text)303 protected void addLine(String text) { 304 this.lines.add(text); 305 } writeLine()306 protected void writeLine() throws CoreException { 307 try { 308 IResource resource = this.match.getResource(); 309 IJavaElement element = getElement(this.match); 310 this.line = new StringBuffer(); 311 if ((this.flags & SHOW_MATCH_KIND) != 0) { 312 String matchClassName = this.match.getClass().getName(); 313 this.line.append(matchClassName.substring(matchClassName.lastIndexOf('.')+1)); 314 this.line.append(": "); 315 } 316 this.line.append(getPathString(resource, element)); 317 if ((this.flags & SHOW_PROJECT) != 0) { 318 IProject project = element.getJavaProject().getProject(); 319 this.line.append(" [in "); 320 this.line.append(project.getName()); 321 this.line.append("]"); 322 } 323 ICompilationUnit unit = null; 324 if (element instanceof IModuleDescription) { 325 IModuleDescription md = (IModuleDescription) element; 326 this.line.append(" "); 327 append(md); 328 unit = md.getCompilationUnit(); 329 } else if (element instanceof IMethod) { 330 this.line.append(" "); 331 IMethod method = (IMethod)element; 332 append(method); 333 unit = method.getCompilationUnit(); 334 } else if (element instanceof IType) { 335 this.line.append(" "); 336 IType type = (IType)element; 337 append(type); 338 unit = type.getCompilationUnit(); 339 } else if (element instanceof IField) { 340 this.line.append(" "); 341 IField field = (IField)element; 342 append(field); 343 unit = field.getCompilationUnit(); 344 } else if (element instanceof IInitializer) { 345 this.line.append(" "); 346 IInitializer initializer = (IInitializer)element; 347 append(initializer); 348 unit = initializer.getCompilationUnit(); 349 } else if (element instanceof IPackageFragment) { 350 this.line.append(" "); 351 append((IPackageFragment)element); 352 } else if (element instanceof ILocalVariable) { 353 this.line.append(" "); 354 ILocalVariable localVar = (ILocalVariable)element; 355 IJavaElement parent = localVar.getDeclaringMember(); 356 if (parent instanceof IInitializer) { 357 IInitializer initializer = (IInitializer)parent; 358 append(initializer); 359 } else { // IMethod 360 IMethod method = (IMethod)parent; 361 append(method); 362 } 363 this.line.append("."); 364 this.line.append(localVar.getElementName()); 365 unit = (ICompilationUnit)localVar.getAncestor(IJavaElement.COMPILATION_UNIT); 366 } else if (element instanceof ITypeParameter) { 367 this.line.append(" "); 368 ITypeParameter typeParam = (ITypeParameter)element; 369 IJavaElement parent = typeParam.getParent(); 370 if (parent instanceof IType) { 371 IType type = (IType)parent; 372 append(type); 373 unit = type.getCompilationUnit(); 374 } else if (parent instanceof IMethod) { 375 IMethod method = (IMethod)parent; 376 append(method); 377 unit = method.getCompilationUnit(); 378 } else { 379 this.line.append("<Unexpected kind of parent for type parameter>"); 380 unit = (ICompilationUnit)typeParam.getAncestor(IJavaElement.COMPILATION_UNIT); 381 } 382 this.line.append("."); 383 this.line.append(typeParam.getElementName()); 384 } else if (element instanceof IImportDeclaration) { 385 IImportDeclaration importDeclaration = (IImportDeclaration)element; 386 unit = (ICompilationUnit)importDeclaration.getAncestor(IJavaElement.COMPILATION_UNIT); 387 } else if (element instanceof IPackageDeclaration) { 388 IPackageDeclaration packageDeclaration = (IPackageDeclaration)element; 389 unit = (ICompilationUnit)packageDeclaration.getAncestor(IJavaElement.COMPILATION_UNIT); 390 } else if (element instanceof IAnnotation) { 391 this.line.append(" "); 392 append((IAnnotation)element); 393 unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); 394 } 395 if (resource instanceof IFile) { 396 char[] contents = getSource(resource, element, unit); 397 int start = this.match.getOffset(); 398 int end = start + this.match.getLength(); 399 if (start == -1 || (contents != null && contents.length > 0)) { // retrieving attached source not implemented here 400 this.line.append(" ["); 401 if (start > -1) { 402 if ((this.flags & SHOW_SELECTION) != 0) { 403 int lineStart1 = CharOperation.lastIndexOf('\n', contents, 0, start); 404 int lineStart2 = CharOperation.lastIndexOf('\r', contents, 0, start); 405 int lineStart = Math.max(lineStart1, lineStart2) + 1; 406 this.line.append(CharOperation.subarray(contents, lineStart, start)); 407 this.line.append("!|"); 408 } 409 this.line.append(CharOperation.subarray(contents, start, end)); 410 if ((this.flags & SHOW_SELECTION) != 0) { 411 this.line.append("|!"); 412 int lineEnd1 = CharOperation.indexOf('\n', contents, end); 413 int lineEnd2 = CharOperation.indexOf('\r', contents, end); 414 int lineEnd = lineEnd1 > 0 && lineEnd2 > 0 ? Math.min(lineEnd1, lineEnd2) : Math.max(lineEnd1, lineEnd2); 415 if (lineEnd == -1) lineEnd = contents.length; 416 this.line.append(CharOperation.subarray(contents, end, lineEnd)); 417 } 418 if ((this.flags & SHOW_OFFSET) != 0) { 419 this.line.append('@'); 420 this.line.append(start); 421 } 422 } else { 423 this.line.append("No source"); 424 } 425 this.line.append("]"); 426 } 427 } 428 if ((this.flags & SHOW_ACCURACY) != 0) { 429 this.line.append(" "); 430 if (this.match.getAccuracy() == SearchMatch.A_ACCURATE) { 431 if ((this.flags & SHOW_RULE) != 0) { 432 if (this.match.isExact()) { 433 this.line.append("EXACT_"); 434 } else if (this.match.isEquivalent()) { 435 this.line.append("EQUIVALENT_"); 436 } else if (this.match.isErasure()) { 437 this.line.append("ERASURE_"); 438 } else { 439 this.line.append("INVALID_RULE_"); 440 } 441 if (this.match.isRaw()) { 442 this.line.append("RAW_"); 443 } 444 } else { 445 this.line.append("EXACT_"); 446 } 447 this.line.append("MATCH"); 448 } else { 449 this.line.append("POTENTIAL_MATCH"); 450 } 451 } 452 if ((this.flags & SHOW_INSIDE_DOC) != 0) { 453 this.line.append(" "); 454 if (this.match.isInsideDocComment()) { 455 this.line.append("INSIDE_JAVADOC"); 456 } else { 457 this.line.append("OUTSIDE_JAVADOC"); 458 } 459 } 460 if ((this.flags & SHOW_SYNTHETIC) != 0) { 461 if (this.match instanceof MethodReferenceMatch) { 462 MethodReferenceMatch methRef = (MethodReferenceMatch) this.match; 463 if (methRef.isSynthetic()) { 464 this.line.append(" SYNTHETIC"); 465 } 466 } 467 } 468 if (this.showFlavors > 0) { 469 if (this.match instanceof MethodReferenceMatch) { 470 MethodReferenceMatch methRef = (MethodReferenceMatch) this.match; 471 if (methRef.isSuperInvocation() && showSuperInvocation()) { 472 this.line.append(" SUPER INVOCATION"); 473 } 474 } 475 } 476 if ((this.flags & SHOW_ACCESS) != 0) { 477 if (this.match instanceof FieldReferenceMatch) { 478 FieldReferenceMatch fieldRef = (FieldReferenceMatch) this.match; 479 if (fieldRef.isReadAccess()) { 480 this.line.append(" READ"); 481 if (fieldRef.isWriteAccess()) this.line.append("/WRITE"); 482 this.line.append(" ACCESS"); 483 } else if (fieldRef.isWriteAccess()) { 484 this.line.append(" WRITE ACCESS"); 485 } 486 } else if (this.match instanceof LocalVariableReferenceMatch) { 487 LocalVariableReferenceMatch variableRef = (LocalVariableReferenceMatch) this.match; 488 if (variableRef.isReadAccess()) { 489 this.line.append(" READ"); 490 if (variableRef.isWriteAccess()) this.line.append("/WRITE"); 491 this.line.append(" ACCESS"); 492 } else if (variableRef.isWriteAccess()) { 493 this.line.append(" WRITE ACCESS"); 494 } 495 } 496 } 497 } catch (JavaModelException e) { 498 this.line.append("\n"); 499 this.line.append(e.toString()); 500 } 501 } showSuperInvocation()502 private boolean showSuperInvocation() { 503 return (this.showFlavors & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0; 504 } showAccess()505 public void showAccess() { 506 this.flags |= SHOW_ACCESS; 507 } showAccuracy(boolean on)508 public void showAccuracy(boolean on) { 509 if (on) { 510 this.flags |= SHOW_ACCURACY; 511 } else { 512 this.flags &= ~SHOW_ACCURACY; 513 } 514 } showInsideDoc()515 public void showInsideDoc() { 516 this.flags |= SHOW_INSIDE_DOC; 517 } showJarFile()518 public void showJarFile() { 519 this.flags |= SHOW_JAR_FILE; 520 } showMatchKind()521 public void showMatchKind() { 522 this.flags |= SHOW_MATCH_KIND; 523 } showOffset()524 public void showOffset() { 525 this.flags |= SHOW_OFFSET; 526 } showPotential(boolean on)527 public void showPotential(boolean on) { 528 if (on) { 529 this.flags |= SHOW_POTENTIAL; 530 } else { 531 this.flags &= ~SHOW_POTENTIAL; 532 } 533 } showProject()534 public void showProject() { 535 this.flags |= SHOW_PROJECT; 536 } showRule()537 public void showRule() { 538 this.flags |= SHOW_RULE; 539 } showSelection()540 public void showSelection() { 541 this.flags |= SHOW_SELECTION; 542 } showSynthetic()543 public void showSynthetic() { 544 this.flags |= SHOW_SYNTHETIC; 545 } append(IAnnotation annotation)546 protected void append(IAnnotation annotation) throws JavaModelException { 547 this.line.append("@"); 548 this.line.append(annotation.getElementName()); 549 this.line.append('('); 550 IMemberValuePair[] pairs = annotation.getMemberValuePairs(); 551 int length = pairs == null ? 0 : pairs.length; 552 for (int i=0; i<length; i++) { 553 this.line.append(pairs[i].getMemberName()); 554 this.line.append('='); 555 Object value = pairs[i].getValue(); 556 switch (pairs[i].getValueKind()) { 557 case IMemberValuePair.K_CLASS: 558 this.line.append(value); 559 this.line.append(".class"); 560 break; 561 default: 562 this.line.append(value); 563 break; 564 } 565 } 566 this.line.append(')'); 567 } append(IField field)568 protected void append(IField field) throws JavaModelException { 569 append(field.getDeclaringType()); 570 this.line.append("."); 571 this.line.append(field.getElementName()); 572 } append(IInitializer initializer)573 private void append(IInitializer initializer) throws JavaModelException { 574 append(initializer.getDeclaringType()); 575 this.line.append("."); 576 if (Flags.isStatic(initializer.getFlags())) { 577 this.line.append("static "); 578 } 579 this.line.append("{}"); 580 } append(IMethod method)581 private void append(IMethod method) throws JavaModelException { 582 if (!method.isConstructor()) { 583 this.line.append(Signature.toString(method.getReturnType())); 584 this.line.append(" "); 585 } 586 append(method.getDeclaringType()); 587 if (!method.isConstructor()) { 588 this.line.append("."); 589 this.line.append(method.getElementName()); 590 } 591 this.line.append("("); 592 String[] parameters = method.getParameterTypes(); 593 boolean varargs = Flags.isVarargs(method.getFlags()); 594 for (int i = 0, length=parameters.length; i<length; i++) { 595 if (i < length - 1) { 596 this.line.append(Signature.toString(parameters[i])); 597 this.line.append(", "); //$NON-NLS-1$ 598 } else if (varargs) { 599 // remove array from signature 600 String parameter = parameters[i].substring(1); 601 this.line.append(Signature.toString(parameter)); 602 this.line.append(" ..."); //$NON-NLS-1$ 603 } else { 604 this.line.append(Signature.toString(parameters[i])); 605 } 606 } 607 this.line.append(")"); 608 } append(IModuleDescription md)609 private void append(IModuleDescription md) { 610 this.line.append(md.getElementName()); 611 } append(IPackageFragment pkg)612 private void append(IPackageFragment pkg) { 613 this.line.append(pkg.getElementName()); 614 } append(IType type)615 private void append(IType type) throws JavaModelException { 616 IJavaElement parent = type.getParent(); 617 boolean isLocal = false; 618 switch (parent.getElementType()) { 619 case IJavaElement.COMPILATION_UNIT: 620 IPackageFragment pkg = type.getPackageFragment(); 621 append(pkg); 622 if (!pkg.getElementName().equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) { 623 this.line.append("."); 624 } 625 break; 626 case IJavaElement.CLASS_FILE: 627 IType declaringType = type.getDeclaringType(); 628 if (declaringType != null) { 629 append(type.getDeclaringType()); 630 this.line.append("$"); 631 } else { 632 pkg = type.getPackageFragment(); 633 append(pkg); 634 if (!pkg.getElementName().equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) { 635 this.line.append("."); 636 } 637 } 638 break; 639 case IJavaElement.TYPE: 640 append((IType)parent); 641 this.line.append("$"); 642 break; 643 case IJavaElement.FIELD: 644 append((IField)parent); 645 isLocal = true; 646 break; 647 case IJavaElement.INITIALIZER: 648 append((IInitializer)parent); 649 isLocal = true; 650 break; 651 case IJavaElement.METHOD: 652 append((IMethod)parent); 653 isLocal = true; 654 break; 655 } 656 if (isLocal) { 657 this.line.append(":"); 658 } 659 String typeName = type.getElementName(); 660 boolean anonymous = false; 661 try { 662 anonymous = type.isAnonymous(); 663 } catch(JavaModelException jme) { 664 } 665 if (anonymous) { 666 this.line.append("<anonymous>"); 667 } else if (type.isLambda()) { 668 ((LambdaExpression) type).toStringName(this.line); 669 } else { 670 this.line.append(typeName); 671 } 672 if (isLocal && !(type instanceof LambdaExpression)) { // don't want occurrence counts for lambdas. it can be confusing at best, as not all are built. 673 this.line.append("#"); 674 this.line.append(((SourceRefElement)type).occurrenceCount); 675 } 676 } getElement(SearchMatch searchMatch)677 protected IJavaElement getElement(SearchMatch searchMatch) { 678 return (IJavaElement) searchMatch.getElement(); 679 } getPathString(IResource resource, IJavaElement element)680 protected String getPathString(IResource resource, IJavaElement element) { 681 String pathString; 682 if (resource != null) { 683 IPath path = resource.getProjectRelativePath(); 684 if ((this.flags & SHOW_JAR_FILE) != 0 && element instanceof Member) { 685 IPackageFragmentRoot pkgFragmentRoot = null; 686 try { 687 pkgFragmentRoot = element.getJavaProject().findPackageFragmentRoot(resource.getFullPath()); 688 } catch (JavaModelException e) { 689 // ignore 690 } 691 if (pkgFragmentRoot != null && pkgFragmentRoot.isArchive()) { 692 if (pkgFragmentRoot.isExternal()) { 693 pathString = pkgFragmentRoot.getPath().toOSString(); 694 } else { 695 pathString = path.toString(); 696 } 697 return pathString + "|" + ((Member)element).getTypeRoot().getElementName(); 698 } 699 } 700 if (path.segmentCount() == 0) { 701 IJavaElement root = element; 702 while (root != null && !(root instanceof IPackageFragmentRoot)) { 703 root = root.getParent(); 704 } 705 if (root != null) { 706 IPackageFragmentRoot pkgFragmentRoot = (IPackageFragmentRoot)root; 707 if (pkgFragmentRoot.isExternal()) { 708 pathString = pkgFragmentRoot.getPath().toOSString(); 709 } else { 710 pathString = pkgFragmentRoot.getPath().toString(); 711 } 712 } else { 713 pathString = ""; 714 } 715 } else { 716 pathString = path.toString(); 717 } 718 } else { 719 pathString = element.getPath().toString(); 720 } 721 return pathString; 722 } getSource(IResource resource, IJavaElement element, ICompilationUnit unit)723 protected char[] getSource(IResource resource, IJavaElement element, ICompilationUnit unit) throws CoreException { 724 char[] contents = CharOperation.NO_CHAR; 725 if ("java".equals(resource.getFileExtension())) { 726 ICompilationUnit cu = (ICompilationUnit)element.getAncestor(IJavaElement.COMPILATION_UNIT); 727 if (cu != null && cu.isWorkingCopy()) { 728 // working copy 729 contents = unit.getBuffer().getCharacters(); 730 } else { 731 IFile file = ((IFile) resource); 732 try { 733 contents = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit( 734 null, 735 file.getLocation().toFile().getPath(), 736 file.getCharset()).getContents(); 737 } catch(AbortCompilationUnit e) { 738 // TODO (philippe) occured with a FileNotFoundException 739 // ignore 740 } 741 } 742 } 743 return contents; 744 } toString()745 public String toString() { 746 StringBuffer buffer = new StringBuffer(); 747 List displayedLines = new ArrayList(this.lines); 748 if (this.sorted) { 749 Collections.sort(displayedLines, new Comparator() { 750 @Override 751 public int compare(Object o1, Object o2) { 752 return o1.toString().compareTo(o2.toString()); 753 } 754 }); 755 } 756 int size = displayedLines.size(); 757 for (int i=0; i<size; i++) { 758 if (i > 0) buffer.append('\n'); 759 buffer.append(displayedLines.get(i).toString()); 760 } 761 return buffer.toString(); 762 } 763 } 764 765 static class MethodNameMatchCollector extends MethodNameMatchRequestor { 766 List matches = new ArrayList(); acceptMethodNameMatch(MethodNameMatch match)767 public void acceptMethodNameMatch(MethodNameMatch match) { 768 IMethod method = match.getMethod(); 769 if (method != null) { 770 this.matches.add(method); 771 } 772 } size()773 public int size() { 774 return this.matches.size(); 775 } toString(boolean withTypeName)776 private String toString(boolean withTypeName) { 777 int size = size(); 778 if (size == 0) return ""; 779 String[] strings = new String[size]; 780 for (int i=0; i<size; i++) { 781 IMethod method = (IMethod) this.matches.get(i); 782 IType type = method.getDeclaringType(); 783 String path = type.getPath().toPortableString(); 784 String declaringTypeName = type.getFullyQualifiedName('.'); 785 String[] parameterTypes = method.getParameterTypes(); 786 String[] parameterNames; 787 try { 788 parameterNames = method.getParameterNames(); 789 } catch (JavaModelException e1) { 790 parameterNames = new String[] {Util.EMPTY_STRING}; 791 } 792 int nParameterNames = parameterNames.length; 793 794 StringBuffer buf = new StringBuffer(); 795 buf.append(path); 796 buf.append(' '); 797 try { 798 buf.append(Signature.toString(Signature.getTypeErasure(method.getReturnType()))); 799 buf.append(' '); 800 } catch (JavaModelException e) { 801 // do nothing 802 } 803 if (withTypeName) { 804 buf.append(declaringTypeName); 805 buf.append('.'); 806 } 807 buf.append(method.getElementName()); 808 buf.append('('); 809 int l = parameterTypes.length; 810 if (l > 0) { 811 buf.append(Signature.toString(Signature.getTypeErasure(parameterTypes[0]))); 812 if (nParameterNames > 0) { 813 buf.append(' '); 814 buf.append(parameterNames[0]); 815 } 816 for (int j = 1; j < l; ++j) { 817 buf.append(','); 818 buf.append(Signature.toString(Signature.getTypeErasure(parameterTypes[j]))); 819 if (j < nParameterNames) { 820 buf.append(' '); 821 buf.append(parameterNames[j]); 822 } 823 } 824 } 825 buf.append(')'); 826 if (i < size - 1) buf.append('\n'); 827 strings[i] = buf.toString(); 828 } 829 StringBuffer buffer = new StringBuffer(); 830 for (int i=0; i<size; i++) { 831 buffer.append(strings[i]); 832 } 833 return buffer.toString(); 834 } toString()835 public String toString() { 836 return toString(false); 837 } toFullyQualifiedNamesString()838 public String toFullyQualifiedNamesString() { 839 return toString(true); 840 } 841 } 842 843 static class TypeNameMatchCollector extends TypeNameMatchRequestor { 844 List matches = new ArrayList(); acceptTypeNameMatch(TypeNameMatch match)845 public void acceptTypeNameMatch(TypeNameMatch match) { 846 IType type = match.getType(); 847 if (type != null) { 848 this.matches.add(type); 849 } 850 } size()851 public int size() { 852 return this.matches.size(); 853 } toString(int kind)854 private String toString(int kind) { 855 int size = size(); 856 if (size == 0) return ""; 857 String[] strings = new String[size]; 858 for (int i=0; i<size; i++) { 859 IType type = (IType) this.matches.get(i); 860 switch (kind) { 861 case 1: // fully qualified name 862 strings[i] = type.getFullyQualifiedName(); 863 break; 864 case 0: 865 default: 866 strings[i] = type.toString(); 867 } 868 } 869 Arrays.sort(strings); 870 StringBuffer buffer = new StringBuffer(); 871 for (int i=0; i<size; i++) { 872 if (i>0) buffer.append('\n'); 873 buffer.append(strings[i]); 874 } 875 return buffer.toString(); 876 } toString()877 public String toString() { 878 return toString(0); 879 } toFullyQualifiedNamesString()880 public String toFullyQualifiedNamesString() { 881 return toString(1); 882 } 883 } 884 885 protected JavaSearchResultCollector resultCollector; 886 AbstractJavaSearchTests(String name)887 public AbstractJavaSearchTests(String name) { 888 this(name, 2); 889 } AbstractJavaSearchTests(String name, int tabs)890 public AbstractJavaSearchTests(String name, int tabs) { 891 super(name, tabs); 892 this.displayName = true; 893 } 894 895 /* (non-Javadoc) 896 * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#assertSearchResults(java.lang.String, java.lang.Object) 897 */ assertSearchResults(String expected)898 protected void assertSearchResults(String expected) { 899 assertSearchResults(expected, this.resultCollector); 900 } assertSearchResults(String expected, JavaSearchResultCollector collector)901 protected void assertSearchResults(String expected, JavaSearchResultCollector collector) { 902 assertSearchResults("Unexpected search results", expected, collector); 903 } assertSearchResults(String message, String expected, JavaSearchResultCollector collector)904 protected void assertSearchResults(String message, String expected, JavaSearchResultCollector collector) { 905 String actual = collector.toString(); 906 if (!expected.equals(actual)) { 907 if (this.displayName) { 908 System.out.print(getName()); 909 System.out.print(" got "); 910 if (collector.count==0) 911 System.out.println("no result!"); 912 else { 913 System.out.print(collector.count); 914 System.out.print(" result"); 915 if (collector.count==1) 916 System.out.println(":"); 917 else 918 System.out.println("s:"); 919 } 920 } 921 if (!this.displayName || collector.count>0) { 922 System.out.print(displayString(actual, this.tabs)); 923 System.out.println(this.endChar); 924 } 925 if (this.workingCopies != null) { 926 int length = this.workingCopies.length; 927 String[] sources = new String[length*2]; 928 for (int i=0; i<length; i++) { 929 sources[i*2] = this.workingCopies[i].getPath().toString(); 930 try { 931 sources[i*2+1] = this.workingCopies[i].getSource(); 932 } catch (JavaModelException e) { 933 // ignore 934 } 935 } 936 System.out.println("--------------------------------------------------------------------------------"); 937 length *= 2; 938 for (int i=0; i<length; i+=2) { 939 System.out.println(sources[i]); 940 System.out.println(sources[i+1]); 941 } 942 } 943 } 944 assertEquals( 945 message, 946 expected, 947 actual 948 ); 949 } 950 951 /* (non-Javadoc) 952 * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#copyDirectory(java.io.File, java.io.File) 953 */ 954 @Override copyDirectory(File sourceDir, File targetDir)955 protected void copyDirectory(File sourceDir, File targetDir) throws IOException { 956 if (COPY_DIRS) { 957 super.copyDirectory(sourceDir, targetDir); 958 } else { 959 targetDir.mkdirs(); 960 File sourceFile = new File(sourceDir, ".project"); 961 File targetFile = new File(targetDir, ".project"); 962 targetFile.createNewFile(); 963 copy(sourceFile, targetFile); 964 sourceFile = new File(sourceDir, ".classpath"); 965 targetFile = new File(targetDir, ".classpath"); 966 targetFile.createNewFile(); 967 copy(sourceFile, targetFile); 968 } 969 } getJavaSearchScope()970 IJavaSearchScope getJavaSearchScope() { 971 return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearch")}); 972 } getJavaSearchScope15()973 IJavaSearchScope getJavaSearchScope15() { 974 return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearch15")}); 975 } getJavaSearchScope15(String packageName, boolean addSubpackages)976 IJavaSearchScope getJavaSearchScope15(String packageName, boolean addSubpackages) throws JavaModelException { 977 if (packageName == null) return getJavaSearchScope15(); 978 return getJavaSearchPackageScope("JavaSearch15", packageName, addSubpackages); 979 } getJavaSearchPackageScope(String projectName, String packageName, boolean addSubpackages)980 IJavaSearchScope getJavaSearchPackageScope(String projectName, String packageName, boolean addSubpackages) throws JavaModelException { 981 IPackageFragment fragment = getPackageFragment(projectName, "src", packageName); 982 if (fragment == null) return null; 983 IJavaElement[] searchPackages = null; 984 if (addSubpackages) { 985 // Create list of package with first found one 986 List packages = new ArrayList(); 987 packages.add(fragment); 988 // Add all possible subpackages 989 IJavaElement[] children= ((IPackageFragmentRoot)fragment.getParent()).getChildren(); 990 String[] names = ((PackageFragment)fragment).names; 991 int namesLength = names.length; 992 nextPackage: for (int i= 0, length = children.length; i < length; i++) { 993 PackageFragment currentPackage = (PackageFragment) children[i]; 994 String[] otherNames = currentPackage.names; 995 if (otherNames.length <= namesLength) continue nextPackage; 996 for (int j = 0; j < namesLength; j++) { 997 if (!names[j].equals(otherNames[j])) 998 continue nextPackage; 999 } 1000 packages.add(currentPackage); 1001 } 1002 searchPackages = new IJavaElement[packages.size()]; 1003 packages.toArray(searchPackages); 1004 } else { 1005 searchPackages = new IJavaElement[1]; 1006 searchPackages[0] = fragment; 1007 } 1008 return SearchEngine.createJavaSearchScope(searchPackages); 1009 } getJavaSearchCUScope(String projectName, String packageName, String cuName)1010 IJavaSearchScope getJavaSearchCUScope(String projectName, String packageName, String cuName) throws JavaModelException { 1011 ICompilationUnit cu = getCompilationUnit(projectName, "src", packageName, cuName); 1012 return SearchEngine.createJavaSearchScope(new ICompilationUnit[] { cu }); 1013 } search(IJavaElement element, int limitTo, IJavaSearchScope scope)1014 protected void search(IJavaElement element, int limitTo, IJavaSearchScope scope) throws CoreException { 1015 search(element, limitTo, EXACT_RULE, scope, this.resultCollector); 1016 } getJavaSearchWorkingCopiesScope(ICompilationUnit workingCopy)1017 IJavaSearchScope getJavaSearchWorkingCopiesScope(ICompilationUnit workingCopy) throws JavaModelException { 1018 return SearchEngine.createJavaSearchScope(new ICompilationUnit[] { workingCopy }); 1019 } getJavaSearchWorkingCopiesScope()1020 IJavaSearchScope getJavaSearchWorkingCopiesScope() throws JavaModelException { 1021 return SearchEngine.createJavaSearchScope(this.workingCopies); 1022 } search(IJavaElement element, int limitTo, int matchRule, IJavaSearchScope scope)1023 protected void search(IJavaElement element, int limitTo, int matchRule, IJavaSearchScope scope) throws CoreException { 1024 search(element, limitTo, matchRule, scope, this.resultCollector); 1025 } 1026 @Override search(IJavaElement element, int limitTo, int matchRule, IJavaSearchScope scope, SearchRequestor requestor)1027 protected void search(IJavaElement element, int limitTo, int matchRule, IJavaSearchScope scope, SearchRequestor requestor) throws CoreException { 1028 SearchPattern pattern = SearchPattern.createPattern(element, limitTo, matchRule); 1029 assertNotNull("Pattern should not be null", pattern); 1030 new SearchEngine(this.workingCopies).search( 1031 pattern, 1032 new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, 1033 scope, 1034 requestor, 1035 null 1036 ); 1037 } search(SearchPattern searchPattern, IJavaSearchScope scope, SearchRequestor requestor)1038 protected void search(SearchPattern searchPattern, IJavaSearchScope scope, SearchRequestor requestor) throws CoreException { 1039 new SearchEngine().search( 1040 searchPattern, 1041 new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, 1042 scope, 1043 requestor, 1044 null); 1045 } search(String patternString, int searchFor, int limitTo, IJavaSearchScope scope)1046 protected void search(String patternString, int searchFor, int limitTo, IJavaSearchScope scope) throws CoreException { 1047 search(patternString, searchFor, limitTo, EXACT_RULE, scope, this.resultCollector); 1048 } search(String patternString, int searchFor, int limitTo, SearchRequestor requestor)1049 protected void search(String patternString, int searchFor, int limitTo, SearchRequestor requestor) throws CoreException { 1050 search(patternString, searchFor, limitTo, EXACT_RULE, getJavaSearchScope(), requestor); 1051 } search(String patternString, int searchFor, int limitTo, int matchRule, IJavaSearchScope scope)1052 protected void search(String patternString, int searchFor, int limitTo, int matchRule, IJavaSearchScope scope) throws CoreException { 1053 search(patternString, searchFor, limitTo, matchRule, scope, this.resultCollector); 1054 } 1055 @Override search(String patternString, int searchFor, int limitTo, int matchRule, IJavaSearchScope scope, SearchRequestor requestor)1056 protected void search(String patternString, int searchFor, int limitTo, int matchRule, IJavaSearchScope scope, SearchRequestor requestor) throws CoreException { 1057 if (patternString.indexOf('*') != -1 || patternString.indexOf('?') != -1) { 1058 matchRule |= SearchPattern.R_PATTERN_MATCH; 1059 } 1060 SearchPattern pattern = SearchPattern.createPattern( 1061 patternString, 1062 searchFor, 1063 limitTo, 1064 matchRule); 1065 assertNotNull("Pattern should not be null", pattern); 1066 new SearchEngine(this.workingCopies).search( 1067 pattern, 1068 new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, 1069 scope, 1070 requestor, 1071 null); 1072 } search(IJavaElement element, int limitTo)1073 protected void search(IJavaElement element, int limitTo) throws CoreException { 1074 search(element, limitTo, EXACT_RULE, getJavaSearchScope(), this.resultCollector); 1075 } search(IJavaElement element, int limitTo, int matchRule)1076 protected void search(IJavaElement element, int limitTo, int matchRule) throws CoreException { 1077 search(element, limitTo, matchRule, getJavaSearchScope(), this.resultCollector); 1078 } search(String patternString, int searchFor, int limitTo)1079 protected void search(String patternString, int searchFor, int limitTo) throws CoreException { 1080 search(patternString, searchFor, limitTo, EXACT_RULE, getJavaSearchScope(), this.resultCollector); 1081 } search(String patternString, int searchFor, int limitTo, int matchRule)1082 protected void search(String patternString, int searchFor, int limitTo, int matchRule) throws CoreException { 1083 search(patternString, searchFor, limitTo, matchRule, getJavaSearchScope(), this.resultCollector); 1084 } searchAllConstructorDeclarations(String pattern, int matchRule, IRestrictedAccessConstructorRequestor requestor)1085 protected void searchAllConstructorDeclarations(String pattern, int matchRule, IRestrictedAccessConstructorRequestor requestor) throws JavaModelException { 1086 new BasicSearchEngine(this.workingCopies).searchAllConstructorDeclarations( 1087 null, 1088 pattern.toCharArray(), 1089 matchRule, 1090 SearchEngine.createWorkspaceScope(), 1091 requestor, 1092 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1093 null); 1094 } searchAllMethodNames(String pattern, int matchRule, IRestrictedAccessMethodRequestor requestor)1095 protected void searchAllMethodNames(String pattern, int matchRule, IRestrictedAccessMethodRequestor requestor) throws JavaModelException { 1096 new BasicSearchEngine(this.workingCopies).searchAllMethodNames( 1097 null, SearchPattern.R_EXACT_MATCH, 1098 null, SearchPattern.R_EXACT_MATCH, 1099 null, SearchPattern.R_EXACT_MATCH, 1100 pattern.toCharArray(), matchRule, 1101 getJavaSearchScope(), 1102 requestor, 1103 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1104 null); 1105 } searchAllMethodNames(String pattern, int matchRule, IJavaSearchScope scope, IRestrictedAccessMethodRequestor requestor)1106 protected void searchAllMethodNames(String pattern, int matchRule, IJavaSearchScope scope, IRestrictedAccessMethodRequestor requestor) throws JavaModelException { 1107 searchAllMethodNames( 1108 null, SearchPattern.R_EXACT_MATCH, 1109 pattern, matchRule, 1110 scope, 1111 requestor); 1112 } searchAllMethodNames( String declSimpleNamePattern, int declSimpleNameMatchRule, String patternMethod, int methodMatchRule, IJavaSearchScope scope, IRestrictedAccessMethodRequestor requestor)1113 protected void searchAllMethodNames( 1114 String declSimpleNamePattern, int declSimpleNameMatchRule, 1115 String patternMethod, int methodMatchRule, 1116 IJavaSearchScope scope, 1117 IRestrictedAccessMethodRequestor requestor) throws JavaModelException { 1118 searchAllMethodNames( 1119 null, SearchPattern.R_EXACT_MATCH, 1120 declSimpleNamePattern, declSimpleNameMatchRule, 1121 patternMethod, methodMatchRule, 1122 scope, 1123 requestor); 1124 } searchAllMethodNames( String declQualificationPattern, int declQualificationMatchRule, String declSimpleNamePattern, int declSimpleNameMatchRule, String patternMethod, int methodMatchRule, IJavaSearchScope scope, IRestrictedAccessMethodRequestor requestor)1125 protected void searchAllMethodNames( 1126 String declQualificationPattern, int declQualificationMatchRule, 1127 String declSimpleNamePattern, int declSimpleNameMatchRule, 1128 String patternMethod, int methodMatchRule, 1129 IJavaSearchScope scope, 1130 IRestrictedAccessMethodRequestor requestor) throws JavaModelException { 1131 searchAllMethodNames( 1132 null, SearchPattern.R_EXACT_MATCH, 1133 declQualificationPattern, declQualificationMatchRule, 1134 declSimpleNamePattern, declSimpleNameMatchRule, 1135 patternMethod, methodMatchRule, 1136 scope, 1137 requestor); 1138 } searchAllMethodNames( String patternPackage, int pkgMatchRule, String declQualificationPattern, int declQualificationMatchRule, String declSimpleNamePattern, int declSimpleNameMatchRule, String patternMethod, int methodMatchRule, IJavaSearchScope scope, IRestrictedAccessMethodRequestor requestor)1139 protected void searchAllMethodNames( 1140 String patternPackage, int pkgMatchRule, 1141 String declQualificationPattern, int declQualificationMatchRule, 1142 String declSimpleNamePattern, int declSimpleNameMatchRule, 1143 String patternMethod, int methodMatchRule, 1144 IJavaSearchScope scope, 1145 IRestrictedAccessMethodRequestor requestor) throws JavaModelException { 1146 new BasicSearchEngine(this.workingCopies).searchAllMethodNames( 1147 patternPackage == null ? null : patternPackage.toCharArray(), pkgMatchRule, 1148 declQualificationPattern == null ? null : declQualificationPattern.toCharArray(), declQualificationMatchRule, 1149 declSimpleNamePattern == null ? null : declSimpleNamePattern.toCharArray(), declSimpleNameMatchRule, 1150 patternMethod == null ? null : patternMethod.toCharArray(), methodMatchRule, 1151 scope, 1152 requestor, 1153 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1154 null); 1155 } 1156 searchAllMethodNames( String packageName, final int pkgMatchRule, String declaringQualification, final int declQualificationMatchRule, String declaringSimpleName, final int declSimpleNameMatchRule, String methodName, final int methodMatchRule, IJavaSearchScope scope, final MethodNameMatchRequestor nameRequestor)1157 public void searchAllMethodNames( 1158 String packageName, 1159 final int pkgMatchRule, 1160 String declaringQualification, 1161 final int declQualificationMatchRule, 1162 String declaringSimpleName, 1163 final int declSimpleNameMatchRule, 1164 String methodName, 1165 final int methodMatchRule, 1166 IJavaSearchScope scope, 1167 final MethodNameMatchRequestor nameRequestor) { 1168 try { 1169 new SearchEngine(this.workingCopies).searchAllMethodNames( 1170 packageName != null ? packageName.toCharArray() : null, pkgMatchRule, 1171 declaringQualification != null ? declaringQualification.toCharArray() : null, declQualificationMatchRule, 1172 declaringSimpleName != null ? declaringSimpleName.toCharArray() : null, declSimpleNameMatchRule, 1173 methodName != null ? methodName.toCharArray() : null, methodMatchRule, 1174 scope, nameRequestor, 1175 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1176 null); 1177 } catch (JavaModelException e) { 1178 e.printStackTrace(); 1179 } 1180 1181 } 1182 searchAllMethodNames( String qualifier, final int qualifierMatchRule, String methodName, final int methodMatchRule, IJavaSearchScope scope, final MethodNameMatchRequestor nameRequestor)1183 public void searchAllMethodNames( 1184 String qualifier, 1185 final int qualifierMatchRule, 1186 String methodName, 1187 final int methodMatchRule, 1188 IJavaSearchScope scope, 1189 final MethodNameMatchRequestor nameRequestor) { 1190 try { 1191 new SearchEngine(this.workingCopies).searchAllMethodNames( 1192 qualifier != null ? qualifier.toCharArray() : null, qualifierMatchRule, 1193 methodName != null ? methodName.toCharArray() : null, methodMatchRule, 1194 scope, nameRequestor, 1195 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1196 null); 1197 } catch (JavaModelException e) { 1198 e.printStackTrace(); 1199 } 1200 1201 } 1202 searchAllTypeNames(String pattern, int matchRule, TypeNameRequestor requestor)1203 protected void searchAllTypeNames(String pattern, int matchRule, TypeNameRequestor requestor) throws JavaModelException { 1204 new SearchEngine(this.workingCopies).searchAllTypeNames( 1205 null, 1206 SearchPattern.R_EXACT_MATCH, 1207 pattern.toCharArray(), 1208 matchRule, 1209 TYPE, 1210 getJavaSearchScope(), 1211 requestor, 1212 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1213 null 1214 ); 1215 } searchAllTypeNames(String pattern, int matchRule, TypeNameMatchCollector collector)1216 protected void searchAllTypeNames(String pattern, int matchRule, TypeNameMatchCollector collector) throws JavaModelException { 1217 searchAllTypeNames(null, pattern, matchRule, collector); 1218 } searchAllTypeNames(String packagePattern, String typePattern, int matchRule, TypeNameMatchCollector collector)1219 protected void searchAllTypeNames(String packagePattern, String typePattern, int matchRule, TypeNameMatchCollector collector) throws JavaModelException { 1220 new SearchEngine(this.workingCopies).searchAllTypeNames( 1221 packagePattern==null ? null : packagePattern.toCharArray(), 1222 SearchPattern.R_EXACT_MATCH, 1223 typePattern==null ? null : typePattern.toCharArray(), 1224 matchRule, 1225 TYPE, 1226 getJavaSearchScope(), 1227 collector, 1228 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, 1229 null 1230 ); 1231 } searchDeclarationsOfAccessedFields(IJavaElement enclosingElement, SearchRequestor requestor)1232 protected void searchDeclarationsOfAccessedFields(IJavaElement enclosingElement, SearchRequestor requestor) throws JavaModelException { 1233 new SearchEngine().searchDeclarationsOfAccessedFields(enclosingElement, requestor, null); 1234 } searchDeclarationsOfReferencedTypes(IJavaElement enclosingElement, SearchRequestor requestor)1235 protected void searchDeclarationsOfReferencedTypes(IJavaElement enclosingElement, SearchRequestor requestor) throws JavaModelException { 1236 new SearchEngine().searchDeclarationsOfReferencedTypes(enclosingElement, requestor, null); 1237 } searchDeclarationsOfSentMessages(IJavaElement enclosingElement, SearchRequestor requestor)1238 protected void searchDeclarationsOfSentMessages(IJavaElement enclosingElement, SearchRequestor requestor) throws JavaModelException { 1239 new SearchEngine().searchDeclarationsOfSentMessages(enclosingElement, requestor, null); 1240 } 1241 @Override setUp()1242 protected void setUp () throws Exception { 1243 super.setUp(); 1244 this.resultCollector = new JavaSearchResultCollector(); 1245 } 1246 } 1247