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

public interface DatatypeHelper extends BaseDatatypeHelper<JavaCodeFragment>
Interface that defines functionality needed to generate Java sourcecode for datatypes.
  • Field Details

  • Method Details

    • getDatatype

      Datatype getDatatype()
      Returns the datatype this is a helper for.
      Specified by:
      getDatatype in interface BaseDatatypeHelper<JavaCodeFragment>
    • setDatatype

      void setDatatype(Datatype datatype)
      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:
      setDatatype in interface BaseDatatypeHelper<JavaCodeFragment>
    • nullExpression

      JavaCodeFragment nullExpression()
      Returns a JavaCodeFragment with sourcecode that is either the String "null" or the sourcecode to get an instance of the appropriate null object.
      Specified by:
      nullExpression in interface BaseDatatypeHelper<JavaCodeFragment>
    • newInstance

      JavaCodeFragment newInstance(String value)
      Returns a JavaCodeFragment with 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:
      newInstance in interface BaseDatatypeHelper<JavaCodeFragment>
    • newInstanceFromExpression

      JavaCodeFragment newInstanceFromExpression(String expression)
      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:
      newInstanceFromExpression in interface BaseDatatypeHelper<JavaCodeFragment>
      Parameters:
      expression - A Java source code expression that yields a String. Examples are a constant String like "FOO", a variable like foo or a method call like getÍd().
    • newInstanceFromExpression

      JavaCodeFragment newInstanceFromExpression(String expression, boolean checkForNull)
      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:
      newInstanceFromExpression in interface BaseDatatypeHelper<JavaCodeFragment>
      Parameters:
      expression - A Java source code expression that yields a String. Examples are a constant String like "FOO", a variable like foo or a method call like getÍd().
      checkForNull - true if this helper has to assume that the given expression can yield null or the empty string. Can be used to generate simpler code, if the null check is not necessary.
    • referenceOrSafeCopyIfNeccessary

      JavaCodeFragment 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. 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

      default String getValueSetJavaClassName()
      Returns the qualified Java class name for the value datatype. This is the same as getJavaClassName() for most datatypes but might differ for example for List typed values, where the datatype of the list's contents is returned.
    • getRangeJavaClassName

      String getRangeJavaClassName(boolean useTypesafeCollections)
      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 a JavaCodeFragment containing the source code to create a new instance of a type specific range.
      Parameters:
      lowerBoundExp - the lower bound expression of the range. Can be null to indicate that the lower bound is open
      upperBoundExp - the upper bound expression of the range. Can be null to indicate that the upper bound is open.
      stepExp - the minimum increment expression for values within the lower and upper bounds. Can be null to 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 a JavaCodeFragment containing 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 method
      containsNull - indicates if null is also contained in the returned enum value set
      useTypesafeCollections - indicates if Java 5 typesafe collections and valuetypes shall be used
    • newEnumValueSetInstance

      JavaCodeFragment newEnumValueSetInstance(JavaCodeFragment collectionExpression, JavaCodeFragment containsNullExpression, boolean useTypesafeCollections)
      Returns a JavaCodeFragment containing the source code to create a new enum value set instance.
      Parameters:
      collectionExpression - a JavaCodeFragment is expected that contains an expression of the type java.util.Collection The collection has to contain instances of the datatype of this helper.
      containsNullExpression - a JavaCodeFragment is expected that contains an expression of the type boolean
      useTypesafeCollections - indicates if Java 5 typesafe collections and valuetypes shall be used
    • getToStringExpression

      JavaCodeFragment getToStringExpression(String fieldName)
      Returns a JavaCodeFragment containing 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 is null, the toString-code will yield null as 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(). Custom DatatypeHelpers may override.

      Specified by:
      getToStringExpression in interface BaseDatatypeHelper<JavaCodeFragment>
      Parameters:
      fieldName - the name of the field in the generated class that should be converted to a string
      Returns:
      a JavaCodeFragment containing the toString() code.
    • createCastExpression

      default JavaCodeFragment createCastExpression(String valueAsString)
      Returns a JavaCodeFragment with a new 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 this datatype
      Returns:
      a JavaCodeFragment containing the code to create (and cast) the value
    • newValueInstance

      default JavaCodeFragment newValueInstance(String value)
      Returns a JavaCodeFragment for the value datatype. This is the same as newInstance(String) for most datatypes but might differ for example for List typed values, where the datatype of the list's contents is returned.