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

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

public class KeyUtil
extends java.lang.Object

Util object that offers Key retrieval and manipulation methods.


Constructor Summary
KeyUtil(com.google.gwt.core.ext.typeinfo.TypeOracle typeOracle, MemberCollector memberCollector)
           
 
Method Summary
 com.google.gwt.core.ext.typeinfo.JClassType getClassType(Key<?> key)
           
 com.google.gwt.core.ext.typeinfo.JClassType getClassType(java.lang.reflect.Type type)
          Returns the GWT equivalent of the passed java type.
 Key<?> getKey(com.google.gwt.core.ext.typeinfo.JField field)
           
 Key<?> getKey(com.google.gwt.core.ext.typeinfo.JMethod method)
           
 Key<?> getKey(com.google.gwt.core.ext.typeinfo.JParameter param)
           
 Key<?> getKey(com.google.gwt.core.ext.typeinfo.JType gwtType, java.lang.annotation.Annotation... annotations)
          Gets the Guice binding key for a given GWT type with optional annotations.
 Key<?> getKey(java.lang.reflect.Type type, java.lang.annotation.Annotation... annotations)
          Gets the Guice binding key for a given Java type with optional annotations.
 com.google.gwt.core.ext.typeinfo.JClassType getRawClassType(Key<?> key)
           
 java.lang.Class<?> getRawType(Key<?> key)
           
 RequiredKeys getRequiredKeys(com.google.gwt.core.ext.typeinfo.JAbstractMethod method)
          Collects and returns all keys required to inject the given method.
 RequiredKeys getRequiredKeys(com.google.gwt.core.ext.typeinfo.JClassType classType)
          Collects and returns all keys required to inject the given class.
 boolean isMemberInject(com.google.gwt.core.ext.typeinfo.JMethod method)
           
 boolean isOptional(com.google.gwt.core.ext.typeinfo.HasAnnotations member)
          Returns true if the passed class member has an @Inject annotation and the injection is marked as optional ( @Inject(optional=true)).
 com.google.gwt.core.ext.typeinfo.JConstructor javaToGwtConstructor(java.lang.reflect.Constructor<?> javaConstructor, TypeLiteral<?> declaringType)
          Returns a JConstructor that represents the same constructor as the provided Constructor reflection object.
 com.google.gwt.core.ext.typeinfo.JField javaToGwtField(java.lang.reflect.Field javaField)
          Returns a JField that represents the same method as the provided Field reflection object.
 com.google.gwt.core.ext.typeinfo.JMethod javaToGwtMethod(java.lang.reflect.Method javaMethod)
          Returns a JMethod that represents the same method as the provided Method reflection object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyUtil

@Inject
public KeyUtil(com.google.gwt.core.ext.typeinfo.TypeOracle typeOracle,
                      MemberCollector memberCollector)
Method Detail

getKey

public Key<?> getKey(com.google.gwt.core.ext.typeinfo.JMethod method)

getKey

public Key<?> getKey(com.google.gwt.core.ext.typeinfo.JParameter param)

getKey

public Key<?> getKey(com.google.gwt.core.ext.typeinfo.JField field)

isMemberInject

public boolean isMemberInject(com.google.gwt.core.ext.typeinfo.JMethod method)

getRawType

public java.lang.Class<?> getRawType(Key<?> key)

getRawClassType

public com.google.gwt.core.ext.typeinfo.JClassType getRawClassType(Key<?> key)

getClassType

public com.google.gwt.core.ext.typeinfo.JClassType getClassType(Key<?> key)

getClassType

public com.google.gwt.core.ext.typeinfo.JClassType getClassType(java.lang.reflect.Type type)
Returns the GWT equivalent of the passed java type. If the GWT type cannot be resolved, returns null.

Parameters:
type - java type
Returns:
gwt type or null if it cannot be resolved

getKey

public Key<?> getKey(com.google.gwt.core.ext.typeinfo.JType gwtType,
                     java.lang.annotation.Annotation... annotations)
              throws ProvisionException
Gets the Guice binding key for a given GWT type with optional annotations.

Parameters:
gwtType - GWT type to convert in to a key
annotations - Optional array of Annotations. If this contains one and only one BindingAnnotation, it will be included in the key. If it includes more than one, an exception will be thrown.
Returns:
Guice Key instance for this type/annotations
Throws:
ProvisionException - in case of any failure

getKey

public Key<?> getKey(java.lang.reflect.Type type,
                     java.lang.annotation.Annotation... annotations)
              throws ProvisionException
Gets the Guice binding key for a given Java type with optional annotations.

Parameters:
type - Java type to convert in to a key
annotations - Optional array of Annotations. If this contains one and only one BindingAnnotation, it will be included in the key. If it includes more than one, an exception will be thrown.
Returns:
Guice Key instance for this type/annotations
Throws:
ProvisionException - in case of any failure

javaToGwtMethod

public com.google.gwt.core.ext.typeinfo.JMethod javaToGwtMethod(java.lang.reflect.Method javaMethod)
                                                         throws com.google.gwt.core.ext.typeinfo.NotFoundException
Returns a JMethod that represents the same method as the provided Method reflection object.

Parameters:
javaMethod - method as used by reflection
Returns:
method as used by the GWT compiler
Throws:
com.google.gwt.core.ext.typeinfo.NotFoundException - if method cannot be found in source

javaToGwtConstructor

public com.google.gwt.core.ext.typeinfo.JConstructor javaToGwtConstructor(java.lang.reflect.Constructor<?> javaConstructor,
                                                                          TypeLiteral<?> declaringType)
                                                                   throws com.google.gwt.core.ext.typeinfo.NotFoundException
Returns a JConstructor that represents the same constructor as the provided Constructor reflection object. Note: This is almost the same method as javaToGwtMethod(Method) but cannot be merged since constructors and methods do not derive from a common interface in reflection.

Parameters:
javaConstructor - method as used by reflection
declaringType - type which declares the constructor (with type parameters)
Returns:
constructor as used by the GWT compiler
Throws:
com.google.gwt.core.ext.typeinfo.NotFoundException - if constructor cannot be found in source

javaToGwtField

public com.google.gwt.core.ext.typeinfo.JField javaToGwtField(java.lang.reflect.Field javaField)
Returns a JField that represents the same method as the provided Field reflection object.

Parameters:
javaField - field as used by reflection
Returns:
field as used by the GWT compiler

isOptional

public boolean isOptional(com.google.gwt.core.ext.typeinfo.HasAnnotations member)
Returns true if the passed class member has an @Inject annotation and the injection is marked as optional ( @Inject(optional=true)). Note that Inject does not have an optional parameter and therefore cannot be optional.

Parameters:
member - member to be checked
Returns:
true if member is injected optionally

getRequiredKeys

public RequiredKeys getRequiredKeys(com.google.gwt.core.ext.typeinfo.JClassType classType)
Collects and returns all keys required to inject the given class.

Parameters:
classType - class for which required keys are calculated
Returns:
keys required to inject given class

getRequiredKeys

public RequiredKeys getRequiredKeys(com.google.gwt.core.ext.typeinfo.JAbstractMethod method)
Collects and returns all keys required to inject the given method.

Parameters:
method - method for which required keys are calculated
Returns:
required keys