01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.core.ext;
17:
18: import com.google.gwt.core.ext.typeinfo.TypeOracle;
19:
20: import java.io.OutputStream;
21: import java.io.PrintWriter;
22:
23: /**
24: * Provides metadata to deferred binding generators.
25: */
26: public interface GeneratorContext {
27:
28: /**
29: * Commits source generation begun with
30: * {@link #tryCreate(TreeLogger, String, String)}.
31: */
32: void commit(TreeLogger logger, PrintWriter pw);
33:
34: /**
35: * Commits resource generation begun with
36: * {@link #tryCreateResource(TreeLogger, String)}.
37: *
38: * @throws UnableToCompleteException if the resource cannot be written to
39: * disk, if the specified stream is unknown, or if the stream has
40: * already been committed
41: */
42: void commitResource(TreeLogger logger, OutputStream os)
43: throws UnableToCompleteException;
44:
45: /**
46: * Gets the property oracle for the current generator context. Generators can
47: * use the property oracle to query deferred binding properties.
48: */
49: PropertyOracle getPropertyOracle();
50:
51: /**
52: * Gets the type oracle for the current generator context. Generators can use
53: * the type oracle to ask questions about the entire translatable code base.
54: *
55: * @return a TypeOracle over all the relevant translatable compilation units
56: * in the source path
57: */
58: TypeOracle getTypeOracle();
59:
60: /**
61: * Attempts to get a <code>PrintWriter</code> so that the caller can
62: * generate the source code for the named type. If the named types already
63: * exists, <code>null</code> is returned to indicate that no work needs to
64: * be done. The file is not committed until
65: * {@link #commit(TreeLogger, PrintWriter)} is called.
66: *
67: * @param logger a logger; normally the logger passed into
68: * {@link Generator#generate(TreeLogger, GeneratorContext, String)}
69: * or a branch thereof
70: * @param packageName the name of the package to which the create type belongs
71: * @param simpleName the unqualified source name of the type being generated
72: * @return <code>null</code> if the package and class already exists,
73: * otherwise a <code>PrintWriter</code> is returned.
74: */
75: PrintWriter tryCreate(TreeLogger logger, String packageName,
76: String simpleName);
77:
78: /**
79: * Attempts to get an <code>OutputStream</code> so that the caller can write
80: * file contents into the named file underneath the compilation output
81: * directory. The file is not committed until
82: * {@link #commitResource(TreeLogger, OutputStream)} is called.
83: *
84: * @param logger a logger; normally the logger passed into
85: * {@link Generator#generate(TreeLogger, GeneratorContext, String)}
86: * or a branch thereof
87: * @param partialPath the name of the file whose contents are to be written;
88: * the name can include subdirectories separated by forward slashes
89: * ('/')
90: * @return an <code>OutputStream</code> into which file contents can be
91: * written, or <code>null</code> if a resource by that name is
92: * already pending or already exists
93: * @throws UnableToCompleteException if the resource could not be initialized
94: * for some reason, such as if the specified partial path is invalid
95: */
96: OutputStream tryCreateResource(TreeLogger logger, String partialPath)
97: throws UnableToCompleteException;
98: }
|