Class JavaConstant<T>

java.lang.Object
io.github.mmm.code.base.item.BaseItem
io.github.mmm.code.base.expression.BaseExpression
io.github.mmm.code.impl.java.expression.constant.JavaConstant<T>
Type Parameters:
T - type of getValue().
All Implemented Interfaces:
io.github.mmm.code.api.expression.CodeConstant, io.github.mmm.code.api.expression.CodeExpression, io.github.mmm.code.api.item.CodeItem, JavaExpression
Direct Known Subclasses:
JavaEnumConstant, JavaFactoryConstant, JavaLiteral

public abstract class JavaConstant<T> extends BaseExpression implements io.github.mmm.code.api.expression.CodeConstant, JavaExpression
Implementation of CodeConstant for Java.
Since:
1.0.0
Author:
hohwille
  • Constructor Details

    • JavaConstant

      public JavaConstant(T value)
      The constructor.
      Parameters:
      value - the value.
  • Method Details

    • getValue

      public T getValue()
      Specified by:
      getValue in interface io.github.mmm.code.api.expression.CodeConstant
    • getJavaClass

      public Class<? extends T> getJavaClass()
      Returns:
      the Class reflecting the type of this constant.
    • isPrimitive

      public boolean isPrimitive()
      Returns:
      true if the type is primitive.
    • evaluate

      public JavaConstant<T> evaluate()
      Specified by:
      evaluate in interface io.github.mmm.code.api.expression.CodeConstant
      Specified by:
      evaluate in interface io.github.mmm.code.api.expression.CodeExpression
      Specified by:
      evaluate in interface JavaExpression
    • getSourceCode

      public abstract String getSourceCode()
      Specified by:
      getSourceCode in interface io.github.mmm.code.api.item.CodeItem
      Overrides:
      getSourceCode in class BaseItem
    • doWrite

      protected void doWrite(Appendable sink, String newline, String defaultIndent, String currentIndent, io.github.mmm.code.api.language.CodeLanguage language) throws IOException
      Specified by:
      doWrite in class BaseItem
      Throws:
      IOException
    • withValue

      public abstract JavaConstant<T> withValue(T newValue)
      Parameters:
      newValue - the new value. May not be null.
      Returns:
      the corresponding JavaConstant of the same type with the given value.
    • of

      public static JavaConstant<?> of(Object value, boolean primitive)
      Parameters:
      value - the literal value.
      primitive - true if the value is primitive and a primitve JavaLiteral shall be created, false otherwise.
      Returns:
      the JavaConstant for the given value. May be null if the type of the given value is not supported.