Class HxmClass
- All Implemented Interfaces:
AutoCloseable
Each instance of an HxmClass represents a class available and loaded in a module. Each HXM object has a type represented by an HxmClass whether it comes from a builtin or a user defined class. Therefore, it is possible to retrieve the class of any value that is not a boolean, integer, double or nil.
The methods below can be used to introspect the contents of all HXM classes
and, in particular, to extract the various methods, properties and fields
of the class, including static fields. It is also possible to build new
instances of this class using the newInstance(HxmValue...) method.
An HxmClass is itself a modeler value. In other words, an HxmClass is a
first-class citizen and can be passed as a parameter to any method that
expects an object or a value. Managing the lifetime of an HxmClass is the
same as any other modeler object (using HxmReferenceScope or the
close() method).
Since an HxmClass is a value, each HxmClass also has a type represented by another HxmClass that describes the fundamental type of all other types.
- Since:
- 13.0
-
Method Summary
Modifier and TypeMethodDescriptionasValue()Gets the HxmClass as HxmValue.voidclose()Releases the reference.booleanintfindMemberId(String memberName) Returns the id of the member with the given name or -1 if no such member exists in the class.intfindStaticMemberId(String staticMemberName) Returns the id of the static member with the given name or -1 if no such member exists in the class.Gets the full qualified name of the class.getField(int memberId) Returns the field with the given id as anHxmField.Returns the field with the given name as anHxmField.getMemberName(int memberId) Returns the name of the member with the given id.getMemberType(int memberId) Returns the type of the member with the given id.getMemberType(String memberName) Returns the type of the member with the given name.getMethod(int memberId) Returns the method with the given id as anHxmFunction.Returns the method with the given name as anHxmFunction.intReturns the number of members present in this class.intReturns the number of static members declared in the class.getProperty(int memberId) Returns the property with the given id as anHxmProperty.getProperty(String memberName) Returns the property with the given name as anHxmProperty.getStaticMember(int staticMemberId) Returns the value of the static member with the given id.getStaticMember(String staticMemberName) Returns the value of the static member with the given name.getStaticMemberName(int staticMemberId) Returns the name of the static member with the given id.Returns the class extended by this class.inthashCode()booleanReturns true if this class extends another class.booleanisField(int memberId) Returns true if the member with the given id is a field.booleanReturns true if a field with the given name is present in the class or inherited from a parent class.booleanisFinal()Returns true if the class has been declared as final.booleanisInstance(HxmValue value) Returns true if the value passed in parameter is an instance of this class.booleanReturns true if a member with the given name is present in the class.booleanisMethod(int memberId) Returns true if the member with the given id is a method.booleanReturns true if a method with the given name is present in the class or inherited from a parent class.booleanisProperty(int memberId) Returns true if the member with the given id is a property.booleanisProperty(String memberName) Returns true if a property with the given name is present in the class or inherited from a parent class.booleanisStaticMember(String staticMemberName) Returns true if a static member with the given name is declared in the class.booleanisSubClassOf(HxmClass other) Returns true if this class is a subclass of the class given as parameter.newInstance(HxmValue... arguments) Returns a new instance of this class.newInstance(List<HxmValue> arguments) Returns a new instance of this class.voidsetStaticMember(int staticMemberId, HxmValue value) Sets the value of the static member with the given id.voidsetStaticMember(String staticMemberName, HxmValue value) Sets the value of the static member with the given id.
-
Method Details
-
close
public void close()Releases the reference. If this class was already released, returns immediately and does nothing. Invoking any method on this object after this operation will throw an exception.
Note: Releasing a reference does not necessarily imply that the underlying module object is destroyed. It is only destroyed if no more references point to it.
- Specified by:
closein interfaceAutoCloseable
-
newInstance
Returns a new instance of this class. The constructor is called with the arguments passed as parameters.- Parameters:
arguments- List of arguments for the constructor.- Returns:
- A new instance of this class.
- See Also:
-
newInstance
Returns a new instance of this class. The constructor is called with the arguments passed as parameters.- Parameters:
arguments- List of arguments for the constructor.- Returns:
- A new instance of this class.
- See Also:
-
getDeclaredName
Gets the full qualified name of the class. The name includes the name of the module in which the class is declared.- Returns:
- The full name of the class.
-
isFinal
public boolean isFinal()Returns true if the class has been declared as final. A final class is a class that cannot be extended by inheritance.- Returns:
- True if the class is final.
-
isSubClassOf
Returns true if this class is a subclass of the class given as parameter. To be considered a subclass, this class must inherit directly or indirectly from the class given as parameter.- Parameters:
other- Other class from which the inheritance will be tested.- Returns:
- True if this class is a subclass of the class given as parameter.
-
hasSuperClass
public boolean hasSuperClass()Returns true if this class extends another class. The extended class can be retrieved with the methodgetSuperClass().- Returns:
- True if this class extends another class.
-
getSuperClass
Returns the class extended by this class. An exception is thrown if this class does not have a super class.- Returns:
- The class extended by this class.
-
isInstance
Returns true if the value passed in parameter is an instance of this class. An object is considered to be an instance of the class if the object's type is equal to this class, or if the object's type is a subclass of this class. If the value passed in parameter is not an object (such as a boolean, integer, double or nil), then false is always returned.- Parameters:
value- Value for which the inheritance will be tested.- Returns:
- True if the given value is an instance of this class.
- See Also:
-
getNbMembers
public int getNbMembers()Returns the number of members present in this class. The members considered are those declared in this class or inherited from parent classes. A member is a field, property, method or constructor. The returned number can be used to browse members using the following methods, which take amemberIdparameter ranging from 0 togetNbMembers().- Returns:
- The number of members in this class or in the parent classes.
-
getMemberName
Returns the name of the member with the given id. An exception is thrown ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().- Parameters:
memberId- Id of the member to get the name.- Returns:
- Name of the member with the given id.
-
findMemberId
Returns the id of the member with the given name or -1 if no such member exists in the class. The considered members are those declared in this class or inherited from parent classes. The member name is case sensitive.- Parameters:
memberName- Name of the member to get the id.- Returns:
- The id of the member with the given name.
-
isMember
Returns true if a member with the given name is present in the class. The considered members are those declared in this class or inherited from parent classes. The member name is case sensitive. This method is equivalent tofindMemberId(memberName) != -1.- Parameters:
memberName- Name of the member to check.- Returns:
- True if a member with the given name is present in the class.
-
isMethod
Returns true if a method with the given name is present in the class or inherited from a parent class. Returns false if no method with the given name is present or if the member is not a method. The member name is case sensitive.- Parameters:
memberName- Name of the member to check.- Returns:
- True if a method with the given name is present in the class.
-
isMethod
public boolean isMethod(int memberId) Returns true if the member with the given id is a method. False is returned otherwise or an exception is thrown ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().- Parameters:
memberId- Id of the member to check.- Returns:
- True if a method with the given id is present in the class.
-
isField
Returns true if a field with the given name is present in the class or inherited from a parent class. Returns false if no field with the given name is present or if the member is not a field. The member name is case sensitive.- Parameters:
memberName- Name of the member to check.- Returns:
- True if a field with the given name is present in the class.
-
isField
public boolean isField(int memberId) Returns true if the member with the given id is a field. False is returned otherwise or an exception is thrown ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().- Parameters:
memberId- Id of the member to check.- Returns:
- True if a field with the given id is present in the class.
-
isProperty
Returns true if a property with the given name is present in the class or inherited from a parent class. Returns false if no property with the given name is present or if the member is not a property. The member name is case sensitive.- Parameters:
memberName- Name of the member to check.- Returns:
- True if a property with the given name is present in the class.
-
isProperty
public boolean isProperty(int memberId) Returns true if the member with the given id is a property. False is returned otherwise or an exception is thrown ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers()- Parameters:
memberId- Id of the member to check.- Returns:
- True if a property with the given id is present in the class.
-
getMemberType
Returns the type of the member with the given id. An exception is thrown ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().- Parameters:
memberId- Id of the member to get the type.- Returns:
- Type of the member with the given id.
- See Also:
-
getMemberType
Returns the type of the member with the given name. An exception is thrown if no member with the given name is present in the class. The member name is case sensitive.- Parameters:
memberName- Name of the member to get the type.- Returns:
- Type of the member with the given name.
- See Also:
-
getMethod
Returns the method with the given name as an
HxmFunction. An exception is thrown if the member is not a method or if no member with the given name is present in the class. The member name is case sensitive.Once the method has been retrieved as a
HxmFunction, you can call it withHxmFunction.callThis(HxmValue)by passing an object of this class as the first argument.- Parameters:
memberName- Name of the method to get.- Returns:
- The method with the given name.
-
getMethod
Returns the method with the given id as an
HxmFunction. An exception is thrown if the member is not a method or ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().Once the method has been retrieved as a
HxmFunction, you can call it withHxmFunction.callThis(HxmValue)by passing an object of this class as the first argument.- Parameters:
memberId- Id of the method to get.- Returns:
- The method with the given id.
-
getField
Returns the field with the given name as an
HxmField. An exception is thrown if the member is not a field or if no member with the given name is present in the class. The member name is case sensitive.Once the field has been retrieved as a
HxmField, you can retrieve or modify the value of the field for any object of this class using the various get and set methods likeHxmField.getValue(HxmValue).- Parameters:
memberName- Name of the field to get.- Returns:
- The field with the given name.
-
getField
Returns the field with the given id as an
HxmField. An exception is thrown if the member is not a field or ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().Once the field has been retrieved as a
HxmField, you can retrieve or modify the value of the field for any object of this class using the various get and set methods likeHxmField.getValue(HxmValue).- Parameters:
memberId- Id of the field to get.- Returns:
- The field with the given id.
-
getProperty
Returns the property with the given name as an
HxmProperty. An exception is thrown if the member is not a property or if no member with the given name is present in the class. The member name is case sensitive.Once the property has been retrieved as a
HxmProperty, you can retrieve or modify the value of the property for any object of this class using the various get and set methods likeHxmProperty.getValue(HxmValue).- Parameters:
memberName- Name of the property to get.- Returns:
- The property with the given name.
-
getProperty
Returns the property with the given id as an
HxmProperty. An exception is thrown if the member is not a property or ifmemberIdis less than 0 or greater than the number of members returned by the methodgetNbMembers().Once the property has been retrieved as a
HxmProperty, you can retrieve or modify the value of the property for any object of this class using the various get and set methods likeHxmProperty.getValue(HxmValue).- Parameters:
memberId- Id of the property to get.- Returns:
- The property with the given id.
-
getNbStaticMembers
public int getNbStaticMembers()Returns the number of static members declared in the class. Only the static members declared specfically in this class actually count. There is no inheritance for static members and therefore parent classes are ignored. The returned number can be used to browse static members using the following methods, which take astaticMemberIdparameter ranging from 0 togetNbStaticMembers().- Returns:
- The number of static members in this class.
-
getStaticMemberName
Returns the name of the static member with the given id. An exception is thrown ifstaticMemberIdis less than 0 or greater than the number of static members returned by the methodgetNbStaticMembers().- Parameters:
staticMemberId- Id of the static member to get the name.- Returns:
- The name of the static member with the given id.
-
findStaticMemberId
Returns the id of the static member with the given name or -1 if no such member exists in the class. Only the static members declared specfically in this class are actually considered for the search. The static member name is case sensitive.- Parameters:
staticMemberName- Name of the static member to get the id.- Returns:
- The id of the static member with the given name.
-
isStaticMember
Returns true if a static member with the given name is declared in the class. The considered static members are only those specifically declared in the current class. There is no inheritance for static members, therefore parent classes are ignored in the search. The static member name is case sensitive.- Parameters:
staticMemberName- Name of the static member to check.- Returns:
- True if a static member with the given name is declared in the class.
-
getStaticMember
Returns the value of the static member with the given name. An exception is thrown if no static member with the given name is present in the class. The static member name is case sensitive.- Parameters:
staticMemberName- Name of the static member to get.- Returns:
- The value of the static member with the given name.
- See Also:
-
getStaticMember
Returns the value of the static member with the given id. An exception is thrown ifstaticMemberIdis less than 0 or greater than the number of static members returned by the methodgetNbStaticMembers().- Parameters:
staticMemberId- Id of the static member to get.- Returns:
- The value of the static member with the given id.
- See Also:
-
setStaticMember
Sets the value of the static member with the given id. An exception is thrown if no static member with the given name is present in the class. The static member name is case sensitive.- Parameters:
staticMemberName- Name of the static member to set.value- Value of the static member to set.- See Also:
-
setStaticMember
Sets the value of the static member with the given id. An exception is thrown ifstaticMemberIdis less than 0 or greater than the number of static members returned by the methodgetNbStaticMembers().- Parameters:
staticMemberId- Id of the static member to set.value- Value of the static member to set.- See Also:
-
asValue
Gets the HxmClass as HxmValue.- See Also:
-
hashCode
public int hashCode() -
equals
-