Package com.oracle.truffle.api.library
Class Message
java.lang.Object
com.oracle.truffle.api.library.Message
Represents a description of library message. A message description refers to one public method in
a
library
subclass. Messages may be resolved dynamically by calling
resolve(Class, String)
with a known library class and message name. Message instances
provide meta-data about the simple and qualified name of the message, return type, receiver type,
parameter types and library name. Message instances are used to invoke library messages or
implement library messages reflectively using the reflection library
.
Message instances are globally unique and can safely be compared by identity. In other words, if
the same message is resolved
twice the same instance will be
returned. Since they are shared message instances must not be used as locks to avoid deadlocks.
Note: This class is intended to be sub-classed by generated code only and must *not* be sub-classed by user-code.
- Since:
- 19.0
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Message
(Class<? extends Library> libraryClass, String messageName, int id, boolean deprecated, Class<?> returnType, Class<?>... parameterTypes) protected
Message
(Class<? extends Library> libraryClass, String messageName, int id, Class<?> returnType, Class<?>... parameterTypes) -
Method Summary
Modifier and TypeMethodDescriptionprotected final Object
clone()
final boolean
final LibraryFactory
<?> final int
getId()
Returns a unique message id within a library.Returns the library class of this message.final String
Returns the name of the library of this message.final int
Returns the number of parameters including the receiver type.final Class
<?> getParameterType
(int index) Just likegetParameterTypes()
but returns the parameter of a given index in a partial evaluation safe way.Returns all parameter types including the receiver type of the message.final String
Returns a qualified and unique name of this message.final Class
<?> Returns the receiver type of the message.final Class
<?> Returns the return type of the message.final String
Returns the simple name of this message.final int
hashCode()
final boolean
Returns true if this message is deprecated.static Message
Resolves a message globally for a given library class and message name.static Message
Resolves a message globally for a given library class and message name.final String
toString()
-
Constructor Details
-
Message
protected Message(Class<? extends Library> libraryClass, String messageName, int id, Class<?> returnType, Class<?>... parameterTypes) - Since:
- 22.0
-
Message
protected Message(Class<? extends Library> libraryClass, String messageName, int id, boolean deprecated, Class<?> returnType, Class<?>... parameterTypes) - Since:
- 23.0
-
-
Method Details
-
getId
public final int getId()Returns a unique message id within a library.- Returns:
- a non-negative message id or
-1
if the message is not assigned a unique id. - Since:
- 22.0
-
getQualifiedName
Returns a qualified and unique name of this message. The qualified name is specified asgetLibraryName() + "." + getSimpleName()
. The returned name isinterned
can can safely be compared by identity. The returned name is nevernull
.- Since:
- 19.0
- See Also:
-
getSimpleName
Returns the simple name of this message. The simple name is unique per library and equals the method name of the method in the library specification class. The returned name isinterned
can can safely be compared by identity. The returned name is nevernull
.- Since:
- 19.0
-
getLibraryName
Returns the name of the library of this message. The name of the library is specified as thename
of thelibrary class
. The returned name is nevernull
.- Since:
- 19.0
-
getReturnType
Returns the return type of the message. The return type can be useful forreflective
invocations of the message.- Since:
- 19.0
-
getReceiverType
Returns the receiver type of the message. The receiver type is always the same as the firstparameter type
. In many cases the receiver type of a message isObject
. However, it possible for libraries to restrict the receiver type to sub-types. The receiver type may be useful forreflective
invocations of the message.- Since:
- 19.0
-
getParameterTypes
Returns all parameter types including the receiver type of the message. The returned immutable parameter types list corresponds to theMethod.getParameterTypes()
parameter types of the declared library method. The parameter types may be useful forreflective
invocations of the message.- Since:
- 19.0
-
getParameterType
Just likegetParameterTypes()
but returns the parameter of a given index in a partial evaluation safe way.- Since:
- 21.3
-
getParameterCount
public final int getParameterCount()Returns the number of parameters including the receiver type.- Since:
- 19.0
-
isDeprecated
public final boolean isDeprecated()Returns true if this message is deprecated.- Since:
- 23.0
-
getLibraryClass
Returns the library class of this message. The library class may be used toresolve
other messages of the same library.- Since:
- 19.0
-
getFactory
- Since:
- 19.0
-
equals
-
hashCode
public final int hashCode() -
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
- Since:
- 19.0
-
toString
-
resolve
Resolves a message globally for a given library class and message name. The message name corresponds to the method name of the library message. The returned message always returns the same instance for a combination of library class and message. The provided library class and message name must not benull
. If the library or message is invalid or not found anIllegalArgumentException
is thrown.- Parameters:
libraryClass
- the class of the library this message is contained in.messageName
- the simple name of this message.- Since:
- 19.0
-
resolve
public static Message resolve(Class<? extends Library> libraryClass, String messageName, boolean fail) Resolves a message globally for a given library class and message name. The message name corresponds to the method name of the library message. The returned message always returns the same instance for a combination of library class and message. The provided library class and message name must not benull
.- Parameters:
libraryClass
- the class of the library this message is contained in.messageName
- the simple name of this message.fail
- whether to fail with anIllegalArgumentException
or returnnull
if the message was not found.- Since:
- 19.0
-