annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/Compile.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 9c8c0937da41
children 5309cc9668e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21420
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 *
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * accompanied this code).
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 *
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 *
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * questions.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 */
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test.processor;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
25 import java.io.ByteArrayOutputStream;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
26 import java.io.IOException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
27 import java.io.OutputStream;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
28 import java.net.URI;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
29 import java.net.URISyntaxException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
30 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
31 import java.util.Arrays;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
32 import java.util.HashMap;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
33 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
34 import java.util.Locale;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
35 import java.util.Map;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
36 import javax.tools.Diagnostic;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
37 import javax.tools.DiagnosticListener;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
38 import javax.tools.FileObject;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
39 import javax.tools.ForwardingJavaFileManager;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
40 import javax.tools.JavaFileManager;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
41 import javax.tools.JavaFileObject;
21420
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
42 import javax.tools.JavaFileObject.Kind;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
43 import javax.tools.SimpleJavaFileObject;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
44 import javax.tools.StandardJavaFileManager;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
45 import javax.tools.ToolProvider;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
46 import static org.junit.Assert.assertFalse;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
47 import static org.junit.Assert.assertTrue;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
48 import static org.junit.Assert.fail;
21420
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
49
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
50 final class Compile implements DiagnosticListener<JavaFileObject> {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51 private final List<Diagnostic<? extends JavaFileObject>> errors = new ArrayList<>();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52 private final Map<String, byte[]> classes;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53 private final String sourceLevel;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55 private Compile(Class<?> processor, String code, String sl) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
56 this.sourceLevel = sl;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
57 classes = compile(processor, code);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 /**
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 * Performs compilation of given HTML page and associated Java code.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62 */
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 public static Compile create(Class<?> processor, String code) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
64 return new Compile(processor, code, "1.7");
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
65 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
66
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
67 /** Checks for given class among compiled resources. */
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
68 public byte[] get(String res) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
69 return classes.get(res);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
70 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
71
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
72 /**
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
73 * Obtains errors created during compilation.
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
74 */
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
75 public List<Diagnostic<? extends JavaFileObject>> getErrors() {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
76 List<Diagnostic<? extends JavaFileObject>> err;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
77 err = new ArrayList<>();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
78 for (Diagnostic<? extends JavaFileObject> diagnostic : errors) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
79 if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
80 err.add(diagnostic);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
81 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
82 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
83 return err;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
84 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
85
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
86 private Map<String, byte[]> compile(Class<?> processor, final String code) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
87 StandardJavaFileManager sjfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(this, null, null);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
88
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
89 final Map<String, ByteArrayOutputStream> class2BAOS;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
90 class2BAOS = new HashMap<>();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
91
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
92 JavaFileObject file = new SimpleJavaFileObject(URI.create("mem://mem"), Kind.SOURCE) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
93 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
94 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 return code;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
96 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
97 };
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
99 JavaFileManager jfm = new ForwardingJavaFileManager<JavaFileManager>(sjfm) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
100 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
101 public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
102 if (kind == Kind.CLASS) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
103 final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
104
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
105 class2BAOS.put(className.replace('.', '/') + ".class", buffer);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
106 return new SimpleJavaFileObject(sibling.toUri(), kind) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
107 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
108 public OutputStream openOutputStream() {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
109 return buffer;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
110 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
111 };
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
112 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
113
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
114 if (kind == Kind.SOURCE) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
115 final String n = className.replace('.', '/') + ".java";
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
116 final URI un;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
117 try {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
118 un = new URI("mem://" + n);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
119 } catch (URISyntaxException ex) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
120 throw new IOException(ex);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
121 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
122 return new VirtFO(un/* sibling.toUri() */, kind, n);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
123 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
124
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
125 throw new IllegalStateException();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
126 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
127
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
128 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
129 public boolean isSameFile(FileObject a, FileObject b) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
130 if (a instanceof VirtFO && b instanceof VirtFO) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
131 return ((VirtFO) a).getName().equals(((VirtFO) b).getName());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
132 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
133
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
134 return super.isSameFile(a, b);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
135 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
136
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
137 class VirtFO extends SimpleJavaFileObject {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
138
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
139 private final String n;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
140
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
141 public VirtFO(URI uri, Kind kind, String n) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
142 super(uri, kind);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
143 this.n = n;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
144 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
145
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
146 private final ByteArrayOutputStream data = new ByteArrayOutputStream();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
147
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
148 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
149 public OutputStream openOutputStream() {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
150 return data;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
151 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
152
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
153 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
154 public String getName() {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
155 return n;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
156 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
157
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
158 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
159 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
160 data.close();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
161 return new String(data.toByteArray());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
162 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
163 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
164 };
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
165 List<String> args = Arrays.asList("-source", sourceLevel, "-target", "1.7", //
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
166 "-processor", processor.getName());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
167
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
168 ToolProvider.getSystemJavaCompiler().getTask(null, jfm, this, args, null, Arrays.asList(file)).call();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
169
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
170 Map<String, byte[]> result = new HashMap<>();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
171
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
172 for (Map.Entry<String, ByteArrayOutputStream> e : class2BAOS.entrySet()) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
173 result.put(e.getKey(), e.getValue().toByteArray());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
174 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
175
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
176 return result;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
177 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
178
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
179 @Override
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
180 public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
181 errors.add(diagnostic);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
182 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
183
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
184 void assertErrors() {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
185 assertFalse("There are supposed to be some errors", getErrors().isEmpty());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
186 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
187
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
188 void assertNoErrors() {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
189 assertTrue("There are supposed to be no errors: " + getErrors(), getErrors().isEmpty());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
190 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
191
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
192 void assertError(String expMsg) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
193 StringBuilder sb = new StringBuilder();
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
194 sb.append("Can't find ").append(expMsg).append(" among:");
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
195 for (Diagnostic<? extends JavaFileObject> e : errors) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
196 String msg = e.getMessage(Locale.US);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
197 if (msg.contains(expMsg)) {
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
198 return;
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
199 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
200 sb.append("\n");
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
201 sb.append(msg);
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
202 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
203 fail(sb.toString());
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
204 }
fb17e716b03c The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
205 }