6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 7029150
27 * @summary Test support for union types
28 * @library ../../../lib
29 */
30
31 import java.net.URI;
32 import java.util.*;
33 import javax.annotation.processing.*;
34 import javax.lang.model.element.*;
35 import javax.lang.model.type.*;
36 import javax.lang.model.util.*;
37 import javax.tools.*;
38
39 import com.sun.source.tree.*;
40 import com.sun.source.util.*;
41
42
43 public class TestUnionType extends JavacTestingAbstractProcessor {
44 enum TestKind {
45 SingleType("E1", "E1",
46 "VariableTree: E1 e",
177 if (types.asElement(tm) != null)
178 log("VariableTree: type.elem.type " + print(types.asElement(tm).asType()));
179 }
180 return super.visitVariable(tree, null);
181 }
182
183 String print(TypeMirror tm) {
184 return (tm == null) ? null : new TypePrinter().visit(tm);
185 }
186
187 String print(Element e) {
188 return (e == null) ? null : (e.getKind() + " " + e.getSimpleName());
189 }
190
191 void log(String msg) {
192 System.err.println(msg);
193 log.add(msg);
194 }
195 }
196
197 class TypePrinter extends SimpleTypeVisitor7<String, Void> {
198 @Override
199 protected String defaultAction(TypeMirror tm, Void ignore) {
200 return String.valueOf(tm.getKind());
201 }
202
203 @Override
204 public String visitUnion(UnionType t, Void ignore) {
205 return (t.getKind() + " " + t.getAlternatives());
206 }
207 }
208 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 7029150 7025809
27 * @summary Test support for union types
28 * @library ../../../lib
29 */
30
31 import java.net.URI;
32 import java.util.*;
33 import javax.annotation.processing.*;
34 import javax.lang.model.element.*;
35 import javax.lang.model.type.*;
36 import javax.lang.model.util.*;
37 import javax.tools.*;
38
39 import com.sun.source.tree.*;
40 import com.sun.source.util.*;
41
42
43 public class TestUnionType extends JavacTestingAbstractProcessor {
44 enum TestKind {
45 SingleType("E1", "E1",
46 "VariableTree: E1 e",
177 if (types.asElement(tm) != null)
178 log("VariableTree: type.elem.type " + print(types.asElement(tm).asType()));
179 }
180 return super.visitVariable(tree, null);
181 }
182
183 String print(TypeMirror tm) {
184 return (tm == null) ? null : new TypePrinter().visit(tm);
185 }
186
187 String print(Element e) {
188 return (e == null) ? null : (e.getKind() + " " + e.getSimpleName());
189 }
190
191 void log(String msg) {
192 System.err.println(msg);
193 log.add(msg);
194 }
195 }
196
197 class TypePrinter extends JavacTestingAbstractProcessor.LatestSimpleTypeVisitor<String, Void> {
198 @Override
199 protected String defaultAction(TypeMirror tm, Void ignore) {
200 return String.valueOf(tm.getKind());
201 }
202
203 @Override
204 public String visitUnion(UnionType t, Void ignore) {
205 return (t.getKind() + " " + t.getAlternatives());
206 }
207 }
208 }
|