Lines 536-539
Link Here
|
536 |
}, |
536 |
}, |
537 |
""); // no specific success output string |
537 |
""); // no specific success output string |
538 |
} |
538 |
} |
|
|
539 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
540 |
public void test322817() { |
541 |
Map customOptions = getCompilerOptions(); |
542 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
543 |
this.runNegativeTest( |
544 |
new String[] { |
545 |
"X.java", |
546 |
"interface Adaptable {\n" + |
547 |
" public Object getAdapter(Class clazz); \n" + |
548 |
"}\n" + |
549 |
"public class X implements Adaptable {\n" + |
550 |
" public Object getAdapter(Class clazz) {\n" + |
551 |
" return null;\n" + |
552 |
" }\n" + |
553 |
"}\n" |
554 |
}, |
555 |
"----------\n" + |
556 |
"1. WARNING in X.java (at line 2)\n" + |
557 |
" public Object getAdapter(Class clazz); \n" + |
558 |
" ^^^^^\n" + |
559 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
560 |
"----------\n", |
561 |
null, |
562 |
true, |
563 |
customOptions); |
564 |
} |
565 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
566 |
public void test322817b() { |
567 |
Map customOptions = getCompilerOptions(); |
568 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); |
569 |
this.runNegativeTest( |
570 |
new String[] { |
571 |
"X.java", |
572 |
"interface Adaptable {\n" + |
573 |
" public Object getAdapter(Class clazz); \n" + |
574 |
"}\n" + |
575 |
"public class X implements Adaptable {\n" + |
576 |
" public Object getAdapter(Class clazz) {\n" + |
577 |
" return null;\n" + |
578 |
" }\n" + |
579 |
"}\n" |
580 |
}, |
581 |
"----------\n" + |
582 |
"1. WARNING in X.java (at line 2)\n" + |
583 |
" public Object getAdapter(Class clazz); \n" + |
584 |
" ^^^^^\n" + |
585 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
586 |
"----------\n" + |
587 |
"2. WARNING in X.java (at line 5)\n" + |
588 |
" public Object getAdapter(Class clazz) {\n" + |
589 |
" ^^^^^\n" + |
590 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
591 |
"----------\n", |
592 |
null, |
593 |
true, |
594 |
customOptions); |
595 |
} |
596 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
597 |
public void test322817c() { |
598 |
Map customOptions = getCompilerOptions(); |
599 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
600 |
this.runNegativeTest( |
601 |
new String[] { |
602 |
"X.java", |
603 |
"interface Adaptable {\n" + |
604 |
" public Object getAdapter(Class<String> clazz); \n" + |
605 |
"}\n" + |
606 |
"public class X implements Adaptable {\n" + |
607 |
" public Object getAdapter(Class clazz) {\n" + |
608 |
" return null;\n" + |
609 |
" }\n" + |
610 |
"}\n" |
611 |
}, |
612 |
"----------\n" + |
613 |
"1. WARNING in X.java (at line 5)\n" + |
614 |
" public Object getAdapter(Class clazz) {\n" + |
615 |
" ^^^^^\n" + |
616 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
617 |
"----------\n", |
618 |
null, |
619 |
true, |
620 |
customOptions); |
621 |
} |
622 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
623 |
public void test322817d() { |
624 |
Map customOptions = getCompilerOptions(); |
625 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
626 |
this.runNegativeTest( |
627 |
new String[] { |
628 |
"X.java", |
629 |
"interface Adaptable {\n" + |
630 |
" public Object getAdapter(Class<String> clazz); \n" + |
631 |
"}\n" + |
632 |
"public class X implements Adaptable {\n" + |
633 |
" public Object getAdapter(Class clazz) {\n" + |
634 |
" return null;\n" + |
635 |
" }\n" + |
636 |
"}\n" + |
637 |
"class Y extends X {\n" + |
638 |
" @Override\n" + |
639 |
" public Object getAdapter(Class clazz) {\n" + |
640 |
" return null;\n" + |
641 |
" }\n" + |
642 |
"}\n" |
643 |
|
644 |
}, |
645 |
"----------\n" + |
646 |
"1. WARNING in X.java (at line 5)\n" + |
647 |
" public Object getAdapter(Class clazz) {\n" + |
648 |
" ^^^^^\n" + |
649 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
650 |
"----------\n", |
651 |
null, |
652 |
true, |
653 |
customOptions); |
654 |
} |
655 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
656 |
public void test322817e() { |
657 |
Map customOptions = getCompilerOptions(); |
658 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
659 |
this.runNegativeTest( |
660 |
new String[] { |
661 |
"X.java", |
662 |
"import java.util.List;\n" + |
663 |
"class Top {\n" + |
664 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
665 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
666 |
"}\n" + |
667 |
"class Sub extends Top {\n" + |
668 |
" @Override\n" + |
669 |
" public void set(List arg) { // should not warn (overrides)\n" + |
670 |
" }\n" + |
671 |
" @Override\n" + |
672 |
" public List get() { // should not warn (overrides)\n" + |
673 |
" return super.get();\n" + |
674 |
" }\n" + |
675 |
"}\n" + |
676 |
"public class X {\n" + |
677 |
"}\n" |
678 |
}, |
679 |
"----------\n" + |
680 |
"1. WARNING in X.java (at line 3)\n" + |
681 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
682 |
" ^^^^\n" + |
683 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
684 |
"----------\n" + |
685 |
"2. WARNING in X.java (at line 4)\n" + |
686 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
687 |
" ^^^^\n" + |
688 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
689 |
"----------\n", |
690 |
null, |
691 |
true, |
692 |
customOptions); |
693 |
} |
694 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
695 |
public void test322817f() { |
696 |
Map customOptions = getCompilerOptions(); |
697 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
698 |
this.runNegativeTest( |
699 |
new String[] { |
700 |
"X.java", |
701 |
"import java.util.List;\n" + |
702 |
"class Top {\n" + |
703 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
704 |
" public List<String> get() { return null; }\n" + |
705 |
"}\n" + |
706 |
"class Sub extends Top {\n" + |
707 |
" @Override\n" + |
708 |
" public void set(List arg) { // should not warn (overrides)\n" + |
709 |
" }\n" + |
710 |
" @Override\n" + |
711 |
" public List get() { // should warn (super's return type is not raw)\n" + |
712 |
" return super.get();\n" + |
713 |
" }\n" + |
714 |
"}\n" + |
715 |
"public class X {\n" + |
716 |
"}\n" |
717 |
}, |
718 |
"----------\n" + |
719 |
"1. WARNING in X.java (at line 3)\n" + |
720 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
721 |
" ^^^^\n" + |
722 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
723 |
"----------\n" + |
724 |
"2. WARNING in X.java (at line 11)\n" + |
725 |
" public List get() { // should warn (super\'s return type is not raw)\n" + |
726 |
" ^^^^\n" + |
727 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
728 |
"----------\n" + |
729 |
"3. WARNING in X.java (at line 11)\n" + |
730 |
" public List get() { // should warn (super\'s return type is not raw)\n" + |
731 |
" ^^^^\n" + |
732 |
"Type safety: The return type List for get() from the type Sub needs unchecked conversion to conform to List<String> from the type Top\n" + |
733 |
"----------\n", |
734 |
null, |
735 |
true, |
736 |
customOptions); |
737 |
} |
738 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
739 |
public void test322817g() { |
740 |
Map customOptions = getCompilerOptions(); |
741 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
742 |
this.runNegativeTest( |
743 |
new String[] { |
744 |
"X.java", |
745 |
"import java.util.List;\n" + |
746 |
"class Top {\n" + |
747 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
748 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
749 |
"}\n" + |
750 |
"class Sub extends Top {\n" + |
751 |
" @Override\n" + |
752 |
" public void set(List arg) { // should not warn (overrides)\n" + |
753 |
" super.set(arg);\n" + |
754 |
" arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + |
755 |
" }\n" + |
756 |
" @Override\n" + |
757 |
" public List get() { // should not warn (overrides)\n" + |
758 |
" return super.get();\n" + |
759 |
" }\n" + |
760 |
"}\n" + |
761 |
"public class X {\n" + |
762 |
// " void run() {\n" + |
763 |
// " new Top().get().add(\"arg\"); // should not warn (uses raw API)\n" + |
764 |
// " List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + |
765 |
// " raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + |
766 |
// " // When Top#get() is generified, both of the following will fail\n" + |
767 |
// " // with a compile error if type arguments don't match:\n" + |
768 |
// " List<String> unchecked= new Top().get(); // should not warn (forced)\n" + |
769 |
// " unchecked.add(\"x\");\n" + |
770 |
// " // Should not warn about unchecked cast, but should warn about\n" + |
771 |
// " // unnecessary cast:\n" + |
772 |
// " List<String> cast= (List<String>) new Top().get();\n" + |
773 |
// " cast.add(\"x\");\n" + |
774 |
// " }\n" + |
775 |
"}\n" |
776 |
}, |
777 |
"----------\n" + |
778 |
"1. WARNING in X.java (at line 3)\n" + |
779 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
780 |
" ^^^^\n" + |
781 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
782 |
"----------\n" + |
783 |
"2. WARNING in X.java (at line 4)\n" + |
784 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
785 |
" ^^^^\n" + |
786 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
787 |
"----------\n", |
788 |
null, |
789 |
true, |
790 |
customOptions); |
791 |
} |
792 |
|
539 |
} |
793 |
} |