001    /*
002     * Copyright 2006 Google Inc.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package com.google.gwt.core.ext;
017    
018    import com.google.gwt.core.ext.typeinfo.TypeOracle;
019    
020    import java.io.PrintWriter;
021    
022    public interface GeneratorContext {
023    
024      /**
025       * Attempts to get a <code>PrintWriter</code> so that the caller can
026       * generate the source code for the named type. If the named types already
027       * exists, <code>null</code> is returned to indicate that no work needs to
028       * be done.
029       * 
030       * @param logger a logger; normally the logger passed into
031       *          {@link Generator#generate(TreeLogger, GeneratorContext, String)}
032       *          or a branch thereof
033       * @param packageName the name of the package to which the create type belongs
034       * @param simpleName the unqualified source name of the type being generated
035       * @return null if the package and class already exists, otherwise a
036       *         <code>PrintWriter</code> is returned.
037       */
038      PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleName);
039    
040      /**
041       * Commits source generation begun with
042       * {@link #tryCreate(TreeLogger, String, String)}.
043       */
044      void commit(TreeLogger logger, PrintWriter pw);
045    
046      /**
047       * Gets the type oracle for the current generator context. Generators can use
048       * the type oracle to ask questions about the entire translatable code base.
049       * 
050       * @return a TypeOracle over all the relevant translatable compilation units
051       *         in the source path
052       */
053      TypeOracle getTypeOracle();
054    
055      /**
056       * Gets the property oracle for the current generator context. Generators can
057       * use the property oracle to query deferred binding properties.
058       */
059      PropertyOracle getPropertyOracle();
060    }