Lines 11-16
Link Here
|
11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
package org.eclipse.jdt.core.tests.compiler.regression; |
13 |
|
13 |
|
|
|
14 |
import java.io.File; |
14 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
15 |
import java.util.Map; |
16 |
import java.util.Map; |
16 |
|
17 |
|
Lines 35-42
Link Here
|
35 |
// Only the highest compliance level is run; add the VM argument |
36 |
// Only the highest compliance level is run; add the VM argument |
36 |
// -Dcompliance=1.4 (for example) to lower it if needed |
37 |
// -Dcompliance=1.4 (for example) to lower it if needed |
37 |
static { |
38 |
static { |
38 |
// TESTS_NAMES = new String[] { "test001" }; |
39 |
// TESTS_NAMES = new String[] { "test0055" }; |
39 |
// TESTS_NUMBERS = new int[] { 43 }; |
40 |
// TESTS_NUMBERS = new int[] { 56 }; |
40 |
// TESTS_RANGE = new int[] { 1, -1 }; |
41 |
// TESTS_RANGE = new int[] { 1, -1 }; |
41 |
} |
42 |
} |
42 |
|
43 |
|
Lines 47-53
Link Here
|
47 |
public static Class testClass() { |
48 |
public static Class testClass() { |
48 |
return ProgrammingProblemsTest.class; |
49 |
return ProgrammingProblemsTest.class; |
49 |
} |
50 |
} |
50 |
|
51 |
protected Map getCompilerOptions() { |
|
|
52 |
Map compilerOptions = super.getCompilerOptions(); |
53 |
compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); |
54 |
return compilerOptions; |
55 |
} |
51 |
void runTest( |
56 |
void runTest( |
52 |
String[] testFiles, |
57 |
String[] testFiles, |
53 |
String[] errorOptions, |
58 |
String[] errorOptions, |
Lines 141-148
Link Here
|
141 |
null /* ignoreOptions */, |
146 |
null /* ignoreOptions */, |
142 |
false /* expectingCompilerErrors */, |
147 |
false /* expectingCompilerErrors */, |
143 |
"----------\n" + |
148 |
"----------\n" + |
144 |
"1. WARNING in X.java (at line 2)\r\n" + |
149 |
"1. WARNING in X.java (at line 2)\n" + |
145 |
" public void foo(boolean b) {\r\n" + |
150 |
" public void foo(boolean b) {\n" + |
146 |
" ^\n" + |
151 |
" ^\n" + |
147 |
"The value of the parameter b is not used\n" + |
152 |
"The value of the parameter b is not used\n" + |
148 |
"----------\n" /* expectedCompilerLog */, |
153 |
"----------\n" /* expectedCompilerLog */, |
Lines 277-284
Link Here
|
277 |
null /* ignoreOptions */, |
282 |
null /* ignoreOptions */, |
278 |
true /* expectingCompilerErrors */, |
283 |
true /* expectingCompilerErrors */, |
279 |
"----------\n" + |
284 |
"----------\n" + |
280 |
"1. ERROR in X.java (at line 2)\r\n" + |
285 |
"1. ERROR in X.java (at line 2)\n" + |
281 |
" public void foo(boolean b) {\r\n" + |
286 |
" public void foo(boolean b) {\n" + |
282 |
" ^\n" + |
287 |
" ^\n" + |
283 |
"The value of the parameter b is not used\n" + |
288 |
"The value of the parameter b is not used\n" + |
284 |
"----------\n" /* expectedCompilerLog */, |
289 |
"----------\n" /* expectedCompilerLog */, |
Lines 2120-2124
Link Here
|
2120 |
true/*shouldFlushOutputDirectory*/, |
2125 |
true/*shouldFlushOutputDirectory*/, |
2121 |
customOptions); |
2126 |
customOptions); |
2122 |
} |
2127 |
} |
2123 |
|
2128 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 |
|
|
2129 |
public void test0053() throws Exception { |
2130 |
Map customOptions = getCompilerOptions(); |
2131 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2132 |
this.runConformTest( |
2133 |
new String[] { |
2134 |
"X.java", |
2135 |
"class X {\n" + |
2136 |
" int foo() {\n" + |
2137 |
" int i=1;\n" + |
2138 |
" i++;\n" + // value after increment is still not used |
2139 |
" return 0;\n" + |
2140 |
" }\n" + |
2141 |
"}" |
2142 |
}, |
2143 |
"", |
2144 |
null/*classLibraries*/, |
2145 |
true/*shouldFlushOutputDirectory*/, |
2146 |
null, |
2147 |
customOptions, |
2148 |
null); |
2149 |
String expectedOutput = |
2150 |
" // Method descriptor #15 ()I\n" + |
2151 |
" // Stack: 1, Locals: 1\n" + |
2152 |
" int foo();\n" + |
2153 |
" 0 iconst_0\n" + |
2154 |
" 1 ireturn\n" + |
2155 |
" Line numbers:\n" + |
2156 |
" [pc: 0, line: 5]\n" + |
2157 |
" Local variable table:\n" + |
2158 |
" [pc: 0, pc: 2] local: this index: 0 type: X\n"; |
2159 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2160 |
} |
2161 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 |
2162 |
public void test0054() throws Exception { |
2163 |
Map customOptions = getCompilerOptions(); |
2164 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2165 |
this.runConformTest( |
2166 |
new String[] { |
2167 |
"X.java", |
2168 |
"class X {\n" + |
2169 |
" int foo() {\n" + |
2170 |
" int i=1;\n" + |
2171 |
" return i+=1;\n" + // value is used as it is returned |
2172 |
" }\n" + |
2173 |
"}" |
2174 |
}, |
2175 |
"", |
2176 |
null/*classLibraries*/, |
2177 |
true/*shouldFlushOutputDirectory*/, |
2178 |
null, |
2179 |
customOptions, |
2180 |
null); |
2181 |
String expectedOutput = |
2182 |
" // Method descriptor #15 ()I\n" + |
2183 |
" // Stack: 1, Locals: 2\n" + |
2184 |
" int foo();\n" + |
2185 |
" 0 iconst_1\n" + |
2186 |
" 1 istore_1 [i]\n" + |
2187 |
" 2 iinc 1 1 [i]\n" + |
2188 |
" 5 iload_1 [i]\n" + |
2189 |
" 6 ireturn\n" + |
2190 |
" Line numbers:\n" + |
2191 |
" [pc: 0, line: 3]\n" + |
2192 |
" [pc: 2, line: 4]\n" + |
2193 |
" Local variable table:\n" + |
2194 |
" [pc: 0, pc: 7] local: this index: 0 type: X\n" + |
2195 |
" [pc: 2, pc: 7] local: i index: 1 type: int\n"; |
2196 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2197 |
} |
2198 |
|
2199 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=329613 |
2200 |
// regression caused by https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 |
2201 |
public void test0055() { |
2202 |
Map customOptions = getCompilerOptions(); |
2203 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
2204 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2205 |
customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); |
2206 |
this.runNegativeTest( |
2207 |
new String[] { |
2208 |
"test1/E.java", |
2209 |
"package test1;\n" + |
2210 |
"public class E {\n" + |
2211 |
" private void foo() {\n" + |
2212 |
" int a= 10;\n" + |
2213 |
" a++;\n" + |
2214 |
" a--;\n" + |
2215 |
" --a;\n" + |
2216 |
" ++a;\n" + |
2217 |
" for ( ; ; a++) {\n" + |
2218 |
" }\n" + |
2219 |
" }\n" + |
2220 |
"}" |
2221 |
}, |
2222 |
"----------\n" + |
2223 |
"1. WARNING in test1\\E.java (at line 4)\n" + |
2224 |
" int a= 10;\n" + |
2225 |
" ^\n" + |
2226 |
"The value of the local variable a is not used\n" + |
2227 |
"----------\n", |
2228 |
null/*classLibraries*/, |
2229 |
true/*shouldFlushOutputDirectory*/, |
2230 |
customOptions); |
2231 |
} |
2232 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 |
2233 |
public void test0056() throws Exception { |
2234 |
Map customOptions = getCompilerOptions(); |
2235 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2236 |
this.runConformTest( |
2237 |
new String[] { |
2238 |
"X.java", |
2239 |
"public class X {\n" + |
2240 |
" static int foo() {\n" + |
2241 |
" int i = 2;\n" + |
2242 |
" int j = 3;\n" + |
2243 |
" return (i += j *= 3);\n" + // value is used as it is returned |
2244 |
" }\n" + |
2245 |
" public static void main(String[] args) {\n" + |
2246 |
" System.out.println(foo());\n" + |
2247 |
" }\n" + |
2248 |
"}" |
2249 |
}, |
2250 |
"11", |
2251 |
null/*classLibraries*/, |
2252 |
true/*shouldFlushOutputDirectory*/, |
2253 |
null, |
2254 |
customOptions, |
2255 |
null); |
2256 |
} |
2124 |
} |
2257 |
} |