Class JVar

All Implemented Interfaces:
JAnnotatable, JAssignmentTarget, JDeclaration, JExpression, JGenerable
Direct Known Subclasses:
JFieldVar

public class JVar extends JExpressionImpl implements JDeclaration, JAssignmentTarget, JAnnotatable
Variables and fields.
  • Method Details

    • init

      public JVar init(JExpression init)
      Initialize this variable
      Parameters:
      init - JExpression to be used to initialize this field
    • name

      public String name()
      Get the name of this variable
      Returns:
      Name of the variable
    • name

      public void name(String name)
      Changes the name of this variable.
    • type

      public JType type()
      Return the type of this variable.
      Returns:
      always non-null.
    • mods

      public JMods mods()
      Returns:
      the current modifiers of this method. Always return non-null valid object.
    • type

      public JType type(JType newType)
      Sets the type of this variable.
      Parameters:
      newType - must not be null.
      Returns:
      the old type value. always non-null.
    • annotate

      public JAnnotationUse annotate(JClass clazz)
      Adds an annotation to this variable.
      Specified by:
      annotate in interface JAnnotatable
      Parameters:
      clazz - The annotation class to annotate the field with
    • annotate

      public void annotate(JAnnotationUse annotation)
    • annotate

      public JAnnotationUse annotate(Class<? extends Annotation> clazz)
      Adds an annotation to this variable.
      Specified by:
      annotate in interface JAnnotatable
      Parameters:
      clazz - The annotation class to annotate the field with
    • annotate2

      public <W extends JAnnotationWriter<? extends Annotation>> W annotate2(Class<W> clazz)
      Description copied from interface: JAnnotatable
      Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.
      Specified by:
      annotate2 in interface JAnnotatable
    • removeAnnotation

      public boolean removeAnnotation(JAnnotationUse annotation)
      Description copied from interface: JAnnotatable
      Removes annotation from this program element.
      Specified by:
      removeAnnotation in interface JAnnotatable
      Parameters:
      annotation - The annotation to be removed from the program element
    • annotations

      public Collection<JAnnotationUse> annotations()
      Description copied from interface: JAnnotatable
      Read-only live view of all annotations on this
      Specified by:
      annotations in interface JAnnotatable
      Returns:
      Can be empty but never null.
    • isAnnotated

      protected boolean isAnnotated()
    • bind

      public void bind(JFormatter f)
    • declare

      public void declare(JFormatter f)
      Specified by:
      declare in interface JDeclaration
    • generate

      public void generate(JFormatter f)
      Specified by:
      generate in interface JGenerable
    • assign

      public JExpression assign(JExpression rhs)
      Specified by:
      assign in interface JAssignmentTarget
    • assignPlus

      public JExpression assignPlus(JExpression rhs)
      Specified by:
      assignPlus in interface JAssignmentTarget