annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/CodeWriter.java @ 20048:8af4e7e0ac9f

Make IGV more robust when parsing block information
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Fri, 27 Mar 2015 14:09:21 +0100
parents 7fab6f106989
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16786
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.dsl.processor;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import java.io.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import javax.annotation.processing.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28 import javax.lang.model.element.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import javax.tools.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import com.oracle.truffle.dsl.processor.java.compiler.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import com.oracle.truffle.dsl.processor.java.model.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 import com.oracle.truffle.dsl.processor.java.transform.*;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 public final class CodeWriter extends AbstractCodeWriter {
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 private final Element originalElement;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 private final ProcessingEnvironment env;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 public CodeWriter(ProcessingEnvironment env, Element originalElement) {
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 this.env = env;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 this.originalElement = originalElement;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 }
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 @Override
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 protected Writer createWriter(CodeTypeElement clazz) throws IOException {
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 JavaFileObject jfo = env.getFiler().createSourceFile(clazz.getQualifiedName(), originalElement);
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 return new BufferedWriter(jfo.openWriter());
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 }
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 @Override
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 protected void writeHeader() {
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 if (env == null) {
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 return;
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 }
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 String comment = CompilerFactory.getCompiler(originalElement).getHeaderComment(env, originalElement);
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 if (comment != null) {
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 writeLn(comment);
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 }
18772
7fab6f106989 Truffle-DSL: avoid some checkstyle errors for generated code.
Christian Humer <christian.humer@gmail.com>
parents: 18163
diff changeset
60 writeLn("// CheckStyle: start generated");
16786
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 }
45c8f64978d6 Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 16786
diff changeset
63 }