|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.inject.rebind.reflect.ReflectUtil
public class ReflectUtil
Utility providing helper methods around reflection.
Nested Class Summary | |
---|---|
static class |
ReflectUtil.SignatureBuilder
Builder that produces the signature of a method. |
Constructor Summary | |
---|---|
ReflectUtil()
|
Method Summary | |
---|---|
static java.lang.String |
formatParameterName(int position)
Returns a string representing a parameter name for a method signature. |
static Key<?> |
getProvidedKey(Key<?> key)
Given a parameterized type (such as a Provider<Foo> ) return the
parameter (Foo ). |
static 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. |
static java.lang.String |
getSourceName(TypeLiteral<?> typeLiteral)
Alternate toString method for TypeLiterals that fixes a JDK bug that was replicated in Guice. |
static java.lang.String |
getUserPackageName(Key<?> key)
Return the name of the package from which the given key can be used. |
static java.lang.String |
getUserPackageName(TypeLiteral<?> typeLiteral)
Return the name of the package from which the given type can be used. |
static boolean |
hasAccessibleDefaultConstructor(java.lang.Class<?> clazz)
Returns true if the given class has a non-private default
constructor, or has no constructor at all. |
static boolean |
isClassOrInterface(java.lang.reflect.Type type)
Returns true if the passed type is either a class or an interface
(but not a primitive, enum or similar). |
static boolean |
isPrivate(java.lang.Class<?> type)
Returns true if the passed type's visibility is private . |
static boolean |
isPrivate(java.lang.reflect.Member member)
Returns true if the passed member's visibility is private . |
static boolean |
isPrivate(TypeLiteral<?> type)
Returns true if the passed type's visibility is private . |
static boolean |
isPublic(java.lang.Class<?> type)
Returns true if the passed type's visibility is public . |
static int |
nonAbstractModifiers(MethodLiteral<?,java.lang.reflect.Method> method)
If present, strips the "abstract" modifier from the passed method's modifiers. |
static ReflectUtil.SignatureBuilder |
signatureBuilder(MethodLiteral<?,?> method)
Builds the signature of a method with all types in source form. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ReflectUtil()
Method Detail |
---|
public static java.lang.String getSourceName(TypeLiteral<?> typeLiteral) throws NoSourceNameException
typeLiteral
- type for which string will be returned
NoSourceNameException
- if source name is not available for typepublic static java.lang.String getSourceName(java.lang.reflect.Type type) throws NoSourceNameException
type
- type for which string will be returned
NoSourceNameException
- if source name is not available for typepublic static java.lang.String getUserPackageName(TypeLiteral<?> typeLiteral)
Returns a package from which all the type names contained in the given
type literal are visible. Throws IllegalArgumentException
if there
is no such package. If there are multiple such packages, then the type
name can be used from any package; the package containing the outermost
class is used arbitrarily.
This method is intentionally not overloaded on Class, because it's normally an error to use a raw Class token to determine the package in which to manipulate a type.
public static java.lang.String getUserPackageName(Key<?> key)
Returns a package from which all the type names contained in the given
key are visible. Throws IllegalArgumentException
if there is no
such package.
public static boolean isPublic(java.lang.Class<?> type)
true
if the passed type's visibility is public
.
public static boolean isPrivate(java.lang.Class<?> type)
true
if the passed type's visibility is private
.
public static boolean isPrivate(TypeLiteral<?> type)
true
if the passed type's visibility is private
.
public static boolean isPrivate(java.lang.reflect.Member member)
true
if the passed member's visibility is private
.
public static ReflectUtil.SignatureBuilder signatureBuilder(MethodLiteral<?,?> method)
public static java.lang.String formatParameterName(int position)
Use this method to keep parameter names the same throughout Gin code. Creating synthetic parameter names is necessary since java reflection does not expose source parameter names.
position
- position of the parameter in the signature
public static int nonAbstractModifiers(MethodLiteral<?,java.lang.reflect.Method> method)
Useful since interface methods are abstract but we're often writing an implementation for them.
public static boolean isClassOrInterface(java.lang.reflect.Type type)
true
if the passed type is either a class or an interface
(but not a primitive, enum or similar).
type
- class to be checked
true
if the passed type is a class or interfacepublic static Key<?> getProvidedKey(Key<?> key)
Provider<Foo>
) return the
parameter (Foo
).
public static boolean hasAccessibleDefaultConstructor(java.lang.Class<?> clazz)
true
if the given class has a non-private default
constructor, or has no constructor at all.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |