public abstract class Message extends Object
library
subclass. Messages may be resolved dynamically by calling
Message.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.
ReflectionLibrary
,
Library
Modifier | Constructor and Description |
---|---|
protected |
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) |
Modifier and Type | Method and Description |
---|---|
protected Object |
clone() |
boolean |
equals(Object obj) |
LibraryFactory<?> |
getFactory() |
int |
getId()
Returns a unique message id within a library.
|
Class<? extends Library> |
getLibraryClass()
Returns the library class of this message.
|
String |
getLibraryName()
Returns the name of the library of this message.
|
int |
getParameterCount()
Returns the number of parameters including the receiver type.
|
Class<?> |
getParameterType(int index)
Just like
Message.getParameterTypes() but returns the parameter of a given index in a
partial evaluation safe way. |
List<Class<?>> |
getParameterTypes()
Returns all parameter types including the receiver type of the message.
|
String |
getQualifiedName()
Returns a qualified and unique name of this message.
|
Class<?> |
getReceiverType()
Returns the receiver type of the message.
|
Class<?> |
getReturnType()
Returns the return type of the message.
|
String |
getSimpleName()
Returns the simple name of this message.
|
int |
hashCode() |
boolean |
isDeprecated()
Returns true if this message is deprecated.
|
static Message |
resolve(Class<? extends Library> libraryClass,
String messageName)
Resolves a message globally for a given library class and message name.
|
static Message |
resolve(Class<? extends Library> libraryClass,
String messageName,
boolean fail)
Resolves a message globally for a given library class and message name.
|
String |
toString() |
protected Message(Class<? extends Library> libraryClass, String messageName, int id, Class<?> returnType, Class<?>... parameterTypes)
public final int getId()
-1
if the message is not assigned a unique id.public final String getQualifiedName()
getLibraryName() + "." + getSimpleName()
. The returned name is
interned
can can safely be compared by identity. The returned name is
never null
.Message.getSimpleName()
,
Message.getLibraryName()
public final String getSimpleName()
interned
can can safely be compared by identity. The returned name is
never null
.public final String getLibraryName()
name
of the library class
. The returned
name is never null
.public final Class<?> getReturnType()
reflective
invocations of the message.public final Class<?> getReceiverType()
parameter type
. In many cases the receiver type of a message is
Object
. However, it possible for libraries to restrict the receiver type to
sub-types. The receiver type may be useful for reflective
invocations of the message.public final List<Class<?>> getParameterTypes()
Method.getParameterTypes()
parameter types of the declared library method. The parameter types may be useful for
reflective
invocations of the message.public final Class<?> getParameterType(int index)
Message.getParameterTypes()
but returns the parameter of a given index in a
partial evaluation safe way.public final int getParameterCount()
public final boolean isDeprecated()
public final Class<? extends Library> getLibraryClass()
resolve
other messages of the same library.public final LibraryFactory<?> getFactory()
protected final Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public static Message resolve(Class<? extends Library> libraryClass, String messageName)
null
. If the library or message is invalid or not
found an IllegalArgumentException
is thrown.libraryClass
- the class of the library this message is contained in.messageName
- the simple name of this message.public static Message resolve(Class<? extends Library> libraryClass, String messageName, boolean fail)
null
.libraryClass
- the class of the library this message is contained in.messageName
- the simple name of this message.fail
- whether to fail with an IllegalArgumentException
or return
null
if the message was not found.