0001: /*******************************************************************************
0002: * Copyright (c) 2000, 2007 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Eclipse Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/epl-v10.html
0007: *
0008: * Contributors:
0009: * IBM Corporation - initial API and implementation
0010: *******************************************************************************/package org.eclipse.jdt.core.search;
0011:
0012: import org.eclipse.core.resources.*;
0013: import org.eclipse.core.runtime.*;
0014:
0015: import org.eclipse.jdt.core.*;
0016: import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
0017: import org.eclipse.jdt.internal.core.search.*;
0018: import org.eclipse.jdt.internal.core.search.matching.*;
0019:
0020: /**
0021: * A {@link SearchEngine} searches for Java elements following a search pattern.
0022: * The search can be limited to a search scope.
0023: * <p>
0024: * Various search patterns can be created using the factory methods
0025: * {@link SearchPattern#createPattern(String, int, int, int)}, {@link SearchPattern#createPattern(IJavaElement, int)},
0026: * {@link SearchPattern#createOrPattern(SearchPattern, SearchPattern)}.
0027: * </p>
0028: * <p>For example, one can search for references to a method in the hierarchy of a type,
0029: * or one can search for the declarations of types starting with "Abstract" in a project.
0030: * </p>
0031: * <p>
0032: * This class may be instantiated; it is not intended to be subclassed.
0033: * </p>
0034: */
0035: public class SearchEngine {
0036:
0037: /**
0038: * Internal adapter class.
0039: * @deprecated marking deprecated as it uses deprecated ISearchPattern
0040: */
0041: static class SearchPatternAdapter implements ISearchPattern {
0042: SearchPattern pattern;
0043:
0044: SearchPatternAdapter(SearchPattern pattern) {
0045: this .pattern = pattern;
0046: }
0047: }
0048:
0049: /**
0050: * Internal adapter class.
0051: * @deprecated marking deprecated as it uses deprecated IJavaSearchResultCollector
0052: */
0053: static class ResultCollectorAdapter extends SearchRequestor {
0054: IJavaSearchResultCollector resultCollector;
0055:
0056: ResultCollectorAdapter(
0057: IJavaSearchResultCollector resultCollector) {
0058: this .resultCollector = resultCollector;
0059: }
0060:
0061: /**
0062: * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
0063: */
0064: public void acceptSearchMatch(SearchMatch match)
0065: throws CoreException {
0066: this .resultCollector.accept(match.getResource(), match
0067: .getOffset(),
0068: match.getOffset() + match.getLength(),
0069: (IJavaElement) match.getElement(), match
0070: .getAccuracy());
0071: }
0072:
0073: /**
0074: * @see org.eclipse.jdt.core.search.SearchRequestor#beginReporting()
0075: */
0076: public void beginReporting() {
0077: this .resultCollector.aboutToStart();
0078: }
0079:
0080: /**
0081: * @see org.eclipse.jdt.core.search.SearchRequestor#endReporting()
0082: */
0083: public void endReporting() {
0084: this .resultCollector.done();
0085: }
0086: }
0087:
0088: /**
0089: * Internal adapter class.
0090: * @deprecated marking deprecated as it uses deprecated ITypeNameRequestor
0091: */
0092: static class TypeNameRequestorAdapter implements
0093: IRestrictedAccessTypeRequestor {
0094: ITypeNameRequestor nameRequestor;
0095:
0096: TypeNameRequestorAdapter(ITypeNameRequestor requestor) {
0097: this .nameRequestor = requestor;
0098: }
0099:
0100: public void acceptType(int modifiers, char[] packageName,
0101: char[] simpleTypeName, char[][] enclosingTypeNames,
0102: String path, AccessRestriction access) {
0103: if (Flags.isInterface(modifiers)) {
0104: nameRequestor.acceptInterface(packageName,
0105: simpleTypeName, enclosingTypeNames, path);
0106: } else {
0107: nameRequestor.acceptClass(packageName, simpleTypeName,
0108: enclosingTypeNames, path);
0109: }
0110: }
0111: }
0112:
0113: // Search engine now uses basic engine functionalities
0114: private BasicSearchEngine basicEngine;
0115:
0116: /**
0117: * Creates a new search engine.
0118: */
0119: public SearchEngine() {
0120: this .basicEngine = new BasicSearchEngine();
0121: }
0122:
0123: /**
0124: * Creates a new search engine with a list of working copies that will take precedence over
0125: * their original compilation units in the subsequent search operations.
0126: * <p>
0127: * Note that passing an empty working copy will be as if the original compilation
0128: * unit had been deleted.</p>
0129: * <p>
0130: * Since 3.0 the given working copies take precedence over primary working copies (if any).
0131: *
0132: * @param workingCopies the working copies that take precedence over their original compilation units
0133: * @since 3.0
0134: */
0135: public SearchEngine(ICompilationUnit[] workingCopies) {
0136: this .basicEngine = new BasicSearchEngine(workingCopies);
0137: }
0138:
0139: /**
0140: * Creates a new search engine with a list of working copies that will take precedence over
0141: * their original compilation units in the subsequent search operations.
0142: * <p>
0143: * Note that passing an empty working copy will be as if the original compilation
0144: * unit had been deleted.</p>
0145: * <p>
0146: * Since 3.0 the given working copies take precedence over primary working copies (if any).
0147: *
0148: * @param workingCopies the working copies that take precedence over their original compilation units
0149: * @since 2.0
0150: * @deprecated Use {@link #SearchEngine(ICompilationUnit[])} instead.
0151: */
0152: public SearchEngine(IWorkingCopy[] workingCopies) {
0153: int length = workingCopies.length;
0154: ICompilationUnit[] units = new ICompilationUnit[length];
0155: System.arraycopy(workingCopies, 0, units, 0, length);
0156: this .basicEngine = new BasicSearchEngine(units);
0157: }
0158:
0159: /**
0160: * Creates a new search engine with the given working copy owner.
0161: * The working copies owned by this owner will take precedence over
0162: * the primary compilation units in the subsequent search operations.
0163: *
0164: * @param workingCopyOwner the owner of the working copies that take precedence over their original compilation units
0165: * @since 3.0
0166: */
0167: public SearchEngine(WorkingCopyOwner workingCopyOwner) {
0168: this .basicEngine = new BasicSearchEngine(workingCopyOwner);
0169: }
0170:
0171: /**
0172: * Returns a Java search scope limited to the hierarchy of the given type.
0173: * The Java elements resulting from a search with this scope will
0174: * be types in this hierarchy, or members of the types in this hierarchy.
0175: *
0176: * @param type the focus of the hierarchy scope
0177: * @return a new hierarchy scope
0178: * @exception JavaModelException if the hierarchy could not be computed on the given type
0179: */
0180: public static IJavaSearchScope createHierarchyScope(IType type)
0181: throws JavaModelException {
0182: return BasicSearchEngine.createHierarchyScope(type);
0183: }
0184:
0185: /**
0186: * Returns a Java search scope limited to the hierarchy of the given type.
0187: * When the hierarchy is computed, the types defined in the working copies owned
0188: * by the given owner take precedence over the original compilation units.
0189: * The Java elements resulting from a search with this scope will
0190: * be types in this hierarchy, or members of the types in this hierarchy.
0191: *
0192: * @param type the focus of the hierarchy scope
0193: * @param owner the owner of working copies that take precedence over original compilation units
0194: * @return a new hierarchy scope
0195: * @exception JavaModelException if the hierarchy could not be computed on the given type
0196: * @since 3.0
0197: */
0198: public static IJavaSearchScope createHierarchyScope(IType type,
0199: WorkingCopyOwner owner) throws JavaModelException {
0200: return BasicSearchEngine.createHierarchyScope(type, owner);
0201: }
0202:
0203: /**
0204: * Returns a Java search scope limited to the given resources.
0205: * The Java elements resulting from a search with this scope will
0206: * have their underlying resource included in or equals to one of the given
0207: * resources.
0208: * <p>
0209: * Resources must not overlap, for example, one cannot include a folder and its children.
0210: * </p>
0211: *
0212: * @param resources the resources the scope is limited to
0213: * @return a new Java search scope
0214: * @deprecated Use {@link #createJavaSearchScope(IJavaElement[])} instead.
0215: */
0216: public static IJavaSearchScope createJavaSearchScope(
0217: IResource[] resources) {
0218: int length = resources.length;
0219: IJavaElement[] elements = new IJavaElement[length];
0220: for (int i = 0; i < length; i++) {
0221: elements[i] = JavaCore.create(resources[i]);
0222: }
0223: return createJavaSearchScope(elements);
0224: }
0225:
0226: /**
0227: * Returns a Java search scope limited to the given Java elements.
0228: * The Java elements resulting from a search with this scope will
0229: * be children of the given elements.
0230: * <p>
0231: * If an element is an IJavaProject, then the project's source folders,
0232: * its jars (external and internal) and its referenced projects (with their source
0233: * folders and jars, recursively) will be included.
0234: * If an element is an IPackageFragmentRoot, then only the package fragments of
0235: * this package fragment root will be included.
0236: * If an element is an IPackageFragment, then only the compilation unit and class
0237: * files of this package fragment will be included. Subpackages will NOT be
0238: * included.</p>
0239: * <p>
0240: * In other words, this is equivalent to using SearchEngine.createJavaSearchScope(elements, true).</p>
0241: *
0242: * @param elements the Java elements the scope is limited to
0243: * @return a new Java search scope
0244: * @since 2.0
0245: */
0246: public static IJavaSearchScope createJavaSearchScope(
0247: IJavaElement[] elements) {
0248: return BasicSearchEngine.createJavaSearchScope(elements);
0249: }
0250:
0251: /**
0252: * Returns a Java search scope limited to the given Java elements.
0253: * The Java elements resulting from a search with this scope will
0254: * be children of the given elements.
0255: *
0256: * If an element is an IJavaProject, then the project's source folders,
0257: * its jars (external and internal) and - if specified - its referenced projects
0258: * (with their source folders and jars, recursively) will be included.
0259: * If an element is an IPackageFragmentRoot, then only the package fragments of
0260: * this package fragment root will be included.
0261: * If an element is an IPackageFragment, then only the compilation unit and class
0262: * files of this package fragment will be included. Subpackages will NOT be
0263: * included.
0264: *
0265: * @param elements the Java elements the scope is limited to
0266: * @param includeReferencedProjects a flag indicating if referenced projects must be
0267: * recursively included
0268: * @return a new Java search scope
0269: * @since 2.0
0270: */
0271: public static IJavaSearchScope createJavaSearchScope(
0272: IJavaElement[] elements, boolean includeReferencedProjects) {
0273: return BasicSearchEngine.createJavaSearchScope(elements,
0274: includeReferencedProjects);
0275: }
0276:
0277: /**
0278: * Returns a Java search scope limited to the given Java elements.
0279: * The Java elements resulting from a search with this scope will
0280: * be children of the given elements.
0281: *
0282: * If an element is an IJavaProject, then it includes:
0283: * - its source folders if IJavaSearchScope.SOURCES is specified,
0284: * - its application libraries (internal and external jars, class folders that are on the raw classpath,
0285: * or the ones that are coming from a classpath path variable,
0286: * or the ones that are coming from a classpath container with the K_APPLICATION kind)
0287: * if IJavaSearchScope.APPLICATION_LIBRARIES is specified
0288: * - its system libraries (internal and external jars, class folders that are coming from an
0289: * IClasspathContainer with the K_SYSTEM kind)
0290: * if IJavaSearchScope.APPLICATION_LIBRARIES is specified
0291: * - its referenced projects (with their source folders and jars, recursively)
0292: * if IJavaSearchScope.REFERENCED_PROJECTS is specified.
0293: * If an element is an IPackageFragmentRoot, then only the package fragments of
0294: * this package fragment root will be included.
0295: * If an element is an IPackageFragment, then only the compilation unit and class
0296: * files of this package fragment will be included. Subpackages will NOT be
0297: * included.
0298: *
0299: * @param elements the Java elements the scope is limited to
0300: * @param includeMask the bit-wise OR of all include types of interest
0301: * @return a new Java search scope
0302: * @see IJavaSearchScope#SOURCES
0303: * @see IJavaSearchScope#APPLICATION_LIBRARIES
0304: * @see IJavaSearchScope#SYSTEM_LIBRARIES
0305: * @see IJavaSearchScope#REFERENCED_PROJECTS
0306: * @since 3.0
0307: */
0308: public static IJavaSearchScope createJavaSearchScope(
0309: IJavaElement[] elements, int includeMask) {
0310: return BasicSearchEngine.createJavaSearchScope(elements,
0311: includeMask);
0312: }
0313:
0314: /**
0315: * Returns a search pattern that combines the given two patterns into a "or" pattern.
0316: * The search result will match either the left pattern or the right pattern.
0317: *
0318: * @param leftPattern the left pattern
0319: * @param rightPattern the right pattern
0320: * @return a "or" pattern
0321: * @deprecated Use {@link SearchPattern#createOrPattern(SearchPattern, SearchPattern)} instead.
0322: */
0323: public static ISearchPattern createOrSearchPattern(
0324: ISearchPattern leftPattern, ISearchPattern rightPattern) {
0325: SearchPattern left = ((SearchPatternAdapter) leftPattern).pattern;
0326: SearchPattern right = ((SearchPatternAdapter) rightPattern).pattern;
0327: SearchPattern pattern = SearchPattern.createOrPattern(left,
0328: right);
0329: return new SearchPatternAdapter(pattern);
0330: }
0331:
0332: /**
0333: * Returns a search pattern based on a given string pattern. The string patterns support '*' wild-cards.
0334: * The remaining parameters are used to narrow down the type of expected results.
0335: *
0336: * <br>
0337: * Examples:
0338: * <ul>
0339: * <li>search for case insensitive references to <code>Object</code>:
0340: * <code>createSearchPattern("Object", TYPE, REFERENCES, false);</code></li>
0341: * <li>search for case sensitive references to exact <code>Object()</code> constructor:
0342: * <code>createSearchPattern("java.lang.Object()", CONSTRUCTOR, REFERENCES, true);</code></li>
0343: * <li>search for implementers of <code>java.lang.Runnable</code>:
0344: * <code>createSearchPattern("java.lang.Runnable", TYPE, IMPLEMENTORS, true);</code></li>
0345: * </ul>
0346: * @param stringPattern the given pattern
0347: * @param searchFor determines the nature of the searched elements
0348: * <ul>
0349: * <li>{@link IJavaSearchConstants#CLASS}: only look for classes</li>
0350: * <li>{@link IJavaSearchConstants#INTERFACE}: only look for interfaces</li>
0351: * <li>{@link IJavaSearchConstants#TYPE}: look for both classes and interfaces</li>
0352: * <li>{@link IJavaSearchConstants#FIELD}: look for fields</li>
0353: * <li>{@link IJavaSearchConstants#METHOD}: look for methods</li>
0354: * <li>{@link IJavaSearchConstants#CONSTRUCTOR}: look for constructors</li>
0355: * <li>{@link IJavaSearchConstants#PACKAGE}: look for packages</li>
0356: * </ul>
0357: * @param limitTo determines the nature of the expected matches
0358: * <ul>
0359: * <li>{@link IJavaSearchConstants#DECLARATIONS}: will search declarations matching with the corresponding
0360: * element. In case the element is a method, declarations of matching methods in subtypes will also
0361: * be found, allowing to find declarations of abstract methods, etc.</li>
0362: *
0363: * <li>{@link IJavaSearchConstants#REFERENCES}: will search references to the given element.</li>
0364: *
0365: * <li>{@link IJavaSearchConstants#ALL_OCCURRENCES}: will search for either declarations or references as specified
0366: * above.</li>
0367: *
0368: * <li>{@link IJavaSearchConstants#IMPLEMENTORS}: for types, will find all types
0369: * which directly implement/extend a given interface.
0370: * Note that types may be only classes or only interfaces if {@link IJavaSearchConstants#CLASS } or
0371: * {@link IJavaSearchConstants#INTERFACE} is respectively used instead of {@link IJavaSearchConstants#TYPE}.
0372: * </li>
0373: * </ul>
0374: *
0375: * @param isCaseSensitive indicates whether the search is case sensitive or not.
0376: * @return a search pattern on the given string pattern, or <code>null</code> if the string pattern is ill-formed.
0377: * @deprecated Use {@link SearchPattern#createPattern(String, int, int, int)} instead.
0378: */
0379: public static ISearchPattern createSearchPattern(
0380: String stringPattern, int searchFor, int limitTo,
0381: boolean isCaseSensitive) {
0382: int matchMode = stringPattern.indexOf('*') != -1
0383: || stringPattern.indexOf('?') != -1 ? SearchPattern.R_PATTERN_MATCH
0384: : SearchPattern.R_EXACT_MATCH;
0385: int matchRule = isCaseSensitive ? matchMode
0386: | SearchPattern.R_CASE_SENSITIVE : matchMode;
0387: return new SearchPatternAdapter(SearchPattern.createPattern(
0388: stringPattern, searchFor, limitTo, matchRule));
0389: }
0390:
0391: /**
0392: * Returns a search pattern based on a given Java element.
0393: * The pattern is used to trigger the appropriate search, and can be parameterized as follows:
0394: *
0395: * @param element the Java element the search pattern is based on
0396: * @param limitTo determines the nature of the expected matches
0397: * <ul>
0398: * <li>{@link IJavaSearchConstants#DECLARATIONS}: will search declarations matching with the corresponding
0399: * element. In case the element is a method, declarations of matching methods in subtypes will also
0400: * be found, allowing to find declarations of abstract methods, etc.</li>
0401: *
0402: * <li>{@link IJavaSearchConstants#REFERENCES}: will search references to the given element.</li>
0403: *
0404: * <li>{@link IJavaSearchConstants#ALL_OCCURRENCES}: will search for either declarations or references as specified
0405: * above.</li>
0406: *
0407: * <li>{@link IJavaSearchConstants#IMPLEMENTORS}: for types, will find all types
0408: * which directly implement/extend a given interface.</li>
0409: * </ul>
0410: * @return a search pattern for a Java element or <code>null</code> if the given element is ill-formed
0411: * @deprecated Use {@link SearchPattern#createPattern(IJavaElement, int)} instead.
0412: */
0413: public static ISearchPattern createSearchPattern(
0414: IJavaElement element, int limitTo) {
0415: return new SearchPatternAdapter(SearchPattern.createPattern(
0416: element, limitTo));
0417: }
0418:
0419: /**
0420: * Create a type name match on a given type with specific modifiers.
0421: *
0422: * @param type The java model handle of the type
0423: * @param modifiers Modifiers of the type
0424: * @return A non-null match on the given type.
0425: * @since 3.3
0426: */
0427: public static TypeNameMatch createTypeNameMatch(IType type,
0428: int modifiers) {
0429: return BasicSearchEngine.createTypeNameMatch(type, modifiers);
0430: }
0431:
0432: /**
0433: * Returns a Java search scope with the workspace as the only limit.
0434: *
0435: * @return a new workspace scope
0436: */
0437: public static IJavaSearchScope createWorkspaceScope() {
0438: return BasicSearchEngine.createWorkspaceScope();
0439: }
0440:
0441: /**
0442: * Returns a new default Java search participant.
0443: *
0444: * @return a new default Java search participant
0445: * @since 3.0
0446: */
0447: public static SearchParticipant getDefaultSearchParticipant() {
0448: return BasicSearchEngine.getDefaultSearchParticipant();
0449: }
0450:
0451: /**
0452: * Searches for the Java element determined by the given signature. The signature
0453: * can be incomplete. For example, a call like
0454: * <code>search(ws, "run()", METHOD,REFERENCES, col)</code>
0455: * searches for all references to the method <code>run</code>.
0456: *
0457: * Note that by default the pattern will be case insensitive. For specifying case s
0458: * sensitive search, use <code>search(workspace, createSearchPattern(patternString, searchFor, limitTo, true), scope, resultCollector);</code>
0459: *
0460: * @param workspace the workspace
0461: * @param patternString the pattern to be searched for
0462: * @param searchFor a hint what kind of Java element the string pattern represents.
0463: * Look into {@link IJavaSearchConstants} for valid values
0464: * @param limitTo one of the following values:
0465: * <ul>
0466: * <li>{@link IJavaSearchConstants#DECLARATIONS}: search
0467: * for declarations only </li>
0468: * <li>{@link IJavaSearchConstants#REFERENCES}: search
0469: * for all references </li>
0470: * <li>{@link IJavaSearchConstants#ALL_OCCURRENCES}: search
0471: * for both declarations and all references </li>
0472: * <li>{@link IJavaSearchConstants#IMPLEMENTORS}: for types, will find all types
0473: * which directly implement/extend a given interface.<br>
0474: * Note that types may be only classes or only interfaces if respectively {@link IJavaSearchConstants#CLASS} or
0475: * {@link IJavaSearchConstants#INTERFACE} is used for searchFor parameter instead of {@link IJavaSearchConstants#TYPE}.
0476: * </li>
0477: * </ul>
0478: * @param scope the search result has to be limited to the given scope
0479: * @param resultCollector a callback object to which each match is reported
0480: * @exception JavaModelException if the search failed. Reasons include:
0481: * <ul>
0482: * <li>the classpath is incorrectly set</li>
0483: * </ul>
0484: * @deprecated Use {@link #search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor)} instead.
0485: */
0486: public void search(IWorkspace workspace, String patternString,
0487: int searchFor, int limitTo, IJavaSearchScope scope,
0488: IJavaSearchResultCollector resultCollector)
0489: throws JavaModelException {
0490: try {
0491: int matchMode = patternString.indexOf('*') != -1
0492: || patternString.indexOf('?') != -1 ? SearchPattern.R_PATTERN_MATCH
0493: : SearchPattern.R_EXACT_MATCH;
0494: search(
0495: SearchPattern.createPattern(patternString,
0496: searchFor, limitTo, matchMode
0497: | SearchPattern.R_CASE_SENSITIVE),
0498: new SearchParticipant[] { getDefaultSearchParticipant() },
0499: scope, new ResultCollectorAdapter(resultCollector),
0500: resultCollector.getProgressMonitor());
0501: } catch (CoreException e) {
0502: if (e instanceof JavaModelException)
0503: throw (JavaModelException) e;
0504: throw new JavaModelException(e);
0505: }
0506: }
0507:
0508: /**
0509: * Searches for the given Java element.
0510: *
0511: * @param workspace the workspace
0512: * @param element the Java element to be searched for
0513: * @param limitTo one of the following values:
0514: * <ul>
0515: * <li>{@link IJavaSearchConstants#DECLARATIONS}: search
0516: * for declarations only </li>
0517: * <li>{@link IJavaSearchConstants#REFERENCES}: search
0518: * for all references </li>
0519: * <li>{@link IJavaSearchConstants#ALL_OCCURRENCES}: search
0520: * for both declarations and all references </li>
0521: * <li>{@link IJavaSearchConstants#IMPLEMENTORS}: for types, will find all types
0522: * which directly implement/extend a given interface.</li>
0523: * </ul>
0524: * @param scope the search result has to be limited to the given scope
0525: * @param resultCollector a callback object to which each match is reported
0526: * @exception JavaModelException if the search failed. Reasons include:
0527: * <ul>
0528: * <li>the element doesn't exist</li>
0529: * <li>the classpath is incorrectly set</li>
0530: * </ul>
0531: * @deprecated Use {@link #search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor)} instead.
0532: */
0533: public void search(IWorkspace workspace, IJavaElement element,
0534: int limitTo, IJavaSearchScope scope,
0535: IJavaSearchResultCollector resultCollector)
0536: throws JavaModelException {
0537: search(workspace, createSearchPattern(element, limitTo), scope,
0538: resultCollector);
0539: }
0540:
0541: /**
0542: * Searches for matches of a given search pattern. Search patterns can be created using helper
0543: * methods (from a String pattern or a Java element) and encapsulate the description of what is
0544: * being searched (for example, search method declarations in a case sensitive way).
0545: *
0546: * @param workspace the workspace
0547: * @param searchPattern the pattern to be searched for
0548: * @param scope the search result has to be limited to the given scope
0549: * @param resultCollector a callback object to which each match is reported
0550: * @exception JavaModelException if the search failed. Reasons include:
0551: * <ul>
0552: * <li>the classpath is incorrectly set</li>
0553: * </ul>
0554: * @deprecated Use {@link #search(SearchPattern, SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor)} instead.
0555: */
0556: public void search(IWorkspace workspace,
0557: ISearchPattern searchPattern, IJavaSearchScope scope,
0558: IJavaSearchResultCollector resultCollector)
0559: throws JavaModelException {
0560: try {
0561: search(
0562: ((SearchPatternAdapter) searchPattern).pattern,
0563: new SearchParticipant[] { getDefaultSearchParticipant() },
0564: scope, new ResultCollectorAdapter(resultCollector),
0565: resultCollector.getProgressMonitor());
0566: } catch (CoreException e) {
0567: if (e instanceof JavaModelException)
0568: throw (JavaModelException) e;
0569: throw new JavaModelException(e);
0570: }
0571: }
0572:
0573: /**
0574: * Searches for matches of a given search pattern. Search patterns can be created using helper
0575: * methods (from a String pattern or a Java element) and encapsulate the description of what is
0576: * being searched (for example, search method declarations in a case sensitive way).
0577: *
0578: * @param pattern the pattern to search
0579: * @param participants the particpants in the search
0580: * @param scope the search scope
0581: * @param requestor the requestor to report the matches to
0582: * @param monitor the progress monitor used to report progress
0583: * @exception CoreException if the search failed. Reasons include:
0584: * <ul>
0585: * <li>the classpath is incorrectly set</li>
0586: * </ul>
0587: *@since 3.0
0588: */
0589: public void search(SearchPattern pattern,
0590: SearchParticipant[] participants, IJavaSearchScope scope,
0591: SearchRequestor requestor, IProgressMonitor monitor)
0592: throws CoreException {
0593: this .basicEngine.search(pattern, participants, scope,
0594: requestor, monitor);
0595: }
0596:
0597: /**
0598: * Searches for all top-level types and member types in the given scope.
0599: * The search can be selecting specific types (given a package exact full name or
0600: * a type name with specific match mode).
0601: *
0602: * @param packageExactName the exact package full name of the searched types.<br>
0603: * If you want to use a prefix or a wild-carded string for package, you need to use
0604: * {@link #searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)}
0605: * method instead. May be <code>null</code>, then any package name is accepted.
0606: * @param typeName the dot-separated qualified name of the searched type (the qualification include
0607: * the enclosing types if the searched type is a member type), or a prefix
0608: * for this type, or a wild-carded string for this type.
0609: * May be <code>null</code>, then any type name is accepted.
0610: * @param matchRule type name match rule one of
0611: * <ul>
0612: * <li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
0613: * of the searched types.</li>
0614: * <li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
0615: * of the searched types.</li>
0616: * <li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0617: * <li>{@link SearchPattern#R_CAMEL_CASE_MATCH} if type name are camel case of the names of the searched types.</li>
0618: * </ul>
0619: * combined with {@link SearchPattern#R_CASE_SENSITIVE},
0620: * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested,
0621: * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
0622: * @param searchFor determines the nature of the searched elements
0623: * <ul>
0624: * <li>{@link IJavaSearchConstants#CLASS}: only look for classes</li>
0625: * <li>{@link IJavaSearchConstants#INTERFACE}: only look for interfaces</li>
0626: * <li>{@link IJavaSearchConstants#ENUM}: only look for enumeration</li>
0627: * <li>{@link IJavaSearchConstants#ANNOTATION_TYPE}: only look for annotation type</li>
0628: * <li>{@link IJavaSearchConstants#CLASS_AND_ENUM}: only look for classes and enumerations</li>
0629: * <li>{@link IJavaSearchConstants#CLASS_AND_INTERFACE}: only look for classes and interfaces</li>
0630: * <li>{@link IJavaSearchConstants#TYPE}: look for all types (ie. classes, interfaces, enum and annotation types)</li>
0631: * </ul>
0632: * @param scope the scope to search in
0633: * @param nameRequestor the requestor that collects the results of the search
0634: * @param waitingPolicy one of
0635: * <ul>
0636: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
0637: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
0638: * underlying indexer has not finished indexing the workspace</li>
0639: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
0640: * underlying indexer to finish indexing the workspace</li>
0641: * </ul>
0642: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
0643: * monitor is provided
0644: * @exception JavaModelException if the search failed. Reasons include:
0645: * <ul>
0646: * <li>the classpath is incorrectly set</li>
0647: * </ul>
0648: * @since 3.1
0649: * @deprecated Use {@link #searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)}
0650: * instead
0651: */
0652: public void searchAllTypeNames(final char[] packageExactName,
0653: final char[] typeName, final int matchRule, int searchFor,
0654: IJavaSearchScope scope,
0655: final TypeNameRequestor nameRequestor, int waitingPolicy,
0656: IProgressMonitor progressMonitor) throws JavaModelException {
0657:
0658: searchAllTypeNames(packageExactName,
0659: SearchPattern.R_EXACT_MATCH, typeName, matchRule,
0660: searchFor, scope, nameRequestor, waitingPolicy,
0661: progressMonitor);
0662: }
0663:
0664: /**
0665: * Searches for all top-level types and member types in the given scope.
0666: * The search can be selecting specific types (given a package name using specific match mode
0667: * and/or a type name using another specific match mode).
0668: *
0669: * @param packageName the full name of the package of the searched types, or a prefix for this
0670: * package, or a wild-carded string for this package.
0671: * May be <code>null</code>, then any package name is accepted.
0672: * @param typeName the dot-separated qualified name of the searched type (the qualification include
0673: * the enclosing types if the searched type is a member type), or a prefix
0674: * for this type, or a wild-carded string for this type.
0675: * May be <code>null</code>, then any type name is accepted.
0676: * @param packageMatchRule one of
0677: * <ul>
0678: * <li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
0679: * of the searched types.</li>
0680: * <li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
0681: * of the searched types.</li>
0682: * <li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0683: * <li>{@link SearchPattern#R_CAMEL_CASE_MATCH} if type name are camel case of the names of the searched types.</li>
0684: * </ul>
0685: * combined with {@link SearchPattern#R_CASE_SENSITIVE},
0686: * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested,
0687: * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
0688: * @param typeMatchRule one of
0689: * <ul>
0690: * <li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
0691: * of the searched types.</li>
0692: * <li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
0693: * of the searched types.</li>
0694: * <li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0695: * <li>{@link SearchPattern#R_CAMEL_CASE_MATCH} if type name are camel case of the names of the searched types.</li>
0696: * </ul>
0697: * combined with {@link SearchPattern#R_CASE_SENSITIVE},
0698: * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested,
0699: * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
0700: * @param searchFor determines the nature of the searched elements
0701: * <ul>
0702: * <li>{@link IJavaSearchConstants#CLASS}: only look for classes</li>
0703: * <li>{@link IJavaSearchConstants#INTERFACE}: only look for interfaces</li>
0704: * <li>{@link IJavaSearchConstants#ENUM}: only look for enumeration</li>
0705: * <li>{@link IJavaSearchConstants#ANNOTATION_TYPE}: only look for annotation type</li>
0706: * <li>{@link IJavaSearchConstants#CLASS_AND_ENUM}: only look for classes and enumerations</li>
0707: * <li>{@link IJavaSearchConstants#CLASS_AND_INTERFACE}: only look for classes and interfaces</li>
0708: * <li>{@link IJavaSearchConstants#TYPE}: look for all types (ie. classes, interfaces, enum and annotation types)</li>
0709: * </ul>
0710: * @param scope the scope to search in
0711: * @param nameRequestor the requestor that collects the results of the search
0712: * @param waitingPolicy one of
0713: * <ul>
0714: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
0715: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
0716: * underlying indexer has not finished indexing the workspace</li>
0717: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
0718: * underlying indexer to finish indexing the workspace</li>
0719: * </ul>
0720: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
0721: * monitor is provided
0722: * @exception JavaModelException if the search failed. Reasons include:
0723: * <ul>
0724: * <li>the classpath is incorrectly set</li>
0725: * </ul>
0726: * @since 3.3
0727: */
0728: public void searchAllTypeNames(final char[] packageName,
0729: final int packageMatchRule, final char[] typeName,
0730: final int typeMatchRule, int searchFor,
0731: IJavaSearchScope scope,
0732: final TypeNameRequestor nameRequestor, int waitingPolicy,
0733: IProgressMonitor progressMonitor) throws JavaModelException {
0734:
0735: TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper(
0736: nameRequestor);
0737: this .basicEngine
0738: .searchAllTypeNames(packageName, packageMatchRule,
0739: typeName, SearchPattern
0740: .updateMatchRule(typeMatchRule),
0741: searchFor, scope, requestorWrapper,
0742: waitingPolicy, progressMonitor);
0743: }
0744:
0745: /**
0746: * Searches for all top-level types and member types in the given scope.
0747: * The search can be selecting specific types (given a package name using specific match mode
0748: * and/or a type name using another specific match mode).
0749: * <p>
0750: * Provided {@link TypeNameMatchRequestor} requestor will collect {@link TypeNameMatch}
0751: * matches found during the search.
0752: * </p>
0753: *
0754: * @param packageName the full name of the package of the searched types, or a prefix for this
0755: * package, or a wild-carded string for this package.
0756: * May be <code>null</code>, then any package name is accepted.
0757: * @param packageMatchRule one of
0758: * <ul>
0759: * <li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
0760: * of the searched types.</li>
0761: * <li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
0762: * of the searched types.</li>
0763: * <li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0764: * <li>{@link SearchPattern#R_CAMEL_CASE_MATCH} if type name are camel case of the names of the searched types.</li>
0765: * </ul>
0766: * combined with {@link SearchPattern#R_CASE_SENSITIVE},
0767: * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested,
0768: * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
0769: * @param typeName the dot-separated qualified name of the searched type (the qualification include
0770: * the enclosing types if the searched type is a member type), or a prefix
0771: * for this type, or a wild-carded string for this type.
0772: * May be <code>null</code>, then any type name is accepted.
0773: * @param typeMatchRule one of
0774: * <ul>
0775: * <li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
0776: * of the searched types.</li>
0777: * <li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
0778: * of the searched types.</li>
0779: * <li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0780: * <li>{@link SearchPattern#R_CAMEL_CASE_MATCH} if type name are camel case of the names of the searched types.</li>
0781: * </ul>
0782: * combined with {@link SearchPattern#R_CASE_SENSITIVE},
0783: * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested,
0784: * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
0785: * @param searchFor determines the nature of the searched elements
0786: * <ul>
0787: * <li>{@link IJavaSearchConstants#CLASS}: only look for classes</li>
0788: * <li>{@link IJavaSearchConstants#INTERFACE}: only look for interfaces</li>
0789: * <li>{@link IJavaSearchConstants#ENUM}: only look for enumeration</li>
0790: * <li>{@link IJavaSearchConstants#ANNOTATION_TYPE}: only look for annotation type</li>
0791: * <li>{@link IJavaSearchConstants#CLASS_AND_ENUM}: only look for classes and enumerations</li>
0792: * <li>{@link IJavaSearchConstants#CLASS_AND_INTERFACE}: only look for classes and interfaces</li>
0793: * <li>{@link IJavaSearchConstants#TYPE}: look for all types (ie. classes, interfaces, enum and annotation types)</li>
0794: * </ul>
0795: * @param scope the scope to search in
0796: * @param nameMatchRequestor the {@link TypeNameMatchRequestor requestor} that collects
0797: * {@link TypeNameMatch matches} of the search.
0798: * @param waitingPolicy one of
0799: * <ul>
0800: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
0801: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
0802: * underlying indexer has not finished indexing the workspace</li>
0803: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
0804: * underlying indexer to finish indexing the workspace</li>
0805: * </ul>
0806: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
0807: * monitor is provided
0808: * @exception JavaModelException if the search failed. Reasons include:
0809: * <ul>
0810: * <li>the classpath is incorrectly set</li>
0811: * </ul>
0812: * @since 3.3
0813: */
0814: public void searchAllTypeNames(final char[] packageName,
0815: final int packageMatchRule, final char[] typeName,
0816: final int typeMatchRule, int searchFor,
0817: IJavaSearchScope scope,
0818: final TypeNameMatchRequestor nameMatchRequestor,
0819: int waitingPolicy, IProgressMonitor progressMonitor)
0820: throws JavaModelException {
0821:
0822: TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(
0823: nameMatchRequestor, scope);
0824: this .basicEngine
0825: .searchAllTypeNames(packageName, packageMatchRule,
0826: typeName, SearchPattern
0827: .updateMatchRule(typeMatchRule),
0828: searchFor, scope, requestorWrapper,
0829: waitingPolicy, progressMonitor);
0830: }
0831:
0832: /**
0833: * Searches for all top-level types and member types in the given scope matching any of the given qualifications
0834: * and type names in a case sensitive way.
0835: *
0836: * @param qualifications the qualified name of the package/enclosing type of the searched types.
0837: * May be <code>null</code>, then any package name is accepted.
0838: * @param typeNames the simple names of the searched types.
0839: * If this parameter is <code>null</code>, then no type will be found.
0840: * @param scope the scope to search in
0841: * @param nameRequestor the requestor that collects the results of the search
0842: * @param waitingPolicy one of
0843: * <ul>
0844: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
0845: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
0846: * underlying indexer has not finished indexing the workspace</li>
0847: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
0848: * underlying indexer to finish indexing the workspace</li>
0849: * </ul>
0850: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
0851: * monitor is provided
0852: * @exception JavaModelException if the search failed. Reasons include:
0853: * <ul>
0854: * <li>the classpath is incorrectly set</li>
0855: * </ul>
0856: * @since 3.1
0857: */
0858: public void searchAllTypeNames(final char[][] qualifications,
0859: final char[][] typeNames, IJavaSearchScope scope,
0860: final TypeNameRequestor nameRequestor, int waitingPolicy,
0861: IProgressMonitor progressMonitor) throws JavaModelException {
0862:
0863: TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper(
0864: nameRequestor);
0865: this .basicEngine.searchAllTypeNames(qualifications, typeNames,
0866: SearchPattern.R_EXACT_MATCH
0867: | SearchPattern.R_CASE_SENSITIVE,
0868: IJavaSearchConstants.TYPE, scope, requestorWrapper,
0869: waitingPolicy, progressMonitor);
0870: }
0871:
0872: /**
0873: * Searches for all top-level types and member types in the given scope matching any of the given qualifications
0874: * and type names in a case sensitive way.
0875: * <p>
0876: * Provided {@link TypeNameMatchRequestor} requestor will collect {@link TypeNameMatch}
0877: * matches found during the search.
0878: * </p>
0879: *
0880: * @param qualifications the qualified name of the package/enclosing type of the searched types.
0881: * May be <code>null</code>, then any package name is accepted.
0882: * @param typeNames the simple names of the searched types.
0883: * If this parameter is <code>null</code>, then no type will be found.
0884: * @param scope the scope to search in
0885: * @param nameMatchRequestor the {@link TypeNameMatchRequestor requestor} that collects
0886: * {@link TypeNameMatch matches} of the search.
0887: * @param waitingPolicy one of
0888: * <ul>
0889: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
0890: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
0891: * underlying indexer has not finished indexing the workspace</li>
0892: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
0893: * underlying indexer to finish indexing the workspace</li>
0894: * </ul>
0895: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
0896: * monitor is provided
0897: * @exception JavaModelException if the search failed. Reasons include:
0898: * <ul>
0899: * <li>the classpath is incorrectly set</li>
0900: * </ul>
0901: * @since 3.3
0902: */
0903: public void searchAllTypeNames(final char[][] qualifications,
0904: final char[][] typeNames, IJavaSearchScope scope,
0905: final TypeNameMatchRequestor nameMatchRequestor,
0906: int waitingPolicy, IProgressMonitor progressMonitor)
0907: throws JavaModelException {
0908:
0909: TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(
0910: nameMatchRequestor, scope);
0911: this .basicEngine.searchAllTypeNames(qualifications, typeNames,
0912: SearchPattern.R_EXACT_MATCH
0913: | SearchPattern.R_CASE_SENSITIVE,
0914: IJavaSearchConstants.TYPE, scope, requestorWrapper,
0915: waitingPolicy, progressMonitor);
0916: }
0917:
0918: /**
0919: * Searches for all top-level types and member types in the given scope.
0920: * The search can be selecting specific types (given a package or a type name
0921: * prefix and match modes).
0922: *
0923: * @param packageName the full name of the package of the searched types, or a prefix for this
0924: * package, or a wild-carded string for this package.
0925: * @param typeName the dot-separated qualified name of the searched type (the qualification include
0926: * the enclosing types if the searched type is a member type), or a prefix
0927: * for this type, or a wild-carded string for this type.
0928: * @param matchRule one of
0929: * <ul>
0930: * <li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
0931: * of the searched types.</li>
0932: * <li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
0933: * of the searched types.</li>
0934: * <li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0935: * </ul>
0936: * combined with {@link SearchPattern#R_CASE_SENSITIVE},
0937: * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested,
0938: * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
0939: * @param searchFor one of
0940: * <ul>
0941: * <li>{@link IJavaSearchConstants#CLASS} if searching for classes only</li>
0942: * <li>{@link IJavaSearchConstants#INTERFACE} if searching for interfaces only</li>
0943: * <li>{@link IJavaSearchConstants#TYPE} if searching for both classes and interfaces</li>
0944: * </ul>
0945: * @param scope the scope to search in
0946: * @param nameRequestor the requestor that collects the results of the search
0947: * @param waitingPolicy one of
0948: * <ul>
0949: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
0950: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
0951: * underlying indexer has not finished indexing the workspace</li>
0952: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
0953: * underlying indexer to finish indexing the workspace</li>
0954: * </ul>
0955: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
0956: * monitor is provided
0957: * @exception JavaModelException if the search failed. Reasons include:
0958: * <ul>
0959: * <li>the classpath is incorrectly set</li>
0960: * </ul>
0961: * @since 3.0
0962: *@deprecated Use {@link #searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)} instead
0963: */
0964: public void searchAllTypeNames(final char[] packageName,
0965: final char[] typeName, final int matchRule, int searchFor,
0966: IJavaSearchScope scope,
0967: final ITypeNameRequestor nameRequestor, int waitingPolicy,
0968: IProgressMonitor progressMonitor) throws JavaModelException {
0969:
0970: TypeNameRequestorAdapter requestorAdapter = new TypeNameRequestorAdapter(
0971: nameRequestor);
0972: this .basicEngine.searchAllTypeNames(packageName,
0973: SearchPattern.R_EXACT_MATCH, typeName, matchRule,
0974: searchFor, scope, requestorAdapter, waitingPolicy,
0975: progressMonitor);
0976: }
0977:
0978: /**
0979: * Searches for all top-level types and member types in the given scope.
0980: * The search can be selecting specific types (given a package or a type name
0981: * prefix and match modes).
0982: *
0983: * @param workspace the workspace to search in
0984: * @param packageName the full name of the package of the searched types, or a prefix for this
0985: * package, or a wild-carded string for this package.
0986: * @param typeName the dot-separated qualified name of the searched type (the qualification include
0987: * the enclosing types if the searched type is a member type), or a prefix
0988: * for this type, or a wild-carded string for this type.
0989: * @param matchMode one of
0990: * <ul>
0991: * <li>{@link IJavaSearchConstants#EXACT_MATCH} if the package name and type name are the full names
0992: * of the searched types.</li>
0993: * <li>{@link IJavaSearchConstants#PREFIX_MATCH} if the package name and type name are prefixes of the names
0994: * of the searched types.</li>
0995: * <li>{@link IJavaSearchConstants#PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
0996: * </ul>
0997: * @param isCaseSensitive whether the search should be case sensitive
0998: * @param searchFor one of
0999: * <ul>
1000: * <li>{@link IJavaSearchConstants#CLASS} if searching for classes only</li>
1001: * <li>{@link IJavaSearchConstants#INTERFACE} if searching for interfaces only</li>
1002: * <li>{@link IJavaSearchConstants#TYPE} if searching for both classes and interfaces</li>
1003: * </ul>
1004: * @param scope the scope to search in
1005: * @param nameRequestor the requestor that collects the results of the search
1006: * @param waitingPolicy one of
1007: * <ul>
1008: * <li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
1009: * <li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
1010: * underlying indexer has not finished indexing the workspace</li>
1011: * <li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
1012: * underlying indexer to finish indexing the workspace</li>
1013: * </ul>
1014: * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
1015: * monitor is provided
1016: * @exception JavaModelException if the search failed. Reasons include:
1017: * <ul>
1018: * <li>the classpath is incorrectly set</li>
1019: * </ul>
1020: *@deprecated Use {@link #searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, ITypeNameRequestor, int, IProgressMonitor)} instead
1021: */
1022: public void searchAllTypeNames(IWorkspace workspace,
1023: final char[] packageName, final char[] typeName,
1024: final int matchMode, final boolean isCaseSensitive,
1025: int searchFor, IJavaSearchScope scope,
1026: final ITypeNameRequestor nameRequestor, int waitingPolicy,
1027: IProgressMonitor progressMonitor) throws JavaModelException {
1028:
1029: searchAllTypeNames(packageName, typeName,
1030: isCaseSensitive ? matchMode
1031: | SearchPattern.R_CASE_SENSITIVE : matchMode,
1032: searchFor, scope, nameRequestor, waitingPolicy,
1033: progressMonitor);
1034: }
1035:
1036: /**
1037: * Searches for all declarations of the fields accessed in the given element.
1038: * The element can be a compilation unit or a source type/method/field.
1039: * Reports the field declarations using the given requestor.
1040: * <p>
1041: * Consider the following code:
1042: * <code>
1043: * <pre>
1044: * class A {
1045: * int field1;
1046: * }
1047: * class B extends A {
1048: * String value;
1049: * }
1050: * class X {
1051: * void test() {
1052: * B b = new B();
1053: * System.out.println(b.value + b.field1);
1054: * };
1055: * }
1056: * </pre>
1057: * </code>
1058: * then searching for declarations of accessed fields in method
1059: * <code>X.test()</code> would collect the fields
1060: * <code>B.value</code> and <code>A.field1</code>.
1061: * </p>
1062: *
1063: * @param enclosingElement the field, method, type, or compilation unit to be searched in
1064: * @param requestor a callback object to which each match is reported
1065: * @param monitor the progress monitor used to report progress
1066: * @exception JavaModelException if the search failed. Reasons include:
1067: * <ul>
1068: * <li>the element doesn't exist</li>
1069: * <li>the classpath is incorrectly set</li>
1070: * </ul>
1071: *@exception IllegalArgumentException if the given java element has not the right type
1072: * @since 3.0
1073: */
1074: public void searchDeclarationsOfAccessedFields(
1075: IJavaElement enclosingElement, SearchRequestor requestor,
1076: IProgressMonitor monitor) throws JavaModelException {
1077: this .basicEngine.searchDeclarationsOfAccessedFields(
1078: enclosingElement, requestor, monitor);
1079: }
1080:
1081: /**
1082: * Searches for all declarations of the fields accessed in the given element.
1083: * The element can be a compilation unit, a source type, or a source method.
1084: * Reports the field declarations using the given collector.
1085: * <p>
1086: * Consider the following code:
1087: * <code>
1088: * <pre>
1089: * class A {
1090: * int field1;
1091: * }
1092: * class B extends A {
1093: * String value;
1094: * }
1095: * class X {
1096: * void test() {
1097: * B b = new B();
1098: * System.out.println(b.value + b.field1);
1099: * };
1100: * }
1101: * </pre>
1102: * </code>
1103: * then searching for declarations of accessed fields in method
1104: * <code>X.test()</code> would collect the fields
1105: * <code>B.value</code> and <code>A.field1</code>.
1106: * </p>
1107: *
1108: * @param workspace the workspace
1109: * @param enclosingElement the method, type, or compilation unit to be searched in
1110: * @param resultCollector a callback object to which each match is reported
1111: * @exception JavaModelException if the search failed. Reasons include:
1112: * <ul>
1113: * <li>the element doesn't exist</li>
1114: * <li>the classpath is incorrectly set</li>
1115: * </ul>
1116: * @deprecated Use {@link #searchDeclarationsOfAccessedFields(IJavaElement, SearchRequestor, IProgressMonitor)} instead.
1117: */
1118: public void searchDeclarationsOfAccessedFields(
1119: IWorkspace workspace, IJavaElement enclosingElement,
1120: IJavaSearchResultCollector resultCollector)
1121: throws JavaModelException {
1122: SearchPattern pattern = new DeclarationOfAccessedFieldsPattern(
1123: enclosingElement);
1124: this .basicEngine.searchDeclarations(enclosingElement,
1125: new ResultCollectorAdapter(resultCollector), pattern,
1126: resultCollector.getProgressMonitor());
1127: }
1128:
1129: /**
1130: * Searches for all declarations of the types referenced in the given element.
1131: * The element can be a compilation unit or a source type/method/field.
1132: * Reports the type declarations using the given requestor.
1133: * <p>
1134: * Consider the following code:
1135: * <code>
1136: * <pre>
1137: * class A {
1138: * }
1139: * class B extends A {
1140: * }
1141: * interface I {
1142: * int VALUE = 0;
1143: * }
1144: * class X {
1145: * void test() {
1146: * B b = new B();
1147: * this.foo(b, I.VALUE);
1148: * };
1149: * }
1150: * </pre>
1151: * </code>
1152: * then searching for declarations of referenced types in method <code>X.test()</code>
1153: * would collect the class <code>B</code> and the interface <code>I</code>.
1154: * </p>
1155: *
1156: * @param enclosingElement the field, method, type, or compilation unit to be searched in
1157: * @param requestor a callback object to which each match is reported
1158: * @param monitor the progress monitor used to report progress
1159: * @exception JavaModelException if the search failed. Reasons include:
1160: * <ul>
1161: * <li>the element doesn't exist</li>
1162: * <li>the classpath is incorrectly set</li>
1163: * </ul>
1164: *@exception IllegalArgumentException if the given java element has not the right type
1165: * @since 3.0
1166: */
1167: public void searchDeclarationsOfReferencedTypes(
1168: IJavaElement enclosingElement, SearchRequestor requestor,
1169: IProgressMonitor monitor) throws JavaModelException {
1170: this .basicEngine.searchDeclarationsOfReferencedTypes(
1171: enclosingElement, requestor, monitor);
1172: }
1173:
1174: /**
1175: * Searches for all declarations of the types referenced in the given element.
1176: * The element can be a compilation unit, a source type, or a source method.
1177: * Reports the type declarations using the given collector.
1178: * <p>
1179: * Consider the following code:
1180: * <code>
1181: * <pre>
1182: * class A {
1183: * }
1184: * class B extends A {
1185: * }
1186: * interface I {
1187: * int VALUE = 0;
1188: * }
1189: * class X {
1190: * void test() {
1191: * B b = new B();
1192: * this.foo(b, I.VALUE);
1193: * };
1194: * }
1195: * </pre>
1196: * </code>
1197: * then searching for declarations of referenced types in method <code>X.test()</code>
1198: * would collect the class <code>B</code> and the interface <code>I</code>.
1199: * </p>
1200: *
1201: * @param workspace the workspace
1202: * @param enclosingElement the method, type, or compilation unit to be searched in
1203: * @param resultCollector a callback object to which each match is reported
1204: * @exception JavaModelException if the search failed. Reasons include:
1205: * <ul>
1206: * <li>the element doesn't exist</li>
1207: * <li>the classpath is incorrectly set</li>
1208: * </ul>
1209: * @deprecated Use {@link #searchDeclarationsOfReferencedTypes(IJavaElement, SearchRequestor, IProgressMonitor)} instead.
1210: */
1211: public void searchDeclarationsOfReferencedTypes(
1212: IWorkspace workspace, IJavaElement enclosingElement,
1213: IJavaSearchResultCollector resultCollector)
1214: throws JavaModelException {
1215: SearchPattern pattern = new DeclarationOfReferencedTypesPattern(
1216: enclosingElement);
1217: this .basicEngine.searchDeclarations(enclosingElement,
1218: new ResultCollectorAdapter(resultCollector), pattern,
1219: resultCollector.getProgressMonitor());
1220: }
1221:
1222: /**
1223: * Searches for all declarations of the methods invoked in the given element.
1224: * The element can be a compilation unit or a source type/method/field.
1225: * Reports the method declarations using the given requestor.
1226: * <p>
1227: * Consider the following code:
1228: * <code>
1229: * <pre>
1230: * class A {
1231: * void foo() {};
1232: * void bar() {};
1233: * }
1234: * class B extends A {
1235: * void foo() {};
1236: * }
1237: * class X {
1238: * void test() {
1239: * A a = new B();
1240: * a.foo();
1241: * B b = (B)a;
1242: * b.bar();
1243: * };
1244: * }
1245: * </pre>
1246: * </code>
1247: * then searching for declarations of sent messages in method
1248: * <code>X.test()</code> would collect the methods
1249: * <code>A.foo()</code>, <code>B.foo()</code>, and <code>A.bar()</code>.
1250: * </p>
1251: *
1252: * @param enclosingElement the field, method, type or compilation unit to be searched in
1253: * @param requestor a callback object to which each match is reported
1254: * @param monitor the progress monitor used to report progress
1255: * @exception JavaModelException if the search failed. Reasons include:
1256: * <ul>
1257: * <li>the element doesn't exist</li>
1258: * <li>the classpath is incorrectly set</li>
1259: * </ul>
1260: *@exception IllegalArgumentException if the given java element has not the right type
1261: * @since 3.0
1262: */
1263: public void searchDeclarationsOfSentMessages(
1264: IJavaElement enclosingElement, SearchRequestor requestor,
1265: IProgressMonitor monitor) throws JavaModelException {
1266: this .basicEngine.searchDeclarationsOfSentMessages(
1267: enclosingElement, requestor, monitor);
1268: }
1269:
1270: /**
1271: * Searches for all declarations of the methods invoked in the given element.
1272: * The element can be a compilation unit, a source type, or a source method.
1273: * Reports the method declarations using the given collector.
1274: * <p>
1275: * Consider the following code:
1276: * <code>
1277: * <pre>
1278: * class A {
1279: * void foo() {};
1280: * void bar() {};
1281: * }
1282: * class B extends A {
1283: * void foo() {};
1284: * }
1285: * class X {
1286: * void test() {
1287: * A a = new B();
1288: * a.foo();
1289: * B b = (B)a;
1290: * b.bar();
1291: * };
1292: * }
1293: * </pre>
1294: * </code>
1295: * then searching for declarations of sent messages in method
1296: * <code>X.test()</code> would collect the methods
1297: * <code>A.foo()</code>, <code>B.foo()</code>, and <code>A.bar()</code>.
1298: * </p>
1299: *
1300: * @param workspace the workspace
1301: * @param enclosingElement the method, type, or compilation unit to be searched in
1302: * @param resultCollector a callback object to which each match is reported
1303: * @exception JavaModelException if the search failed. Reasons include:
1304: * <ul>
1305: * <li>the element doesn't exist</li>
1306: * <li>the classpath is incorrectly set</li>
1307: * </ul>
1308: * @deprecated Use {@link #searchDeclarationsOfSentMessages(IJavaElement, SearchRequestor, IProgressMonitor)} instead.
1309: */
1310: public void searchDeclarationsOfSentMessages(IWorkspace workspace,
1311: IJavaElement enclosingElement,
1312: IJavaSearchResultCollector resultCollector)
1313: throws JavaModelException {
1314: SearchPattern pattern = new DeclarationOfReferencedMethodsPattern(
1315: enclosingElement);
1316: this .basicEngine.searchDeclarations(enclosingElement,
1317: new ResultCollectorAdapter(resultCollector), pattern,
1318: resultCollector.getProgressMonitor());
1319: }
1320: }
|