Package org.faktorips.codegen
Interface DatatypeHelper
- All Superinterfaces:
BaseDatatypeHelper<JavaCodeFragment>
- All Known Subinterfaces:
PrimitiveDatatypeHelper
- All Known Implementing Classes:
AbstractDatatypeHelper,AbstractPrimitiveDatatypeHelper,AbstractTimeHelper,ArrayOfValueDatatypeHelper,BaseJodaDatatypeHelper,BigDecimalHelper,BooleanHelper,CurrencyHelper,DateHelper,DecimalHelper,DoubleHelper,GenericValueDatatypeHelper,GregorianCalendarAsDateHelper,IntegerHelper,InternationalStringDatatypeHelper,ListOfValueDatatypeHelper,LocalDateHelper,LocalDateHelper,LocalDateTimeHelper,LocalDateTimeHelper,LocalTimeHelper,LocalTimeHelper,LongHelper,MoneyHelper,MonthDayHelper,MonthDayHelper,PrimitiveBooleanHelper,PrimitiveIntegerHelper,PrimitiveLongHelper,StringHelper
Interface that defines functionality needed to generate Java sourcecode for datatypes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DatatypeHelperHelper forDatatype.BIG_DECIMAL.static final DatatypeHelperHelper forDatatype.BOOLEAN.static final DatatypeHelperHelper forDatatype.DECIMAL.static final DatatypeHelperHelper forDatatype.INTEGER.static final DatatypeHelperHelper forDatatype.LONG.static final DatatypeHelperHelper forDatatype.MONEY.static final PrimitiveDatatypeHelperHelper forDatatype.PRIMITIVE_BOOLEAN.static final PrimitiveDatatypeHelperHelper forDatatype.PRIMITIVE_INTEGER.static final DatatypeHelperHelper forDatatype.STRING. -
Method Summary
Modifier and TypeMethodDescriptiondefault JavaCodeFragmentcreateCastExpression(String valueAsString) 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.Returns the qualified Java class name the datatype represents.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.default StringReturns the qualified Java class name for the value datatype.newEnumValueSetInstance(String[] values, boolean containsNull, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.newEnumValueSetInstance(JavaCodeFragment collectionExpression, JavaCodeFragment containsNullExpression, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.newInstance(String value) Returns aJavaCodeFragmentwith sourcecode that creates an instance of the datatype's Java class with the given value.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.default JavaCodeFragmentnewValueInstance(String value) Returns aJavaCodeFragmentfor the value datatype.Returns aJavaCodeFragmentwith sourcecode that is either the String "null" or the sourcecode to get an instance of the appropriate null object.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.
-
Field Details
-
BOOLEAN
Helper forDatatype.BOOLEAN. -
DECIMAL
Helper forDatatype.DECIMAL. -
BIG_DECIMAL
Helper forDatatype.BIG_DECIMAL. -
INTEGER
Helper forDatatype.INTEGER. -
LONG
Helper forDatatype.LONG. -
MONEY
Helper forDatatype.MONEY. -
PRIMITIVE_BOOLEAN
Helper forDatatype.PRIMITIVE_BOOLEAN. -
PRIMITIVE_INTEGER
Helper forDatatype.PRIMITIVE_INTEGER. -
STRING
Helper forDatatype.STRING.
-
-
Method Details
-
getDatatype
Datatype getDatatype()Returns the datatype this is a helper for.- Specified by:
getDatatypein interfaceBaseDatatypeHelper<JavaCodeFragment>
-
setDatatype
Sets 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>
-
nullExpression
JavaCodeFragment nullExpression()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>
-
newInstance
Returns aJavaCodeFragmentwith sourcecode that creates an instance of the datatype's Java class with the given value. If the value is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object.- Specified by:
newInstancein interfaceBaseDatatypeHelper<JavaCodeFragment>
-
newInstanceFromExpression
Returns 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>- 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
Returns 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>- 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.
-
referenceOrSafeCopyIfNeccessary
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. For immutable data types this method returns the expression unmodified.- Parameters:
expression- An expression (as Java sourcecode)- Returns:
- s. above
-
getJavaClassName
String getJavaClassName()Returns the qualified Java class name the datatype represents. -
getValueSetJavaClassName
Returns the qualified Java class name for the value datatype. This is the same asgetJavaClassName()for most datatypes but might differ for example forListtyped values, where the datatype of the list's contents is returned. -
getRangeJavaClassName
Returns the qualified Java class name of the range class of the datatype this is a helper for. -
newRangeInstance
JavaCodeFragment 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.- 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
JavaCodeFragment newEnumValueSetInstance(String[] values, boolean containsNull, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.- 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
JavaCodeFragment newEnumValueSetInstance(JavaCodeFragment collectionExpression, JavaCodeFragment containsNullExpression, boolean useTypesafeCollections) Returns aJavaCodeFragmentcontaining the source code to create a new enum value set instance.- Parameters:
collectionExpression- 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 used
-
getToStringExpression
Returns 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>- Parameters:
fieldName- the name of the field in the generated class that should be converted to a string- Returns:
- a
JavaCodeFragmentcontaining the toString() code.
-
createCastExpression
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.- Parameters:
valueAsString- the String representation of a value of thisdatatype- Returns:
- a
JavaCodeFragmentcontaining the code to create (and cast) the value
-
newValueInstance
Returns aJavaCodeFragmentfor the value datatype. This is the same asnewInstance(String)for most datatypes but might differ for example forListtyped values, where the datatype of the list's contents is returned.
-