Class ClassElement

All Implemented Interfaces:
Cloneable

public final class ClassElement extends PropertyNode
IR representation for class elements.
  • Method Details

    • createMethod

      public static ClassElement createMethod(long token, int finish, Expression key, Expression value, List<Expression> decorators, boolean isStatic, boolean hasComputedKey)
      Create a Method class element.
      Parameters:
      token - token.
      finish - finish.
      key - The name of the method.
      value - The value of the method.
      decorators - The decorators of the method. Optional.
      isStatic - static method.
      hasComputedKey - has computed key.
      Returns:
      A ClassElement node representing a method.
    • createAccessor

      public static ClassElement createAccessor(long token, int finish, Expression key, FunctionNode get, FunctionNode set, List<Expression> decorators, boolean isPrivate, boolean isStatic, boolean hasComputedKey)
      Create an Accessor (i.e., get/set) element.
      Parameters:
      token - token.
      finish - finish.
      key - The name of the accessor.
      get - The getter of the accessor. Optional.
      set - The setter of the accessor. Optional.
      decorators - The decorators of the accessor. Optional.
      isPrivate - private accessor.
      isStatic - static accessor.
      hasComputedKey - has computed key.
      Returns:
      A ClassElement node representing an accessor (getter, setter).
    • createField

      public static ClassElement createField(long token, int finish, Expression key, Expression initialize, List<Expression> decorators, boolean isStatic, boolean hasComputedKey, boolean anonymousFunctionDefinition)
      Create a class field element.
      Parameters:
      token - token.
      finish - finish.
      key - The name of the field.
      initialize - The initialization value of the field. Optional.
      decorators - The decorators of the field. Optional.
      isStatic - static field,
      hasComputedKey - has computed key.
      anonymousFunctionDefinition - is anonymous function definition.
      Returns:
      A ClassElement node representing a field.
    • createDefaultConstructor

      public static ClassElement createDefaultConstructor(long token, int finish, Expression key, Expression value)
      Create the class default constructor.
      Parameters:
      token - token.
      finish - finish.
      key - class name.
      value - value.
      Returns:
      A ClassElement node representing a default constructor.
    • createStaticInitializer

      public static ClassElement createStaticInitializer(long token, int finish, FunctionNode functionNode)
      Create a static initializer element.
      Parameters:
      token - token.
      finish - finish.
      functionNode - function node.
      Returns:
      A ClassElement node representing a static initializer.
    • createAutoAccessor

      public static ClassElement createAutoAccessor(long token, int finish, Expression key, FunctionNode initializer, List<Expression> classElementDecorators, boolean isStatic, boolean hasComputedKey, boolean anonymousFunctionDefinition)
      Create an auto-accessor class element.
      Parameters:
      token - token.
      finish - finish.
      key - key name.
      initializer - initializer body.
      classElementDecorators - decorators.
      isStatic - is static.
      hasComputedKey - has computed key.
      anonymousFunctionDefinition - is anonymous function definition.
      Returns:
      A ClassElement node representing an auto-accessor.
    • accept

      public Node accept(NodeVisitor<? extends LexicalContext> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      Overrides:
      accept in class PropertyNode
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • accept

      public <R> R accept(TranslatorNodeVisitor<? extends LexicalContext, R> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      Overrides:
      accept in class PropertyNode
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • getDecorators

      public List<Expression> getDecorators()
    • setDecorators

      public ClassElement setDecorators(List<Expression> decorators)
    • setGetter

      public ClassElement setGetter(FunctionNode get)
      Description copied from class: PropertyNode
      Set the getter of this property, null if none
      Overrides:
      setGetter in class PropertyNode
      Parameters:
      get - getter
      Returns:
      same node or new node if state changed
    • setKey

      public ClassElement setKey(Expression key)
    • setSetter

      public ClassElement setSetter(FunctionNode set)
      Description copied from class: PropertyNode
      Set the setter for this property, null if none
      Overrides:
      setSetter in class PropertyNode
      Parameters:
      set - setter
      Returns:
      same node or new node if state changed
    • setValue

      public ClassElement setValue(Expression value)
      Description copied from class: PropertyNode
      Set the value of this property
      Overrides:
      setValue in class PropertyNode
      Parameters:
      value - new value
      Returns:
      same node or new node if state changed
    • isAccessor

      public boolean isAccessor()
      Overrides:
      isAccessor in class PropertyNode
    • isAutoAccessor

      public boolean isAutoAccessor()
    • isClassField

      public boolean isClassField()
      Overrides:
      isClassField in class PropertyNode
    • isClassFieldOrAutoAccessor

      public boolean isClassFieldOrAutoAccessor()
      Returns true if the class element is one of: field, auto accessor.
    • isClassStaticBlock

      public boolean isClassStaticBlock()
      Overrides:
      isClassStaticBlock in class PropertyNode
    • isMethod

      public boolean isMethod()
    • isMethodOrAccessor

      public boolean isMethodOrAccessor()
      Returns true if the class element is one of: method, getter, setter, auto accessor.
    • isPrivate

      public boolean isPrivate()
      Overrides:
      isPrivate in class PropertyNode
    • isStatic

      public boolean isStatic()
      Overrides:
      isStatic in class PropertyNode
    • toString

      public void toString(StringBuilder sb, boolean printType)
      Description copied from class: Node
      Print logic that decides whether to show the optimistic type or not - for example it should not be printed after just parse, when it hasn't been computed, or has been set to a trivially provable value
      Overrides:
      toString in class PropertyNode
      Parameters:
      sb - string builder
      printType - print type?