|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.amazon.carbonado.gen.CodeBuilderUtil
public class CodeBuilderUtil
Collection of useful utilities for generating Carbonado code.
| Constructor Summary | |
|---|---|
CodeBuilderUtil()
|
|
| Method Summary | ||
|---|---|---|
static void |
addEqualsCall(CodeBuilder b,
String fieldName,
TypeDesc fieldType,
boolean testForNull,
Label fail,
LocalVariable other)
Generates code to compare a field in this object against the same one in a different instance. |
|
static void |
addValuesEqualCall(CodeBuilder b,
TypeDesc valueType,
boolean testForNull,
Label label,
boolean choice)
Generates code to compare two values on the stack, and branch to the provided Label if they are not equal. |
|
static void |
assertParameterNotNull(CodeBuilder b,
int paramIndex)
Generate code to throw an exception if a parameter is null |
|
static TypeDesc |
bindQueryParam(Class clazz)
Determines which overloaded "with" method on Query should be bound to. |
|
static void |
blankValue(CodeBuilder b,
TypeDesc type)
Generates code to push a blank value to the stack. |
|
static void |
callStringBuilderAppendChar(CodeBuilder b)
Appends a char to a StringBuilder. |
|
static void |
callStringBuilderAppendString(CodeBuilder b)
Appends a String to a StringBuilder. |
|
static void |
callStringBuilderLength(CodeBuilder b)
Calls length on a StringBuilder on the stack, leaving an int on the stack. |
|
static void |
callStringBuilderSetLength(CodeBuilder b)
Calls setLength on a StringBuilder. |
|
static void |
callStringBuilderToString(CodeBuilder b)
Calls toString on a StringBuilder. |
|
static void |
convertValue(CodeBuilder b,
Class from,
Class to)
Converts a value on the stack. |
|
static
|
createStorableClassFile(ClassInjector ci,
Class<S> type,
boolean isAbstract,
String aSourcefileName)
Define a classfile appropriate for most Storables. |
|
static void |
defineCopyBridges(ClassFile cf,
Class leaf)
Add copy bridge methods for all classes/interfaces between the leaf (genericised class) and the root (genericised baseclass). |
|
static void |
definePrepareBridges(ClassFile cf,
Class leaf)
Add prepare bridge methods for all classes/interfaces between the leaf (genericised class) and the root (genericised baseclass). |
|
static void |
definePrepareMethod(ClassFile cf,
Class storableClass,
TypeDesc supportCtorType)
Defines a Storable prepare method, which assumes that a support field exists and a single-argument constructor exists which accepts a support instance. |
|
static void |
definePrepareMethod(ClassFile cf,
Class storableClass,
TypeDesc supportCtorType,
String supportFieldName,
TypeDesc supportFieldType)
Defines a Storable prepare method, which assumes that a support field exists and a single-argument constructor exists which accepts a support instance. |
|
static Set<Class> |
gatherAllBridgeTypes(Set<Class> set,
Class leaf)
Collect a set of all the interfaces and recursively all superclasses for the leaf (genericised class) and root (genericised base class). |
|
static void |
incrementVersion(CodeBuilder b,
TypeDesc type)
Generates code to increment a version property value, already on the stack. |
|
static void |
initialVersion(CodeBuilder b,
TypeDesc type,
int value)
Generates code to push an initial version property value on the stack. |
|
static boolean |
isPublicMethodFinal(Class clazz,
String name,
TypeDesc retType,
TypeDesc[] params)
Returns true if a public final method exists which matches the given specification. |
|
static void |
throwConcatException(CodeBuilder b,
Class type,
String... messages)
Generate code to throw an exception with a message concatenated at runtime. |
|
static void |
throwException(CodeBuilder b,
Class type,
String message)
Generate code to throw an exception with an optional message. |
|
static LocalVariable |
uneraseGenericParameter(CodeBuilder b,
TypeDesc paramType,
int paramIndex)
Generate code to create a local variable containing the specified parameter coerced to the specified type. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CodeBuilderUtil()
| Method Detail |
|---|
public static void assertParameterNotNull(CodeBuilder b,
int paramIndex)
b - CodeBuilder into which to append the codeparamIndex - index of the parameter to check
public static LocalVariable uneraseGenericParameter(CodeBuilder b,
TypeDesc paramType,
int paramIndex)
b - CodeBuilder into which to append the codeparamType - the more specific type which was erased during compilationparamIndex - index of the parameter to unerase
public static void throwException(CodeBuilder b,
Class type,
String message)
b - CodeBuilder to which to add codetype - type of the object to throwmessage - optional message to provide to the constructor
public static void throwConcatException(CodeBuilder b,
Class type,
String... messages)
b - CodeBuilder to which to add codetype - type of the object to throwmessages - messages to concat at runtime
public static Set<Class> gatherAllBridgeTypes(Set<Class> set,
Class leaf)
A copy must be coercible into any of these types, and copy bridge methods must be provided to do so.
Note that the official documentation for this is in draft form, and you have to be psychic to have figured out the necessity in the first place.
set - set into which the class types will be collectedleaf - leaf class
public static void defineCopyBridges(ClassFile cf,
Class leaf)
cf - file to which to add the copy bridgeleaf - leaf class
public static void definePrepareMethod(ClassFile cf,
Class storableClass,
TypeDesc supportCtorType)
cf - file to which to add the prepare method
public static void definePrepareMethod(ClassFile cf,
Class storableClass,
TypeDesc supportCtorType,
String supportFieldName,
TypeDesc supportFieldType)
cf - file to which to add the prepare method
public static void definePrepareBridges(ClassFile cf,
Class leaf)
cf - file to which to add the prepare bridgeleaf - leaf class
public static boolean isPublicMethodFinal(Class clazz,
String name,
TypeDesc retType,
TypeDesc[] params)
public static <S extends Storable> ClassFile createStorableClassFile(ClassInjector ci,
Class<S> type,
boolean isAbstract,
String aSourcefileName)
ci - ClassInjector for the storabletype - specific Storable implementation to generateisAbstract - true if the class should be abstractaSourcefileName - identifier for the classfile, typically the factory class name
public static void addEqualsCall(CodeBuilder b,
String fieldName,
TypeDesc fieldType,
boolean testForNull,
Label fail,
LocalVariable other)
b - CodeBuilder to which to add the codefieldName - the name of the fieldfieldType - the type of the fieldtestForNull - if true and the values are references, they will be considered
unequal unless neither or both are null. If false, assume neither is null.fail - the label to branch toother - the other instance to test
public static void addValuesEqualCall(CodeBuilder b,
TypeDesc valueType,
boolean testForNull,
Label label,
boolean choice)
The generated instruction consumes both values on the stack.
b - CodeBuilder to which to add the codevalueType - the type of the valuestestForNull - if true and the values are references, they will be considered
unequal unless neither or both are null. If false, assume neither is null.label - the label to branch tochoice - when true, branch to label if values are equal, else
branch to label if values are unequal.
public static void convertValue(CodeBuilder b,
Class from,
Class to)
public static void initialVersion(CodeBuilder b,
TypeDesc type,
int value)
throws SupportException
SupportException - if version type is not supported
public static void incrementVersion(CodeBuilder b,
TypeDesc type)
throws SupportException
SupportException - if version type is not supported
public static void blankValue(CodeBuilder b,
TypeDesc type)
public static TypeDesc bindQueryParam(Class clazz)
public static void callStringBuilderAppendString(CodeBuilder b)
public static void callStringBuilderAppendChar(CodeBuilder b)
public static void callStringBuilderLength(CodeBuilder b)
public static void callStringBuilderSetLength(CodeBuilder b)
public static void callStringBuilderToString(CodeBuilder b)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||