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 36-42
Link Here
|
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[] { "test001" }; |
39 |
// TESTS_NUMBERS = new int[] { 43 }; |
40 |
// TESTS_NUMBERS = new int[] { 53 }; |
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 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 test0052() throws Exception { |
2130 |
Map customOptions = getCompilerOptions(); |
2131 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2132 |
this.runConformTest( |
2133 |
new String[] { |
2134 |
"X.java", |
2135 |
"class X {\n" + |
2136 |
" int foo() {\n" + |
2137 |
" int i=1;\n" + |
2138 |
" return i++;\n" + // value is used as it is returned |
2139 |
" }\n" + |
2140 |
"}" |
2141 |
}, |
2142 |
"", |
2143 |
null/*classLibraries*/, |
2144 |
true/*shouldFlushOutputDirectory*/, |
2145 |
null, |
2146 |
customOptions, |
2147 |
null); |
2148 |
String expectedOutput = |
2149 |
" // Method descriptor #15 ()I\n" + |
2150 |
" // Stack: 1, Locals: 2\n" + |
2151 |
" int foo();\n" + |
2152 |
" 0 iconst_1\n" + |
2153 |
" 1 istore_1 [i]\n" + |
2154 |
" 2 iload_1 [i]\n" + |
2155 |
" 3 iinc 1 1 [i]\n" + |
2156 |
" 6 ireturn\n" + |
2157 |
" Line numbers:\n" + |
2158 |
" [pc: 0, line: 3]\n" + |
2159 |
" [pc: 2, line: 4]\n" + |
2160 |
" Local variable table:\n" + |
2161 |
" [pc: 0, pc: 7] local: this index: 0 type: X\n" + |
2162 |
" [pc: 2, pc: 7] local: i index: 1 type: int\n"; |
2163 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2164 |
} |
2165 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 |
2166 |
public void test0053() throws Exception { |
2167 |
Map customOptions = getCompilerOptions(); |
2168 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2169 |
this.runConformTest( |
2170 |
new String[] { |
2171 |
"X.java", |
2172 |
"class X {\n" + |
2173 |
" int foo() {\n" + |
2174 |
" int i=1;\n" + |
2175 |
" i++;\n" + // value after increment is still not used |
2176 |
" return 0;\n" + |
2177 |
" }\n" + |
2178 |
"}" |
2179 |
}, |
2180 |
"", |
2181 |
null/*classLibraries*/, |
2182 |
true/*shouldFlushOutputDirectory*/, |
2183 |
null, |
2184 |
customOptions, |
2185 |
null); |
2186 |
String expectedOutput = |
2187 |
" // Method descriptor #15 ()I\n" + |
2188 |
" // Stack: 1, Locals: 1\n" + |
2189 |
" int foo();\n" + |
2190 |
" 0 iconst_0\n" + |
2191 |
" 1 ireturn\n" + |
2192 |
" Line numbers:\n" + |
2193 |
" [pc: 0, line: 5]\n" + |
2194 |
" Local variable table:\n" + |
2195 |
" [pc: 0, pc: 2] local: this index: 0 type: X\n"; |
2196 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2197 |
} |
2198 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 |
2199 |
public void test0054() throws Exception { |
2200 |
Map customOptions = getCompilerOptions(); |
2201 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); |
2202 |
this.runConformTest( |
2203 |
new String[] { |
2204 |
"X.java", |
2205 |
"class X {\n" + |
2206 |
" int foo() {\n" + |
2207 |
" int i=1;\n" + |
2208 |
" return i+=1;\n" + // value is used as it is returned |
2209 |
" }\n" + |
2210 |
"}" |
2211 |
}, |
2212 |
"", |
2213 |
null/*classLibraries*/, |
2214 |
true/*shouldFlushOutputDirectory*/, |
2215 |
null, |
2216 |
customOptions, |
2217 |
null); |
2218 |
String expectedOutput = |
2219 |
" // Method descriptor #15 ()I\n" + |
2220 |
" // Stack: 1, Locals: 2\n" + |
2221 |
" int foo();\n" + |
2222 |
" 0 iconst_1\n" + |
2223 |
" 1 istore_1 [i]\n" + |
2224 |
" 2 iinc 1 1 [i]\n" + |
2225 |
" 5 iload_1 [i]\n" + |
2226 |
" 6 ireturn\n" + |
2227 |
" Line numbers:\n" + |
2228 |
" [pc: 0, line: 3]\n" + |
2229 |
" [pc: 2, line: 4]\n" + |
2230 |
" Local variable table:\n" + |
2231 |
" [pc: 0, pc: 7] local: this index: 0 type: X\n" + |
2232 |
" [pc: 2, pc: 7] local: i index: 1 type: int\n"; |
2233 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
2234 |
} |
2124 |
} |
2235 |
} |