Class ConversionCodeGenerator<T extends CodeFragment>

java.lang.Object
org.faktorips.codegen.ConversionCodeGenerator<T>
All Implemented Interfaces:
ConversionMatrix

public class ConversionCodeGenerator<T extends CodeFragment> extends Object implements ConversionMatrix
The ConversionCodeGenerator extends the ConversionMatrix with the ability to generate the Java source code needed to convert the value of a given data type to another (if the conversion is possible).
  • Constructor Details

    • ConversionCodeGenerator

      public ConversionCodeGenerator()
  • Method Details

    • getDefault

      public static final ConversionCodeGenerator<JavaCodeFragment> getDefault()
      Returns a default ConversionCodeGenerator that contains the following conversions.
      • Primitive boolean to Boolean
      • Boolean to primitive boolean
      • Primitive int to Integer
      • Integer to primitive int
      • Primitive int to Decimal
      • Integer to Decimal
      • Any data type to String
    • add

      public void add(SingleConversionCg<T> conversion)
    • canConvert

      public boolean canConvert(Datatype from, Datatype to)
      Description copied from interface: ConversionMatrix
      Returns true if a value of datatype from can be converted into one of datatype to. If datatype from and to are equal, the method returns true.
      Specified by:
      canConvert in interface ConversionMatrix
    • getConversionCode

      public T getConversionCode(Datatype from, Datatype to, T fromValue)
      Returns the Java source code that converts a value of Datatype from to a value of Datatype to if possible. Returns null if the conversion is not possible.
      Parameters:
      from - The data type to convert from.
      to - The data type to convert to.
      fromValue - A Java source code fragment containing an expression that evaluates to a value of Datatype from.