Class HxmClass

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class HxmClass
    extends java.lang.Object
    implements java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HxmValue asValue()
      Gets the HxmClass as HxmValue.
      void close()
      Releases the reference.
      boolean equals​(java.lang.Object obj)  
      int findMemberId​(java.lang.String memberName)
      Returns the id of the member with the given name or -1 if no such member exists in the class.
      int findStaticMemberId​(java.lang.String staticMemberName)
      Returns the id of the static member with the given name or -1 if no such member exists in the class.
      java.lang.String getDeclaredName()
      Gets the full qualified name of the class.
      HxmField getField​(int memberId)
      Returns the field with the given id as an HxmField.
      HxmField getField​(java.lang.String memberName)
      Returns the field with the given name as an HxmField.
      java.lang.String getMemberName​(int memberId)
      Returns the name of the member with the given id.
      HxmMemberType getMemberType​(int memberId)
      Returns the type of the member with the given id.
      HxmMemberType getMemberType​(java.lang.String memberName)
      Returns the type of the member with the given name.
      HxmFunction getMethod​(int memberId)
      Returns the method with the given id as an HxmFunction.
      HxmFunction getMethod​(java.lang.String memberName)
      Returns the method with the given name as an HxmFunction.
      int getNbMembers()
      Returns the number of members present in this class.
      int getNbStaticMembers()
      Returns the number of static members declared in the class.
      HxmProperty getProperty​(int memberId)
      Returns the property with the given id as an HxmProperty.
      HxmProperty getProperty​(java.lang.String memberName)
      Returns the property with the given name as an HxmProperty.
      HxmValue getStaticMember​(int staticMemberId)
      Returns the value of the static member with the given id.
      HxmValue getStaticMember​(java.lang.String staticMemberName)
      Returns the value of the static member with the given name.
      java.lang.String getStaticMemberName​(int staticMemberId)
      Returns the name of the static member with the given id.
      HxmClass getSuperClass()
      Returns the class extended by this class.
      int hashCode()  
      boolean hasSuperClass()
      Returns true if this class extends another class.
      boolean isField​(int memberId)
      Returns true if the member with the given id is a field.
      boolean isField​(java.lang.String memberName)
      Returns true if a field with the given name is present in the class or inherited from a parent class.
      boolean isFinal()
      Returns true if the class has been declared as final.
      boolean isInstance​(HxmValue value)
      Returns true if the value passed in parameter is an instance of this class.
      boolean isMember​(java.lang.String memberName)
      Returns true if a member with the given name is present in the class.
      boolean isMethod​(int memberId)
      Returns true if the member with the given id is a method.
      boolean isMethod​(java.lang.String memberName)
      Returns true if a method with the given name is present in the class or inherited from a parent class.
      boolean isProperty​(int memberId)
      Returns true if the member with the given id is a property.
      boolean isProperty​(java.lang.String memberName)
      Returns true if a property with the given name is present in the class or inherited from a parent class.
      boolean isStaticMember​(java.lang.String staticMemberName)
      Returns true if a static member with the given name is declared in the class.
      boolean isSubClassOf​(HxmClass other)
      Returns true if this class is a subclass of the class given as parameter.
      HxmValue newInstance​(HxmValue... arguments)
      Returns a new instance of this class.
      HxmValue newInstance​(java.util.List<HxmValue> arguments)
      Returns a new instance of this class.
      void setStaticMember​(int staticMemberId, HxmValue value)
      Sets the value of the static member with the given id.
      void setStaticMember​(java.lang.String staticMemberName, HxmValue value)
      Sets the value of the static member with the given id.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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:
        close in interface java.lang.AutoCloseable
      • newInstance

        public HxmValue newInstance​(HxmValue... arguments)
        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:
        HxmValue
      • newInstance

        public HxmValue newInstance​(java.util.List<HxmValue> arguments)
        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:
        HxmValue
      • getDeclaredName

        public java.lang.String 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

        public boolean isSubClassOf​(HxmClass other)
        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 method getSuperClass().
        Returns:
        True if this class extends another class.
      • getSuperClass

        public HxmClass 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

        public boolean isInstance​(HxmValue value)
        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:
        HxmValue
      • 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 a memberId parameter ranging from 0 to getNbMembers().
        Returns:
        The number of members in this class or in the parent classes.
      • getMemberName

        public java.lang.String getMemberName​(int memberId)
        Returns the name of the member with the given id. An exception is thrown if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().
        Parameters:
        memberId - Id of the member to get the name.
        Returns:
        Name of the member with the given id.
      • findMemberId

        public int findMemberId​(java.lang.String memberName)
        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

        public boolean isMember​(java.lang.String memberName)
        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 to findMemberId(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

        public boolean isMethod​(java.lang.String memberName)
        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 if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().
        Parameters:
        memberId - Id of the member to check.
        Returns:
        True if a method with the given id is present in the class.
      • isField

        public boolean isField​(java.lang.String memberName)
        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 if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().
        Parameters:
        memberId - Id of the member to check.
        Returns:
        True if a field with the given id is present in the class.
      • isProperty

        public boolean isProperty​(java.lang.String memberName)
        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 if memberId is less than 0 or greater than the number of members returned by the method getNbMembers()
        Parameters:
        memberId - Id of the member to check.
        Returns:
        True if a property with the given id is present in the class.
      • getMemberType

        public HxmMemberType getMemberType​(int memberId)
        Returns the type of the member with the given id. An exception is thrown if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().
        Parameters:
        memberId - Id of the member to get the type.
        Returns:
        Type of the member with the given id.
        See Also:
        HxmMemberType
      • getMemberType

        public HxmMemberType getMemberType​(java.lang.String memberName)
        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:
        HxmMemberType
      • getMethod

        public HxmFunction getMethod​(java.lang.String memberName)

        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 with HxmFunction.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

        public HxmFunction getMethod​(int memberId)

        Returns the method with the given id as an HxmFunction. An exception is thrown if the member is not a method or if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().

        Once the method has been retrieved as a HxmFunction, you can call it with HxmFunction.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

        public HxmField getField​(java.lang.String memberName)

        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 like HxmField.getValue(HxmValue).

        Parameters:
        memberName - Name of the field to get.
        Returns:
        The field with the given name.
      • getField

        public HxmField getField​(int memberId)

        Returns the field with the given id as an HxmField. An exception is thrown if the member is not a field or if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().

        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 like HxmField.getValue(HxmValue).

        Parameters:
        memberId - Id of the field to get.
        Returns:
        The field with the given id.
      • getProperty

        public HxmProperty getProperty​(java.lang.String memberName)

        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 like HxmProperty.getValue(HxmValue).

        Parameters:
        memberName - Name of the property to get.
        Returns:
        The property with the given name.
      • getProperty

        public HxmProperty getProperty​(int memberId)

        Returns the property with the given id as an HxmProperty. An exception is thrown if the member is not a property or if memberId is less than 0 or greater than the number of members returned by the method getNbMembers().

        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 like HxmProperty.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 a staticMemberId parameter ranging from 0 to getNbStaticMembers().
        Returns:
        The number of static members in this class.
      • getStaticMemberName

        public java.lang.String getStaticMemberName​(int staticMemberId)
        Returns the name of the static member with the given id. An exception is thrown if staticMemberId is less than 0 or greater than the number of static members returned by the method getNbStaticMembers().
        Parameters:
        staticMemberId - Id of the static member to get the name.
        Returns:
        The name of the static member with the given id.
      • findStaticMemberId

        public int findStaticMemberId​(java.lang.String staticMemberName)
        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

        public boolean isStaticMember​(java.lang.String staticMemberName)
        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

        public HxmValue getStaticMember​(java.lang.String staticMemberName)
        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:
        HxmValue
      • getStaticMember

        public HxmValue getStaticMember​(int staticMemberId)
        Returns the value of the static member with the given id. An exception is thrown if staticMemberId is less than 0 or greater than the number of static members returned by the method getNbStaticMembers().
        Parameters:
        staticMemberId - Id of the static member to get.
        Returns:
        The value of the static member with the given id.
        See Also:
        HxmValue
      • setStaticMember

        public void setStaticMember​(java.lang.String staticMemberName,
                                    HxmValue value)
        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:
        HxmValue
      • setStaticMember

        public void setStaticMember​(int staticMemberId,
                                    HxmValue value)
        Sets the value of the static member with the given id. An exception is thrown if staticMemberId is less than 0 or greater than the number of static members returned by the method getNbStaticMembers().
        Parameters:
        staticMemberId - Id of the static member to set.
        value - Value of the static member to set.
        See Also:
        HxmValue
      • asValue

        public HxmValue asValue()
        Gets the HxmClass as HxmValue.
        See Also:
        HxmValue
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object