|
Lines 877-882
Link Here
|
| 877 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
877 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 878 |
} |
878 |
} |
| 879 |
|
879 |
|
|
|
880 |
public void testUnusedCodeBug335173_1() throws Exception { |
| 881 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 882 |
StringBuffer buf= new StringBuffer(); |
| 883 |
|
| 884 |
buf.append("package test1;\n"); |
| 885 |
buf.append("import java.util.Comparator;\n"); |
| 886 |
buf.append("\n"); |
| 887 |
buf.append("class IntComp implements Comparator<Integer> {\n"); |
| 888 |
buf.append(" public int compare(Integer o1, Integer o2) {\n"); |
| 889 |
buf.append(" return ((Integer) o1).intValue() - ((Integer) o2).intValue();\n"); |
| 890 |
buf.append(" }\n"); |
| 891 |
buf.append("}\n"); |
| 892 |
|
| 893 |
ICompilationUnit cu1= pack1.createCompilationUnit("IntComp.java", buf.toString(), false, null); |
| 894 |
|
| 895 |
enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); |
| 896 |
|
| 897 |
buf= new StringBuffer(); |
| 898 |
buf.append("package test1;\n"); |
| 899 |
buf.append("import java.util.Comparator;\n"); |
| 900 |
buf.append("\n"); |
| 901 |
buf.append("class IntComp implements Comparator<Integer> {\n"); |
| 902 |
buf.append(" public int compare(Integer o1, Integer o2) {\n"); |
| 903 |
buf.append(" return o1.intValue() - o2.intValue();\n"); |
| 904 |
buf.append(" }\n"); |
| 905 |
buf.append("}\n"); |
| 906 |
String expected1= buf.toString(); |
| 907 |
|
| 908 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 909 |
} |
| 910 |
|
| 911 |
public void testUnusedCodeBug335173_2() throws Exception { |
| 912 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 913 |
StringBuffer buf= new StringBuffer(); |
| 914 |
buf.append("package test1;\n"); |
| 915 |
buf.append("\n"); |
| 916 |
buf.append("public class E1 {\n"); |
| 917 |
buf.append(" public void foo(Integer n) {\n"); |
| 918 |
buf.append(" int i = (((Integer) n)).intValue();\n"); |
| 919 |
buf.append(" }\n"); |
| 920 |
buf.append("}\n"); |
| 921 |
ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); |
| 922 |
|
| 923 |
enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); |
| 924 |
|
| 925 |
buf= new StringBuffer(); |
| 926 |
buf.append("package test1;\n"); |
| 927 |
buf.append("\n"); |
| 928 |
buf.append("public class E1 {\n"); |
| 929 |
buf.append(" public void foo(Integer n) {\n"); |
| 930 |
buf.append(" int i = (n).intValue();\n"); |
| 931 |
buf.append(" }\n"); |
| 932 |
buf.append("}\n"); |
| 933 |
String expected1= buf.toString(); |
| 934 |
|
| 935 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 936 |
} |
| 937 |
|
| 938 |
public void testUnusedCodeBug335173_3() throws Exception { |
| 939 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 940 |
StringBuffer buf= new StringBuffer(); |
| 941 |
buf.append("package test1;\n"); |
| 942 |
buf.append("\n"); |
| 943 |
buf.append("public class E1 {\n"); |
| 944 |
buf.append(" public void foo(Integer n) {\n"); |
| 945 |
buf.append(" int i = ((Integer) (n)).intValue();\n"); |
| 946 |
buf.append(" }\n"); |
| 947 |
buf.append("}\n"); |
| 948 |
ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); |
| 949 |
|
| 950 |
enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); |
| 951 |
|
| 952 |
buf= new StringBuffer(); |
| 953 |
buf.append("package test1;\n"); |
| 954 |
buf.append("\n"); |
| 955 |
buf.append("public class E1 {\n"); |
| 956 |
buf.append(" public void foo(Integer n) {\n"); |
| 957 |
buf.append(" int i = (n).intValue();\n"); |
| 958 |
buf.append(" }\n"); |
| 959 |
buf.append("}\n"); |
| 960 |
String expected1= buf.toString(); |
| 961 |
|
| 962 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 963 |
} |
| 964 |
|
| 880 |
public void testJava5001() throws Exception { |
965 |
public void testJava5001() throws Exception { |
| 881 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
966 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 882 |
StringBuffer buf= new StringBuffer(); |
967 |
StringBuffer buf= new StringBuffer(); |
|
Lines 5868-5874
Link Here
|
| 5868 |
buf.append("package test1;\n"); |
5953 |
buf.append("package test1;\n"); |
| 5869 |
buf.append("public class E1 {\n"); |
5954 |
buf.append("public class E1 {\n"); |
| 5870 |
buf.append(" public void foo() {\n"); |
5955 |
buf.append(" public void foo() {\n"); |
| 5871 |
buf.append(" double d = 2.0 * 0.5 / 4.0;\n"); |
5956 |
buf.append(" double d = 2.0 * (0.5 / 4.0);\n"); |
| 5872 |
buf.append(" int spaceCount = 3;\n"); |
5957 |
buf.append(" int spaceCount = 3;\n"); |
| 5873 |
buf.append(" spaceCount = 2 * (spaceCount / 2);\n"); |
5958 |
buf.append(" spaceCount = 2 * (spaceCount / 2);\n"); |
| 5874 |
buf.append(" }\n"); |
5959 |
buf.append(" }\n"); |
|
Lines 5937-5942
Link Here
|
| 5937 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { buf.toString() }); |
6022 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { buf.toString() }); |
| 5938 |
} |
6023 |
} |
| 5939 |
|
6024 |
|
|
|
6025 |
public void testRemoveParenthesesBug335173_1() throws Exception { |
| 6026 |
//while loop's expression |
| 6027 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6028 |
StringBuffer buf= new StringBuffer(); |
| 6029 |
buf.append("package test;\n"); |
| 6030 |
buf.append("public class E {\n"); |
| 6031 |
buf.append(" public void foo(boolean a) {\n"); |
| 6032 |
buf.append(" while (((a))) {\n"); |
| 6033 |
buf.append(" }\n"); |
| 6034 |
buf.append(" }\n"); |
| 6035 |
buf.append(" public void bar(int x) {\n"); |
| 6036 |
buf.append(" while ((x > 2)) {\n"); |
| 6037 |
buf.append(" }\n"); |
| 6038 |
buf.append(" }\n"); |
| 6039 |
buf.append("}\n"); |
| 6040 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6041 |
|
| 6042 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6043 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6044 |
|
| 6045 |
buf= new StringBuffer(); |
| 6046 |
buf.append("package test;\n"); |
| 6047 |
buf.append("public class E {\n"); |
| 6048 |
buf.append(" public void foo(boolean a) {\n"); |
| 6049 |
buf.append(" while (a) {\n"); |
| 6050 |
buf.append(" }\n"); |
| 6051 |
buf.append(" }\n"); |
| 6052 |
buf.append(" public void bar(int x) {\n"); |
| 6053 |
buf.append(" while (x > 2) {\n"); |
| 6054 |
buf.append(" }\n"); |
| 6055 |
buf.append(" }\n"); |
| 6056 |
buf.append("}\n"); |
| 6057 |
String expected1= buf.toString(); |
| 6058 |
|
| 6059 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6060 |
} |
| 6061 |
|
| 6062 |
public void testRemoveParenthesesBug335173_2() throws Exception { |
| 6063 |
//do while loop's expression |
| 6064 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6065 |
StringBuffer buf= new StringBuffer(); |
| 6066 |
buf.append("package test;\n"); |
| 6067 |
buf.append("public class E {\n"); |
| 6068 |
buf.append(" public void foo(int x) {\n"); |
| 6069 |
buf.append(" do {\n"); |
| 6070 |
buf.append(" } while ((x > 2));\n"); |
| 6071 |
buf.append(" }\n"); |
| 6072 |
buf.append("}\n"); |
| 6073 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6074 |
|
| 6075 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6076 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6077 |
|
| 6078 |
buf= new StringBuffer(); |
| 6079 |
buf.append("package test;\n"); |
| 6080 |
buf.append("public class E {\n"); |
| 6081 |
buf.append(" public void foo(int x) {\n"); |
| 6082 |
buf.append(" do {\n"); |
| 6083 |
buf.append(" } while (x > 2);\n"); |
| 6084 |
buf.append(" }\n"); |
| 6085 |
buf.append("}\n"); |
| 6086 |
String expected1= buf.toString(); |
| 6087 |
|
| 6088 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6089 |
} |
| 6090 |
|
| 6091 |
public void testRemoveParenthesesBug335173_3() throws Exception { |
| 6092 |
//for loop's expression |
| 6093 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6094 |
StringBuffer buf= new StringBuffer(); |
| 6095 |
buf.append("package test;\n"); |
| 6096 |
buf.append("public class E {\n"); |
| 6097 |
buf.append(" public void foo(int x) {\n"); |
| 6098 |
buf.append(" for (int x = 0; (x > 2); x++) {\n"); |
| 6099 |
buf.append(" }\n"); |
| 6100 |
buf.append(" }\n"); |
| 6101 |
buf.append("}\n"); |
| 6102 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6103 |
|
| 6104 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6105 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6106 |
|
| 6107 |
buf= new StringBuffer(); |
| 6108 |
buf.append("package test;\n"); |
| 6109 |
buf.append("public class E {\n"); |
| 6110 |
buf.append(" public void foo(int x) {\n"); |
| 6111 |
buf.append(" for (int x = 0; x > 2; x++) {\n"); |
| 6112 |
buf.append(" }\n"); |
| 6113 |
buf.append(" }\n"); |
| 6114 |
buf.append("}\n"); |
| 6115 |
String expected1= buf.toString(); |
| 6116 |
|
| 6117 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6118 |
} |
| 6119 |
|
| 6120 |
public void testRemoveParenthesesBug335173_4() throws Exception { |
| 6121 |
//switch statement expression |
| 6122 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6123 |
StringBuffer buf= new StringBuffer(); |
| 6124 |
buf.append("package test;\n"); |
| 6125 |
buf.append("public class E {\n"); |
| 6126 |
buf.append(" public void foo(int x) {\n"); |
| 6127 |
buf.append(" switch ((x - 2)) {\n"); |
| 6128 |
buf.append(" }\n"); |
| 6129 |
buf.append(" }\n"); |
| 6130 |
buf.append("}\n"); |
| 6131 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6132 |
|
| 6133 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6134 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6135 |
|
| 6136 |
buf= new StringBuffer(); |
| 6137 |
buf.append("package test;\n"); |
| 6138 |
buf.append("public class E {\n"); |
| 6139 |
buf.append(" public void foo(int x) {\n"); |
| 6140 |
buf.append(" switch (x - 2) {\n"); |
| 6141 |
buf.append(" }\n"); |
| 6142 |
buf.append(" }\n"); |
| 6143 |
buf.append("}\n"); |
| 6144 |
String expected1= buf.toString(); |
| 6145 |
|
| 6146 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6147 |
} |
| 6148 |
|
| 6149 |
public void testRemoveParenthesesBug335173_5() throws Exception { |
| 6150 |
//switch case expression |
| 6151 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6152 |
StringBuffer buf= new StringBuffer(); |
| 6153 |
buf.append("package test;\n"); |
| 6154 |
buf.append("public class E {\n"); |
| 6155 |
buf.append(" public void foo(int x) {\n"); |
| 6156 |
buf.append(" switch (x) {\n"); |
| 6157 |
buf.append(" case (1 + 2):\n"); |
| 6158 |
buf.append(" break;\n"); |
| 6159 |
buf.append(" }\n"); |
| 6160 |
buf.append(" }\n"); |
| 6161 |
buf.append("}\n"); |
| 6162 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6163 |
|
| 6164 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6165 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6166 |
|
| 6167 |
buf= new StringBuffer(); |
| 6168 |
buf.append("package test;\n"); |
| 6169 |
buf.append("public class E {\n"); |
| 6170 |
buf.append(" public void foo(int x) {\n"); |
| 6171 |
buf.append(" switch (x) {\n"); |
| 6172 |
buf.append(" case 1 + 2:\n"); |
| 6173 |
buf.append(" break;\n"); |
| 6174 |
buf.append(" }\n"); |
| 6175 |
buf.append(" }\n"); |
| 6176 |
buf.append("}\n"); |
| 6177 |
String expected1= buf.toString(); |
| 6178 |
|
| 6179 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6180 |
} |
| 6181 |
|
| 6182 |
public void testRemoveParenthesesBug335173_6() throws Exception { |
| 6183 |
//throw statement expression |
| 6184 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6185 |
StringBuffer buf= new StringBuffer(); |
| 6186 |
buf.append("package test;\n"); |
| 6187 |
buf.append("public class E {\n"); |
| 6188 |
buf.append(" public void foo(int type) throws Exception {\n"); |
| 6189 |
buf.append(" throw (type == 1 ? new IllegalArgumentException() : new Exception());\n"); |
| 6190 |
buf.append(" }\n"); |
| 6191 |
buf.append("}\n"); |
| 6192 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6193 |
|
| 6194 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6195 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6196 |
|
| 6197 |
buf= new StringBuffer(); |
| 6198 |
buf.append("package test;\n"); |
| 6199 |
buf.append("public class E {\n"); |
| 6200 |
buf.append(" public void foo(int type) throws Exception {\n"); |
| 6201 |
buf.append(" throw type == 1 ? new IllegalArgumentException() : new Exception();\n"); |
| 6202 |
buf.append(" }\n"); |
| 6203 |
buf.append("}\n"); |
| 6204 |
String expected1= buf.toString(); |
| 6205 |
|
| 6206 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6207 |
} |
| 6208 |
|
| 6209 |
public void testRemoveParenthesesBug335173_7() throws Exception { |
| 6210 |
//synchronized statement expression |
| 6211 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6212 |
StringBuffer buf= new StringBuffer(); |
| 6213 |
buf.append("package test;\n"); |
| 6214 |
buf.append("public class E {\n"); |
| 6215 |
buf.append(" private static final Object OBJECT = new Object();\n"); |
| 6216 |
buf.append(" private static final String STRING = new String();\n"); |
| 6217 |
buf.append(" \n"); |
| 6218 |
buf.append(" public void foo(int x) {\n"); |
| 6219 |
buf.append(" synchronized ((x == 1 ? STRING : OBJECT)) {\n"); |
| 6220 |
buf.append(" }\n"); |
| 6221 |
buf.append(" }\n"); |
| 6222 |
buf.append("}\n"); |
| 6223 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6224 |
|
| 6225 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6226 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6227 |
|
| 6228 |
buf= new StringBuffer(); |
| 6229 |
buf.append("package test;\n"); |
| 6230 |
buf.append("public class E {\n"); |
| 6231 |
buf.append(" private static final Object OBJECT = new Object();\n"); |
| 6232 |
buf.append(" private static final String STRING = new String();\n"); |
| 6233 |
buf.append(" \n"); |
| 6234 |
buf.append(" public void foo(int x) {\n"); |
| 6235 |
buf.append(" synchronized (x == 1 ? STRING : OBJECT) {\n"); |
| 6236 |
buf.append(" }\n"); |
| 6237 |
buf.append(" }\n"); |
| 6238 |
buf.append("}\n"); |
| 6239 |
String expected1= buf.toString(); |
| 6240 |
|
| 6241 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6242 |
} |
| 6243 |
|
| 6244 |
public void testRemoveParenthesesBug335173_8() throws Exception { |
| 6245 |
//assert statement expression |
| 6246 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6247 |
StringBuffer buf= new StringBuffer(); |
| 6248 |
buf.append("package test;\n"); |
| 6249 |
buf.append("public class E {\n"); |
| 6250 |
buf.append(" public void foo(int x) {\n"); |
| 6251 |
buf.append(" assert (x > 2);\n"); |
| 6252 |
buf.append(" }\n"); |
| 6253 |
buf.append("}\n"); |
| 6254 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6255 |
|
| 6256 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6257 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6258 |
|
| 6259 |
buf= new StringBuffer(); |
| 6260 |
buf.append("package test;\n"); |
| 6261 |
buf.append("public class E {\n"); |
| 6262 |
buf.append(" public void foo(int x) {\n"); |
| 6263 |
buf.append(" assert x > 2;\n"); |
| 6264 |
buf.append(" }\n"); |
| 6265 |
buf.append("}\n"); |
| 6266 |
String expected1= buf.toString(); |
| 6267 |
|
| 6268 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6269 |
} |
| 6270 |
|
| 6271 |
public void testRemoveParenthesesBug335173_9() throws Exception { |
| 6272 |
//assert statement message expression |
| 6273 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6274 |
StringBuffer buf= new StringBuffer(); |
| 6275 |
buf.append("package test;\n"); |
| 6276 |
buf.append("public class E {\n"); |
| 6277 |
buf.append(" public void foo(int x) {\n"); |
| 6278 |
buf.append(" assert x > 2 : (x - 2);\n"); |
| 6279 |
buf.append(" }\n"); |
| 6280 |
buf.append("}\n"); |
| 6281 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6282 |
|
| 6283 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6284 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6285 |
|
| 6286 |
buf= new StringBuffer(); |
| 6287 |
buf.append("package test;\n"); |
| 6288 |
buf.append("public class E {\n"); |
| 6289 |
buf.append(" public void foo(int x) {\n"); |
| 6290 |
buf.append(" assert x > 2 : x - 2;\n"); |
| 6291 |
buf.append(" }\n"); |
| 6292 |
buf.append("}\n"); |
| 6293 |
String expected1= buf.toString(); |
| 6294 |
|
| 6295 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6296 |
} |
| 6297 |
|
| 6298 |
public void testRemoveParenthesesBug335173_10() throws Exception { |
| 6299 |
//array access index expression |
| 6300 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6301 |
StringBuffer buf= new StringBuffer(); |
| 6302 |
buf.append("package test;\n"); |
| 6303 |
buf.append("public class E {\n"); |
| 6304 |
buf.append(" public void foo(int a[], int x) {\n"); |
| 6305 |
buf.append(" int i = a[(x + 2)];\n"); |
| 6306 |
buf.append(" }\n"); |
| 6307 |
buf.append("}\n"); |
| 6308 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6309 |
|
| 6310 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6311 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6312 |
|
| 6313 |
buf= new StringBuffer(); |
| 6314 |
buf.append("package test;\n"); |
| 6315 |
buf.append("public class E {\n"); |
| 6316 |
buf.append(" public void foo(int a[], int x) {\n"); |
| 6317 |
buf.append(" int i = a[x + 2];\n"); |
| 6318 |
buf.append(" }\n"); |
| 6319 |
buf.append("}\n"); |
| 6320 |
String expected1= buf.toString(); |
| 6321 |
|
| 6322 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6323 |
} |
| 6324 |
|
| 6325 |
public void testRemoveParenthesesBug335173_11() throws Exception { |
| 6326 |
//conditional expression's then expression |
| 6327 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6328 |
StringBuffer buf= new StringBuffer(); |
| 6329 |
buf.append("package test;\n"); |
| 6330 |
buf.append("public class E {\n"); |
| 6331 |
buf.append(" public void foo(int x) {\n"); |
| 6332 |
buf.append(" int i = x > 10 ? (x > 5 ? x - 1 : x - 2): x;\n"); |
| 6333 |
buf.append(" }\n"); |
| 6334 |
buf.append("}\n"); |
| 6335 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6336 |
|
| 6337 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6338 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6339 |
|
| 6340 |
buf= new StringBuffer(); |
| 6341 |
buf.append("package test;\n"); |
| 6342 |
buf.append("public class E {\n"); |
| 6343 |
buf.append(" public void foo(int x) {\n"); |
| 6344 |
buf.append(" int i = x > 10 ? x > 5 ? x - 1 : x - 2: x;\n"); |
| 6345 |
buf.append(" }\n"); |
| 6346 |
buf.append("}\n"); |
| 6347 |
String expected1= buf.toString(); |
| 6348 |
|
| 6349 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6350 |
} |
| 6351 |
|
| 6352 |
public void testRemoveParenthesesBug335173_12() throws Exception { |
| 6353 |
//conditional expression's else expression |
| 6354 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6355 |
StringBuffer buf= new StringBuffer(); |
| 6356 |
buf.append("package test;\n"); |
| 6357 |
buf.append("public class E {\n"); |
| 6358 |
buf.append(" public void foo(int x) {\n"); |
| 6359 |
buf.append(" int i = x > 10 ? x: (x > 5 ? x - 1 : x - 2);\n"); |
| 6360 |
buf.append(" }\n"); |
| 6361 |
buf.append("}\n"); |
| 6362 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6363 |
|
| 6364 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6365 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6366 |
|
| 6367 |
buf= new StringBuffer(); |
| 6368 |
buf.append("package test;\n"); |
| 6369 |
buf.append("public class E {\n"); |
| 6370 |
buf.append(" public void foo(int x) {\n"); |
| 6371 |
buf.append(" int i = x > 10 ? x: x > 5 ? x - 1 : x - 2;\n"); |
| 6372 |
buf.append(" }\n"); |
| 6373 |
buf.append("}\n"); |
| 6374 |
String expected1= buf.toString(); |
| 6375 |
|
| 6376 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6377 |
} |
| 6378 |
|
| 6379 |
public void testRemoveParenthesesBug335173_13() throws Exception { |
| 6380 |
//conditional expression's then expression |
| 6381 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6382 |
StringBuffer buf= new StringBuffer(); |
| 6383 |
buf.append("package test;\n"); |
| 6384 |
buf.append("public class E {\n"); |
| 6385 |
buf.append(" public void foo(int x) {\n"); |
| 6386 |
buf.append(" int i = x > 10 ? (x = x - 2): x;\n"); |
| 6387 |
buf.append(" }\n"); |
| 6388 |
buf.append("}\n"); |
| 6389 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6390 |
|
| 6391 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6392 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6393 |
|
| 6394 |
buf= new StringBuffer(); |
| 6395 |
buf.append("package test;\n"); |
| 6396 |
buf.append("public class E {\n"); |
| 6397 |
buf.append(" public void foo(int x) {\n"); |
| 6398 |
buf.append(" int i = x > 10 ? (x = x - 2): x;\n"); |
| 6399 |
buf.append(" }\n"); |
| 6400 |
buf.append("}\n"); |
| 6401 |
String expected1= buf.toString(); |
| 6402 |
|
| 6403 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6404 |
} |
| 6405 |
|
| 6406 |
public void testRemoveParenthesesBug335173_14() throws Exception { |
| 6407 |
//conditional expression's else expression |
| 6408 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6409 |
StringBuffer buf= new StringBuffer(); |
| 6410 |
buf.append("package test;\n"); |
| 6411 |
buf.append("public class E {\n"); |
| 6412 |
buf.append(" public void foo(int x) {\n"); |
| 6413 |
buf.append(" int i = x > 10 ? x: (x = x - 2);\n"); |
| 6414 |
buf.append(" }\n"); |
| 6415 |
buf.append("}\n"); |
| 6416 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6417 |
|
| 6418 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6419 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6420 |
|
| 6421 |
buf= new StringBuffer(); |
| 6422 |
buf.append("package test;\n"); |
| 6423 |
buf.append("public class E {\n"); |
| 6424 |
buf.append(" public void foo(int x) {\n"); |
| 6425 |
buf.append(" int i = x > 10 ? x: (x = x - 2);\n"); |
| 6426 |
buf.append(" }\n"); |
| 6427 |
buf.append("}\n"); |
| 6428 |
String expected1= buf.toString(); |
| 6429 |
|
| 6430 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6431 |
} |
| 6432 |
|
| 6433 |
public void testRemoveParenthesesBug335173_15() throws Exception { |
| 6434 |
//shift operators |
| 6435 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6436 |
StringBuffer buf= new StringBuffer(); |
| 6437 |
buf.append("package test;\n"); |
| 6438 |
buf.append("public class E {\n"); |
| 6439 |
buf.append(" public void foo(int x) {\n"); |
| 6440 |
buf.append(" int m= (x >> 2) >> 1;\n"); |
| 6441 |
buf.append(" m= x >> (2 >> 1);\n"); |
| 6442 |
buf.append(" int n= (x << 2) << 1;\n"); |
| 6443 |
buf.append(" n= x << (2 << 1);\n"); |
| 6444 |
buf.append(" }\n"); |
| 6445 |
buf.append("}\n"); |
| 6446 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6447 |
|
| 6448 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6449 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6450 |
|
| 6451 |
buf= new StringBuffer(); |
| 6452 |
buf.append("package test;\n"); |
| 6453 |
buf.append("public class E {\n"); |
| 6454 |
buf.append(" public void foo(int x) {\n"); |
| 6455 |
buf.append(" int m= x >> 2 >> 1;\n"); |
| 6456 |
buf.append(" m= x >> (2 >> 1);\n"); |
| 6457 |
buf.append(" int n= x << 2 << 1;\n"); |
| 6458 |
buf.append(" n= x << (2 << 1);\n"); |
| 6459 |
buf.append(" }\n"); |
| 6460 |
buf.append("}\n"); |
| 6461 |
String expected1= buf.toString(); |
| 6462 |
|
| 6463 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6464 |
} |
| 6465 |
|
| 6466 |
public void testRemoveParenthesesBug335173_16() throws Exception { |
| 6467 |
//integer multiplication |
| 6468 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6469 |
StringBuffer buf= new StringBuffer(); |
| 6470 |
buf.append("package test;\n"); |
| 6471 |
buf.append("public class E {\n"); |
| 6472 |
buf.append(" public void foo(int x, long y) {\n"); |
| 6473 |
buf.append(" int m= (4 * x) * 2;\n"); |
| 6474 |
buf.append(" int n= 4 * (x * 2);\n"); |
| 6475 |
buf.append(" int p= 4 * (x % 3);\n"); |
| 6476 |
buf.append(" int q= 4 * (x / 3);\n"); |
| 6477 |
buf.append(" int r= 4 * (x * y);\n"); |
| 6478 |
buf.append(" }\n"); |
| 6479 |
buf.append("}\n"); |
| 6480 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6481 |
|
| 6482 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6483 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6484 |
|
| 6485 |
buf= new StringBuffer(); |
| 6486 |
buf.append("package test;\n"); |
| 6487 |
buf.append("public class E {\n"); |
| 6488 |
buf.append(" public void foo(int x, long y) {\n"); |
| 6489 |
buf.append(" int m= 4 * x * 2;\n"); |
| 6490 |
buf.append(" int n= 4 * x * 2;\n"); |
| 6491 |
buf.append(" int p= 4 * (x % 3);\n"); |
| 6492 |
buf.append(" int q= 4 * (x / 3);\n"); |
| 6493 |
buf.append(" int r= 4 * (x * y);\n"); |
| 6494 |
buf.append(" }\n"); |
| 6495 |
buf.append("}\n"); |
| 6496 |
String expected1= buf.toString(); |
| 6497 |
|
| 6498 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6499 |
} |
| 6500 |
|
| 6501 |
public void testRemoveParenthesesBug335173_17() throws Exception { |
| 6502 |
//floating point multiplication |
| 6503 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6504 |
StringBuffer buf= new StringBuffer(); |
| 6505 |
buf.append("package test;\n"); |
| 6506 |
buf.append("public class E {\n"); |
| 6507 |
buf.append(" public void foo(double x) {\n"); |
| 6508 |
buf.append(" int m= (4.0 * x) * 0.5;\n"); |
| 6509 |
buf.append(" int n= 4.0 * (x * 0.5);\n"); |
| 6510 |
buf.append(" int p= 4.0 * (x / 100);\n"); |
| 6511 |
buf.append(" int q= 4.0 * (x % 3);\n"); |
| 6512 |
buf.append(" }\n"); |
| 6513 |
buf.append("}\n"); |
| 6514 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6515 |
|
| 6516 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6517 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6518 |
|
| 6519 |
buf= new StringBuffer(); |
| 6520 |
buf.append("package test;\n"); |
| 6521 |
buf.append("public class E {\n"); |
| 6522 |
buf.append(" public void foo(double x) {\n"); |
| 6523 |
buf.append(" int m= 4.0 * x * 0.5;\n"); |
| 6524 |
buf.append(" int n= 4.0 * (x * 0.5);\n"); |
| 6525 |
buf.append(" int p= 4.0 * (x / 100);\n"); |
| 6526 |
buf.append(" int q= 4.0 * (x % 3);\n"); |
| 6527 |
buf.append(" }\n"); |
| 6528 |
buf.append("}\n"); |
| 6529 |
String expected1= buf.toString(); |
| 6530 |
|
| 6531 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6532 |
} |
| 6533 |
|
| 6534 |
public void testRemoveParenthesesBug335173_18() throws Exception { |
| 6535 |
//integer addition |
| 6536 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6537 |
StringBuffer buf= new StringBuffer(); |
| 6538 |
buf.append("package test;\n"); |
| 6539 |
buf.append("public class E {\n"); |
| 6540 |
buf.append(" public void foo(int x, long y) {\n"); |
| 6541 |
buf.append(" int m= (4 + x) + 2;\n"); |
| 6542 |
buf.append(" int n= 4 + (x + 2);\n"); |
| 6543 |
buf.append(" int p= 4 + (x + y);\n"); |
| 6544 |
buf.append(" }\n"); |
| 6545 |
buf.append("}\n"); |
| 6546 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6547 |
|
| 6548 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6549 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6550 |
|
| 6551 |
buf= new StringBuffer(); |
| 6552 |
buf.append("package test;\n"); |
| 6553 |
buf.append("public class E {\n"); |
| 6554 |
buf.append(" public void foo(int x, long y) {\n"); |
| 6555 |
buf.append(" int m= 4 + x + 2;\n"); |
| 6556 |
buf.append(" int n= 4 + x + 2;\n"); |
| 6557 |
buf.append(" int p= 4 + (x + y);\n"); |
| 6558 |
buf.append(" }\n"); |
| 6559 |
buf.append("}\n"); |
| 6560 |
String expected1= buf.toString(); |
| 6561 |
|
| 6562 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6563 |
} |
| 6564 |
|
| 6565 |
public void testRemoveParenthesesBug335173_19() throws Exception { |
| 6566 |
//floating point addition |
| 6567 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); |
| 6568 |
StringBuffer buf= new StringBuffer(); |
| 6569 |
buf.append("package test;\n"); |
| 6570 |
buf.append("public class E {\n"); |
| 6571 |
buf.append(" public void foo(double x) {\n"); |
| 6572 |
buf.append(" int m= (4.0 + x) + 100.0;\n"); |
| 6573 |
buf.append(" int n= 4.0 + (x + 100.0);\n"); |
| 6574 |
buf.append(" }\n"); |
| 6575 |
buf.append("}\n"); |
| 6576 |
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 6577 |
|
| 6578 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); |
| 6579 |
enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); |
| 6580 |
|
| 6581 |
buf= new StringBuffer(); |
| 6582 |
buf.append("package test;\n"); |
| 6583 |
buf.append("public class E {\n"); |
| 6584 |
buf.append(" public void foo(double x) {\n"); |
| 6585 |
buf.append(" int m= 4.0 + x + 100.0;\n"); |
| 6586 |
buf.append(" int n= 4.0 + (x + 100.0);\n"); |
| 6587 |
buf.append(" }\n"); |
| 6588 |
buf.append("}\n"); |
| 6589 |
String expected1= buf.toString(); |
| 6590 |
|
| 6591 |
assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); |
| 6592 |
} |
| 6593 |
|
| 5940 |
public void testRemoveQualifier01() throws Exception { |
6594 |
public void testRemoveQualifier01() throws Exception { |
| 5941 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
6595 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 5942 |
StringBuffer buf= new StringBuffer(); |
6596 |
StringBuffer buf= new StringBuffer(); |