]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.corext.refactoring; | |
12 | ||
13 | import org.eclipse.core.runtime.CoreException; | |
14 | ||
15 | import org.eclipse.jdt.core.ICompilationUnit; | |
16 | import org.eclipse.jdt.core.IJavaProject; | |
17 | import org.eclipse.jdt.core.JavaCore; | |
18 | import org.eclipse.jdt.core.ToolFactory; | |
19 | import org.eclipse.jdt.core.compiler.IScanner; | |
20 | import org.eclipse.jdt.core.search.SearchMatch; | |
21 | ||
22 | import org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext; | |
23 | import org.eclipse.jdt.internal.corext.util.SearchUtils; | |
24 | ||
25 | /** | |
26 | * Collects the results returned by a <code>SearchEngine</code>. | |
27 | * Only collects matches in CUs ands offers a scanner to trim match ranges. | |
28 | * If a {@link ReferencesInBinaryContext} is passed, matches that are | |
29 | * inside a binary element are not collected (but added to the context if they are accurate). | |
30 | */ | |
31 | public class CuCollectingSearchRequestor extends CollectingSearchRequestor { | |
32 | ||
33 | private IJavaProject fProjectCache; | |
34 | private IScanner fScannerCache; | |
35 | ||
36 | public CuCollectingSearchRequestor() { | |
37 | this(null); | |
38 | } | |
39 | ||
40 | public CuCollectingSearchRequestor(ReferencesInBinaryContext binaryRefs) { | |
41 | super(binaryRefs); | |
42 | } | |
43 | ||
44 | protected IScanner getScanner(ICompilationUnit unit) { | |
45 | IJavaProject project= unit.getJavaProject(); | |
46 | if (project.equals(fProjectCache)) | |
47 | return fScannerCache; | |
48 | ||
49 | fProjectCache= project; | |
50 | String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true); | |
51 | String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true); | |
52 | fScannerCache= ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel); | |
53 | return fScannerCache; | |
54 | } | |
55 | ||
56 | /** | |
57 | * This is an internal method. Do not call from subclasses! | |
58 | * Use {@link #collectMatch(SearchMatch)} instead. | |
59 | * @param match | |
60 | * @throws CoreException | |
61 | * @deprecated | |
62 | */ | |
63 | @Override | |
64 | public final void acceptSearchMatch(SearchMatch match) throws CoreException { | |
65 | if (filterMatch(match)) | |
66 | return; | |
67 | ||
68 | ICompilationUnit unit= SearchUtils.getCompilationUnit(match); | |
69 | if (unit != null) { | |
70 | acceptSearchMatch(unit, match); | |
71 | } | |
72 | } | |
73 | ||
74 | /** | |
75 | * Handles the given match in the given compilation unit. | |
76 | * The default implementation accepts all matches. | |
77 | * Subclasses can override and call {@link #collectMatch(SearchMatch)} to collect matches. | |
78 | * | |
79 | * @param unit the enclosing CU of the match, never <code>null</code> | |
80 | * @param match the match | |
81 | * @throws CoreException if something bad happens | |
82 | */ | |
83 | protected void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException { | |
84 | collectMatch(match); | |
85 | } | |
86 | ||
87 | @Override | |
88 | public void endReporting() { | |
89 | fProjectCache= null; | |
90 | fScannerCache= null; | |
91 | } | |
92 | } | |
93 | ||
94 |