Class LocalVariable

All Implemented Interfaces:
Annotatable, Attributeable, Commentable, Erasable<LocalVariable>, Expression, Node, Renderable, WithName, WithReferences

public class LocalVariable extends Variable<TypeRef> implements Erasable<LocalVariable>
  • Constructor Details

  • Method Details

    • newLocalVariable

      public static LocalVariable newLocalVariable(String name)
    • newLocalVariable

      public static LocalVariable newLocalVariable(Class<?> type, String name)
    • newLocalVariable

      public static LocalVariable newLocalVariable(TypeRef typeRef, String name)
    • newFinalLocalVariable

      public static LocalVariable newFinalLocalVariable(TypeRef typeRef, String name)
    • withVarInference

      public static LocalVariable withVarInference(String name, Expression initializer)
    • withFinalVarInference

      public static LocalVariable withFinalVarInference(String name, Expression initializer)
    • isFinal

      public boolean isFinal()
      Overrides:
      isFinal in class ModifierSupport
    • withFinal

      public LocalVariable withFinal(boolean isFinal)
    • withInitialValue

      public LocalVariable withInitialValue(Expression initialValue)
    • withInitialValue

      public LocalVariable withInitialValue(Optional<Expression> initialValue)
    • isVarInferred

      public boolean isVarInferred()
    • withInferredType

      public LocalVariable withInferredType(TypeRef inferredType)
    • withErasure

      public LocalVariable withErasure()
      Description copied from interface: Erasable
      Returns an erased version of this object with generic type information removed. This creates a canonical instance that can be used for comparison and resolution.
      Specified by:
      withErasure in interface Erasable<LocalVariable>
      Returns:
      the erased version of this object
    • getErasure

      public String getErasure()
      Description copied from interface: Erasable
      Returns the erasure of this type as a canonical string representation. The erasure removes generic type parameters and provides a stable way to compare types regardless of generic instantiation.
      Specified by:
      getErasure in interface Erasable<LocalVariable>
      Returns:
      the type erasure string
    • render

      public String render()
      Description copied from interface: Renderable
      Render the type into a String for the purpose of code generation. This is slightly different from the `toString()` method as `toString()` is mostly needed for logging / debugging and should be idempotent. Regarding idempotency this method may yield different result based on the context it is used even if the internal state of the object does not change. An example of such case, is a reference to class that may change based on the package from which it's refenced.
      Specified by:
      render in interface Renderable
      Returns:
      the String representation of the object as it's meant to appear in the generated code.
    • toString

      public String toString()
      Overrides:
      toString in class Variable<TypeRef>