KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > CuCollectingSearchRequestor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.util.SearchUtils;
23
24 /**
25  * Collects the results returned by a <code>SearchEngine</code>.
26  * Only collects matches in CUs ands offers a scanner to trim match ranges.
27  */

28 public abstract class CuCollectingSearchRequestor extends 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 JavaDoc sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
40         String JavaDoc complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
41         fScannerCache= ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel);
42         return fScannerCache;
43     }
44     
45     /**
46      * This is an internal method. Do not call from subclasses!
47      * Use {@link #collectMatch(SearchMatch)} instead.
48      * @param match
49      * @throws CoreException
50      * @deprecated
51      */

52     public final void acceptSearchMatch(SearchMatch match) throws CoreException {
53         ICompilationUnit unit= SearchUtils.getCompilationUnit(match);
54         if (unit == null)
55             return;
56         acceptSearchMatch(unit, match);
57     }
58     
59     public void collectMatch(SearchMatch match) throws CoreException {
60         super.acceptSearchMatch(match);
61     }
62     
63     protected abstract void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException;
64
65     public void endReporting() {
66         fCuCache= null;
67         fScannerCache= null;
68     }
69 }
70
71
72
Popular Tags