Lines 7-25
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
|
13 |
|
13 |
import java.util.HashMap; |
14 |
import java.util.HashMap; |
14 |
import java.util.Map; |
15 |
import java.util.Map; |
15 |
|
16 |
|
|
|
17 |
import junit.framework.Test; |
18 |
|
16 |
import org.eclipse.jdt.core.JavaCore; |
19 |
import org.eclipse.jdt.core.JavaCore; |
17 |
import org.eclipse.jdt.core.compiler.CategorizedProblem; |
20 |
import org.eclipse.jdt.core.compiler.CategorizedProblem; |
18 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
21 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
19 |
import org.eclipse.jdt.internal.compiler.ICompilerRequestor; |
22 |
import org.eclipse.jdt.internal.compiler.ICompilerRequestor; |
20 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
23 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
21 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
24 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
22 |
import junit.framework.Test; |
|
|
23 |
|
25 |
|
24 |
/* Collects potential programming problems tests that are not segregated in a |
26 |
/* Collects potential programming problems tests that are not segregated in a |
25 |
* dedicated test class (aka NullReferenceTest). */ |
27 |
* dedicated test class (aka NullReferenceTest). */ |
Lines 34-40
Link Here
|
34 |
// Only the highest compliance level is run; add the VM argument |
36 |
// Only the highest compliance level is run; add the VM argument |
35 |
// -Dcompliance=1.4 (for example) to lower it if needed |
37 |
// -Dcompliance=1.4 (for example) to lower it if needed |
36 |
static { |
38 |
static { |
37 |
// TESTS_NAMES = new String[] { "test001" }; |
39 |
// TESTS_NAMES = new String[] { "test0047" }; |
38 |
// TESTS_NUMBERS = new int[] { 43 }; |
40 |
// TESTS_NUMBERS = new int[] { 43 }; |
39 |
// TESTS_RANGE = new int[] { 1, -1 }; |
41 |
// TESTS_RANGE = new int[] { 1, -1 }; |
40 |
} |
42 |
} |
Lines 143-149
Link Here
|
143 |
"1. WARNING in X.java (at line 2)\r\n" + |
145 |
"1. WARNING in X.java (at line 2)\r\n" + |
144 |
" public void foo(boolean b) {\r\n" + |
146 |
" public void foo(boolean b) {\r\n" + |
145 |
" ^\n" + |
147 |
" ^\n" + |
146 |
"The parameter b is never read\n" + |
148 |
"The parameter b is never used\n" + |
147 |
"----------\n" /* expectedCompilerLog */, |
149 |
"----------\n" /* expectedCompilerLog */, |
148 |
"" /* expectedOutputString */, |
150 |
"" /* expectedOutputString */, |
149 |
false /* forceExecution */, |
151 |
false /* forceExecution */, |
Lines 214-220
Link Here
|
214 |
"1. WARNING in X.java (at line 3)\n" + |
216 |
"1. WARNING in X.java (at line 3)\n" + |
215 |
" public void foo(boolean b) {\n" + |
217 |
" public void foo(boolean b) {\n" + |
216 |
" ^\n" + |
218 |
" ^\n" + |
217 |
"The parameter b is never read\n" + |
219 |
"The parameter b is never used\n" + |
218 |
"----------\n" /* expectedCompilerLog */, |
220 |
"----------\n" /* expectedCompilerLog */, |
219 |
"" /* expectedOutputString */, |
221 |
"" /* expectedOutputString */, |
220 |
false /* forceExecution */, |
222 |
false /* forceExecution */, |
Lines 279-285
Link Here
|
279 |
"1. ERROR in X.java (at line 2)\r\n" + |
281 |
"1. ERROR in X.java (at line 2)\r\n" + |
280 |
" public void foo(boolean b) {\r\n" + |
282 |
" public void foo(boolean b) {\r\n" + |
281 |
" ^\n" + |
283 |
" ^\n" + |
282 |
"The parameter b is never read\n" + |
284 |
"The parameter b is never used\n" + |
283 |
"----------\n" /* expectedCompilerLog */, |
285 |
"----------\n" /* expectedCompilerLog */, |
284 |
"" /* expectedOutputString */, |
286 |
"" /* expectedOutputString */, |
285 |
false /* forceExecution */, |
287 |
false /* forceExecution */, |
Lines 555-561
Link Here
|
555 |
"1. WARNING in X.java (at line 3)\n" + |
557 |
"1. WARNING in X.java (at line 3)\n" + |
556 |
" void foo(int unused) throws IOException {}\n" + |
558 |
" void foo(int unused) throws IOException {}\n" + |
557 |
" ^^^^^^\n" + |
559 |
" ^^^^^^\n" + |
558 |
"The parameter unused is never read\n" + |
560 |
"The parameter unused is never used\n" + |
559 |
"----------\n" + |
561 |
"----------\n" + |
560 |
"2. ERROR in X.java (at line 3)\n" + |
562 |
"2. ERROR in X.java (at line 3)\n" + |
561 |
" void foo(int unused) throws IOException {}\n" + |
563 |
" void foo(int unused) throws IOException {}\n" + |
Lines 594-600
Link Here
|
594 |
"1. WARNING in X.java (at line 3)\n" + |
596 |
"1. WARNING in X.java (at line 3)\n" + |
595 |
" void foo(int unused) throws IOException {}\n" + |
597 |
" void foo(int unused) throws IOException {}\n" + |
596 |
" ^^^^^^\n" + |
598 |
" ^^^^^^\n" + |
597 |
"The parameter unused is never read\n" + |
599 |
"The parameter unused is never used\n" + |
598 |
"----------\n" + |
600 |
"----------\n" + |
599 |
"2. WARNING in X.java (at line 3)\n" + |
601 |
"2. WARNING in X.java (at line 3)\n" + |
600 |
" void foo(int unused) throws IOException {}\n" + |
602 |
" void foo(int unused) throws IOException {}\n" + |
Lines 631-637
Link Here
|
631 |
"1. ERROR in X.java (at line 2)\n" + |
633 |
"1. ERROR in X.java (at line 2)\n" + |
632 |
" public X(boolean b) {\n" + |
634 |
" public X(boolean b) {\n" + |
633 |
" ^\n" + |
635 |
" ^\n" + |
634 |
"The parameter b is never read\n" + |
636 |
"The parameter b is never used\n" + |
635 |
"----------\n" /* expectedCompilerLog */, |
637 |
"----------\n" /* expectedCompilerLog */, |
636 |
"" /* expectedOutputString */, |
638 |
"" /* expectedOutputString */, |
637 |
false /* forceExecution */, |
639 |
false /* forceExecution */, |
Lines 1683-1686
Link Here
|
1683 |
"The assignment to variable nvx has no effect\n" + |
1685 |
"The assignment to variable nvx has no effect\n" + |
1684 |
"----------\n"); |
1686 |
"----------\n"); |
1685 |
} |
1687 |
} |
|
|
1688 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1689 |
public void test0046() { |
1690 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1691 |
return; |
1692 |
Map customOptions = getCompilerOptions(); |
1693 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1694 |
this.runNegativeTest( |
1695 |
new String[] { |
1696 |
"X.java", |
1697 |
"class X {\n" + |
1698 |
" int foo() {\n" + |
1699 |
" int i=1;\n" + |
1700 |
" boolean b=false;\n" + |
1701 |
" b|=true;\n" + // not a relevant usage |
1702 |
" int k = 2;\n" + |
1703 |
" --k;\n" + // not a relevant usage |
1704 |
" k+=3;\n" + // not a relevant usage |
1705 |
" Integer j = 3;\n" + |
1706 |
" j++;\n" + // relevant because unboxing is involved |
1707 |
" i++;\n" + // not relevant but should still not report because next is relevant |
1708 |
" return i++;\n" + // value after increment is used |
1709 |
" }\n" + |
1710 |
"}" |
1711 |
}, |
1712 |
"----------\n" + |
1713 |
"1. WARNING in X.java (at line 4)\n" + |
1714 |
" boolean b=false;\n" + |
1715 |
" ^\n" + |
1716 |
"The local variable b is never used\n" + |
1717 |
"----------\n" + |
1718 |
"2. WARNING in X.java (at line 6)\n" + |
1719 |
" int k = 2;\n" + |
1720 |
" ^\n" + |
1721 |
"The local variable k is never used\n" + |
1722 |
"----------\n", |
1723 |
null/*classLibraries*/, |
1724 |
true/*shouldFlushOutputDirectory*/, |
1725 |
customOptions); |
1726 |
} |
1727 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1728 |
// variant with private fields instead of locals |
1729 |
public void test0046_field() { |
1730 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1731 |
return; |
1732 |
Map customOptions = getCompilerOptions(); |
1733 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1734 |
this.runNegativeTest( |
1735 |
new String[] { |
1736 |
"X.java", |
1737 |
"class X {\n" + |
1738 |
" private int i=1;\n" + |
1739 |
" private boolean b=false;\n" + |
1740 |
" private int k = 2;\n" + |
1741 |
" private Integer j = 3;\n" + |
1742 |
" int foo() {\n" + |
1743 |
" b|=true;\n" + // not a relevant usage |
1744 |
" --k;\n" + // not a relevant usage |
1745 |
" k+=3;\n" + // not a relevant usage |
1746 |
" j++;\n" + // relevant because unboxing is involved |
1747 |
" return i++;\n" + // value after increment is used |
1748 |
" }\n" + |
1749 |
"}" |
1750 |
}, |
1751 |
"----------\n" + |
1752 |
"1. WARNING in X.java (at line 3)\n" + |
1753 |
" private boolean b=false;\n" + |
1754 |
" ^\n" + |
1755 |
"The private field X.b is never used\n" + |
1756 |
"----------\n" + |
1757 |
"2. WARNING in X.java (at line 4)\n" + |
1758 |
" private int k = 2;\n" + |
1759 |
" ^\n" + |
1760 |
"The private field X.k is never used\n" + |
1761 |
"----------\n", |
1762 |
null/*classLibraries*/, |
1763 |
true/*shouldFlushOutputDirectory*/, |
1764 |
customOptions); |
1765 |
} |
1766 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1767 |
// variant with private fields instead of locals - this-qualified access |
1768 |
public void test0046_field_this_qualified() { |
1769 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1770 |
return; |
1771 |
Map customOptions = getCompilerOptions(); |
1772 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1773 |
this.runNegativeTest( |
1774 |
new String[] { |
1775 |
"X.java", |
1776 |
"class X {\n" + |
1777 |
" private int i=1;\n" + |
1778 |
" private boolean b=false;\n" + |
1779 |
" private int k = 2;\n" + |
1780 |
" private Integer j = 3;\n" + |
1781 |
" int foo() {\n" + |
1782 |
" this.b|=true;\n" + // not a relevant usage |
1783 |
" --this.k;\n" + // not a relevant usage |
1784 |
" getThis().k+=3;\n" + // not a relevant usage |
1785 |
" this.j++;\n" + // relevant because unboxing is involved |
1786 |
" return this.i++;\n" + // value after increment is used |
1787 |
" }\n" + |
1788 |
" X getThis() { return this; }\n" + |
1789 |
"}" |
1790 |
}, |
1791 |
"----------\n" + |
1792 |
"1. WARNING in X.java (at line 3)\n" + |
1793 |
" private boolean b=false;\n" + |
1794 |
" ^\n" + |
1795 |
"The private field X.b is never used\n" + |
1796 |
"----------\n" + |
1797 |
"2. WARNING in X.java (at line 4)\n" + |
1798 |
" private int k = 2;\n" + |
1799 |
" ^\n" + |
1800 |
"The private field X.k is never used\n" + |
1801 |
"----------\n", |
1802 |
null/*classLibraries*/, |
1803 |
true/*shouldFlushOutputDirectory*/, |
1804 |
customOptions); |
1805 |
} |
1806 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1807 |
// variant with private fields instead of locals - regular qualified access |
1808 |
public void test0046_field_qualified() { |
1809 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1810 |
return; |
1811 |
Map customOptions = getCompilerOptions(); |
1812 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1813 |
this.runNegativeTest( |
1814 |
new String[] { |
1815 |
"X.java", |
1816 |
"class X {\n" + |
1817 |
" private int i=1;\n" + |
1818 |
" private boolean b=false;\n" + |
1819 |
" private int k = 2;\n" + |
1820 |
" private Integer j = 3;\n" + |
1821 |
" int foo(X that) {\n" + |
1822 |
" that.b|=true;\n" + // not a relevant usage |
1823 |
" --that.k;\n" + // not a relevant usage |
1824 |
" that.k+=3;\n" + // not a relevant usage |
1825 |
" that.j++;\n" + // relevant because unboxing is involved |
1826 |
" that.i++;\n"+ // not relevant but should still not report because next is relevant |
1827 |
" return that.i++;\n" + // value after increment is used |
1828 |
" }\n" + |
1829 |
"}" |
1830 |
}, |
1831 |
"----------\n" + |
1832 |
"1. WARNING in X.java (at line 3)\n" + |
1833 |
" private boolean b=false;\n" + |
1834 |
" ^\n" + |
1835 |
"The private field X.b is never used\n" + |
1836 |
"----------\n" + |
1837 |
"2. WARNING in X.java (at line 4)\n" + |
1838 |
" private int k = 2;\n" + |
1839 |
" ^\n" + |
1840 |
"The private field X.k is never used\n" + |
1841 |
"----------\n", |
1842 |
null/*classLibraries*/, |
1843 |
true/*shouldFlushOutputDirectory*/, |
1844 |
customOptions); |
1845 |
} |
1846 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1847 |
// variant with fields inside a private type |
1848 |
public void test0046_field_in_private_type() { |
1849 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1850 |
return; |
1851 |
Map customOptions = getCompilerOptions(); |
1852 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1853 |
this.runNegativeTest( |
1854 |
new String[] { |
1855 |
"X.java", |
1856 |
"class X {\n" + |
1857 |
" private class Y {\n" + |
1858 |
" int i=1;\n" + |
1859 |
" public boolean b=false;\n" + |
1860 |
" protected int k = 2;\n" + |
1861 |
" Integer j = 3;\n" + |
1862 |
" }\n" + |
1863 |
" int foo(Y y) {\n" + |
1864 |
" y.b|=true;\n" + // not a relevant usage |
1865 |
" --y.k;\n" + // not a relevant usage |
1866 |
" y.k+=3;\n" + // not a relevant usage |
1867 |
" y.j++;\n" + // relevant because unboxing is involved |
1868 |
" int result = y.i++;\n" + // value after increment is used |
1869 |
" y.i++;\n" + // not relevant, but previous is |
1870 |
" return result;\n" + |
1871 |
" }\n" + |
1872 |
"}" |
1873 |
}, |
1874 |
"----------\n" + |
1875 |
"1. WARNING in X.java (at line 4)\n" + |
1876 |
" public boolean b=false;\n" + |
1877 |
" ^\n" + |
1878 |
"The field X.Y.b is never used locally\n" + |
1879 |
"----------\n" + |
1880 |
"2. WARNING in X.java (at line 5)\n" + |
1881 |
" protected int k = 2;\n" + |
1882 |
" ^\n" + |
1883 |
"The field X.Y.k is never used locally\n" + |
1884 |
"----------\n", |
1885 |
null/*classLibraries*/, |
1886 |
true/*shouldFlushOutputDirectory*/, |
1887 |
customOptions); |
1888 |
} |
1889 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1890 |
public void test0047() { |
1891 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1892 |
return; |
1893 |
Map customOptions = getCompilerOptions(); |
1894 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); |
1895 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1896 |
this.runNegativeTest( |
1897 |
new String[] { |
1898 |
"X.java", |
1899 |
"class X {\n" + |
1900 |
" void foo(int param1, int param2, Integer param3) {\n" + |
1901 |
" boolean b=false;\n" + |
1902 |
" b|=true;\n" + // not a relevant usage |
1903 |
" param1++;\n" + // not a relevant usage |
1904 |
" {\n" + |
1905 |
" int val=23;\n" + |
1906 |
" param2 += val;\n" +// not a relevant usage of param2 |
1907 |
" }\n" + |
1908 |
" param3++;\n" + // relevant because unboxing is involved |
1909 |
" }\n" + |
1910 |
"}" |
1911 |
}, |
1912 |
"----------\n" + |
1913 |
"1. WARNING in X.java (at line 2)\n" + |
1914 |
" void foo(int param1, int param2, Integer param3) {\n" + |
1915 |
" ^^^^^^\n" + |
1916 |
"The parameter param1 is never used\n" + |
1917 |
"----------\n" + |
1918 |
"2. WARNING in X.java (at line 2)\n" + |
1919 |
" void foo(int param1, int param2, Integer param3) {\n" + |
1920 |
" ^^^^^^\n" + |
1921 |
"The parameter param2 is never used\n" + |
1922 |
"----------\n" + |
1923 |
"3. WARNING in X.java (at line 3)\n" + |
1924 |
" boolean b=false;\n" + |
1925 |
" ^\n" + |
1926 |
"The local variable b is never used\n" + |
1927 |
"----------\n", |
1928 |
null/*classLibraries*/, |
1929 |
true/*shouldFlushOutputDirectory*/, |
1930 |
customOptions); |
1931 |
} |
1932 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1933 |
// To verify that unused parameter warning is not shown for an implementing method's parameter when |
1934 |
// CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract is disabled |
1935 |
public void test0048() { |
1936 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
1937 |
return; |
1938 |
Map customOptions = getCompilerOptions(); |
1939 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); |
1940 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); |
1941 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
1942 |
this.runNegativeTest( |
1943 |
new String[] { |
1944 |
"X.java", |
1945 |
"public class X extends A implements Y{\n" + |
1946 |
" public void foo(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn |
1947 |
" boolean b=false;\n" + |
1948 |
" b|=true;\n" + // not a relevant usage |
1949 |
" param1++;\n" + // not a relevant usage |
1950 |
" param2 += 1;\n" + // not a relevant usage |
1951 |
" param3++;\n" + // relevant because unboxing is involved |
1952 |
" }\n" + |
1953 |
" public void foo(int param1, int param2) {\n" + // warn |
1954 |
" boolean b=false;\n" + |
1955 |
" b|=true;\n" + // not a relevant usage |
1956 |
" param1++;\n" + // not a relevant usage |
1957 |
" param2 += 1;\n" + // not a relevant usage |
1958 |
" }\n" + |
1959 |
" public void bar(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn |
1960 |
" param1++;\n" + // not a relevant usage |
1961 |
" param2 += 1;\n" + // not a relevant usage |
1962 |
" param3++;\n" + // relevant because unboxing is involved |
1963 |
" }\n" + |
1964 |
"}\n" + |
1965 |
"interface Y{\n" + |
1966 |
" public void foo(int param1, int param2, Integer param3);" + |
1967 |
"}\n" + |
1968 |
"abstract class A{\n" + |
1969 |
" public abstract void bar(int param1, int param2, Integer param3);" + |
1970 |
"}\n" |
1971 |
}, |
1972 |
"----------\n" + |
1973 |
"1. WARNING in X.java (at line 3)\n" + |
1974 |
" boolean b=false;\n" + |
1975 |
" ^\n" + |
1976 |
"The local variable b is never used\n" + |
1977 |
"----------\n" + |
1978 |
"2. WARNING in X.java (at line 9)\n" + |
1979 |
" public void foo(int param1, int param2) {\n" + |
1980 |
" ^^^^^^\n" + |
1981 |
"The parameter param1 is never used\n" + |
1982 |
"----------\n" + |
1983 |
"3. WARNING in X.java (at line 9)\n" + |
1984 |
" public void foo(int param1, int param2) {\n" + |
1985 |
" ^^^^^^\n" + |
1986 |
"The parameter param2 is never used\n" + |
1987 |
"----------\n" + |
1988 |
"4. WARNING in X.java (at line 10)\n" + |
1989 |
" boolean b=false;\n" + |
1990 |
" ^\n" + |
1991 |
"The local variable b is never used\n" + |
1992 |
"----------\n", |
1993 |
null/*classLibraries*/, |
1994 |
true/*shouldFlushOutputDirectory*/, |
1995 |
customOptions); |
1996 |
} |
1997 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
1998 |
// To verify that unused parameter warning is not shown for an overriding method's parameter when |
1999 |
// CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete is disabled |
2000 |
public void test0049() { |
2001 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
2002 |
return; |
2003 |
Map customOptions = getCompilerOptions(); |
2004 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); |
2005 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); |
2006 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2007 |
this.runNegativeTest( |
2008 |
new String[] { |
2009 |
"X.java", |
2010 |
"public class X extends A {\n" + |
2011 |
" public void foo(int param1, int param2, Integer param3) {\n" + // overriding method, so dont warn |
2012 |
" boolean b=false;\n" + |
2013 |
" b|=true;\n" + // not a relevant usage |
2014 |
" param1++;\n" + // not a relevant usage |
2015 |
" param2 += 1;\n" + // not a relevant usage |
2016 |
" param3++;\n" + // relevant because unboxing is involved |
2017 |
" }\n" + |
2018 |
" public void foo(int param1, Integer param3) {\n" + // overriding method, so dont warn |
2019 |
" param1++;\n" + // not a relevant usage |
2020 |
" param3++;\n" + // relevant because unboxing is involved |
2021 |
" }\n" + |
2022 |
"}\n" + |
2023 |
"class A{\n" + |
2024 |
" public void foo(int param1, int param2, Integer param3) {\n" + |
2025 |
" param1 -=1;\n" + // not a relevant usage |
2026 |
" param2--;\n" + // not a relevant usage |
2027 |
" param3--;\n" + // relevant because unboxing is involved |
2028 |
" }\n" + |
2029 |
"}\n" |
2030 |
}, |
2031 |
"----------\n" + |
2032 |
"1. WARNING in X.java (at line 3)\n" + |
2033 |
" boolean b=false;\n" + |
2034 |
" ^\n" + |
2035 |
"The local variable b is never used\n" + |
2036 |
"----------\n" + |
2037 |
"2. WARNING in X.java (at line 9)\n" + |
2038 |
" public void foo(int param1, Integer param3) {\n" + |
2039 |
" ^^^^^^\n" + |
2040 |
"The parameter param1 is never used\n" + |
2041 |
"----------\n" + |
2042 |
"3. WARNING in X.java (at line 15)\n" + |
2043 |
" public void foo(int param1, int param2, Integer param3) {\n" + |
2044 |
" ^^^^^^\n" + |
2045 |
"The parameter param1 is never used\n" + |
2046 |
"----------\n" + |
2047 |
"4. WARNING in X.java (at line 15)\n" + |
2048 |
" public void foo(int param1, int param2, Integer param3) {\n" + |
2049 |
" ^^^^^^\n" + |
2050 |
"The parameter param2 is never used\n" + |
2051 |
"----------\n", |
2052 |
null/*classLibraries*/, |
2053 |
true/*shouldFlushOutputDirectory*/, |
2054 |
customOptions); |
2055 |
} |
2056 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 |
2057 |
// To verify that unused local warning is not shown for locals declared in unreachable code |
2058 |
public void test0050() { |
2059 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
2060 |
return; |
2061 |
Map customOptions = getCompilerOptions(); |
2062 |
customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); |
2063 |
this.runNegativeTest( |
2064 |
new String[] { |
2065 |
"X.java", |
2066 |
"class X {\n" + |
2067 |
" int foo() {\n" + |
2068 |
" int i=1;\n" + |
2069 |
" if (false) {\n" + |
2070 |
" boolean b=false;\n" + // don't complain as unused |
2071 |
" b|=true;\n" + |
2072 |
" }\n" + // not a relevant usage |
2073 |
" int k = 2;\n" + |
2074 |
" --k;\n" + // not a relevant usage |
2075 |
" k+=3;\n" + // not a relevant usage |
2076 |
" Integer j = 3;\n" + |
2077 |
" j++;\n" + // relevant because unboxing is involved |
2078 |
" return i++;\n" + // value after increment is used |
2079 |
" }\n" + |
2080 |
"}" |
2081 |
}, |
2082 |
"----------\n" + |
2083 |
"1. WARNING in X.java (at line 4)\n" + |
2084 |
" if (false) {\n" + |
2085 |
" boolean b=false;\n" + |
2086 |
" b|=true;\n" + |
2087 |
" }\n" + |
2088 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
2089 |
"Dead code\n" + |
2090 |
"----------\n" + |
2091 |
"2. WARNING in X.java (at line 8)\n" + |
2092 |
" int k = 2;\n" + |
2093 |
" ^\n" + |
2094 |
"The local variable k is never used\n" + |
2095 |
"----------\n", |
2096 |
null/*classLibraries*/, |
2097 |
true/*shouldFlushOutputDirectory*/, |
2098 |
customOptions); |
2099 |
} |
1686 |
} |
2100 |
} |