public class ReflectUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ReflectUtil.SignatureBuilder
Builder that produces the signature of a method.
|
Constructor and Description |
---|
ReflectUtil() |
Modifier and Type | Method and Description |
---|---|
static 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 String |
getSourceName(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 String |
getSourceName(TypeLiteral<?> typeLiteral)
Alternate toString method for TypeLiterals that fixes a JDK bug that was
replicated in Guice.
|
static String |
getUserPackageName(Key<?> key)
Return the name of the package from which the given key can be used.
|
static String |
getUserPackageName(TypeLiteral<?> typeLiteral)
Return the name of the package from which the given type can be used.
|
static boolean |
hasAccessibleDefaultConstructor(Class<?> clazz)
Returns
true if the given class has a non-private default
constructor, or has no constructor at all. |
static boolean |
isClassOrInterface(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(Class<?> type)
Returns
true if the passed type's visibility is private . |
static boolean |
isPrivate(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(Class<?> type)
Returns
true if the passed type's visibility is public . |
static int |
nonAbstractModifiers(MethodLiteral<?,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.
|
public static String getSourceName(TypeLiteral<?> typeLiteral) throws NoSourceNameException
typeLiteral
- type for which string will be returnedNoSourceNameException
- if source name is not available for typepublic static String getSourceName(Type type) throws NoSourceNameException
type
- type for which string will be returnedNoSourceNameException
- if source name is not available for typepublic static 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 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(Class<?> type)
true
if the passed type's visibility is public
.public static boolean isPrivate(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(Member member)
true
if the passed member's visibility is private
.public static ReflectUtil.SignatureBuilder signatureBuilder(MethodLiteral<?,?> method)
public static 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 signaturepublic static int nonAbstractModifiers(MethodLiteral<?,Method> method)
Useful since interface methods are abstract but we're often writing an implementation for them.
public static boolean isClassOrInterface(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 checkedtrue
if the passed type is a class or interfacepublic static Key<?> getProvidedKey(Key<?> key)
Provider<Foo>
) return the
parameter (Foo
).public static boolean hasAccessibleDefaultConstructor(Class<?> clazz)
true
if the given class has a non-private default
constructor, or has no constructor at all.Copyright © 2008–2018. All rights reserved.