Package com.sun.codemodel
Class JVar
- java.lang.Object
-
- com.sun.codemodel.JExpressionImpl
-
- com.sun.codemodel.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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<JAnnotationUse>
annotations
Annotations on this variable.private JExpression
init
Initialization of the variable in its declarationprivate JMods
mods
Modifiers.private java.lang.String
name
Name of the variableprivate JType
type
JType of the variable
-
Constructor Summary
Constructors Constructor Description JVar(JMods mods, JType type, java.lang.String name, JExpression init)
JVar constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JAnnotationUse
annotate(JClass clazz)
Adds an annotation to this variable.JAnnotationUse
annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Adds an annotation to this variable.<W extends JAnnotationWriter>
Wannotate2(java.lang.Class<W> clazz)
Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.java.util.Collection<JAnnotationUse>
annotations()
Read-only live view of all annotations on thisJAnnotatable
JExpression
assign(JExpression rhs)
JExpression
assignPlus(JExpression rhs)
void
bind(JFormatter f)
void
declare(JFormatter f)
void
generate(JFormatter f)
JVar
init(JExpression init)
Initialize this variableprotected boolean
isAnnotated()
JMods
mods()
java.lang.String
name()
Get the name of this variablevoid
name(java.lang.String name)
Changes the name of this variable.JType
type()
Return the type of this variable.JType
type(JType newType)
Sets the type of this variable.-
Methods inherited from class com.sun.codemodel.JExpressionImpl
_instanceof, band, bor, cand, complement, component, cor, decr, div, eq, gt, gte, incr, invoke, invoke, lt, lte, minus, minus, mod, mul, ne, not, plus, ref, ref, shl, shr, shrz, xor
-
-
-
-
Field Detail
-
mods
private JMods mods
Modifiers.
-
type
private JType type
JType of the variable
-
name
private java.lang.String name
Name of the variable
-
init
private JExpression init
Initialization of the variable in its declaration
-
annotations
private java.util.List<JAnnotationUse> annotations
Annotations on this variable. Lazily created.
-
-
Constructor Detail
-
JVar
JVar(JMods mods, JType type, java.lang.String name, JExpression init)
JVar constructor- Parameters:
type
- Datatype of this variablename
- Name of this variableinit
- Value to initialize this variable to
-
-
Method Detail
-
init
public JVar init(JExpression init)
Initialize this variable- Parameters:
init
- JExpression to be used to initialize this field
-
name
public java.lang.String name()
Get the name of this variable- Returns:
- Name of the variable
-
name
public void name(java.lang.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 interfaceJAnnotatable
- Parameters:
clazz
- The annotation class to annotate the field with
-
annotate
public JAnnotationUse annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Adds an annotation to this variable.- Specified by:
annotate
in interfaceJAnnotatable
- Parameters:
clazz
- The annotation class to annotate the field with
-
annotate2
public <W extends JAnnotationWriter> W annotate2(java.lang.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 interfaceJAnnotatable
-
annotations
public java.util.Collection<JAnnotationUse> annotations()
Description copied from interface:JAnnotatable
Read-only live view of all annotations on thisJAnnotatable
- Specified by:
annotations
in interfaceJAnnotatable
- 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 interfaceJDeclaration
-
generate
public void generate(JFormatter f)
- Specified by:
generate
in interfaceJGenerable
-
assign
public JExpression assign(JExpression rhs)
- Specified by:
assign
in interfaceJAssignmentTarget
-
assignPlus
public JExpression assignPlus(JExpression rhs)
- Specified by:
assignPlus
in interfaceJAssignmentTarget
-
-