Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
|
13 |
import java.util.Map; |
14 |
|
15 |
import junit.framework.Test; |
16 |
|
17 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
18 |
|
19 |
public class InnerClass15Test extends AbstractRegressionTest { |
20 |
public InnerClass15Test(String name) { |
21 |
super(name); |
22 |
} |
23 |
static { |
24 |
// TESTS_NUMBERS = new int[] { 2 }; |
25 |
} |
26 |
public static Test suite() { |
27 |
return buildMinimalComplianceTestSuite(testClass(), F_1_5); |
28 |
} |
29 |
protected Map getCompilerOptions() { |
30 |
Map options = super.getCompilerOptions(); |
31 |
options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
32 |
return options; |
33 |
} |
34 |
public void test001() { |
35 |
this.runNegativeTest(new String[] { |
36 |
"X.java", |
37 |
"class X {\n" + |
38 |
" <X> void foo() {\n" + |
39 |
" class X {}\n" + |
40 |
" }\n" + |
41 |
"}", |
42 |
}, |
43 |
"----------\n" + |
44 |
"1. WARNING in X.java (at line 2)\n" + |
45 |
" <X> void foo() {\n" + |
46 |
" ^\n" + |
47 |
"The type parameter X is hiding the type X\n" + |
48 |
"----------\n" + |
49 |
"2. WARNING in X.java (at line 3)\n" + |
50 |
" class X {}\n" + |
51 |
" ^\n" + |
52 |
"The nested type X is hiding the type parameter X of the generic method foo() of type X\n" + |
53 |
"----------\n" + |
54 |
"3. ERROR in X.java (at line 3)\n" + |
55 |
" class X {}\n" + |
56 |
" ^\n" + |
57 |
"The nested type X cannot hide an enclosing type\n" + |
58 |
"----------\n"); |
59 |
} |
60 |
public void test002() { |
61 |
this.runNegativeTest(new String[] { |
62 |
"X.java", |
63 |
"class X<X> {\n" + |
64 |
" void foo() {\n" + |
65 |
" class X {}\n" + |
66 |
" }\n" + |
67 |
"}", |
68 |
}, |
69 |
"----------\n" + |
70 |
"1. WARNING in X.java (at line 1)\n" + |
71 |
" class X<X> {\n" + |
72 |
" ^\n" + |
73 |
"The type parameter X is hiding the type X<X>\n" + |
74 |
"----------\n" + |
75 |
"2. WARNING in X.java (at line 3)\n" + |
76 |
" class X {}\n" + |
77 |
" ^\n" + |
78 |
"The nested type X is hiding the type parameter X of type X<X>\n" + |
79 |
"----------\n" + |
80 |
"3. ERROR in X.java (at line 3)\n" + |
81 |
" class X {}\n" + |
82 |
" ^\n" + |
83 |
"The nested type X cannot hide an enclosing type\n" + |
84 |
"----------\n"); |
85 |
} |
86 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989 |
87 |
// note javac reports an error for this test, but that is |
88 |
// incorrect, compare and contrast javac behavior with |
89 |
// test004. |
90 |
public void test003() { |
91 |
this.runNegativeTest(new String[] { |
92 |
"Y.java", |
93 |
"class Y {\n" + |
94 |
"class X {}\n" + |
95 |
" <X> void foo() {\n" + |
96 |
" class X {}\n" + |
97 |
" }\n" + |
98 |
"}", |
99 |
}, |
100 |
"----------\n" + |
101 |
"1. WARNING in Y.java (at line 3)\n" + |
102 |
" <X> void foo() {\n" + |
103 |
" ^\n" + |
104 |
"The type parameter X is hiding the type Y.X\n" + |
105 |
"----------\n" + |
106 |
"2. WARNING in Y.java (at line 4)\n" + |
107 |
" class X {}\n" + |
108 |
" ^\n" + |
109 |
"The nested type X is hiding the type parameter X of the generic method foo() of type Y\n" + |
110 |
"----------\n" + |
111 |
"3. WARNING in Y.java (at line 4)\n" + |
112 |
" class X {}\n" + |
113 |
" ^\n" + |
114 |
"The type X is never used locally\n" + |
115 |
"----------\n"); |
116 |
} |
117 |
public void test004() { |
118 |
this.runNegativeTest(new String[] { |
119 |
"Y.java", |
120 |
"class Y {\n" + |
121 |
"class X {}\n" + |
122 |
" void foo() {\n" + |
123 |
" class X {}\n" + |
124 |
" }\n" + |
125 |
"}", |
126 |
}, |
127 |
"----------\n" + |
128 |
"1. WARNING in Y.java (at line 4)\n" + |
129 |
" class X {}\n" + |
130 |
" ^\n" + |
131 |
"The type X is hiding the type Y.X\n" + |
132 |
"----------\n" + |
133 |
"2. WARNING in Y.java (at line 4)\n" + |
134 |
" class X {}\n" + |
135 |
" ^\n" + |
136 |
"The type X is never used locally\n" + |
137 |
"----------\n"); |
138 |
} |
139 |
public static Class testClass() { |
140 |
return InnerClass15Test.class; |
141 |
} |
142 |
} |