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

Helper object for source writing.


Nested Class Summary
static interface SourceWriteUtil.Factory
          Factory for SourceWriteUtil.
 
Constructor Summary
protected SourceWriteUtil(GuiceUtil guiceUtil, MemberCollector memberCollector, MethodCallUtil methodCallUtil, BindingIndex bindingIndex)
           
 
Method Summary
 SourceSnippet createFieldInjection(FieldLiteral<?> field, java.lang.String injecteeName, NameGenerator nameGenerator, java.util.List<InjectorMethod> methodsOutput)
          Creates a field injecting method and returns a string that invokes the written method.
 SourceSnippet createFieldInjections(java.lang.Iterable<FieldLiteral<?>> fields, java.lang.String injecteeName, NameGenerator nameGenerator, java.util.List<InjectorMethod> methodsOutput)
          Appends a field injecting method for each passed field to the sourceWriter and returns a string that invokes all written methods.
 java.lang.String createMemberInjection(TypeLiteral<?> type, NameGenerator nameGenerator, java.util.List<InjectorMethod> methodsOutput)
          Generates all the required injector methods to inject members of the given type, and a standard member-inject method that invokes them.
 SourceSnippet createMethodInjections(java.lang.Iterable<? extends MethodLiteral<?,?>> methods, java.lang.String injecteeName, NameGenerator nameGenerator, java.util.List<InjectorMethod> methodsOutput)
          Creates a method injecting method and returns a string that invokes the new method.
static java.lang.CharSequence join(java.lang.CharSequence delimiter, java.lang.Iterable<? extends java.lang.CharSequence> list)
           
 void writeBindingContext(com.google.gwt.user.rebind.SourceWriter writer, Context context)
          Writes out a binding context, followed by a newline.
 void writeBindingContextJavadoc(com.google.gwt.user.rebind.SourceWriter writer, Context 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, Context bindingContext, java.lang.String description)
          Write a Javadoc comment for a binding, including its context.
 void writeMethod(InjectorMethod method, com.google.gwt.user.rebind.SourceWriter writer, InjectorWriteContext writeContext)
          Writes the given method to the given source writer.
 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 writeMethods(java.lang.Iterable<InjectorMethod> methods, com.google.gwt.user.rebind.SourceWriter writer, InjectorWriteContext writeContext)
          Writes the given methods to the given 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(GuiceUtil guiceUtil,
                                 MemberCollector memberCollector,
                                 MethodCallUtil methodCallUtil,
                                 BindingIndex bindingIndex)
Method Detail

createFieldInjections

public SourceSnippet createFieldInjections(java.lang.Iterable<FieldLiteral<?>> fields,
                                           java.lang.String injecteeName,
                                           NameGenerator nameGenerator,
                                           java.util.List<InjectorMethod> methodsOutput)
                                    throws NoSourceNameException
Appends a field injecting method for each passed field to the sourceWriter and returns a string that invokes all written methods.

Parameters:
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
Throws:
NoSourceNameException

createFieldInjection

public SourceSnippet createFieldInjection(FieldLiteral<?> field,
                                          java.lang.String injecteeName,
                                          NameGenerator nameGenerator,
                                          java.util.List<InjectorMethod> methodsOutput)
                                   throws NoSourceNameException
Creates a field injecting method and returns a string that invokes the written method.

Parameters:
field - field to be injected
injecteeName - variable that references the object into which values are injected, in the context of the returned call string
nameGenerator - NameGenerator to be used for ensuring method name uniqueness
Returns:
string calling the generated method
Throws:
NoSourceNameException

createMethodInjections

public SourceSnippet createMethodInjections(java.lang.Iterable<? extends MethodLiteral<?,?>> methods,
                                            java.lang.String injecteeName,
                                            NameGenerator nameGenerator,
                                            java.util.List<InjectorMethod> methodsOutput)
                                     throws NoSourceNameException
Creates a method injecting method and returns a string that invokes the new 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:
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.
nameGenerator - NameGenerator to be used for ensuring method name uniqueness
methodsOutput - a list where all new methods created by this call are added
Returns:
source snippet calling the generated method
Throws:
NoSourceNameException

writeBindingContext

public void writeBindingContext(com.google.gwt.user.rebind.SourceWriter writer,
                                Context 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,
                                       Context 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,
                                       Context 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

writeMethod

public void writeMethod(InjectorMethod method,
                        com.google.gwt.user.rebind.SourceWriter writer,
                        InjectorWriteContext writeContext)
                 throws NoSourceNameException
Writes the given method to the given source writer.

Throws:
NoSourceNameException

writeMethods

public void writeMethods(java.lang.Iterable<InjectorMethod> methods,
                         com.google.gwt.user.rebind.SourceWriter writer,
                         InjectorWriteContext writeContext)
                  throws NoSourceNameException
Writes the given methods to the given source writer.

Parameters:
methods - the methods to write
writer - the source writer to which the methods should be written
writeContext - the context in which to write the methods
Throws:
NoSourceNameException

createMemberInjection

public java.lang.String createMemberInjection(TypeLiteral<?> type,
                                              NameGenerator nameGenerator,
                                              java.util.List<InjectorMethod> methodsOutput)
                                       throws NoSourceNameException
Generates all the required injector methods to inject members of the given type, and a standard member-inject method that invokes them.

Parameters:
type - type for which the injection is performed
nameGenerator - the name generator used to create method names
methodsOutput - a list to which the new injection method and all its helpers are added
Returns:
name of the method created
Throws:
NoSourceNameException

join

public static java.lang.CharSequence join(java.lang.CharSequence delimiter,
                                          java.lang.Iterable<? extends java.lang.CharSequence> list)