001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring;
011:
012: import java.util.ArrayList;
013: import java.util.Collection;
014: import java.util.Collections;
015: import java.util.HashMap;
016: import java.util.HashSet;
017: import java.util.Iterator;
018: import java.util.LinkedList;
019: import java.util.List;
020: import java.util.Map;
021: import java.util.Set;
022:
023: import org.eclipse.core.runtime.Assert;
024: import org.eclipse.core.runtime.CoreException;
025: import org.eclipse.core.runtime.IProgressMonitor;
026: import org.eclipse.core.runtime.NullProgressMonitor;
027: import org.eclipse.core.runtime.SubProgressMonitor;
028:
029: import org.eclipse.core.resources.IProject;
030: import org.eclipse.core.resources.IResource;
031:
032: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
033: import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
034:
035: import org.eclipse.jdt.core.ICompilationUnit;
036: import org.eclipse.jdt.core.IJavaElement;
037: import org.eclipse.jdt.core.IJavaProject;
038: import org.eclipse.jdt.core.JavaCore;
039: import org.eclipse.jdt.core.JavaModelException;
040: import org.eclipse.jdt.core.WorkingCopyOwner;
041: import org.eclipse.jdt.core.search.IJavaSearchScope;
042: import org.eclipse.jdt.core.search.SearchEngine;
043: import org.eclipse.jdt.core.search.SearchMatch;
044: import org.eclipse.jdt.core.search.SearchPattern;
045: import org.eclipse.jdt.core.search.SearchRequestor;
046:
047: import org.eclipse.jdt.internal.corext.util.Messages;
048: import org.eclipse.jdt.internal.corext.util.SearchUtils;
049:
050: /**
051: * Helper class to use the search engine in refactorings.
052: *
053: * @since 3.1
054: */
055: public final class RefactoringSearchEngine2 {
056:
057: /** Default implementation of a search requestor */
058: private static class DefaultSearchRequestor implements
059: IRefactoringSearchRequestor {
060:
061: public final SearchMatch acceptSearchMatch(
062: final SearchMatch match) {
063: return match;
064: }
065: }
066:
067: /** Search requestor which only collects compilation units */
068: private class RefactoringCompilationUnitCollector extends
069: RefactoringSearchCollector {
070:
071: /** The collected compilation units */
072: private final Set fCollectedUnits = new HashSet();
073:
074: /** The inaccurate matches */
075: private final Set fInaccurateMatches = new HashSet();
076:
077: public final void acceptSearchMatch(final SearchMatch match)
078: throws CoreException {
079: final SearchMatch accepted = fRequestor
080: .acceptSearchMatch(match);
081: if (accepted != null) {
082: final IResource resource = accepted.getResource();
083: if (!resource.equals(fLastResource)) {
084: final IJavaElement element = JavaCore
085: .create(resource);
086: if (element instanceof ICompilationUnit)
087: fCollectedUnits.add(element);
088: }
089: if (fInaccurate
090: && accepted.getAccuracy() == SearchMatch.A_INACCURATE
091: && !fInaccurateMatches.contains(accepted)) {
092: fStatus
093: .addEntry(
094: fSeverity,
095: Messages
096: .format(
097: RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match,
098: accepted
099: .getResource()
100: .getName()),
101: null, null,
102: RefactoringStatusEntry.NO_CODE);
103: fInaccurateMatches.add(accepted);
104: }
105: }
106: }
107:
108: public final void clearResults() {
109: super .clearResults();
110: fCollectedUnits.clear();
111: fInaccurateMatches.clear();
112: }
113:
114: public final Collection getBinaryResources() {
115: return Collections.EMPTY_SET;
116: }
117:
118: public final Collection getCollectedMatches() {
119: return fCollectedUnits;
120: }
121:
122: public final Collection getInaccurateMatches() {
123: return fInaccurateMatches;
124: }
125: }
126:
127: private abstract class RefactoringSearchCollector extends
128: SearchRequestor {
129:
130: protected IResource fLastResource = null;
131:
132: public void clearResults() {
133: fLastResource = null;
134: }
135:
136: public abstract Collection getBinaryResources();
137:
138: public abstract Collection getCollectedMatches();
139:
140: public abstract Collection getInaccurateMatches();
141: }
142:
143: /** Search requestor which collects every search match */
144: private class RefactoringSearchMatchCollector extends
145: RefactoringSearchCollector {
146:
147: /** The binary resources */
148: private final Set fBinaryResources = new HashSet();
149:
150: /** The collected matches */
151: private final List fCollectedMatches = new ArrayList();
152:
153: /** The inaccurate matches */
154: private final Set fInaccurateMatches = new HashSet();
155:
156: public final void acceptSearchMatch(final SearchMatch match)
157: throws CoreException {
158: final SearchMatch accepted = fRequestor
159: .acceptSearchMatch(match);
160: if (accepted != null) {
161: fCollectedMatches.add(accepted);
162: final IResource resource = accepted.getResource();
163: if (!resource.equals(fLastResource)) {
164: if (fBinary) {
165: final IJavaElement element = JavaCore
166: .create(resource);
167: if (!(element instanceof ICompilationUnit)) {
168: final IProject project = resource
169: .getProject();
170: if (!fGrouping)
171: fStatus
172: .addEntry(
173: fSeverity,
174: Messages
175: .format(
176: RefactoringCoreMessages.RefactoringSearchEngine_binary_match_ungrouped,
177: project
178: .getName()),
179: null,
180: null,
181: RefactoringStatusEntry.NO_CODE);
182: else if (!fBinaryResources
183: .contains(resource))
184: fStatus
185: .addEntry(
186: fSeverity,
187: Messages
188: .format(
189: RefactoringCoreMessages.RefactoringSearchEngine_binary_match_grouped,
190: project
191: .getName()),
192: null,
193: null,
194: RefactoringStatusEntry.NO_CODE);
195: fBinaryResources.add(resource);
196: }
197: }
198: if (fInaccurate
199: && accepted.getAccuracy() == SearchMatch.A_INACCURATE
200: && !fInaccurateMatches.contains(accepted)) {
201: fStatus
202: .addEntry(
203: fSeverity,
204: Messages
205: .format(
206: RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match,
207: resource
208: .getName()),
209: null, null,
210: RefactoringStatusEntry.NO_CODE);
211: fInaccurateMatches.add(accepted);
212: }
213: }
214: }
215: }
216:
217: public final void clearResults() {
218: super .clearResults();
219: fCollectedMatches.clear();
220: fInaccurateMatches.clear();
221: fBinaryResources.clear();
222: }
223:
224: public final Collection getBinaryResources() {
225: return fBinaryResources;
226: }
227:
228: public final Collection getCollectedMatches() {
229: return fCollectedMatches;
230: }
231:
232: public final Collection getInaccurateMatches() {
233: return fInaccurateMatches;
234: }
235: }
236:
237: /** The compilation unit granularity */
238: public static final int GRANULARITY_COMPILATION_UNIT = 2;
239:
240: /** The search match granularity */
241: public static final int GRANULARITY_SEARCH_MATCH = 1;
242:
243: /** Should binary matches be filtered? */
244: private boolean fBinary = false;
245:
246: /** The refactoring search collector */
247: private RefactoringSearchCollector fCollector = null;
248:
249: /** The search granularity */
250: private int fGranularity = GRANULARITY_SEARCH_MATCH;
251:
252: /** Should the matches be grouped by resource? */
253: private boolean fGrouping = true;
254:
255: /** Should inaccurate matches be filtered? */
256: private boolean fInaccurate = true;
257:
258: /** The working copy owner, or <code>null</code> */
259: private WorkingCopyOwner fOwner = null;
260:
261: /** The search pattern, or <code>null</code> */
262: private SearchPattern fPattern = null;
263:
264: /** The search requestor */
265: private IRefactoringSearchRequestor fRequestor = new DefaultSearchRequestor();
266:
267: /** The search scope */
268: private IJavaSearchScope fScope = SearchEngine
269: .createWorkspaceScope();
270:
271: /** The severity */
272: private int fSeverity = RefactoringStatus.WARNING;
273:
274: /** The search status */
275: private RefactoringStatus fStatus = new RefactoringStatus();
276:
277: /** The working copies */
278: private ICompilationUnit[] fWorkingCopies = {};
279:
280: /**
281: * Creates a new refactoring search engine.
282: */
283: public RefactoringSearchEngine2() {
284: // Do nothing
285: }
286:
287: /**
288: * Creates a new refactoring search engine.
289: *
290: * @param pattern the search pattern
291: */
292: public RefactoringSearchEngine2(final SearchPattern pattern) {
293: Assert.isNotNull(pattern);
294: fPattern = pattern;
295: }
296:
297: /**
298: * Clears all results found so far, and sets resets the status to {@link RefactoringStatus#OK}.
299: */
300: public final void clearResults() {
301: getCollector().clearResults();
302: fStatus = new RefactoringStatus();
303: }
304:
305: /**
306: * Returns the affected compilation units of the previous search queries.
307: * <p>
308: * In order to retrieve the compilation units, grouping by resource must have been enabled before searching.
309: *
310: * @return the compilation units of the previous queries
311: */
312: public final ICompilationUnit[] getAffectedCompilationUnits() {
313: if (fGranularity == GRANULARITY_COMPILATION_UNIT) {
314: final Collection collection = getCollector()
315: .getCollectedMatches();
316: final ICompilationUnit[] units = new ICompilationUnit[collection
317: .size()];
318: int index = 0;
319: for (final Iterator iterator = collection.iterator(); iterator
320: .hasNext(); index++)
321: units[index] = (ICompilationUnit) iterator.next();
322: return units;
323: } else {
324: final SearchResultGroup[] groups = getGroupedMatches();
325: final ICompilationUnit[] units = new ICompilationUnit[groups.length];
326: for (int index = 0; index < groups.length; index++)
327: units[index] = groups[index].getCompilationUnit();
328: return units;
329: }
330: }
331:
332: /**
333: * Returns the affected java projects of the previous search queries.
334: * <p>
335: * In order to retrieve the java projects, grouping by resource must have been enabled before searching.
336: *
337: * @return the java projects of the previous queries (element type: <code><IJavaProject, Collection<SearchResultGroup>></code>)
338: */
339: public final Map getAffectedProjects() {
340: final Map map = new HashMap();
341: IJavaProject project = null;
342: ICompilationUnit unit = null;
343: if (fGranularity == GRANULARITY_COMPILATION_UNIT) {
344: final ICompilationUnit[] units = getAffectedCompilationUnits();
345: for (int index = 0; index < units.length; index++) {
346: unit = units[index];
347: project = unit.getJavaProject();
348: if (project != null) {
349: Set set = (Set) map.get(project);
350: if (set == null) {
351: set = new HashSet();
352: map.put(project, set);
353: }
354: set.add(unit);
355: }
356: }
357: } else {
358: final SearchResultGroup[] groups = getGroupedMatches();
359: SearchResultGroup group = null;
360: for (int index = 0; index < groups.length; index++) {
361: group = groups[index];
362: unit = group.getCompilationUnit();
363: if (unit != null) {
364: project = unit.getJavaProject();
365: if (project != null) {
366: Set set = (Set) map.get(project);
367: if (set == null) {
368: set = new HashSet();
369: map.put(project, set);
370: }
371: set.add(group);
372: }
373: }
374: }
375: }
376: return map;
377: }
378:
379: /**
380: * Returns the refactoring search collector.
381: *
382: * @return the refactoring search collector
383: */
384: private RefactoringSearchCollector getCollector() {
385: if (fCollector == null) {
386: if (fGranularity == GRANULARITY_COMPILATION_UNIT)
387: fCollector = new RefactoringCompilationUnitCollector();
388: else if (fGranularity == GRANULARITY_SEARCH_MATCH)
389: fCollector = new RefactoringSearchMatchCollector();
390: else
391: Assert.isTrue(false);
392: }
393: return fCollector;
394: }
395:
396: /**
397: * Returns the found search matches in grouped by their containing resource.
398: *
399: * @return the found search matches
400: */
401: private SearchResultGroup[] getGroupedMatches() {
402: final Map grouped = new HashMap();
403: List matches = null;
404: IResource resource = null;
405: SearchMatch match = null;
406: for (final Iterator iterator = getSearchMatches().iterator(); iterator
407: .hasNext();) {
408: match = (SearchMatch) iterator.next();
409: resource = match.getResource();
410: if (!grouped.containsKey(resource))
411: grouped.put(resource, new ArrayList(4));
412: matches = (List) grouped.get(resource);
413: matches.add(match);
414: }
415: if (fBinary) {
416: final Collection collection = getCollector()
417: .getBinaryResources();
418: for (final Iterator iterator = grouped.keySet().iterator(); iterator
419: .hasNext();) {
420: resource = (IResource) iterator.next();
421: if (collection.contains(resource))
422: iterator.remove();
423: }
424: }
425: final SearchResultGroup[] result = new SearchResultGroup[grouped
426: .keySet().size()];
427: int index = 0;
428: for (final Iterator iterator = grouped.keySet().iterator(); iterator
429: .hasNext();) {
430: resource = (IResource) iterator.next();
431: matches = (List) grouped.get(resource);
432: result[index++] = new SearchResultGroup(resource,
433: ((SearchMatch[]) matches
434: .toArray(new SearchMatch[matches.size()])));
435: }
436: return result;
437: }
438:
439: /**
440: * Returns the search pattern currently used for searching.
441: *
442: * @return the search pattern
443: */
444: public final SearchPattern getPattern() {
445: return fPattern;
446: }
447:
448: /**
449: * Returns the results of the previous search queries.
450: * <p>
451: * The result depends on the following conditions:
452: * <ul>
453: * <li>If the search granularity is {@link #GRANULARITY_COMPILATION_UNIT}, the results are elements of type {@link ICompilationUnit}.</li>
454: * <li>If grouping by resource is enabled, the results are elements of type {@link SearchResultGroup}, otherwise the elements are of type {@link SearchMatch}.</li>
455: * </ul>
456: *
457: * @return the results of the previous queries
458: */
459: public final Object[] getResults() {
460: if (fGranularity == GRANULARITY_COMPILATION_UNIT)
461: return getAffectedCompilationUnits();
462: else {
463: if (fGrouping)
464: return getGroupedMatches();
465: else
466: return getUngroupedMatches();
467: }
468: }
469:
470: /**
471: * Returns the search matches filtered by their accuracy.
472: *
473: * @return the filtered search matches
474: */
475: private Collection getSearchMatches() {
476: Collection results = null;
477: if (fInaccurate) {
478: results = new LinkedList(getCollector()
479: .getCollectedMatches());
480: final Collection collection = getCollector()
481: .getInaccurateMatches();
482: SearchMatch match = null;
483: for (final Iterator iterator = results.iterator(); iterator
484: .hasNext();) {
485: match = (SearchMatch) iterator.next();
486: if (collection.contains(match))
487: iterator.remove();
488: }
489: } else
490: results = getCollector().getCollectedMatches();
491: return results;
492: }
493:
494: /**
495: * Returns the refactoring status of this search engine.
496: *
497: * @return the refactoring status
498: */
499: public final RefactoringStatus getStatus() {
500: return fStatus;
501: }
502:
503: /**
504: * Returns the found search matches in no particular order.
505: *
506: * @return the found search matches
507: */
508: private SearchMatch[] getUngroupedMatches() {
509: Collection results = null;
510: if (fBinary) {
511: results = new LinkedList(getSearchMatches());
512: final Collection collection = getCollector()
513: .getBinaryResources();
514: SearchMatch match = null;
515: for (final Iterator iterator = results.iterator(); iterator
516: .hasNext();) {
517: match = (SearchMatch) iterator.next();
518: if (collection.contains(match.getResource()))
519: iterator.remove();
520: }
521: } else
522: results = getSearchMatches();
523: final SearchMatch[] matches = new SearchMatch[results.size()];
524: results.toArray(matches);
525: return matches;
526: }
527:
528: /**
529: * Performs the search according to the specified pattern.
530: *
531: * @param monitor the progress monitor, or <code>null</code>
532: * @throws JavaModelException if an error occurs during search
533: */
534: public final void searchPattern(IProgressMonitor monitor)
535: throws JavaModelException {
536: Assert.isNotNull(fPattern);
537: if (monitor == null)
538: monitor = new NullProgressMonitor();
539: try {
540: monitor.beginTask("", 1); //$NON-NLS-1$
541: monitor
542: .setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_occurrences);
543: try {
544: SearchEngine engine = null;
545: if (fOwner != null)
546: engine = new SearchEngine(fOwner);
547: else
548: engine = new SearchEngine(fWorkingCopies);
549: engine
550: .search(
551: fPattern,
552: SearchUtils
553: .getDefaultSearchParticipants(),
554: fScope,
555: getCollector(),
556: new SubProgressMonitor(
557: monitor,
558: 1,
559: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
560: } catch (CoreException exception) {
561: throw new JavaModelException(exception);
562: }
563: } finally {
564: monitor.done();
565: }
566: }
567:
568: /**
569: * Performs the search of referenced fields.
570: *
571: * @param element the java element whose referenced fields have to be found
572: * @param monitor the progress monitor, or <code>null</code>
573: * @throws JavaModelException if an error occurs during search
574: */
575: public final void searchReferencedFields(
576: final IJavaElement element, IProgressMonitor monitor)
577: throws JavaModelException {
578: Assert.isNotNull(element);
579: if (monitor == null)
580: monitor = new NullProgressMonitor();
581: try {
582: monitor.beginTask("", 1); //$NON-NLS-1$
583: monitor
584: .setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_fields);
585: try {
586: SearchEngine engine = null;
587: if (fOwner != null)
588: engine = new SearchEngine(fOwner);
589: else
590: engine = new SearchEngine(fWorkingCopies);
591: engine
592: .searchDeclarationsOfAccessedFields(
593: element,
594: getCollector(),
595: new SubProgressMonitor(
596: monitor,
597: 1,
598: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
599: } catch (CoreException exception) {
600: throw new JavaModelException(exception);
601: }
602: } finally {
603: monitor.done();
604: }
605: }
606:
607: /**
608: * Performs the search of referenced methods.
609: *
610: * @param element the java element whose referenced methods have to be found
611: * @param monitor the progress monitor, or <code>null</code>
612: * @throws JavaModelException if an error occurs during search
613: */
614: public final void searchReferencedMethods(
615: final IJavaElement element, IProgressMonitor monitor)
616: throws JavaModelException {
617: Assert.isNotNull(element);
618: if (monitor == null)
619: monitor = new NullProgressMonitor();
620: try {
621: monitor.beginTask("", 1); //$NON-NLS-1$
622: monitor
623: .setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_methods);
624: try {
625: SearchEngine engine = null;
626: if (fOwner != null)
627: engine = new SearchEngine(fOwner);
628: else
629: engine = new SearchEngine(fWorkingCopies);
630: engine
631: .searchDeclarationsOfSentMessages(
632: element,
633: getCollector(),
634: new SubProgressMonitor(
635: monitor,
636: 1,
637: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
638: } catch (CoreException exception) {
639: throw new JavaModelException(exception);
640: }
641: } finally {
642: monitor.done();
643: }
644: }
645:
646: /**
647: * Performs the search of referenced types.
648: *
649: * @param element the java element whose referenced types have to be found
650: * @param monitor the progress monitor, or <code>null</code>
651: * @throws JavaModelException if an error occurs during search
652: */
653: public final void searchReferencedTypes(final IJavaElement element,
654: IProgressMonitor monitor) throws JavaModelException {
655: Assert.isNotNull(element);
656: if (monitor == null)
657: monitor = new NullProgressMonitor();
658: try {
659: monitor.beginTask("", 1); //$NON-NLS-1$
660: monitor
661: .setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_types);
662: try {
663: SearchEngine engine = null;
664: if (fOwner != null)
665: engine = new SearchEngine(fOwner);
666: else
667: engine = new SearchEngine(fWorkingCopies);
668: engine
669: .searchDeclarationsOfReferencedTypes(
670: element,
671: getCollector(),
672: new SubProgressMonitor(
673: monitor,
674: 1,
675: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
676: } catch (CoreException exception) {
677: throw new JavaModelException(exception);
678: }
679: } finally {
680: monitor.done();
681: }
682: }
683:
684: /**
685: * Determines how search matches are filtered.
686: * <p>
687: * This method must be called before start searching. The default is to filter inaccurate matches only.
688: *
689: * @param inaccurate <code>true</code> to filter inaccurate matches, <code>false</code> otherwise
690: * @param binary <code>true</code> to filter binary matches, <code>false</code> otherwise
691: */
692: public final void setFiltering(final boolean inaccurate,
693: final boolean binary) {
694: fInaccurate = inaccurate;
695: fBinary = binary;
696: }
697:
698: /**
699: * Sets the granularity to use during the searches.
700: * <p>
701: * This method must be called before start searching. The default is a granularity of {@link #GRANULARITY_SEARCH_MATCH}.
702: *
703: * @param granularity The granularity to use. Must be one of the <code>GRANULARITY_XXX</code> constants.
704: */
705: public final void setGranularity(final int granularity) {
706: Assert.isTrue(granularity == GRANULARITY_COMPILATION_UNIT
707: || granularity == GRANULARITY_SEARCH_MATCH);
708: fGranularity = granularity;
709: }
710:
711: /**
712: * Sets the working copies to take precedence during the searches.
713: * <p>
714: * This method must be called before start searching. The default is to use no working copies
715: *
716: * @param copies the working copies to use
717: */
718: public final void setWorkingCopies(final ICompilationUnit[] copies) {
719: Assert.isNotNull(copies);
720: fWorkingCopies = new ICompilationUnit[copies.length];
721: System.arraycopy(copies, 0, fWorkingCopies, 0, copies.length);
722: }
723:
724: /**
725: * Determines how search matches are grouped.
726: * <p>
727: * This method must be called before start searching. The default is to group by containing resource.
728: *
729: * @param grouping <code>true</code> to group matches by their containing resource, <code>false</code> otherwise
730: */
731: public final void setGrouping(final boolean grouping) {
732: fGrouping = grouping;
733: }
734:
735: /**
736: * Sets the disjunction of search patterns to be used during search.
737: * <p>
738: * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
739: *
740: * @param first the first search pattern to set
741: * @param second the second search pattern to set
742: */
743: public final void setOrPattern(final SearchPattern first,
744: final SearchPattern second) {
745: Assert.isNotNull(first);
746: Assert.isNotNull(second);
747: fPattern = SearchPattern.createOrPattern(first, second);
748: }
749:
750: /**
751: * Sets the working copy owner to use during search.
752: * <p>
753: * This method must be called before start searching. The default is to use no working copy owner.
754: *
755: * @param owner the working copy owner to use, or <code>null</code> to use none
756: */
757: public final void setOwner(final WorkingCopyOwner owner) {
758: fOwner = owner;
759: }
760:
761: /**
762: * Sets the search pattern to be used during search.
763: * <p>
764: * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
765: *
766: * @param elements the set of elements
767: * @param limitTo determines the nature of the expected matches. This is a combination of {@link org.eclipse.jdt.core.search.IJavaSearchConstants}.
768: */
769: public final void setPattern(final IJavaElement[] elements,
770: final int limitTo) {
771: Assert.isNotNull(elements);
772: Assert.isTrue(elements.length > 0);
773: SearchPattern pattern = SearchPattern.createPattern(
774: elements[0], limitTo,
775: SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
776: IJavaElement element = null;
777: for (int index = 1; index < elements.length; index++) {
778: element = elements[index];
779: pattern = SearchPattern.createOrPattern(pattern,
780: SearchPattern.createPattern(element, limitTo,
781: SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
782: }
783: setPattern(pattern);
784: }
785:
786: /**
787: * Sets the search pattern to be used during search.
788: * <p>
789: * This method must be called before {@link RefactoringSearchEngine2#searchPattern(IProgressMonitor)}
790: *
791: * @param pattern the search pattern to set
792: */
793: public final void setPattern(final SearchPattern pattern) {
794: Assert.isNotNull(pattern);
795: fPattern = pattern;
796: }
797:
798: /**
799: * Sets the search requestor for this search engine.
800: * <p>
801: * This method must be called before start searching. The default is a non-filtering search requestor.
802: *
803: * @param requestor the search requestor to set
804: */
805: public final void setRequestor(
806: final IRefactoringSearchRequestor requestor) {
807: Assert.isNotNull(requestor);
808: fRequestor = requestor;
809: }
810:
811: /**
812: * Sets the search scope for this search engine.
813: * <p>
814: * This method must be called before start searching. The default is the entire workspace as search scope.
815: *
816: * @param scope the search scope to set
817: */
818: public final void setScope(final IJavaSearchScope scope) {
819: Assert.isNotNull(scope);
820: fScope = scope;
821: }
822:
823: /**
824: * Sets the severity of the generated status entries.
825: * <p>
826: * This method must be called before start searching. The default is a severity of {@link RefactoringStatus#OK}.
827: *
828: * @param severity the severity to set
829: */
830: public final void setSeverity(final int severity) {
831: Assert.isTrue(severity == RefactoringStatus.WARNING
832: || severity == RefactoringStatus.INFO
833: || severity == RefactoringStatus.FATAL
834: || severity == RefactoringStatus.ERROR);
835: fSeverity = severity;
836: }
837:
838: /**
839: * Sets the refactoring status for this search engine.
840: * <p>
841: * This method must be called before start searching. The default is an empty status with status {@link RefactoringStatus#OK}.
842: *
843: * @param status the refactoring status to set
844: */
845: public final void setStatus(final RefactoringStatus status) {
846: Assert.isNotNull(status);
847: fStatus = status;
848: }
849: }
|