KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17
18 import org.eclipse.jdt.core.ICompilationUnit;
19 import org.eclipse.jdt.core.dom.CompilationUnit;
20
21 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
22 import org.eclipse.jdt.internal.corext.fix.IFix;
23
24 import org.eclipse.jdt.ui.text.java.IProblemLocation;
25
26 public class CodeFormatCleanUp extends AbstractCleanUp {
27     
28     public CodeFormatCleanUp() {
29         super();
30     }
31     
32     public CodeFormatCleanUp(Map JavaDoc options) {
33         super(options);
34     }
35     
36     /**
37      * {@inheritDoc}
38      */

39     public boolean requireAST(ICompilationUnit unit) throws CoreException {
40         return false;
41     }
42     
43     public IFix createFix(ICompilationUnit compilationUnit) throws CoreException {
44         if (compilationUnit == null)
45             return null;
46         
47         boolean removeWhitespaces= isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES);
48         return CodeFormatFix.createCleanUp(compilationUnit, isEnabled(CleanUpConstants.FORMAT_SOURCE_CODE), removeWhitespaces && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL), removeWhitespaces && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY));
49     }
50     
51     /**
52      * {@inheritDoc}
53      */

54     public IFix createFix(CompilationUnit compilationUnit) throws CoreException {
55         return null;
56     }
57     
58     /**
59      * {@inheritDoc}
60      */

61     public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException {
62         if (compilationUnit == null)
63             return null;
64         
65         return null;
66     }
67     
68     public Map JavaDoc getRequiredOptions() {
69         return null;
70     }
71     
72     /**
73      * {@inheritDoc}
74      */

75     public String JavaDoc[] getDescriptions() {
76         ArrayList JavaDoc result= new ArrayList JavaDoc();
77         if (isEnabled(CleanUpConstants.FORMAT_SOURCE_CODE))
78             result.add(MultiFixMessages.CodeFormatCleanUp_description);
79         
80         if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES)) {
81             if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL)) {
82                 result.add(MultiFixMessages.CodeFormatCleanUp_RemoveTrailingAll_description);
83             } else if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY)) {
84                 result.add(MultiFixMessages.CodeFormatCleanUp_RemoveTrailingNoEmpty_description);
85             }
86         }
87         
88         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
89     }
90     
91     public String JavaDoc getPreview() {
92         StringBuffer JavaDoc buf= new StringBuffer JavaDoc();
93         buf.append("public class Engine {\n"); //$NON-NLS-1$
94
buf.append(" public void start() {}\n"); //$NON-NLS-1$
95
if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES) && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL)) {
96             buf.append("\n"); //$NON-NLS-1$
97
} else {
98             buf.append(" \n"); //$NON-NLS-1$
99
}
100         if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES)) {
101             buf.append(" public\n"); //$NON-NLS-1$
102
} else {
103             buf.append(" public \n"); //$NON-NLS-1$
104
}
105         buf.append(" void stop() {\n"); //$NON-NLS-1$
106
buf.append(" }\n"); //$NON-NLS-1$
107
buf.append("}\n"); //$NON-NLS-1$
108

109         return buf.toString();
110     }
111     
112     /**
113      * {@inheritDoc}
114      */

115     public int maximalNumberOfFixes(CompilationUnit compilationUnit) {
116         return -1;
117     }
118     
119     public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException {
120         return false;
121     }
122 }
123
Popular Tags