KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > fix > ICleanUp


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.ui.fix;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17
18 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
19
20 import org.eclipse.jdt.core.ICompilationUnit;
21 import org.eclipse.jdt.core.IJavaProject;
22 import org.eclipse.jdt.core.dom.CompilationUnit;
23
24 import org.eclipse.jdt.internal.corext.fix.IFix;
25
26 import org.eclipse.jdt.ui.text.java.IProblemLocation;
27
28 /**
29  * A clean up can solve several different problems in a given
30  * <code>CompilationUnit</code>. The <code>CompilationUnit</code> is
31  * compiled by using the compiler options returned by
32  * <code>getRequiredOptions</code>.
33  *
34  * @since 3.2
35  */

36 public interface ICleanUp {
37     
38     /**
39      * Does this clean up require an AST for the given <code>unit</code>. If
40      * true is returned an AST for unit is created by the clean up
41      * infrastructure and {@link #createFix(CompilationUnit)} is executed,
42      * otherwise {@link #createFix(ICompilationUnit)} is executed. The source
43      * from which the AST is created may be differ from the source of
44      * <code>unit</code>.
45      * <p>
46      * Implementors should return false whenever possible because creating an
47      * AST is expensive.
48      *
49      * @param unit
50      * the unit to create an ast for
51      * @return true if {@link #createFix(CompilationUnit)} must be executed,
52      * false if {@link #createFix(ICompilationUnit)} must be executed
53      */

54     public abstract boolean requireAST(ICompilationUnit unit) throws CoreException;
55     
56     /**
57      * Create an <code>IFix</code> which fixes all problems in
58      * <code>unit</code> or <code>null</code> if nothing to fix.
59      * <p>
60      * This is called iff {@link #requireAST(ICompilationUnit)} returns
61      * <code>false</code>.
62      *
63      * @param unit
64      * the ICompilationUnit to fix, not null
65      * @return the fix for the problems or <code>null</code> if nothing to fix
66      */

67     public abstract IFix createFix(ICompilationUnit unit) throws CoreException;
68     
69     /**
70      * Create an <code>IFix</code> which fixes all problems in
71      * <code>compilationUnit</code> or <code>null</code> if nothing to fix.
72      * <p>
73      * This is called iff {@link #requireAST(ICompilationUnit)} returns
74      * <code>true</code>.
75      *
76      * @param compilationUnit
77      * The compilation unit to fix, may be null
78      * @return The fix or null if no fixes possible
79      * @throws CoreException
80      */

81     public abstract IFix createFix(CompilationUnit compilationUnit) throws CoreException;
82     
83     /**
84      * Create a <code>IFix</code> which fixes all <code>problems</code> in
85      * <code>CompilationUnit</code>
86      *
87      * @param compilationUnit
88      * The compilation unit to fix, may be null
89      * @param problems
90      * The locations of the problems to fix
91      * @return The fix or null if no fixes possible
92      * @throws CoreException
93      */

94     public abstract IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException;
95     
96     /**
97      * Required compiler options to allow <code>createFix</code> to work
98      * correct.
99      *
100      * @return The options as map or null
101      */

102     public abstract Map JavaDoc getRequiredOptions();
103     
104     /**
105      * If true a fresh AST, containing all the changes from previous clean ups,
106      * will be created and passed to createFix.
107      *
108      * @param compilationUnit
109      * The current available AST
110      * @return true if the caller needs an up to date AST
111      */

112     public abstract boolean needsFreshAST(CompilationUnit compilationUnit);
113     
114     /**
115      * Description for each operation this clean up will execute
116      *
117      * @return descriptions or null
118      */

119     public String JavaDoc[] getDescriptions();
120     
121     public void initialize(Map JavaDoc settings) throws CoreException;
122     
123     /**
124      * After call to checkPreConditions clients will start creating fixes for
125      * <code>compilationUnits</code> int <code>project</code> unless the
126      * result of checkPreConditions contains a fatal error
127      *
128      * @param project
129      * The project to clean up
130      * @param compilationUnits
131      * The compilation Units to clean up, all member of project
132      * @param monitor
133      * the monitor to show progress
134      * @return the result of the precondition check, not null
135      */

136     public abstract RefactoringStatus checkPreConditions(IJavaProject project, ICompilationUnit[] compilationUnits, IProgressMonitor monitor) throws CoreException;
137     
138     /**
139      * Called when done cleaning up.
140      *
141      * @param monitor
142      * the monitor to show progress
143      * @return the result of the postcondition check, not null
144      */

145     public abstract RefactoringStatus checkPostConditions(IProgressMonitor monitor) throws CoreException;
146     
147     /**
148      * True if <code>problem</code> in <code>CompilationUnit</code> can be
149      * fixed by this CleanUp. If true
150      * <code>createFix(compilationUnit, new IProblemLocation[] {problem})</code>
151      * does not return null.
152      *
153      * @param compilationUnit
154      * The compilation unit to fix not null
155      * @param problem
156      * The location of the problem to fix
157      * @return True if problem can be fixed
158      * @throws CoreException
159      */

160     public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException;
161     
162     /**
163      * Maximal number of problems this clean up will fix in compilation unit.
164      * There may be less then the returned number but never more.
165      *
166      * @param compilationUnit
167      * The compilation unit to fix, not null
168      * @return The maximal number of fixes or -1 if unknown.
169      */

170     public abstract int maximalNumberOfFixes(CompilationUnit compilationUnit);
171     
172     /**
173      * A code snippet which complies to the current settings.
174      *
175      * @return A code snippet, not null.
176      */

177     public abstract String JavaDoc getPreview();
178     
179 }
180
Popular Tags