Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
import java.io.File; |
12 |
import java.io.File; |
|
|
13 |
import java.util.Map; |
13 |
|
14 |
|
14 |
import junit.framework.Test; |
15 |
import junit.framework.Test; |
15 |
|
16 |
|
Lines 393-396
Link Here
|
393 |
"argument cannot be resolved\n" + |
394 |
"argument cannot be resolved\n" + |
394 |
"----------\n"); |
395 |
"----------\n"); |
395 |
} |
396 |
} |
|
|
397 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 |
398 |
// Check return type of array#clone() |
399 |
public void test014() throws Exception { |
400 |
Map optionsMap = getCompilerOptions(); |
401 |
CompilerOptions options = new CompilerOptions(optionsMap); |
402 |
if (options.complianceLevel > ClassFileConstants.JDK1_4) { |
403 |
// check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level) |
404 |
optionsMap.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); |
405 |
} |
406 |
this.runNegativeTest( |
407 |
new String[] { |
408 |
"X.java", |
409 |
"public class X {\n" + |
410 |
" void foo(long[] longs) throws Exception {\n" + |
411 |
" long[] other = longs.clone();\n" + |
412 |
" }\n" + |
413 |
"}\n", |
414 |
}, |
415 |
"----------\n" + |
416 |
"1. ERROR in X.java (at line 3)\n" + |
417 |
" long[] other = longs.clone();\n" + |
418 |
" ^^^^^^^^^^^^^\n" + |
419 |
"Type mismatch: cannot convert from Object to long[]\n" + |
420 |
"----------\n", |
421 |
null, |
422 |
true, |
423 |
optionsMap); |
424 |
} |
425 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation |
426 |
//Check return type of array#clone() |
427 |
public void test015() throws Exception { |
428 |
if ( new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_5) { |
429 |
return; |
430 |
} |
431 |
this.runConformTest( |
432 |
new String[] { |
433 |
"X.java", |
434 |
"public class X {\n" + |
435 |
" void foo(long[] longs) throws Exception {\n" + |
436 |
" long[] other = longs.clone();\n" + |
437 |
" }\n" + |
438 |
"}\n", |
439 |
}, |
440 |
""); |
441 |
} |
442 |
//https:bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation |
443 |
//Check constant pool declaring class of array#clone() |
444 |
public void test016() throws Exception { |
445 |
this.runConformTest( |
446 |
new String[] { |
447 |
"X.java", |
448 |
"public class X {\n" + |
449 |
" void foo(long[] longs) throws Exception {\n" + |
450 |
" Object other = longs.clone();\n" + |
451 |
" }\n" + |
452 |
"}\n", |
453 |
}, |
454 |
""); |
455 |
ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); |
456 |
byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); |
457 |
String actualOutput = |
458 |
disassembler.disassemble( |
459 |
classFileBytes, |
460 |
"\n", |
461 |
ClassFileBytesDisassembler.DETAILED); |
462 |
|
463 |
String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel <= ClassFileConstants.JDK1_4 |
464 |
? " // Method descriptor #15 ([J)V\n" + |
465 |
" // Stack: 1, Locals: 3\n" + |
466 |
" void foo(long[] longs) throws java.lang.Exception;\n" + |
467 |
" 0 aload_1 [longs]\n" + |
468 |
" 1 invokevirtual java.lang.Object.clone() : java.lang.Object [19]\n" + |
469 |
" 4 astore_2 [other]\n" + |
470 |
" 5 return\n" + |
471 |
" Line numbers:\n" + |
472 |
" [pc: 0, line: 3]\n" + |
473 |
" [pc: 5, line: 4]\n" |
474 |
: " // Method descriptor #15 ([J)V\n" + |
475 |
" // Stack: 1, Locals: 3\n" + |
476 |
" void foo(long[] longs) throws java.lang.Exception;\n" + |
477 |
" 0 aload_1 [longs]\n" + |
478 |
" 1 invokevirtual long[].clone() : java.lang.Object [19]\n" + |
479 |
" 4 astore_2 [other]\n" + |
480 |
" 5 return\n" + |
481 |
" Line numbers:\n" + |
482 |
" [pc: 0, line: 3]\n" + |
483 |
" [pc: 5, line: 4]\n"; |
484 |
|
485 |
int index = actualOutput.indexOf(expectedOutput); |
486 |
if (index == -1 || expectedOutput.length() == 0) { |
487 |
System.out.println(Util.displayString(actualOutput, 3)); |
488 |
} |
489 |
if (index == -1) { |
490 |
assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); |
491 |
} |
492 |
return; |
493 |
} |
494 |
|
495 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation |
496 |
//Check constant pool declaring class of array#clone() |
497 |
public void test017() throws Exception { |
498 |
Map optionsMap = getCompilerOptions(); |
499 |
CompilerOptions options = new CompilerOptions(optionsMap); |
500 |
if (options.complianceLevel > ClassFileConstants.JDK1_4) { |
501 |
// check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level) |
502 |
optionsMap.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); |
503 |
} |
504 |
this.runConformTest( |
505 |
new String[] { |
506 |
"X.java", |
507 |
"public class X {\n" + |
508 |
" void foo(long[] longs) throws Exception {\n" + |
509 |
" Object other = longs.clone();\n" + |
510 |
" }\n" + |
511 |
"}\n", |
512 |
}, |
513 |
"", |
514 |
null, |
515 |
true, |
516 |
null, |
517 |
optionsMap, |
518 |
null); |
519 |
ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); |
520 |
byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); |
521 |
String actualOutput = |
522 |
disassembler.disassemble( |
523 |
classFileBytes, |
524 |
"\n", |
525 |
ClassFileBytesDisassembler.DETAILED); |
526 |
|
527 |
String expectedOutput = |
528 |
" // Method descriptor #15 ([J)V\n" + |
529 |
" // Stack: 1, Locals: 3\n" + |
530 |
" void foo(long[] longs) throws java.lang.Exception;\n" + |
531 |
" 0 aload_1 [longs]\n" + |
532 |
" 1 invokevirtual java.lang.Object.clone() : java.lang.Object [19]\n" + |
533 |
" 4 astore_2 [other]\n" + |
534 |
" 5 return\n" + |
535 |
" Line numbers:\n" + |
536 |
" [pc: 0, line: 3]\n" + |
537 |
" [pc: 5, line: 4]\n"; |
538 |
|
539 |
int index = actualOutput.indexOf(expectedOutput); |
540 |
if (index == -1 || expectedOutput.length() == 0) { |
541 |
System.out.println(Util.displayString(actualOutput, 3)); |
542 |
} |
543 |
if (index == -1) { |
544 |
assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); |
545 |
} |
546 |
} |
396 |
} |
547 |
} |