KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > core > ext > GeneratorContext


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
21 import java.io.PrintWriter JavaDoc;
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 JavaDoc 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 JavaDoc 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 JavaDoc tryCreate(TreeLogger logger, String JavaDoc packageName, String JavaDoc simpleName);
76
77   /**
78    * Attempts to get an <code>OutputStream</code> so that the caller can write
79    * file contents into the named file underneath the compilation output
80    * directory. The file is not committed until
81    * {@link #commitResource(TreeLogger, OutputStream)} is called.
82    *
83    * @param logger a logger; normally the logger passed into
84    * {@link Generator#generate(TreeLogger, GeneratorContext, String)}
85    * or a branch thereof
86    * @param partialPath the name of the file whose contents are to be written;
87    * the name can include subdirectories separated by forward slashes
88    * ('/')
89    * @return an <code>OutputStream</code> into which file contents can be
90    * written, or <code>null</code> if a resource by that name is
91    * already pending or already exists
92    * @throws UnableToCompleteException if the resource could not be initialized
93    * for some reason, such as if the specified partial path is invalid
94    */

95   OutputStream JavaDoc tryCreateResource(TreeLogger logger, String JavaDoc partialPath)
96       throws UnableToCompleteException;
97 }
98
Popular Tags