01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring;
11:
12: import org.eclipse.core.runtime.CoreException;
13:
14: import org.eclipse.jdt.core.ICompilationUnit;
15: import org.eclipse.jdt.core.IJavaProject;
16: import org.eclipse.jdt.core.JavaCore;
17: import org.eclipse.jdt.core.ToolFactory;
18: import org.eclipse.jdt.core.compiler.IScanner;
19: import org.eclipse.jdt.core.search.SearchMatch;
20:
21: import org.eclipse.jdt.internal.corext.util.SearchUtils;
22:
23: /**
24: * Collects the results returned by a <code>SearchEngine</code>.
25: * Only collects matches in CUs ands offers a scanner to trim match ranges.
26: */
27: public abstract class CuCollectingSearchRequestor extends
28: CollectingSearchRequestor {
29:
30: private ICompilationUnit fCuCache;
31: private IScanner fScannerCache;
32:
33: protected IScanner getScanner(ICompilationUnit unit) {
34: if (unit.equals(fCuCache))
35: return fScannerCache;
36:
37: fCuCache = unit;
38: IJavaProject project = unit.getJavaProject();
39: String sourceLevel = project.getOption(
40: JavaCore.COMPILER_SOURCE, true);
41: String complianceLevel = project.getOption(
42: JavaCore.COMPILER_COMPLIANCE, true);
43: fScannerCache = ToolFactory.createScanner(false, false, false,
44: sourceLevel, complianceLevel);
45: return fScannerCache;
46: }
47:
48: /**
49: * This is an internal method. Do not call from subclasses!
50: * Use {@link #collectMatch(SearchMatch)} instead.
51: * @param match
52: * @throws CoreException
53: * @deprecated
54: */
55: public final void acceptSearchMatch(SearchMatch match)
56: throws CoreException {
57: ICompilationUnit unit = SearchUtils.getCompilationUnit(match);
58: if (unit == null)
59: return;
60: acceptSearchMatch(unit, match);
61: }
62:
63: public void collectMatch(SearchMatch match) throws CoreException {
64: super .acceptSearchMatch(match);
65: }
66:
67: protected abstract void acceptSearchMatch(ICompilationUnit unit,
68: SearchMatch match) throws CoreException;
69:
70: public void endReporting() {
71: fCuCache = null;
72: fScannerCache = null;
73: }
74: }
|