com.google.gwt.inject.rebind.util
Class SourceWriteUtil

java.lang.Object
  extended by com.google.gwt.inject.rebind.util.SourceWriteUtil

public class SourceWriteUtil
extends java.lang.Object

Simple helper object for source writing.


Constructor Summary
protected SourceWriteUtil(KeyUtil keyUtil, NameGenerator nameGenerator, MemberCollector memberCollector, BindingIndex bindingIndex)
           
 
Method Summary
 java.lang.String appendFieldInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter, java.lang.Iterable<com.google.gwt.core.ext.typeinfo.JField> fields, java.lang.String injecteeName)
          Appends a field injecting method for each passed field to the sourceWriter and returns a string that invokes all written methods.
 java.lang.String appendMemberInjection(com.google.gwt.user.rebind.SourceWriter writer, Key<?> key)
          Appends a full member injection (methods and fields) to the provided writer.
 java.lang.String createConstructorInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter, com.google.gwt.core.ext.typeinfo.JConstructor constructor)
          Appends a constructor injecting method to the sourceWriter and returns a string that invokes the written method.
 java.lang.String createFieldInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter, com.google.gwt.core.ext.typeinfo.JField field, java.lang.String injecteeName)
          Appends a field injecting method to the sourceWriter and returns a string that invokes the written method.
 java.lang.String createMethodCallWithInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter, com.google.gwt.core.ext.typeinfo.JAbstractMethod method, java.lang.String injecteeName)
          Appends a new method to the sourceWriter that calls the passed method and returns a string that invokes the written method.
 java.lang.String createMethodCallWithInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter, com.google.gwt.core.ext.typeinfo.JAbstractMethod method, java.lang.String injecteeName, java.lang.String[] parameterNames)
          Appends a new method to the sourceWriter that calls the passed method and returns a string that invokes the written method.
 java.lang.String createMethodInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter, java.lang.Iterable<? extends com.google.gwt.core.ext.typeinfo.JAbstractMethod> methods, java.lang.String injecteeName)
          Appends a method injecting method to the sourceWriter and returns a string that invokes the written method.
 java.lang.String getSourceName(java.lang.reflect.Type type)
          Returns a string representation of the passed type's name while ensuring that all type names (base and parameters) are converted to source type names.
 java.lang.String getSourceName(TypeLiteral<?> typeLiteral)
          Alternate toString method for TypeLiterals that fixes a JDK bug that was replicated in Guice.
 void writeBindingContext(com.google.gwt.user.rebind.SourceWriter writer, BindingContext context)
          Writes out a binding context, followed by a newline.
 void writeBindingContextJavadoc(com.google.gwt.user.rebind.SourceWriter writer, BindingContext bindingContext, Key key)
          Write the Javadoc for the binding of a particular key, showing the context of the binding.
 void writeBindingContextJavadoc(com.google.gwt.user.rebind.SourceWriter writer, BindingContext bindingContext, java.lang.String description)
          Write a Javadoc comment for a binding, including its context.
 void writeMethod(com.google.gwt.user.rebind.SourceWriter writer, java.lang.String signature, java.lang.String body)
          Writes a method with the given signature and body to the source writer.
 void writeNativeMethod(com.google.gwt.user.rebind.SourceWriter writer, java.lang.String signature, java.lang.String body)
          Writes a native method with the given signature and body to the source writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceWriteUtil

@Inject
protected SourceWriteUtil(KeyUtil keyUtil,
                                 NameGenerator nameGenerator,
                                 MemberCollector memberCollector,
                                 BindingIndex bindingIndex)
Method Detail

appendFieldInjection

public java.lang.String appendFieldInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter,
                                             java.lang.Iterable<com.google.gwt.core.ext.typeinfo.JField> fields,
                                             java.lang.String injecteeName)
Appends a field injecting method for each passed field to the sourceWriter and returns a string that invokes all written methods.

Parameters:
sourceWriter - writer to which the injecting method is written
fields - fields to be injected
injecteeName - variable that references the object into which values are injected, in the context of the returned call string
Returns:
string calling the generated method

createFieldInjection

public java.lang.String createFieldInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter,
                                             com.google.gwt.core.ext.typeinfo.JField field,
                                             java.lang.String injecteeName)
Appends a field injecting method to the sourceWriter and returns a string that invokes the written method.

Parameters:
sourceWriter - writer to which the injecting method is written
field - field to be injected
injecteeName - variable that references the object into which values are injected, in the context of the returned call string
Returns:
string calling the generated method

createMethodInjection

public java.lang.String createMethodInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter,
                                              java.lang.Iterable<? extends com.google.gwt.core.ext.typeinfo.JAbstractMethod> methods,
                                              java.lang.String injecteeName)
Appends a method injecting method to the sourceWriter and returns a string that invokes the written method. The values for the passed method's parameters are retrieved through the Ginjector.

If the passed method collection contains only one actual method, the native method will pass on (i.e. return) the result of the actual method's invocation, if any.

The passed method collection can contain constructors (they'll be treated correctly) if no injecteeName is passed. The same applies for static methods.

If a method without parameters is provided, that method will be called and no parameters will be passed.

Parameters:
sourceWriter - writer to which the injecting method is written
methods - methods to be called & injected
injecteeName - variable that references the object into which values are injected, in the context of the returned call string. If null all passed methods are called as static/constructors.
Returns:
string calling the generated method

createConstructorInjection

public java.lang.String createConstructorInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter,
                                                   com.google.gwt.core.ext.typeinfo.JConstructor constructor)
Appends a constructor injecting method to the sourceWriter and returns a string that invokes the written method. The written method returns the constructed object.

Parameters:
sourceWriter - writer to which the injecting method is written
constructor - constructor to call
Returns:
string calling the generated method

createMethodCallWithInjection

public java.lang.String createMethodCallWithInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter,
                                                      com.google.gwt.core.ext.typeinfo.JAbstractMethod method,
                                                      java.lang.String injecteeName)
Appends a new method to the sourceWriter that calls the passed method and returns a string that invokes the written method. The written method returns the passed method's return value, if any.

If a method without parameters is provided, that method will be called and no parameters will be passed.

Parameters:
sourceWriter - writer to which the injecting method is written
method - method to call (can be constructor)
injecteeName - variable that references the object into which values are injected, in the context of the returned call string. If null all passed methods are called as static/constructors.
Returns:
string calling the generated method

createMethodCallWithInjection

public java.lang.String createMethodCallWithInjection(com.google.gwt.user.rebind.SourceWriter sourceWriter,
                                                      com.google.gwt.core.ext.typeinfo.JAbstractMethod method,
                                                      java.lang.String injecteeName,
                                                      java.lang.String[] parameterNames)
Appends a new method to the sourceWriter that calls the passed method and returns a string that invokes the written method. The written method returns the passed method's return value, if any.

If a method without parameters is provided, that method will be called and no parameters will be passed. If the passed method declared any checked exceptions, the generated method will catch and rethrow those as CreationException.

Parameters:
sourceWriter - writer to which the injecting method is written
method - method to call (can be constructor)
injecteeName - variable that references the object into which values are injected, in the context of the returned call string. If null all passed methods are called as static/constructors.
parameterNames - array with parameter names that can replace getter methods (usually used to fetch injected values) in the returned string. The array length must match the number of method parameters. A null value denotes that the getter method should be used.
Returns:
string calling the generated method

writeBindingContext

public void writeBindingContext(com.google.gwt.user.rebind.SourceWriter writer,
                                BindingContext context)
Writes out a binding context, followed by a newline.

Binding contexts may contain newlines; this routine translates those for the SourceWriter to ensure that indents, Javadoc comments, etc are handled properly.


writeBindingContextJavadoc

public void writeBindingContextJavadoc(com.google.gwt.user.rebind.SourceWriter writer,
                                       BindingContext bindingContext,
                                       java.lang.String description)
Write a Javadoc comment for a binding, including its context.

Parameters:
description - The description of the binding printed before its location, such as "Foo bound at: "
writer - The writer to use in displaying the context.
bindingContext - The context of the binding.

writeBindingContextJavadoc

public void writeBindingContextJavadoc(com.google.gwt.user.rebind.SourceWriter writer,
                                       BindingContext bindingContext,
                                       Key key)
Write the Javadoc for the binding of a particular key, showing the context of the binding.

Parameters:
key - The bound key.
writer - The writer to use to write this comment.
bindingContext - The context of the binding.

writeMethod

public void writeMethod(com.google.gwt.user.rebind.SourceWriter writer,
                        java.lang.String signature,
                        java.lang.String body)
Writes a method with the given signature and body to the source writer.

Parameters:
writer - writer that the method is written to
signature - method's signature
body - method's body

writeNativeMethod

public void writeNativeMethod(com.google.gwt.user.rebind.SourceWriter writer,
                              java.lang.String signature,
                              java.lang.String body)
Writes a native method with the given signature and body to the source writer.

Parameters:
writer - writer that the method is written to
signature - method's signature
body - method's body

appendMemberInjection

public java.lang.String appendMemberInjection(com.google.gwt.user.rebind.SourceWriter writer,
                                              Key<?> key)
Appends a full member injection (methods and fields) to the provided writer.

Parameters:
writer - source writer to write to
key - key for which the injection is performed
Returns:
name of the method created

getSourceName

public java.lang.String getSourceName(TypeLiteral<?> typeLiteral)
                               throws NoSourceNameException
Alternate toString method for TypeLiterals that fixes a JDK bug that was replicated in Guice. See the related Guice bug for details. Also replaces all binary with source names in the types involved (base type and type parameters).

Parameters:
typeLiteral - type for which string will be returned
Returns:
String representation of type
Throws:
NoSourceNameException - if source name is not available for type

getSourceName

public java.lang.String getSourceName(java.lang.reflect.Type type)
                               throws NoSourceNameException
Returns a string representation of the passed type's name while ensuring that all type names (base and parameters) are converted to source type names.

Parameters:
type - type for which string will be returned
Returns:
String representation of type
Throws:
NoSourceNameException - if source name is not available for type