public class JrpcgenConst extends JrpcgenXdrDefinition
JrpcgenConst class represents a single constant defined
in an rpcgen "x"-file.| Modifier and Type | Class and Description |
|---|---|
static class |
JrpcgenConst.Table
Type definition for a table of XDR constants.
|
JrpcgenXdrDefinition.Typedocumentation| Constructor and Description |
|---|
JrpcgenConst(JrpcgenContext context,
String identifier,
String value)
Constructs a
JrpcgenConst and sets the identifier and
the associated value. |
JrpcgenConst(JrpcgenContext context,
String identifier,
String value,
String enclosure)
Constructs a
JrpcgenConst and sets the identifier and
the associated value of an enumeration etc. |
| Modifier and Type | Method and Description |
|---|---|
static String |
detectIdentifier(String expression)
Detects a character sequence at the beginning of the passed
expression, which holds the definition of an identifier as
described in RFC 4506:
An identifier is a letter followed by an optional sequence of letters, digits, or underbar ('_'). |
void |
dump()
Dumps the constant as well as its value to
System.out. |
<T extends Appendable> |
dump(T appendable) |
String |
getAsCaseValue(String forEnclosure)
Delivers a case value representation of the constant.
|
static String |
getAsCaseValue(String constantExpression,
String forEnclosure,
JrpcgenContext context)
Delivers the passed constant expression as a case value, which is intended
to be used within a switch-case-statement.
|
String |
getAsRValue(String forEnclosure)
Delivers an r-value representation of the constant.
|
static String |
getAsRValue(String constantExpression,
JrpcgenContext context)
Delivers the passed constant expression as an r-value.
|
static String |
getAsRValue(String constantExpression,
String forEnclosure,
JrpcgenContext context)
Delivers the passed constant expression as an r-value.
|
JrpcgenContext |
getContext()
Delivers the context the constant definition belongs to.
|
String |
getEnclosure()
Returns the name of the enclosure the constant
lives in.
|
String |
getForEnclosure(String forEnclosure)
Delivers the representation of the constant
with respect to the passed enclosure name.
|
String |
getValue()
Delivers the value defined for the constant.
|
String |
getValueAsRValue(String forEnclosure)
Delivers an r-value representation of the value
defined by the constant.
|
String |
resolveValue()
Returns the value as integer literal (and thus resolving identifiers
recursively, if necessary).
|
void |
setEnclosure(String enclosure)
Sets the name of the enclosure the constant
lives in.
|
void |
setValue(String value)
Sets the value represented by the constant.
|
String |
toString() |
void |
writeDeclaration(JrpcgenJavaFile javaFile) |
getIdentifier, getXdrType, isConst, isEnum, isStruct, isTypedef, isUnionappendDeprecatedOrNothing, appendDeprecatedOrNothing, documentationIsEmpty, documentationIsProvided, emptyDocumentation, getDocumentation, getIdentedDocu, getIdentedDocu, isDeprecated, writeDocumentation, writeDocumentationpublic JrpcgenConst(JrpcgenContext context, String identifier, String value)
JrpcgenConst and sets the identifier and
the associated value.context - The context the new contant belongs to.identifier - Constant identifier to define.value - Value assigned to constant.public JrpcgenConst(JrpcgenContext context, String identifier, String value, String enclosure)
JrpcgenConst and sets the identifier and
the associated value of an enumeration etc.context - The context the new contant belongs to.identifier - Constant identifier to define.value - Value assigned to constant.enclosure - Name of enclosing enumeration, etc.public static String getAsRValue(String constantExpression, JrpcgenContext context)
Passing for example the string literal "42", the
method returns the passed string "42".
Passing for example the string literal "VERSION", the method
may return the string "demo.VERSION" in case the global table
of constants contains a constant definition with the identifier
VERSION nested in the enclosure (namespace) demo.
Otherwise the passed string "VERSION" is returned.
Passing for example the string literal "ENUM_FIRST", the
method may return the string
"EnumerationValues.ENUM_FIRST.getEncoding()"
in case the global table of constants contains a constant definition with
the identifier ENUM_FIRST nested in the enclosure (namespace)
EnumerationValues originating from an enumeration definition
provided that XDR ernumerations are mapped by Java enumerations.
constantExpression - A string containing a constant value or the identifier
of a constant definition known to the global table of constant definitions.context - The context of the rpcgen run, providing the table of global
constant definitions collected so far.public static String getAsRValue(String constantExpression, String forEnclosure, JrpcgenContext context)
Passing for example the string literal "42", the
method returns the passed string "42".
Given a target enclosure (namespace) element and
a global constant definition with the identifier VERSION
nested in the enclosure (namespace) demo, passing the string
literals "VERSION" and "element" results in
returning the string "demo.VERSION".
Given a target enclosure (namespace) demo and
a global constant definition with the identifier VERSION
nested in the enclosure (namespace) demo, passing the string
literals "VERSION" and "demo" results in returning
the string "VERSION".
Given a target enclosure (namespace) element and
a global constant definition with the identifier ENUM_FIRST
nested in the enclosure (namespace) EnumerationValues
originating from an enumeration definition, passing the string literals
"ENUM_FIRST" and "element" results in returning
the string "EnumerationValues.ENUM_FIRST.getEncoding()"
provided that XDR enumerations are mapped by Java enumerations
(see JrpcgenEnum.Element).
constantExpression - A string containing a constant value or the identifier
of a constant definition known to the global table of constant definitions.forEnclosure - The target enclosure (namespace), where the r-value is
intended to be used.context - The context of the rpcgen run, providing the table of global
constant definitions collected so far.public static String getAsCaseValue(String constantExpression, String forEnclosure, JrpcgenContext context)
Passing for example the string literal "42", the method
returns the passed string "42".
Given a target enclosure (namespace) element and a global
constant definition with the identifier VERSION nested in
the enclosure (namespace) demo, passing the string literals
"VERSION" and "element" result in returning
the string "demo.VERSION".
Given a target enclosure (namespace) element and
a global constant definition with the identifier ENUM_FIRST
nested in the enclosure (namespace) EnumerationValues
originating from an enumeration definition, passing the string literals
"ENUM_FIRST" and "element" results in returning
the string "ENUM_FIRST" provided that XDR enumerations
are mapped by Java enumerations (see JrpcgenEnum.Element).
constantExpression - A string containing a constant value or the identifier
of a constant definition known to the global table of constant definitions.forEnclosure - The target enclosure (namespace), where the r-value is
intended to be used.context - The context of the rpcgen run, providing the table of global
constant definitions collected so far.public final JrpcgenContext getContext()
public final String getValue()
public final void setValue(String value)
value - The value of the constant in string
representation.public final String getEnclosure()
public final void setEnclosure(String enclosure)
enclosure - The name of the enclosure.public String getForEnclosure(String forEnclosure)
The passed enclosure name identifies the target enclosure (namespace), where the requested constant representation is intended to be used.
forEnclosure - The name of the target enclosure.public String getAsRValue(String forEnclosure)
The passed enclosure name identifies the target enclosure (namespace), where the requested constant representation is intended to be used.
forEnclosure - The name of the target enclosure.public String getAsCaseValue(String forEnclosure)
The passed enclosure name identifies the target enclosure (namespace), where the requested constant representation is intended to be used.
forEnclosure - The name of the target enclosure.public String getValueAsRValue(String forEnclosure)
The passed eclosure name identifies the target enclosure (namespace), where the requested value representation is intended to be used.
forEnclosure - The name of the target enclosure.public String resolveValue()
This simple kind of resolving is necessary when defining a particular version of an ONC/RPC protocol. We need to be able to resolve the version to an integer literal because we need to append the version number to any remote procedure defined to avoid identifier clashes if the same remote procedure is defined for several versions.
String or null,
if the identifier could not be resolved to an integer literal.public void writeDeclaration(JrpcgenJavaFile javaFile)
public void dump()
System.out.public <T extends Appendable> T dump(T appendable)
public static String detectIdentifier(String expression)
An identifier is a letter followed by an optional sequence of letters, digits, or underbar ('_'). The case of identifiers is not ignored.
Letters are defined by the character set ['a'-'z','A'-'Z'] within this implementation.
Digits are defined by the character set ['0'-'9'] within this implementation.
expression - An expression possibly starting with an identifier like
character sequence.null in case the passed expression does not start with a letter.Copyright © 2025. All rights reserved.