annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/Compile.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/Compile.java@b1530a6cce8c
children dc83cc1f94f2
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
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
25 import static org.junit.Assert.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
26
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
27 import java.io.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
28 import java.net.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
29 import java.util.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
30
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21466
diff changeset
31 import javax.tools.*;
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
32 import javax.tools.JavaFileObject.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
33
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
34 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
35 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
36 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
37 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
38
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
39 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
40 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
41 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
42 }
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
43
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
44 /**
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
45 * 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
46 */
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
47 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
48 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
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
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 /** 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
52 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
53 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
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
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 /**
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 * 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
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 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
60 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
61 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
62 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
63 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
64 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
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 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
68 }
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
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 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
71 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
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 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
74 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
75
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 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
77 @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
78 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
79 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
80 }
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 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
84 @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
85 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
86 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
87 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
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 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
90 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
91 @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
92 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
93 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
94 }
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 };
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 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
99 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
100 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
101 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
102 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
103 } 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
104 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
105 }
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 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
107 }
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
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 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
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 @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
113 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
114 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
115 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
116 }
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
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 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
119 }
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
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 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
122
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 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
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 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
126 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
127 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
128 }
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
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 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
131
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 @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
133 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
134 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
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 @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
138 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
139 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
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
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 @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
143 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
144 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
145 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
146 }
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 };
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 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
150 "-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
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 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
153
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 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
155
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 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
157 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
158 }
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
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 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
161 }
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 @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
164 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
165 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
166 }
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 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
169 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
170 }
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 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
173 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
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 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
177 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
178 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
179 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
180 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
181 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
182 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
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 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
185 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
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 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
188 }
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 }