Package com.klaytn.caver.abi
Class TypeReference<T extends Type>
- java.lang.Object
-
- com.klaytn.caver.abi.TypeReference<T>
-
- All Implemented Interfaces:
java.lang.Comparable<TypeReference<T>>
- Direct Known Subclasses:
TypeReference.StaticArrayTypeReference
,TypeReference.StructTypeReference
public abstract class TypeReference<T extends Type> extends java.lang.Object implements java.lang.Comparable<TypeReference<T>>
Type wrapper to get around limitations of Java's type erasure. This is so that we can pass around TypedArray
types.See this blog post for further details.
It may make sense to switch to using Java's reflection Type to avoid working around this fundamental generics limitation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TypeReference.StaticArrayTypeReference<T extends Type>
Type wrapper class for static array type.static class
TypeReference.StructTypeReference<T extends Type>
Type wrapper class for Struct type(StaticStruct, DynamicStruct).
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.regex.Pattern
ARRAY_SUFFIX
-
Constructor Summary
Constructors Modifier Constructor Description protected
TypeReference()
protected
TypeReference(boolean indexed)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(TypeReference<T> o)
static <T extends Type>
TypeReference<T>create(java.lang.Class<T> cls)
static <T extends Type>
TypeReference<T>create(java.lang.Class<T> cls, boolean indexed)
protected static java.lang.Class<? extends Type>
getAtomicTypeClass(java.lang.String solidityType, boolean primitives)
This is a helper method that only works for atomic types (uint, bytes, etc).java.lang.Class<T>
getClassType()
Workaround to ensure type does not come back as T due to erasure, this enables you to create a TypeReference viaClass<T>
.java.lang.reflect.Type
getType()
boolean
isIndexed()
static TypeReference
makeStructTypeReference(java.lang.String tupleString)
Creates a StructTypeReference instance using tupleString.static TypeReference
makeTypeReference(java.lang.String solidityType)
Create a TypeReference instance using solidity type string.static TypeReference
makeTypeReference(java.lang.String solidityType, boolean indexed, boolean primitives)
Create a TypeReference instance using solidity type string.
-
-
-
Method Detail
-
compareTo
public int compareTo(TypeReference<T> o)
-
getType
public java.lang.reflect.Type getType()
-
isIndexed
public boolean isIndexed()
-
getClassType
public java.lang.Class<T> getClassType() throws java.lang.ClassNotFoundException
Workaround to ensure type does not come back as T due to erasure, this enables you to create a TypeReference viaClass<T>
.- Returns:
- the parameterized Class type if applicable, otherwise a regular class
- Throws:
java.lang.ClassNotFoundException
- if the class type cannot be determined
-
create
public static <T extends Type> TypeReference<T> create(java.lang.Class<T> cls)
-
create
public static <T extends Type> TypeReference<T> create(java.lang.Class<T> cls, boolean indexed)
-
getAtomicTypeClass
protected static java.lang.Class<? extends Type> getAtomicTypeClass(java.lang.String solidityType, boolean primitives) throws java.lang.ClassNotFoundException
This is a helper method that only works for atomic types (uint, bytes, etc). Array types must be wrapped by aParameterizedType
.- Parameters:
solidityType
- the solidity as a string eg Address Intprimitives
- is it a primitive type- Returns:
- returns
- Throws:
java.lang.ClassNotFoundException
- when the class cannot be found.
-
makeTypeReference
public static TypeReference makeTypeReference(java.lang.String solidityType) throws java.lang.ClassNotFoundException
Create a TypeReference instance using solidity type string.- Parameters:
solidityType
- A solidity type string to make TypeReference.- Returns:
- TypeReference
- Throws:
java.lang.ClassNotFoundException
-
makeTypeReference
public static TypeReference makeTypeReference(java.lang.String solidityType, boolean indexed, boolean primitives) throws java.lang.ClassNotFoundException
Create a TypeReference instance using solidity type string.- Parameters:
solidityType
- A solidity type string to make TypeReference.indexed
- true if the field is part of the log's topics, false if it one of the logs data.primitives
- If true, a TypeReference instance is created with a type representing the range of the passed integer type.- Returns:
- TypeReference
- Throws:
java.lang.ClassNotFoundException
-
makeStructTypeReference
public static TypeReference makeStructTypeReference(java.lang.String tupleString) throws java.lang.ClassNotFoundException
Creates a StructTypeReference instance using tupleString.- Parameters:
tupleString
- A tuple type string- Returns:
- StructTypeReference
- Throws:
java.lang.ClassNotFoundException
-
-