public class SourceCodeContext extends Object
| Constructor and Description |
|---|
SourceCodeContext(String baseClassName,
Class<?> superClass,
MappingContext mappingContext,
StringBuilder logDetails)
Constructs a new instance of SourceCodeContext
|
| Modifier and Type | Method and Description |
|---|---|
void |
addField(String fieldSource)
Adds a field definition to the class based on the provided source.
|
void |
addMethod(String methodSource)
Adds a method definition to the class based on the provided source.
|
boolean |
aggregateSpecsApply(FieldMap fieldMap)
Tests whether any aggregate specifications apply for the specified
FieldMap, and if so, adds it to the list of FieldMaps for that spec,
returning true.
|
static void |
append(StringBuilder out,
String... statements)
Appends all of the String values provided to the StringBuilder in order,
as "statements"
|
VariableRef[] |
applyFilters(VariableRef sourceProperty,
VariableRef destinationProperty,
StringBuilder out,
StringBuilder closing) |
String |
assureContainerInstanceExists(FieldMap fieldMap)
Append a statement with assures that the container variable reference
has an existing instance; if it does not, a new object is generated
using MapperFacade.newObject
|
String |
assureInstanceExists(VariableRef propertyRef,
VariableRef source)
Append a statement which assures that the variable reference has an
existing instance; if it does not, a new object is generated using
MapperFacade.newObject
|
String |
callMapper(Type<?> sourceType,
Type<?> destinationType,
String sourceExpression) |
String |
callMapper(Type<?> sourceType,
Type<?> destinationType,
String sourceExpression,
String destExpression) |
String |
callMapper(VariableRef source,
Type<?> destination) |
String |
callMapper(VariableRef source,
VariableRef destination) |
String |
compareFields(FieldMap fieldMap,
VariableRef sourceProperty,
VariableRef destinationProperty,
Type<?> destinationType,
StringBuilder logDetails)
Generates source code for an "equality" comparison of two variables,
based on the FieldMap passed
|
protected Class<?> |
compileClass()
Compile and return the (generated) class; this will also cause the
generated class to be detached from the class-pool, and any (optional)
source and/or class files to be written.
|
String |
currentElementComparator(Node source,
Node dest,
Node.NodeList srcNodes,
Node.NodeList destNodes) |
void |
debug(String msg) |
void |
debugField(FieldMap fieldMap,
String msg) |
static VariableRef |
entrySetRef(VariableRef s)
Creates a VariableRef representing a Set
|
String |
fieldTag(FieldMap fieldMap) |
Set<FieldMap> |
getAssociatedMappings(Collection<FieldMap> fieldMaps,
FieldMap map)
Finds all field maps out of the provided set which are associated with
the map passed in ( including that map itself); by "associated", we mean
any mappings which are connected to the original FieldMap by having a
matching source or destination, including transitive associations.
|
String |
getClassName() |
String |
getClassSimpleName() |
<T extends GeneratedObjectBase> |
getInstance() |
MappingContext |
getMappingContext() |
String |
getPackageName() |
protected StringBuilder |
getSourceBuilder() |
Class<?> |
getSuperClass() |
boolean |
isDebugEnabled() |
static String |
join(List<?> list,
String separator)
Join the items in the list together in a String, separated by the
provided separator
|
String |
mapAggregateFields() |
String |
mapFields(FieldMap fieldMap,
VariableRef source,
VariableRef destination)
Generate the code necessary to process the provided FieldMap.
|
String |
newObject(VariableRef source,
Type<?> destinationType) |
String |
newObjectFromMapper(Type<?> sourceType,
Type<?> destinationType) |
String |
newObjectFromMapper(VariableRef source,
Type<?> destinationType)
Generates a code snippet to generate a new instance of the destination
type from a mapper
|
boolean |
shouldMapNulls() |
static String |
statement(String str,
Object... args)
Appends the provided string as a source code statement, ending it with a
statement terminator as appropriate.
|
String |
toSourceFile() |
String |
usedConverter(Converter<?,?> converter) |
String |
usedFilter(Filter<?,?> filter) |
String |
usedMapperFacadeNewObjectCall(VariableRef source,
VariableRef destination) |
String |
usedType(Type<?> type) |
String |
usedType(VariableRef r)
Generate usedType array index code for the provided variable
|
public SourceCodeContext(String baseClassName, Class<?> superClass, MappingContext mappingContext, StringBuilder logDetails)
baseClassName - superClass - mappingContext - logDetails - public boolean isDebugEnabled()
public void debug(String msg)
protected StringBuilder getSourceBuilder()
public Class<?> getSuperClass()
public String getClassSimpleName()
public String getPackageName()
public String getClassName()
public boolean shouldMapNulls()
public MappingContext getMappingContext()
public void addMethod(String methodSource)
methodSource - public void addField(String fieldSource)
fieldSource - the source from which to compile the fieldpublic String toSourceFile()
protected Class<?> compileClass() throws CompilerStrategy.SourceCodeGenerationException
CannotCompileExceptionIOExceptionCompilerStrategy.SourceCodeGenerationExceptionpublic <T extends GeneratedObjectBase> T getInstance() throws CompilerStrategy.SourceCodeGenerationException, InstantiationException, IllegalAccessException
CannotCompileExceptionIOExceptionInstantiationExceptionIllegalAccessExceptionCompilerStrategy.SourceCodeGenerationExceptionpublic String callMapper(Type<?> sourceType, Type<?> destinationType, String sourceExpression, String destExpression)
sourceType - destinationType - sourceExpression - destExpression - public String callMapper(Type<?> sourceType, Type<?> destinationType, String sourceExpression)
sourceType - destinationType - sourceExpression - public String callMapper(VariableRef source, VariableRef destination)
source - destination - public String callMapper(VariableRef source, Type<?> destination)
source - destination - public String usedMapperFacadeNewObjectCall(VariableRef source, VariableRef destination)
public String newObjectFromMapper(VariableRef source, Type<?> destinationType)
source - destinationType - public String usedType(VariableRef r)
r - public String newObject(VariableRef source, Type<?> destinationType)
source - destinationType - public String assureContainerInstanceExists(FieldMap fieldMap)
fieldMap - public String assureInstanceExists(VariableRef propertyRef, VariableRef source)
propertyRef - the property or variable reference on which to check for an
instancesource - this SourceCodeBuilderpublic static String statement(String str, Object... args)
str - args - this SourceCodeBuilderpublic static void append(StringBuilder out, String... statements)
out - statements - public static String join(List<?> list, String separator)
list - separator - public static VariableRef entrySetRef(VariableRef s)
s - the Map type variable refpublic String currentElementComparator(Node source, Node dest, Node.NodeList srcNodes, Node.NodeList destNodes)
source - dest - srcNodes - destNodes - mappings - any relevant declared field mappingspublic Set<FieldMap> getAssociatedMappings(Collection<FieldMap> fieldMaps, FieldMap map)
fieldMaps - the set of all field mapsmap - the field map from which to start searching for referencepublic boolean aggregateSpecsApply(FieldMap fieldMap)
fieldMap - public String mapAggregateFields()
public String mapFields(FieldMap fieldMap, VariableRef source, VariableRef destination)
fieldMap - the FieldMap describing fields to be mappedsource - a variable reference to the source propertydestination - a variable reference to the destination propertythis CodeSourceBuilderpublic VariableRef[] applyFilters(VariableRef sourceProperty, VariableRef destinationProperty, StringBuilder out, StringBuilder closing)
public String compareFields(FieldMap fieldMap, VariableRef sourceProperty, VariableRef destinationProperty, Type<?> destinationType, StringBuilder logDetails)
fieldMap - sourceProperty - destinationProperty - destinationType - logDetails - Copyright © 2017 Glasnost. All Rights Reserved.