- All Known Subinterfaces:
Field
public interface Variable
Represents a variable bound to the body of a
method.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdd this variable with another variable or a constant, and assign the result to a new variable.addAnnotation(Object annotationType, boolean visible) Add an annotation to this variable.Access an element from this array.alength()Access the length of this array.Compute the bitwise and of this variable with another variable or a constant, and assign the result to a new variable.voidSet an element into this array.box()Box this primitive variable into its object peer.Cast this variable to another type, and assign the result to a new variable.Class<?>Returns the type of this variable, if bound to an existing class.clear()Assign a value of 0, false, or null to this variable, depending on its type.com()Compute the bitwise complement of this variable and assign the result to a new variable.Specify a static bootstrap method for dynamically generating constants, as found in the class type of this variable.Divide this variable with another variable or a constant, and assign the result to a new variable.Determine if this variable is equal to another variable or constant, and assign the result to a new boolean variable.Access a static or instance field from the object referred to by this variable.Determine if this variable is greater than or equal to another variable or constant, and assign the result to a new boolean variable.get()Return a new variable with the same type and value as this one.Determine if this variable is greater than another variable or constant, and assign the result to a new boolean variable.default voidConvenience method to generate conditional code if this variable is equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is equal to another variable or constant.voidConditional goto if this variable is equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is false.default voidConvenience method to generate conditional code if this variable is false.voidConditional goto if this variable is false.default voidConvenience method to generate conditional code if this variable is greater than or equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is greater than or equal to another variable or constant.voidConditional goto if this variable is greater than or equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is greater than another variable or constant.default voidConvenience method to generate conditional code if this variable is greater than another variable or constant.voidConditional goto if this variable is greater than another variable or constant.default voidConvenience method to generate conditional code if this variable is less than or equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is less than or equal to another variable or constant.voidConditional goto if this variable is less than or equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is less than another variable or constant.default voidConvenience method to generate conditional code if this variable is less than another variable or constant.voidConditional goto if this variable is less than another variable or constant.default voidConvenience method to generate conditional code if this variable is not equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is not equal to another variable or constant.voidConditional goto if this variable is not equal to another variable or constant.default voidConvenience method to generate conditional code if this variable is true.default voidConvenience method to generate conditional code if this variable is true.voidConditional goto if this variable is true.voidAdd this variable with another variable or a constant, and assign the result back to this variable.Specify a static bootstrap method for dynamically generating methods, as found in the class type of this variable.instanceOf(Object type) Determine if this variable is an instance of the given class or interface, and assign the result to a new boolean variable.Invoke a static or instance method on the object referenced by this variable.Invoke a static or instance method on the object referenced by this variable.Determine if this variable is less than or equal to another variable or constant, and assign the result to a new boolean variable.Determine if this variable is less than another variable or constant, and assign the result to a new boolean variable.Returns the type of this variable, if bound to a class which is being made.methodHandle(Object returnType, String name, Object... types) Returns aMethodHandlevariable which can invoke a static or instance method on the object referenced by this variable.Returns theMethodMakerthat this variable belongs to.voidEnter a synchronized block on this variable.voidExit a synchronized block on this variable.Multiply this variable with another variable or a constant, and assign the result to a new variable.name()Returns the name of this variable, which is null if unnamed.Optionally assign a variable name.Determine if this variable is not equal to another variable or constant, and assign the result to a new boolean variable.neg()Negate the value of this variable and assign the result to a new variable.not()Compute the logical negation of this boolean variable, and assign the result to a new variable.Compute the bitwise or of this variable with another variable or a constant, and assign the result to a new variable.Compute the division remainder of this variable with another variable or a constant, and assign the result to a new variable.Assign a value to this variable, either from another variable or from a constant.Assign an exact object instance this variable, supported only when the class is built dynamically instead of loaded from a file.Compute the bitwise left shift of this variable with another variable or a constant, and assign the result to a new variable.Compute the bitwise right shift of this variable with another variable or a constant, and assign the result to a new variable.Define a signature for this named variable, which is a string for supporting generic types.Subtract this variable with another variable or a constant, and assign the result to a new variable.voidGenerates a switch statement against thisintor non-nullIntegervariable.voidGenerates a switch statement against this non-nullStringvariable.voidsynchronized_(Runnable body) Convenience method for defining a synchronized block on this variable.voidthrow_()Throw the exception object referred to by this variable.unbox()Unbox this object variable into its primitive peer.Compute the bitwise unsigned right shift of this variable with another variable or a constant, and assign the result to a new variable.Compute the bitwise xor of this variable with another variable or a constant, and assign the result to a new variable.
-
Method Details
-
classType
Class<?> classType()Returns the type of this variable, if bound to an existing class. Null is returned if bound to a class which is being made. -
makerType
ClassMaker makerType()Returns the type of this variable, if bound to a class which is being made. Null is returned if bound to an existing class. -
name
String name()Returns the name of this variable, which is null if unnamed. -
name
Optionally assign a variable name.- Returns:
- this variable
- Throws:
IllegalStateException- if already named
-
signature
Define a signature for this named variable, which is a string for supporting generic types. The components can be strings or types (class, ClassMaker, etc), which are concatenated into a single string. Consult the JVM specification for the signature syntax.- Returns:
- this
- Throws:
IllegalArgumentException- if given an unsupported componentIllegalStateException- if this isn't a plain local variable
-
addAnnotation
Add an annotation to this variable.- Parameters:
annotationType- name or class which refers to an annotation interfacevisible- true if annotation is visible at runtime- Throws:
IllegalArgumentException- if the annotation type is unsupportedIllegalStateException- if this variable doesn't support annotations
-
clear
Variable clear()Assign a value of 0, false, or null to this variable, depending on its type.- Returns:
- this variable
- Throws:
IllegalStateException- if this variable cannot be modified
-
set
Assign a value to this variable, either from another variable or from a constant. A constant value can be a primitive type (boxed or unboxed),null, aString, aClass, anEnum, aMethodType, aMethodHandleInfo, aConstantDesc, or aConstable.Note that a
MethodHandlecan be set with aMethodHandleInfo, which is converted automatically at link time. Handling ofConstantDescandConstableis also treated specially — the actual type is determined by the resolved constant.- Parameters:
value- aVariableor a constant- Returns:
- this variable
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable cannot be modified, or if it's not compatible with the value type
-
setExact
Assign an exact object instance this variable, supported only when the class is built dynamically instead of loaded from a file. At runtime, the object instance provided here is exactly the same as referenced by the generated class. For simple constants, the regular set method is preferred.- Parameters:
value- exact object instance to assign- Returns:
- this variable
- Throws:
IllegalStateException- if this variable cannot be modified, or if it's not compatible with the value type
-
get
Variable get()Return a new variable with the same type and value as this one.- Returns:
- the result in a new variable, with the same type as this one
-
ifTrue
Conditional goto if this variable is true. The label doesn't need to be positioned yet. -
ifTrue
Convenience method to generate conditional code if this variable is true.- Parameters:
then- called to generate the body of the "then" case
-
ifTrue
Convenience method to generate conditional code if this variable is true.- Parameters:
then- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifFalse
Conditional goto if this variable is false. The label doesn't need to be positioned yet. -
ifFalse
Convenience method to generate conditional code if this variable is false.- Parameters:
then- called to generate the body of the "then" case
-
ifFalse
Convenience method to generate conditional code if this variable is false.- Parameters:
then- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifEq
Conditional goto if this variable is equal to another variable or constant. The label doesn't need to be positioned yet.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constant
-
ifEq
Convenience method to generate conditional code if this variable is equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" case
-
ifEq
Convenience method to generate conditional code if this variable is equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifNe
Conditional goto if this variable is not equal to another variable or constant. The label doesn't need to be positioned yet.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constant
-
ifNe
Convenience method to generate conditional code if this variable is not equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" case
-
ifNe
Convenience method to generate conditional code if this variable is not equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifLt
Conditional goto if this variable is less than another variable or constant. The label doesn't need to be positioned yet.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constant
-
ifLt
Convenience method to generate conditional code if this variable is less than another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" case
-
ifLt
Convenience method to generate conditional code if this variable is less than another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifGe
Conditional goto if this variable is greater than or equal to another variable or constant. The label doesn't need to be positioned yet.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constant
-
ifGe
Convenience method to generate conditional code if this variable is greater than or equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" case
-
ifGe
Convenience method to generate conditional code if this variable is greater than or equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifGt
Conditional goto if this variable is greater than another variable or constant. The label doesn't need to be positioned yet.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constant
-
ifGt
Convenience method to generate conditional code if this variable is greater than another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" case
-
ifGt
Convenience method to generate conditional code if this variable is greater than another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
ifLe
Conditional goto if this variable is less than or equal to another variable or constant. The label doesn't need to be positioned yet.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constant
-
ifLe
Convenience method to generate conditional code if this variable is less than or equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" case
-
ifLe
Convenience method to generate conditional code if this variable is less than or equal to another variable or constant.- Parameters:
value- aVariableor a constantthen- called to generate the body of the "then" caseelse_- called to generate the body of the "else" case
-
switch_
Generates a switch statement against thisintor non-nullIntegervariable. None of the labels need to be positioned yet.- Parameters:
defaultLabel- required- Throws:
IllegalArgumentException- if the number of cases and labels don't matchIllegalStateException- if this type cannot be automatically cast to an int
-
switch_
Generates a switch statement against this non-nullStringvariable. None of the labels need to be positioned yet.- Parameters:
defaultLabel- required- Throws:
IllegalArgumentException- if the number of cases and labels don't matchIllegalStateException- if this type isn't a String
-
inc
Add this variable with another variable or a constant, and assign the result back to this variable.- Parameters:
value- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
add
Add this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
sub
Subtract this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
mul
Multiply this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
div
Divide this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
rem
Compute the division remainder of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
eq
Determine if this variable is equal to another variable or constant, and assign the result to a new boolean variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new boolean variable
- Throws:
IllegalArgumentException- if not given a variable or a constant- See Also:
-
ne
Determine if this variable is not equal to another variable or constant, and assign the result to a new boolean variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new boolean variable
- Throws:
IllegalArgumentException- if not given a variable or a constant- See Also:
-
lt
Determine if this variable is less than another variable or constant, and assign the result to a new boolean variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new boolean variable
- Throws:
IllegalArgumentException- if not given a variable or a constant- See Also:
-
ge
Determine if this variable is greater than or equal to another variable or constant, and assign the result to a new boolean variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new boolean variable
- Throws:
IllegalArgumentException- if not given a variable or a constant- See Also:
-
gt
Determine if this variable is greater than another variable or constant, and assign the result to a new boolean variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new boolean variable
- Throws:
IllegalArgumentException- if not given a variable or a constant- See Also:
-
le
Determine if this variable is less than or equal to another variable or constant, and assign the result to a new boolean variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new boolean variable
- Throws:
IllegalArgumentException- if not given a variable or a constant- See Also:
-
instanceOf
Determine if this variable is an instance of the given class or interface, and assign the result to a new boolean variable.- Parameters:
type- class or interface- Returns:
- the result in a new boolean variable
-
cast
Cast this variable to another type, and assign the result to a new variable. If the variable represents a primitive type, a conversion might be applied.- Parameters:
type- class or interface- Returns:
- the result in a new variable
-
not
Variable not()Compute the logical negation of this boolean variable, and assign the result to a new variable.- Returns:
- the result in a new variable, with the same type as this one
-
and
Compute the bitwise and of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
or
Compute the bitwise or of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
xor
Compute the bitwise xor of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
shl
Compute the bitwise left shift of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
shr
Compute the bitwise right shift of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
ushr
Compute the bitwise unsigned right shift of this variable with another variable or a constant, and assign the result to a new variable.- Parameters:
value- aVariableor a constant- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if this variable doesn't support the operation, or if value is incompatible
-
neg
Variable neg()Negate the value of this variable and assign the result to a new variable.- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalStateException- if this variable doesn't support the operation
-
com
Variable com()Compute the bitwise complement of this variable and assign the result to a new variable.- Returns:
- the result in a new variable, with the same type as this one
- Throws:
IllegalStateException- if this variable doesn't support the operation
-
box
Variable box()Box this primitive variable into its object peer. If not a primitive type, then this is equivalent to callingget.- Returns:
- the result in a new variable
-
unbox
Variable unbox()Unbox this object variable into its primitive peer. If already a primitive type, then this is equivalent to callingget.- Returns:
- the result in a new variable
- Throws:
IllegalStateException- if this variable cannot be unboxed
-
alength
Variable alength()Access the length of this array.- Returns:
- the result in a new int variable
- Throws:
IllegalStateException- if not an array type
-
aget
Access an element from this array.- Parameters:
index- aVariableor a constant- Returns:
- the result in a new variable
- Throws:
IllegalStateException- if not an array type
-
aset
Set an element into this array.- Parameters:
index- aVariableor a constantvalue- aVariableor a constant- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if not an array type, or if type doesn't match- See Also:
-
field
Access a static or instance field from the object referred to by this variable.- Parameters:
name- field name- Throws:
IllegalStateException- if field isn't found
-
invoke
Invoke a static or instance method on the object referenced by this variable.- Parameters:
name- method namevalues-Variablesor constants- Returns:
- the result of the method, which is null if void
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if method isn't found
-
invoke
Invoke a static or instance method on the object referenced by this variable.- Parameters:
returnType- method return typename- method name; can be".new"to construct an instance of this variable type, and returnType can be nulltypes- method parameter types; the entire array or individual elements can be null to infer the actual type from the corresponding valuevalues-Variablesor constants- Returns:
- the result of the method, which is null if void
- Throws:
IllegalArgumentException- if not given a variable or a constantIllegalStateException- if method isn't found
-
methodHandle
Returns aMethodHandlevariable which can invoke a static or instance method on the object referenced by this variable. The returned variable is actually a constant, and so it can be supplied as an argument to abootstrapmethod or be used by another method in the same class.- Parameters:
returnType- method return typename- method name; can be".new"to construct an instance of this variable type, and returnType can be nulltypes- method parameter types; can be null if none- Throws:
IllegalArgumentException- if not given a supported type objectIllegalStateException- if method isn't found
-
indy
Specify a static bootstrap method for dynamically generating methods, as found in the class type of this variable.- Parameters:
name- bootstrap method nameargs- constants which are passed to the bootstrap method, not including the first three standard arguments:(Lookup caller, String name, MethodType type)- See Also:
-
condy
Specify a static bootstrap method for dynamically generating constants, as found in the class type of this variable. The variable returned by the bootstrap method cannot be modified. Since it is a constant, it can be supplied as an argument to another bootstrap method or be used by another method in the same class.- Parameters:
name- bootstrap method nameargs- constants which are passed to the bootstrap method, not including the first three standard arguments:(Lookup caller, String name, Class type)- See Also:
-
throw_
void throw_()Throw the exception object referred to by this variable.- Throws:
IllegalStateException- if not an exception type
-
monitorEnter
void monitorEnter()Enter a synchronized block on this variable.- Throws:
IllegalStateException- if this variable isn't an object type
-
monitorExit
void monitorExit()Exit a synchronized block on this variable.- Throws:
IllegalStateException- if this variable isn't an object type
-
synchronized_
Convenience method for defining a synchronized block on this variable.- Parameters:
body- called to generate the body of the synchronized block- Throws:
IllegalStateException- if this variable isn't an object type
-
methodMaker
MethodMaker methodMaker()Returns theMethodMakerthat this variable belongs to.
-