Lines 6633-6636
Link Here
|
6633 |
compilerOptions /* custom options */ |
6633 |
compilerOptions /* custom options */ |
6634 |
); |
6634 |
); |
6635 |
} |
6635 |
} |
|
|
6636 |
|
6637 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |
6638 |
// If method allocates an inner non-static type without an enclosing object, method can't be static |
6639 |
public void testBug335845a() { |
6640 |
Map compilerOptions = getCompilerOptions(); |
6641 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6642 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
6643 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6644 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
6645 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); |
6646 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
6647 |
compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); |
6648 |
this.runNegativeTest( |
6649 |
new String[] { |
6650 |
"X.java", |
6651 |
"public class X {\n" + |
6652 |
" private class Bar {\n" + |
6653 |
" int a = 1;\n" + |
6654 |
" }\n" + |
6655 |
" private void foo() {\n" + // don't warn |
6656 |
" new Bar();\n" + |
6657 |
" }\n" + |
6658 |
"}" |
6659 |
}, |
6660 |
"", |
6661 |
null /* no extra class libraries */, |
6662 |
true /* flush output directory */, |
6663 |
compilerOptions /* custom options */ |
6664 |
); |
6665 |
} |
6666 |
|
6667 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |
6668 |
// If method allocates an inner non-static type without an enclosing object, method can't be static |
6669 |
public void testBug335845b() { |
6670 |
Map compilerOptions = getCompilerOptions(); |
6671 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6672 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
6673 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6674 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
6675 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); |
6676 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
6677 |
compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); |
6678 |
this.runNegativeTest( |
6679 |
new String[] { |
6680 |
"X.java", |
6681 |
"public class X {\n" + |
6682 |
" private class Bar {\n" + |
6683 |
" int a = 1;\n" + |
6684 |
" }\n" + |
6685 |
" private void foo() {\n" + // don't warn |
6686 |
" int x = new Bar().a;\n" + |
6687 |
" }\n" + |
6688 |
"}" |
6689 |
}, |
6690 |
"", |
6691 |
null /* no extra class libraries */, |
6692 |
true /* flush output directory */, |
6693 |
compilerOptions /* custom options */ |
6694 |
); |
6695 |
} |
6696 |
|
6697 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |
6698 |
// If method allocates an inner static type without an enclosing object, method can be static |
6699 |
public void testBug335845c() { |
6700 |
Map compilerOptions = getCompilerOptions(); |
6701 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6702 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
6703 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6704 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
6705 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); |
6706 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
6707 |
compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); |
6708 |
this.runNegativeTest( |
6709 |
new String[] { |
6710 |
"X.java", |
6711 |
"public class X {\n" + |
6712 |
" private static class Bar {\n" + |
6713 |
" int a = 1;\n" + |
6714 |
" }\n" + |
6715 |
" private void foo() {\n" + // warn since Bar is static |
6716 |
" new Bar();\n" + |
6717 |
" int x = new Bar().a;" + |
6718 |
" }\n" + |
6719 |
"}" |
6720 |
}, |
6721 |
"----------\n" + |
6722 |
"1. ERROR in X.java (at line 5)\n" + |
6723 |
" private void foo() {\n" + |
6724 |
" ^^^^^\n" + |
6725 |
"The method foo() from the type X can be declared as static\n" + |
6726 |
"----------\n", |
6727 |
null /* no extra class libraries */, |
6728 |
true /* flush output directory */, |
6729 |
compilerOptions /* custom options */ |
6730 |
); |
6731 |
} |
6732 |
|
6733 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |
6734 |
// If method allocates an inner non-static type without an enclosing object, method can't be static |
6735 |
public void testBug335845d() { |
6736 |
Map compilerOptions = getCompilerOptions(); |
6737 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6738 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
6739 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6740 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
6741 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); |
6742 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
6743 |
compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); |
6744 |
this.runNegativeTest( |
6745 |
new String[] { |
6746 |
"X.java", |
6747 |
"public class X {\n" + |
6748 |
" private class Bar {\n" + |
6749 |
" class Bar2{}\n" + |
6750 |
" }\n" + |
6751 |
" private void foo() {\n" + // don't warn |
6752 |
" new Bar().new Bar2();\n" + |
6753 |
" }\n" + |
6754 |
"}" |
6755 |
}, |
6756 |
"", |
6757 |
null /* no extra class libraries */, |
6758 |
true /* flush output directory */, |
6759 |
compilerOptions /* custom options */ |
6760 |
); |
6761 |
} |
6762 |
|
6763 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |
6764 |
// If method allocates an inner static type without an enclosing object, method can be static |
6765 |
public void testBug335845e() { |
6766 |
Map compilerOptions = getCompilerOptions(); |
6767 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6768 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
6769 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6770 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
6771 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); |
6772 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
6773 |
compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); |
6774 |
this.runNegativeTest( |
6775 |
new String[] { |
6776 |
"X.java", |
6777 |
"public class X {\n" + |
6778 |
" private class Bar {\n" + |
6779 |
" int a = 1;\n" + |
6780 |
" }\n" + |
6781 |
" private void foo() {\n" + // warn since Bar is allocated via Test object |
6782 |
" new X().new Bar();\n" + |
6783 |
" }\n" + |
6784 |
"}" |
6785 |
}, |
6786 |
"----------\n" + |
6787 |
"1. ERROR in X.java (at line 5)\n" + |
6788 |
" private void foo() {\n" + |
6789 |
" ^^^^^\n" + |
6790 |
"The method foo() from the type X can be declared as static\n" + |
6791 |
"----------\n", |
6792 |
null /* no extra class libraries */, |
6793 |
true /* flush output directory */, |
6794 |
compilerOptions /* custom options */ |
6795 |
); |
6796 |
} |
6797 |
|
6798 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |
6799 |
// If method allocates an inner static type without an enclosing object, method can be static |
6800 |
public void testBug335845f() { |
6801 |
Map compilerOptions = getCompilerOptions(); |
6802 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); |
6803 |
compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); |
6804 |
compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); |
6805 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); |
6806 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); |
6807 |
compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); |
6808 |
compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); |
6809 |
this.runNegativeTest( |
6810 |
new String[] { |
6811 |
"X.java", |
6812 |
"public class X {\n" + |
6813 |
" private class Bar {\n" + |
6814 |
" int a = 1;\n" + |
6815 |
" }\n" + |
6816 |
" private void foo() {\n" + // warn since Bar is allocated via Test object |
6817 |
" X x = new X();" + |
6818 |
" x.new Bar().a = 2;\n" + |
6819 |
" }\n" + |
6820 |
"}" |
6821 |
}, |
6822 |
"----------\n" + |
6823 |
"1. ERROR in X.java (at line 5)\n" + |
6824 |
" private void foo() {\n" + |
6825 |
" ^^^^^\n" + |
6826 |
"The method foo() from the type X can be declared as static\n" + |
6827 |
"----------\n", |
6828 |
null /* no extra class libraries */, |
6829 |
true /* flush output directory */, |
6830 |
compilerOptions /* custom options */ |
6831 |
); |
6832 |
} |
6636 |
} |
6833 |
} |