KickJava   Java API By Example, From Geeks To Geeks.

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


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.Assert;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18
19 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
20
21 import org.eclipse.jdt.core.ICompilationUnit;
22 import org.eclipse.jdt.core.IJavaProject;
23 import org.eclipse.jdt.core.compiler.IProblem;
24 import org.eclipse.jdt.core.dom.CompilationUnit;
25
26 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
27 import org.eclipse.jdt.internal.corext.fix.IFix;
28
29 public abstract class AbstractCleanUp implements ICleanUp {
30     
31     private Map JavaDoc fOptions;
32     private final boolean fCanReinitialize;
33     
34     public AbstractCleanUp() {
35         this(null);
36     }
37     
38     public AbstractCleanUp(Map JavaDoc options) {
39         fOptions= options;
40         fCanReinitialize= options == null;
41     }
42     
43     protected int getNumberOfProblems(IProblem[] problems, int problemId) {
44         int result= 0;
45         for (int i= 0; i < problems.length; i++) {
46             if (problems[i].getID() == problemId)
47                 result++;
48         }
49         return result;
50     }
51     
52     /**
53      * {@inheritDoc}
54      */

55     public RefactoringStatus checkPreConditions(IJavaProject project, ICompilationUnit[] compilationUnits, IProgressMonitor monitor) throws CoreException {
56         if (monitor != null)
57             monitor.done();
58         return new RefactoringStatus();
59     }
60     
61     /**
62      * {@inheritDoc}
63      */

64     public RefactoringStatus checkPostConditions(IProgressMonitor monitor) throws CoreException {
65         if (monitor != null)
66             monitor.done();
67         //Default do nothing
68
return new RefactoringStatus();
69     }
70     
71     /**
72      * {@inheritDoc}
73      */

74     public void initialize(Map JavaDoc settings) throws CoreException {
75         if (fCanReinitialize)
76             fOptions= settings;
77     }
78     
79     protected boolean isEnabled(String JavaDoc key) {
80         Assert.isNotNull(key);
81         
82         Object JavaDoc value= fOptions.get(key);
83         return CleanUpConstants.TRUE == value || CleanUpConstants.TRUE.equals(value);
84     }
85     
86     /**
87      * {@inheritDoc}
88      */

89     public boolean needsFreshAST(CompilationUnit compilationUnit) {
90         return false;
91     }
92     
93     /**
94      * {@inheritDoc}
95      */

96     public IFix createFix(ICompilationUnit unit) throws CoreException {
97         return null;
98     }
99 }
100
Popular Tags