Package org.faktorips.codegen.dthelpers
Class AbstractDatatypeHelper
java.lang.Object
org.faktorips.codegen.dthelpers.AbstractDatatypeHelper
- All Implemented Interfaces:
BaseDatatypeHelper<JavaCodeFragment>,DatatypeHelper
- Direct Known Subclasses:
AbstractPrimitiveDatatypeHelper,AbstractTimeHelper,ArrayOfValueDatatypeHelper,BigDecimalHelper,BooleanHelper,CurrencyHelper,DateHelper,DecimalHelper,DoubleHelper,GenericValueDatatypeHelper,GregorianCalendarAsDateHelper,IntegerHelper,InternationalStringDatatypeHelper,ListOfValueDatatypeHelper,LongHelper,MoneyHelper,StringHelper
Abstract base class for datatype helpers.
- Author:
- Jan Ortmann
-
Field Summary
Fields inherited from interface org.faktorips.codegen.DatatypeHelper
BIG_DECIMAL, BOOLEAN, DECIMAL, INTEGER, LONG, MONEY, PRIMITIVE_BOOLEAN, PRIMITIVE_INTEGER, STRING -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new helper without initializing the datatype.AbstractDatatypeHelper(Datatype datatype) Constructs a new helper for the given datatype. -
Method Summary
Modifier and TypeMethodDescriptioncreateCastExpression(String bound) Returns aJavaCodeFragmentwith anew value instance, adding a cast to the value's data type in case the value is empty to avoid problems with generics.Returns the datatype this is a helper for.getRangeJavaClassName(boolean useTypesafeCollections) Returns the qualified Java class name of the range class of the datatype this is a helper for.getToStringExpression(String fieldName) Returns aJavaCodeFragmentcontaining the code for converting the value (of the given field) to a string representation with respect to its data type.newEnumValueSetInstance(String[] values, boolean containsNull, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.newEnumValueSetInstance(JavaCodeFragment valueCollection, JavaCodeFragment containsNullExpression, boolean useTypesafeCollections, boolean virtual) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.newInstanceFromExpression(String expression) Returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression.newInstanceFromExpression(String expression, boolean checkForNull) Returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression.newRangeInstance(JavaCodeFragment lowerBoundExp, JavaCodeFragment upperBoundExp, JavaCodeFragment stepExp, JavaCodeFragment containsNullExp, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new instance of a type specific range.protected JavaCodeFragmentnewSafeCopy(String expression) Helpers for immutable datatypes must override this method to create a copy of the value given in the expression.Returns"null".referenceOrSafeCopyIfNeccessary(String expression) If this is a helper for a mutable data type (like GregorianCalendar for example) this method return the code fragment that creates a copy of the given expression.voidsetDatatype(Datatype datatype) Sets the datatype this is a helper for.protected abstract JavaCodeFragmentvalueOfExpression(String expression) This method is supposed to be overridden by subclasses.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.faktorips.codegen.DatatypeHelper
getJavaClassName, getValueSetJavaClassName, newEnumValueSetInstance, newInstance, newValueInstance
-
Constructor Details
-
AbstractDatatypeHelper
public AbstractDatatypeHelper()Constructs a new helper without initializing the datatype. -
AbstractDatatypeHelper
Constructs a new helper for the given datatype.
-
-
Method Details
-
getDatatype
Description copied from interface:DatatypeHelperReturns the datatype this is a helper for.- Specified by:
getDatatypein interfaceBaseDatatypeHelper<JavaCodeFragment>- Specified by:
getDatatypein interfaceDatatypeHelper
-
setDatatype
Description copied from interface:DatatypeHelperSets the datatype this is a helper for. Introduced to enable setter based dependency injection, needed for example for Eclipse's extension point mechanism.- Specified by:
setDatatypein interfaceBaseDatatypeHelper<JavaCodeFragment>- Specified by:
setDatatypein interfaceDatatypeHelper
-
valueOfExpression
This method is supposed to be overridden by subclasses.It is used within the
newInstanceFromExpression(String)method. It returns aJavaCodeFragmentwith sourcecode that creates an instance of the datatype's Java class with the given expression.If the expression is
nullthe fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object. Preconditions: Expression may not be null or empty. When evaluated the expression must return a String. -
newInstanceFromExpression
Description copied from interface:DatatypeHelperReturns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression. If the expression is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object. When evaluated the expression must return a string.- Specified by:
newInstanceFromExpressionin interfaceBaseDatatypeHelper<JavaCodeFragment>- Specified by:
newInstanceFromExpressionin interfaceDatatypeHelper- Parameters:
expression- A Java source code expression that yields a String. Examples are a constant String like"FOO", a variable likefooor a method call likegetÍd().
-
newInstanceFromExpression
Description copied from interface:DatatypeHelperReturns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression. If the expression is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object. When evaluated the expression must return a string- Specified by:
newInstanceFromExpressionin interfaceBaseDatatypeHelper<JavaCodeFragment>- Specified by:
newInstanceFromExpressionin interfaceDatatypeHelper- Parameters:
expression- A Java source code expression that yields a String. Examples are a constant String like"FOO", a variable likefooor a method call likegetÍd().checkForNull-trueif this helper has to assume that the given expression can yieldnullor the empty string. Can be used to generate simpler code, if the null check is not necessary.
-
getRangeJavaClassName
Description copied from interface:DatatypeHelperReturns the qualified Java class name of the range class of the datatype this is a helper for.- Specified by:
getRangeJavaClassNamein interfaceDatatypeHelper
-
newRangeInstance
public JavaCodeFragment newRangeInstance(JavaCodeFragment lowerBoundExp, JavaCodeFragment upperBoundExp, JavaCodeFragment stepExp, JavaCodeFragment containsNullExp, boolean useTypesafeCollections) Description copied from interface:DatatypeHelperReturns aJavaCodeFragmentcontaining the source code to create a new instance of a type specific range.- Specified by:
newRangeInstancein interfaceDatatypeHelper- Parameters:
lowerBoundExp- the lower bound expression of the range. Can benullto indicate that the lower bound is openupperBoundExp- the upper bound expression of the range. Can benullto indicate that the upper bound is open.stepExp- the minimum increment expression for values within the lower and upper bounds. Can benullto indicate that this is a continuous range.containsNullExp- the containsNull expression- Returns:
- the code fragment to create a new range instance. Can be null to indicate that a range is not supported.
-
newEnumValueSetInstance
public JavaCodeFragment newEnumValueSetInstance(String[] values, boolean containsNull, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance. Code sample(IEnumValueSet)new DefaultEnumValueSet<>( true, GeneratedGender.getGeneratedGender(null), GeneratedGender.getGeneratedGender(Integer.valueOf(1)), GeneratedGender.getGeneratedGender(Integer.valueOf(2)));- Specified by:
newEnumValueSetInstancein interfaceDatatypeHelper- Parameters:
values- the values contained in the enum value set code fragment returned by this methodcontainsNull- indicates ifnullis also contained in the returned enum value setuseTypesafeCollections- indicates if Java 5 typesafe collections and valuetypes shall be used
-
newEnumValueSetInstance
public JavaCodeFragment newEnumValueSetInstance(JavaCodeFragment valueCollection, JavaCodeFragment containsNullExpression, boolean useTypesafeCollections, boolean virtual) Description copied from interface:DatatypeHelperReturns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.- Specified by:
newEnumValueSetInstancein interfaceDatatypeHelper- Parameters:
valueCollection- a JavaCodeFragment is expected that contains an expression of the typejava.util.CollectionThe collection has to contain instances of the datatype of this helper.containsNullExpression- a JavaCodeFragment is expected that contains an expression of the typebooleanuseTypesafeCollections- indicates if Java 5 typesafe collections and valuetypes shall be usedvirtual- a boolean flag indicating whether the generated value set should be marked as virtual. Virtual value sets represent OrderedValueSets created for UnrestrictedValueSets of enumeration and are not meant for persistence.
-
referenceOrSafeCopyIfNeccessary
Description copied from interface:DatatypeHelperIf this is a helper for a mutable data type (like GregorianCalendar for example) this method return the code fragment that creates a copy of the given expression. For immutable data types this method returns the expression unmodified.- Specified by:
referenceOrSafeCopyIfNeccessaryin interfaceDatatypeHelper- Parameters:
expression- An expression (as Java sourcecode)- Returns:
- s. above
-
newSafeCopy
Helpers for immutable datatypes must override this method to create a copy of the value given in the expression.- Parameters:
expression- The expression of which you want to get the new safe copy code fragment from
-
getToStringExpression
Description copied from interface:DatatypeHelperReturns aJavaCodeFragmentcontaining the code for converting the value (of the given field) to a string representation with respect to its data type. The String must be built so that it can be read using the valueOf-Expression. If the value isnull, the toString-code will yieldnullas a result.The default implementation will call the values toString() method or return
null. The default implementation for generic (extensible) data types will call the method defined using setToStringMethodName(). CustomDatatypeHelpers may override.- Specified by:
getToStringExpressionin interfaceBaseDatatypeHelper<JavaCodeFragment>- Specified by:
getToStringExpressionin interfaceDatatypeHelper- Parameters:
fieldName- the name of the field in the generated class that should be converted to a string- Returns:
- a
JavaCodeFragmentcontaining the toString() code.
-
nullExpression
Returns"null". Returns aJavaCodeFragmentwith sourcecode that is either the String "null" or the sourcecode to get an instance of the appropriate null object.- Specified by:
nullExpressionin interfaceBaseDatatypeHelper<JavaCodeFragment>- Specified by:
nullExpressionin interfaceDatatypeHelper
-
createCastExpression
Description copied from interface:DatatypeHelperReturns aJavaCodeFragmentwith anew value instance, adding a cast to the value's data type in case the value is empty to avoid problems with generics.- Specified by:
createCastExpressionin interfaceDatatypeHelper- Parameters:
bound- the String representation of a value of thisdatatype- Returns:
- a
JavaCodeFragmentcontaining the code to create (and cast) the value
-