Bug 567620 - [cleanup] Global preview fix
Change-Id: Ice51bc896ea961238d265f6e7b98d41b00580f60
Signed-off-by: Fabrice Tiercelin <fabrice.tiercelin@yahoo.fr>
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/PotentialProgrammingProblemsCleanUpCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/PotentialProgrammingProblemsCleanUpCore.java
index 3bc20f3..6ac696d 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/PotentialProgrammingProblemsCleanUpCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/PotentialProgrammingProblemsCleanUpCore.java
@@ -110,17 +110,20 @@
@Override
public String getPreview() {
- StringBuilder buf= new StringBuilder();
+ StringBuilder bld= new StringBuilder();
- buf.append("class E implements java.io.Serializable {\n"); //$NON-NLS-1$
+ bld.append("class E implements java.io.Serializable {\n"); //$NON-NLS-1$
if ((isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID) && isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED))) {
- buf.append(" private static final long serialVersionUID = -391484377137870342L;\n"); //$NON-NLS-1$
+ bld.append(" private static final long serialVersionUID = -391484377137870342L;\n"); //$NON-NLS-1$
+ bld.append("}\n"); //$NON-NLS-1$
} else if ((isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID) && isEnabled(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT))) {
- buf.append(" private static final long serialVersionUID = 1L;\n"); //$NON-NLS-1$
+ bld.append(" private static final long serialVersionUID = 1L;\n"); //$NON-NLS-1$
+ bld.append("}\n"); //$NON-NLS-1$
+ } else {
+ bld.append("}\n\n"); //$NON-NLS-1$
}
- buf.append("}\n"); //$NON-NLS-1$
- return buf.toString();
+ return bld.toString();
}
@Override
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/SwitchExpressionsCleanUpCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/SwitchExpressionsCleanUpCore.java
index c51bdf2..f5af851 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/SwitchExpressionsCleanUpCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/SwitchExpressionsCleanUpCore.java
@@ -29,13 +29,11 @@
import org.eclipse.jdt.internal.corext.fix.SwitchExpressionsFixCore;
public class SwitchExpressionsCleanUpCore extends AbstractCleanUpCore {
-
public SwitchExpressionsCleanUpCore(Map<String, String> options) {
super(options);
}
public SwitchExpressionsCleanUpCore() {
- super();
}
@Override
@@ -66,38 +64,33 @@
if (isEnabled(CleanUpConstants.CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS))
result.add(MultiFixMessages.SwitchExpressionsCleanUp_ConvertToSwitchExpressions_description);
- return result.toArray(new String[result.size()]);
+ return result.toArray(new String[0]);
}
@Override
public String getPreview() {
- StringBuilder buf= new StringBuilder();
-
- boolean convert= isEnabled(CleanUpConstants.CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS);
-
- if (convert) {
- buf.append("int i = switch(j) {\n"); //$NON-NLS-1$
- buf.append(" case 1 -> 3;\n"); //$NON-NLS-1$
- buf.append(" case 2 -> 4;\n"); //$NON-NLS-1$
- buf.append(" default -> 0;\n"); //$NON-NLS-1$
- buf.append("};\n"); //$NON-NLS-1$
- buf.append("\n"); //$NON-NLS-1$
- } else {
- buf.append("int i;\n"); //$NON-NLS-1$
- buf.append("switch(j) {\n"); //$NON-NLS-1$
- buf.append(" case 1:\n"); //$NON-NLS-1$
- buf.append(" i = 3;\n"); //$NON-NLS-1$
- buf.append(" break;\n"); //$NON-NLS-1$
- buf.append(" case 2:\n"); //$NON-NLS-1$
- buf.append(" i = 4;\n"); //$NON-NLS-1$
- buf.append(" break;\n"); //$NON-NLS-1$
- buf.append(" default:\n"); //$NON-NLS-1$
- buf.append(" i = 0;\n"); //$NON-NLS-1$
- buf.append(" break;\n"); //$NON-NLS-1$
- buf.append("}\n"); //$NON-NLS-1$
- buf.append("\n"); //$NON-NLS-1$
+ if (isEnabled(CleanUpConstants.CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS)) {
+ return "" //$NON-NLS-1$
+ + "int i = switch(j) {\n" //$NON-NLS-1$
+ + " case 1 -> 3;\n" //$NON-NLS-1$
+ + " case 2 -> 4;\n" //$NON-NLS-1$
+ + " default -> 0;\n" //$NON-NLS-1$
+ + "};\n\n\n\n\n\n\n\n\n"; //$NON-NLS-1$
}
- return buf.toString();
- }
+ return "" //$NON-NLS-1$
+ + "int i;\n" //$NON-NLS-1$
+ + "switch(j) {\n" //$NON-NLS-1$
+ + " case 1:\n" //$NON-NLS-1$
+ + " i = 3;\n" //$NON-NLS-1$
+ + " break;\n" //$NON-NLS-1$
+ + " case 2:\n" //$NON-NLS-1$
+ + " i = 4;\n" //$NON-NLS-1$
+ + " break;\n" //$NON-NLS-1$
+ + " default:\n" //$NON-NLS-1$
+ + " i = 0;\n" //$NON-NLS-1$
+ + " break;\n" //$NON-NLS-1$
+ + "}\n" //$NON-NLS-1$
+ + "\n"; //$NON-NLS-1$
+ }
}
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUpCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUpCore.java
index df8b9d4..77cda55 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUpCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUpCore.java
@@ -137,36 +137,56 @@
public String getPreview() {
StringBuilder buf= new StringBuilder();
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS)) {
buf.append("import pack.Bar;\n"); //$NON-NLS-1$
}
buf.append("class Example {\n"); //$NON-NLS-1$
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) {
buf.append(" private class Sub {}\n"); //$NON-NLS-1$
}
buf.append(" public Example(boolean b) {}\n"); //$NON-NLS-1$
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) {
buf.append(" private Example() {}\n"); //$NON-NLS-1$
}
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) {
buf.append(" private int fField;\n"); //$NON-NLS-1$
}
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) {
buf.append(" private void foo() {}\n"); //$NON-NLS-1$
}
buf.append(" public void bar() {\n"); //$NON-NLS-1$
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) {
buf.append(" int i= 10;\n"); //$NON-NLS-1$
}
buf.append(" }\n"); //$NON-NLS-1$
buf.append("}\n"); //$NON-NLS-1$
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS)) {
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
return buf.toString();
}
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VariableDeclarationCleanUpCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VariableDeclarationCleanUpCore.java
index e1f92eb..29b69ee 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VariableDeclarationCleanUpCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VariableDeclarationCleanUpCore.java
@@ -84,29 +84,30 @@
@Override
public String getPreview() {
- StringBuilder buf= new StringBuilder();
+ StringBuilder bld= new StringBuilder();
if (isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS)) {
- buf.append("private final int i= 0;\n"); //$NON-NLS-1$
+ bld.append("private final int i= 0;\n"); //$NON-NLS-1$
} else {
- buf.append("private int i= 0;\n"); //$NON-NLS-1$
+ bld.append("private int i= 0;\n"); //$NON-NLS-1$
}
if (isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS)) {
- buf.append("public void foo(final int j) {\n"); //$NON-NLS-1$
+ bld.append("public void foo(final int j) {\n"); //$NON-NLS-1$
} else {
- buf.append("public void foo(int j) {\n"); //$NON-NLS-1$
+ bld.append("public void foo(int j) {\n"); //$NON-NLS-1$
}
if (isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES)) {
- buf.append(" final int k;\n"); //$NON-NLS-1$
- buf.append(" int h;\n"); //$NON-NLS-1$
- buf.append(" h= 0;\n"); //$NON-NLS-1$
+ bld.append(" final int k;\n"); //$NON-NLS-1$
+ bld.append(" int h;\n"); //$NON-NLS-1$
+ bld.append(" h= 0;\n"); //$NON-NLS-1$
+ bld.append("}\n"); //$NON-NLS-1$
} else {
- buf.append(" int k, h;\n"); //$NON-NLS-1$
- buf.append(" h= 0;\n"); //$NON-NLS-1$
+ bld.append(" int k, h;\n"); //$NON-NLS-1$
+ bld.append(" h= 0;\n"); //$NON-NLS-1$
+ bld.append("}\n\n"); //$NON-NLS-1$
}
- buf.append("}\n"); //$NON-NLS-1$
- return buf.toString();
+ return bld.toString();
}
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/Java50CleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/Java50CleanUp.java
index 87dc70b..55589b8 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/Java50CleanUp.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/Java50CleanUp.java
@@ -132,9 +132,12 @@
buf.append(" */\n"); //$NON-NLS-1$
if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED)) {
buf.append(" @Deprecated\n"); //$NON-NLS-1$
+ buf.append(" public void foo() {}\n"); //$NON-NLS-1$
+ buf.append("}\n"); //$NON-NLS-1$
+ } else {
+ buf.append(" public void foo() {}\n"); //$NON-NLS-1$
+ buf.append("}\n\n"); //$NON-NLS-1$
}
- buf.append(" public void foo() {}\n"); //$NON-NLS-1$
- buf.append("}\n"); //$NON-NLS-1$
buf.append("class ESub extends E implements Runnable {\n"); //$NON-NLS-1$
if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
buf.append(" @Override\n"); //$NON-NLS-1$
@@ -144,9 +147,15 @@
&& isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)
&& isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION)) {
buf.append(" @Override\n"); //$NON-NLS-1$
+ buf.append(" public void run() {}\n"); //$NON-NLS-1$
+ buf.append("}\n"); //$NON-NLS-1$
+ } else {
+ buf.append(" public void run() {}\n"); //$NON-NLS-1$
+ buf.append("}\n\n"); //$NON-NLS-1$
}
- buf.append(" public void run() {}\n"); //$NON-NLS-1$
- buf.append("}\n"); //$NON-NLS-1$
+ if (!isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) || !isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
return buf.toString();
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MergeConditionalBlocksCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MergeConditionalBlocksCleanUp.java
index 523c48a..9923ae6 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MergeConditionalBlocksCleanUp.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MergeConditionalBlocksCleanUp.java
@@ -75,22 +75,23 @@
@Override
public String getPreview() {
- StringBuilder bld= new StringBuilder();
-
if (isEnabled(CleanUpConstants.MERGE_CONDITIONAL_BLOCKS)) {
- bld.append("if ((i == 0) || (i == 1)) {\n"); //$NON-NLS-1$
- } else {
- bld.append("if (i == 0) {\n"); //$NON-NLS-1$
- bld.append(" System.out.println(\"Duplicate\");\n"); //$NON-NLS-1$
- bld.append("} else if (i == 1) {\n"); //$NON-NLS-1$
+ return "" //$NON-NLS-1$
+ + "if (isValid || (i != 1)) {\n" //$NON-NLS-1$
+ + " System.out.println(\"Duplicate\");\n" //$NON-NLS-1$
+ + "} else {\n" //$NON-NLS-1$
+ + " System.out.println(\"Different\");\n" //$NON-NLS-1$
+ + "}\n\n\n"; //$NON-NLS-1$
}
- bld.append(" System.out.println(\"Duplicate\");\n"); //$NON-NLS-1$
- bld.append("} else {\n"); //$NON-NLS-1$
- bld.append(" System.out.println(\"Different\");\n"); //$NON-NLS-1$
- bld.append("}\n"); //$NON-NLS-1$
-
- return bld.toString();
+ return "" //$NON-NLS-1$
+ + "if (isValid) {\n" //$NON-NLS-1$
+ + " System.out.println(\"Duplicate\");\n" //$NON-NLS-1$
+ + "} else if (i == 1) {\n" //$NON-NLS-1$
+ + " System.out.println(\"Different\");\n" //$NON-NLS-1$
+ + "} else {\n" //$NON-NLS-1$
+ + " System.out.println(\"Duplicate\");\n" //$NON-NLS-1$
+ + "}\n"; //$NON-NLS-1$
}
@Override
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnimplementedCodeCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnimplementedCodeCleanUp.java
index f7335a7..6be7039 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnimplementedCodeCleanUp.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnimplementedCodeCleanUp.java
@@ -65,26 +65,28 @@
@Override
public String getPreview() {
- StringBuilder buf= new StringBuilder();
+ StringBuilder bld= new StringBuilder();
if (isEnabled(MAKE_TYPE_ABSTRACT)) {
- buf.append("public abstract class Face implements IFace {\n"); //$NON-NLS-1$
+ bld.append("public abstract class Face implements IFace {\n"); //$NON-NLS-1$
} else {
- buf.append("public class Face implements IFace {\n"); //$NON-NLS-1$
+ bld.append("public class Face implements IFace {\n"); //$NON-NLS-1$
}
if (isEnabled(CleanUpConstants.ADD_MISSING_METHODES)) {
boolean createComments= Boolean.parseBoolean(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_ADD_COMMENTS, null));
if (createComments)
- buf.append(indent(getOverridingMethodComment(), " ")); //$NON-NLS-1$
+ bld.append(indent(getOverridingMethodComment(), " ")); //$NON-NLS-1$
- buf.append(" @Override\n"); //$NON-NLS-1$
- buf.append(" public void method() {\n"); //$NON-NLS-1$
- buf.append(indent(getMethodBody(), " ")); //$NON-NLS-1$
- buf.append(" }\n"); //$NON-NLS-1$
+ bld.append(" @Override\n"); //$NON-NLS-1$
+ bld.append(" public void method() {\n"); //$NON-NLS-1$
+ bld.append(indent(getMethodBody(), " ")); //$NON-NLS-1$
+ bld.append(" }\n"); //$NON-NLS-1$
+ bld.append("}\n"); //$NON-NLS-1$
+ } else {
+ bld.append("}\n\n\n\n\n\n"); //$NON-NLS-1$
}
- buf.append("}\n"); //$NON-NLS-1$
- return buf.toString();
+ return bld.toString();
}
@Override
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUp.java
index fda8770..2d01f7b 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUp.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UnusedCodeCleanUp.java
@@ -136,36 +136,56 @@
public String getPreview() {
StringBuilder buf= new StringBuilder();
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS)) {
buf.append("import pack.Bar;\n"); //$NON-NLS-1$
}
buf.append("class Example {\n"); //$NON-NLS-1$
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) {
buf.append(" private class Sub {}\n"); //$NON-NLS-1$
}
buf.append(" public Example(boolean b) {}\n"); //$NON-NLS-1$
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) {
buf.append(" private Example() {}\n"); //$NON-NLS-1$
}
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) {
buf.append(" private int fField;\n"); //$NON-NLS-1$
}
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) && isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS) || !isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) {
buf.append(" private void foo() {}\n"); //$NON-NLS-1$
}
buf.append(" public void bar() {\n"); //$NON-NLS-1$
- if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) {
- } else {
+ if (!isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) {
buf.append(" int i= 10;\n"); //$NON-NLS-1$
}
buf.append(" }\n"); //$NON-NLS-1$
buf.append("}\n"); //$NON-NLS-1$
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_IMPORTS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_MEMBERS)) {
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_TYPES)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_CONSTRUCTORS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_FELDS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_PRIVATE_METHODS)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+ }
+
+ if (isEnabled(CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES)) {
+ buf.append("\n"); //$NON-NLS-1$
+ }
+
return buf.toString();
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessContinueCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessContinueCleanUp.java
index e6ff097..fc2268a 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessContinueCleanUp.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessContinueCleanUp.java
@@ -84,7 +84,7 @@
@Override
public String getPreview() {
StringBuilder bld= new StringBuilder();
- bld.append("for (String text : texts) {"); //$NON-NLS-1$
+ bld.append("for (String text : texts) {\n"); //$NON-NLS-1$
if (isEnabled(CleanUpConstants.REMOVE_USELESS_CONTINUE)) {
bld.append("}\n\n"); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessReturnCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessReturnCleanUp.java
index 520194f..6bdeaeb 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessReturnCleanUp.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/UselessReturnCleanUp.java
@@ -80,7 +80,7 @@
@Override
public String getPreview() {
StringBuilder bld= new StringBuilder();
- bld.append("public void foo() {"); //$NON-NLS-1$
+ bld.append("public void foo() {\n"); //$NON-NLS-1$
if (isEnabled(CleanUpConstants.REMOVE_USELESS_RETURN)) {
bld.append("}\n\n"); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
index d144e52..26667e0 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
@@ -113,7 +113,7 @@
UnnecessaryCodeTabPage_CheckboxName_ArraysFill=Use Arrays.&fill() when possible
UnnecessaryCodeTabPage_CheckboxName_Autoboxing=Use Autobo&xing (1.5 or higher)
UnnecessaryCodeTabPage_CheckboxName_Unboxing=Use Un&boxing (1.5 or higher)
-UnnecessaryCodeTabPage_CheckboxName_PatternMatchingForInstanceof=&Pattern matching for instanceof (Java 15 or higher)
+UnnecessaryCodeTabPage_CheckboxName_PatternMatchingForInstanceof=&Pattern matching for instanceof (Java 14 or higher with feature preview)
UnnecessaryCodeTabPage_CheckboxName_PushDownNegation=Push d&own negation
UnnecessaryCodeTabPage_CheckboxName_RedundantSuperCall=Remove redundant s&uper() call in constructor
UnnecessaryCodeTabPage_CheckboxName_MergeConditionalBlocks=Merge &conditions of if/else if/else that have the same blocks
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java
index eaa5c2e..3fda85b 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java
@@ -39,6 +39,7 @@
@Override
protected AbstractCleanUp[] createPreviewCleanUps(Map<String, String> values) {
return new AbstractCleanUp[] {
+ new SwitchExpressionsCleanUp(values),
new ControlStatementsCleanUp(values),
new ConvertLoopCleanUp(values),
new AddOrRemoveAllCleanUp(values),
@@ -47,7 +48,6 @@
new BitwiseConditionalExpressionCleanup(values),
new VariableDeclarationCleanUp(values),
new VarCleanUp(values),
- new SwitchExpressionsCleanUp(values),
new LambdaExpressionsCleanUp(values),
new LambdaExpressionAndMethodRefCleanUp(values)
};
@@ -57,6 +57,9 @@
protected void doCreatePreferences(Composite composite, int numColumns) {
Group controlGroup= createGroup(numColumns, composite, CleanUpMessages.CodeStyleTabPage_GroupName_ControlStatements);
+ CheckboxPreference convertToSwitchExpressions= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_ConvertToSwitchExpressions, CleanUpConstants.CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS, CleanUpModifyDialog.FALSE_TRUE);
+ registerPreference(convertToSwitchExpressions);
+
final CheckboxPreference useBlockPref= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseBlocks, CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, CleanUpModifyDialog.FALSE_TRUE);
intent(controlGroup);
final RadioPreference useBlockAlwaysPref= createRadioPref(controlGroup, numColumns - 1, CleanUpMessages.CodeStyleTabPage_RadioName_AlwaysUseBlocks, CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS_ALWAYS, CleanUpModifyDialog.FALSE_TRUE);
@@ -66,9 +69,6 @@
final RadioPreference useBlockNeverPref= createRadioPref(controlGroup, numColumns - 1, CleanUpMessages.CodeStyleTabPage_RadioName_NeverUseBlocks, CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS_NEVER, CleanUpModifyDialog.FALSE_TRUE);
registerSlavePreference(useBlockPref, new RadioPreference[] {useBlockAlwaysPref, useBlockJDTStylePref, useBlockNeverPref});
- CheckboxPreference convertToSwitchExpressions= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_ConvertToSwitchExpressions, CleanUpConstants.CONTROL_STATEMENTS_CONVERT_TO_SWITCH_EXPRESSIONS, CleanUpModifyDialog.FALSE_TRUE);
- registerPreference(convertToSwitchExpressions);
-
CheckboxPreference convertLoop= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_ConvertForLoopToEnhanced, CleanUpConstants.CONTROL_STATEMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpModifyDialog.FALSE_TRUE);
registerPreference(convertLoop);
intent(controlGroup);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/UnnecessaryCodeTabPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/UnnecessaryCodeTabPage.java
index c7027c6..f5a46e3 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/UnnecessaryCodeTabPage.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/UnnecessaryCodeTabPage.java
@@ -43,8 +43,8 @@
import org.eclipse.jdt.internal.ui.fix.UnnecessaryArrayCreationCleanUp;
import org.eclipse.jdt.internal.ui.fix.UnnecessaryCodeCleanUp;
import org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp;
-import org.eclipse.jdt.internal.ui.fix.UselessReturnCleanUp;
import org.eclipse.jdt.internal.ui.fix.UselessContinueCleanUp;
+import org.eclipse.jdt.internal.ui.fix.UselessReturnCleanUp;
public final class UnnecessaryCodeTabPage extends AbstractCleanUpTabPage {
public static final String ID= "org.eclipse.jdt.ui.cleanup.tabpage.unnecessary_code"; //$NON-NLS-1$
@@ -116,9 +116,6 @@
CheckboxPreference unboxing= createCheckboxPref(unnecessaryGroup, numColumns, CleanUpMessages.UnnecessaryCodeTabPage_CheckboxName_Unboxing, CleanUpConstants.USE_UNBOXING, CleanUpModifyDialog.FALSE_TRUE);
registerPreference(unboxing);
- CheckboxPreference patternMatchingForInstanceof= createCheckboxPref(unnecessaryGroup, numColumns, CleanUpMessages.UnnecessaryCodeTabPage_CheckboxName_PatternMatchingForInstanceof, CleanUpConstants.USE_PATTERN_MATCHING_FOR_INSTANCEOF, CleanUpModifyDialog.FALSE_TRUE);
- registerPreference(patternMatchingForInstanceof);
-
CheckboxPreference pushDownNegation= createCheckboxPref(unnecessaryGroup, numColumns, CleanUpMessages.UnnecessaryCodeTabPage_CheckboxName_PushDownNegation, CleanUpConstants.PUSH_DOWN_NEGATION,
CleanUpModifyDialog.FALSE_TRUE);
registerPreference(pushDownNegation);
@@ -151,6 +148,9 @@
CheckboxPreference embeddedIf= createCheckboxPref(unnecessaryGroup, numColumns, CleanUpMessages.UnnecessaryCodeTabPage_CheckboxName_EmbeddedIf, CleanUpConstants.RAISE_EMBEDDED_IF, CleanUpModifyDialog.FALSE_TRUE);
registerPreference(embeddedIf);
+ CheckboxPreference patternMatchingForInstanceof= createCheckboxPref(unnecessaryGroup, numColumns, CleanUpMessages.UnnecessaryCodeTabPage_CheckboxName_PatternMatchingForInstanceof, CleanUpConstants.USE_PATTERN_MATCHING_FOR_INSTANCEOF, CleanUpModifyDialog.FALSE_TRUE);
+ registerPreference(patternMatchingForInstanceof);
+
CheckboxPreference semicolons= createCheckboxPref(unnecessaryGroup, numColumns, CleanUpMessages.UnnecessaryCodeTabPage_CheckboxName_RedundantSemicolons, CleanUpConstants.REMOVE_REDUNDANT_SEMICOLONS, CleanUpModifyDialog.FALSE_TRUE);
registerPreference(semicolons);