annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/CodeWriter.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 1c38917c00b2
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
25 import com.oracle.truffle.dsl.processor.java.compiler.CompilerFactory;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
26 import com.oracle.truffle.dsl.processor.java.model.CodeTypeElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
27 import com.oracle.truffle.dsl.processor.java.transform.AbstractCodeWriter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
28 import java.io.BufferedWriter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
29 import java.io.IOException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
30 import java.io.Writer;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
31 import javax.annotation.processing.ProcessingEnvironment;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
32 import javax.lang.model.element.Element;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22005
diff changeset
33 import javax.tools.JavaFileObject;
16786
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 }
22005
1c38917c00b2 Fix header check for DSL generated code.
Christian Humer <christian.humer@gmail.com>
parents: 21951
diff changeset
56 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
57 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
58 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
59 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
60 }
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 }