Thu, 21 Feb 2013 14:43:51 -0800
8008405: Now that metafactory is in place, add javac lambda serialization tests
Summary: Tests part of original langtools serialization review.
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 */
24 /*
25 * @test
26 * @bug 6471599
27 * @summary Type of rhs cannot be obtained when assigning to erroneous symbol
28 * @author Peter von der Ah\u00e9
29 * @compile Main.java
30 * @run main Main
31 */
33 import com.sun.source.tree.AssignmentTree;
34 import com.sun.source.tree.CompilationUnitTree;
35 import com.sun.source.util.JavacTask;
36 import com.sun.source.util.TreePath;
37 import com.sun.source.util.TreePathScanner;
38 import com.sun.source.util.Trees;
39 import com.sun.tools.javac.util.List;
40 import java.io.IOException;
41 import java.net.URI;
42 import javax.lang.model.type.TypeKind;
43 import javax.tools.JavaCompiler;
44 import javax.tools.JavaFileObject;
45 import javax.tools.SimpleJavaFileObject;
46 import javax.tools.ToolProvider;
48 public class Main {
49 static class MyFileObject extends SimpleJavaFileObject {
50 public MyFileObject() {
51 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
52 }
53 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
54 return "public class Test { { x = java.util.Collections.emptySet(); } }";
55 }
56 }
57 static Trees trees;
58 public static void main(String[] args) throws IOException {
59 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
60 JavacTask task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
61 trees = Trees.instance(task);
62 Iterable<? extends CompilationUnitTree> asts = task.parse();
63 task.analyze();
64 for (CompilationUnitTree ast : asts) {
65 new MyVisitor().scan(ast, null);
66 }
67 }
69 static class MyVisitor extends TreePathScanner<Void,Void> {
70 @Override
71 public Void visitAssignment(AssignmentTree node, Void ignored) {
72 TreePath path = TreePath.getPath(getCurrentPath(), node.getExpression());
73 if (trees.getTypeMirror(path).getKind() == TypeKind.ERROR)
74 throw new AssertionError(path.getLeaf());
75 return null;
76 }
78 }
79 }