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 ofgetValue().
- 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
-
Field Summary
Fields inherited from interface io.github.mmm.code.api.item.CodeItem
DEFAULT_INDENT, DEFAULT_NEWLINE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoWrite(Appendable sink, String newline, String defaultIndent, String currentIndent, io.github.mmm.code.api.language.CodeLanguage language) evaluate()abstract StringgetValue()booleanstatic JavaConstant<?>abstract JavaConstant<T>Methods inherited from class io.github.mmm.code.base.item.BaseItem
getOwningType, getSpaces, toString, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.mmm.code.api.item.CodeItem
getLanguage, write, write, write, write, write
-
Constructor Details
-
JavaConstant
The constructor.- Parameters:
value- thevalue.
-
-
Method Details
-
getValue
- Specified by:
getValuein interfaceio.github.mmm.code.api.expression.CodeConstant
-
getJavaClass
- Returns:
- the
Classreflecting the type of this constant.
-
isPrimitive
public boolean isPrimitive()- Returns:
trueif thetypeis primitive.
-
evaluate
- Specified by:
evaluatein interfaceio.github.mmm.code.api.expression.CodeConstant- Specified by:
evaluatein interfaceio.github.mmm.code.api.expression.CodeExpression- Specified by:
evaluatein interfaceJavaExpression
-
getSourceCode
- Specified by:
getSourceCodein interfaceio.github.mmm.code.api.item.CodeItem- Overrides:
getSourceCodein classBaseItem
-
doWrite
protected void doWrite(Appendable sink, String newline, String defaultIndent, String currentIndent, io.github.mmm.code.api.language.CodeLanguage language) throws IOException - Specified by:
doWritein classBaseItem- Throws:
IOException
-
withValue
- Parameters:
newValue- the newvalue. May not benull.- Returns:
- the corresponding
JavaConstantof the same type with the given value.
-
of
- Parameters:
value- the literal value.primitive-trueif the value is primitive and aprimitveJavaLiteralshall be created,falseotherwise.- Returns:
- the
JavaConstantfor the givenvalue. May benullif the type of the givenvalueis not supported.
-