Interface IJavaConstant
- All Superinterfaces:
IJavaElement
,IJavaExpression
Java AST interface to represent a literal or constant value.
Constant types are: the eight primitive types (boolean, byte, char, short, int, long, float, double) and the string type.
Rendering of a literal may be customized
(overridden).
-
Field Summary
Fields inherited from interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
FLAG_BUILT, FLAG_FIELD_REFERENCES_OUTERCLASS, FLAG_LAMBDA_CLASS, FLAG_LAMBDA_IMPL, FLAG_OPTIONAL_RENDERING, FLAG_SECOND_PARAMETER_IS_OUTER_REF, FLAG_STICKY
-
Method Summary
Modifier and TypeMethodDescriptionDuplicate this element.boolean
Retrieve the boolean value.byte
getByte()
Retrieve the byte value.char
getChar()
Retrieve the character value.double
Retrieve the double value.float
getFloat()
Retrieve the float value.int
getInt()
Retrieve the integer value.long
getLong()
Retrieve the long value.getName()
Retrieve the optional custom name to override rendering.short
getShort()
Retrieve the short value.Retrieve the string value.getType()
Retrieve the constant type.boolean
isFalse()
Determine if a constant is the false literal.boolean
Determine if a constant is a numeric literal whose value is -1.boolean
Determine if a constant is a numeric literal whose value is strictly negative.boolean
isNull()
Determine if the constant is the 'null' literal.boolean
isOne()
Determine if a constant is a numeric literal whose value is 1.boolean
Determine if a constant is a numeric literal whose value is strictly positive.boolean
isString()
Determine if the constant is of typejava.lang.String
.boolean
isTrue()
Determine if a constant is the true literal.boolean
isZero()
Determine if a constant is a numeric literal whose value is 0.void
Set a custom name to override rendering.Methods inherited from interface com.pnfsoftware.jeb.core.units.code.java.IJavaElement
addFlags, addTag, canCauseException, collectAllPhysicalOffsets, generate, getData, getElementType, getFlags, getOrigin, getPhysicalMethodIndex, getPhysicalOffset, getReconAnon, getReconEnum, getReconEnummap, getReconLambda, getSubElements, getTags, hasFlags, hasPhysicalMethodIndex, hasPhysicalOffset, isReconArtifact, removeFlags, removeTag, replaceSubElement, setData, setFlags, setLambdaRecon, setOrigin, setPhysicalMethodIndex, setPhysicalOffset, setReconAnon, setReconEnum, setReconEnummap, toShortString, visitDepthPost, visitDepthPost, visitDepthPost, visitDepthPost, visitDepthPre, visitDepthPre, visitDepthPre
-
Method Details
-
setName
Set a custom name to override rendering. This is only applicable to non-String immediates.- Parameters:
name
- a name override, or null
-
getName
String getName()Retrieve the optional custom name to override rendering. This is only applicable to non-String immediates.- Returns:
- a name override, or null
-
getType
IJavaType getType()Retrieve the constant type.- Returns:
- the type signature, null if the constant is 'null'
-
isNull
boolean isNull()Determine if the constant is the 'null' literal.- Returns:
- true if the constant is 'null'
-
isString
boolean isString()Determine if the constant is of typejava.lang.String
. Convenience routine.- Returns:
- true if the constant is a Java string
-
getBoolean
boolean getBoolean()Retrieve the boolean value.- Returns:
- the value
- Throws:
IllegalStateException
- if the constant is not a boolean
-
getByte
byte getByte()Retrieve the byte value.- Returns:
- the byte value
- Throws:
IllegalStateException
- if the constant is not a byte
-
getChar
char getChar()Retrieve the character value.- Returns:
- the character value
- Throws:
IllegalStateException
- if the constant is not a char
-
getShort
short getShort()Retrieve the short value.- Returns:
- the short value
- Throws:
IllegalStateException
- if the constant is not a short
-
getInt
int getInt()Retrieve the integer value.- Returns:
- the integer value
- Throws:
IllegalStateException
- if the constant is not an int
-
getLong
long getLong()Retrieve the long value.- Returns:
- the long value
- Throws:
IllegalStateException
- if the constant is not a long
-
getFloat
float getFloat()Retrieve the float value.- Returns:
- the float value
- Throws:
IllegalStateException
- if the constant is not a float
-
getDouble
double getDouble()Retrieve the double value.- Returns:
- the double value
- Throws:
IllegalStateException
- if the constant is not a double
-
getString
String getString()Retrieve the string value.- Returns:
- the string value
- Throws:
IllegalStateException
- if the constant is not a string
-
isTrue
boolean isTrue()Determine if a constant is the true literal. This method does not raise.- Returns:
- true if the constant is a boolean true, false otherwise
-
isFalse
boolean isFalse()Determine if a constant is the false literal. This method does not raise.- Returns:
- true if the constant is a boolean false, false otherwise
-
isZero
boolean isZero()Determine if a constant is a numeric literal whose value is 0. This method does not raise.- Returns:
- true if the constant is a numeric literal whose value is 0, false otherwise
-
isOne
boolean isOne()Determine if a constant is a numeric literal whose value is 1. This method does not raise.- Returns:
- true if the constant is a numeric literal whose value is 1, false otherwise
-
isMinusOne
boolean isMinusOne()Determine if a constant is a numeric literal whose value is -1. This method does not raise.- Returns:
- true if the constant is a numeric literal whose value is -1, false otherwise
-
isPositive
boolean isPositive()Determine if a constant is a numeric literal whose value is strictly positive. This method does not raise.- Returns:
- true if the constant is a numeric literal whose value is strictly positive, false otherwise
-
isNegative
boolean isNegative()Determine if a constant is a numeric literal whose value is strictly negative. This method does not raise.- Returns:
- true if the constant is a numeric literal whose value is strictly negative, false otherwise
-
duplicate
IJavaConstant duplicate()Description copied from interface:IJavaElement
Duplicate this element.- Specified by:
duplicate
in interfaceIJavaElement
- Specified by:
duplicate
in interfaceIJavaExpression
- Returns:
- a (possibly) duplicated object of the same type
-