comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/CodeWriter.java @ 16786:45c8f64978d6

Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
author Christian Humer <christian.humer@gmail.com>
date Tue, 12 Aug 2014 17:21:06 +0200
parents
children c88ab4f1f04a
comparison
equal deleted inserted replaced
16785:af3da93ea934 16786:45c8f64978d6
1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.dsl.processor;
24
25 import java.io.*;
26
27 import javax.annotation.processing.*;
28 import javax.lang.model.element.*;
29 import javax.tools.*;
30
31 import com.oracle.truffle.dsl.processor.java.compiler.*;
32 import com.oracle.truffle.dsl.processor.java.model.*;
33 import com.oracle.truffle.dsl.processor.java.transform.*;
34
35 public final class CodeWriter extends AbstractCodeWriter {
36
37 private final Element originalElement;
38 private final ProcessingEnvironment env;
39
40 public CodeWriter(ProcessingEnvironment env, Element originalElement) {
41 this.env = env;
42 this.originalElement = originalElement;
43 }
44
45 @Override
46 protected Writer createWriter(CodeTypeElement clazz) throws IOException {
47 JavaFileObject jfo = env.getFiler().createSourceFile(clazz.getQualifiedName(), originalElement);
48 return new BufferedWriter(jfo.openWriter());
49 }
50
51 @Override
52 protected void writeHeader() {
53 if (env == null) {
54 return;
55 }
56 String comment = CompilerFactory.getCompiler(originalElement).getHeaderComment(env, originalElement);
57 if (comment != null) {
58 writeLn(comment);
59 }
60 }
61
62 }