]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/fix/ExpressionsCleanUp.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / fix / ExpressionsCleanUp.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.fix;
12
13import java.util.ArrayList;
14import java.util.List;
15import java.util.Map;
16
17import org.eclipse.core.runtime.CoreException;
18
19import org.eclipse.jdt.core.dom.CompilationUnit;
20
21import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
22import org.eclipse.jdt.internal.corext.fix.ExpressionsFix;
23
24import org.eclipse.jdt.ui.cleanup.CleanUpContext;
25import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
26import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
27
28public class ExpressionsCleanUp extends AbstractCleanUp {
29
30 public ExpressionsCleanUp(Map<String, String> options) {
31 super(options);
32 }
33
34 public ExpressionsCleanUp() {
35 super();
36 }
37
38 /**
39 * {@inheritDoc}
40 */
41 @Override
42 public CleanUpRequirements getRequirements() {
43 return new CleanUpRequirements(requireAST(), false, false, null);
44 }
45
46 private boolean requireAST() {
47 boolean usePrentheses= isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES);
48 if (!usePrentheses)
49 return false;
50
51 return isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS) ||
52 isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER);
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 @Override
59 public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
60 CompilationUnit compilationUnit= context.getAST();
61 if (compilationUnit == null)
62 return null;
63
64 boolean usePrentheses= isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES);
65 if (!usePrentheses)
66 return null;
67
68 return ExpressionsFix.createCleanUp(compilationUnit,
69 isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS),
70 isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER));
71 }
72
73 /**
74 * {@inheritDoc}
75 */
76 @Override
77 public String[] getStepDescriptions() {
78 List<String> result= new ArrayList<String>();
79 if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS))
80 result.add(MultiFixMessages.ExpressionsCleanUp_addParanoiac_description);
81
82 if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER))
83 result.add(MultiFixMessages.ExpressionsCleanUp_removeUnnecessary_description);
84
85 return result.toArray(new String[result.size()]);
86 }
87
88 /**
89 * {@inheritDoc}
90 */
91 @Override
92 public String getPreview() {
93 StringBuffer buf= new StringBuffer();
94
95 if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS)) {
96 buf.append("boolean b= (((i > 0) && (i < 10)) || (i == 50));\n"); //$NON-NLS-1$
97 } else if (isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES) && isEnabled(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER)) {
98 buf.append("boolean b= i > 0 && i < 10 || i == 50;\n"); //$NON-NLS-1$
99 } else {
100 buf.append("boolean b= (i > 0 && i < 10 || i == 50);\n"); //$NON-NLS-1$
101 }
102
103 return buf.toString();
104 }
105
106}