Package spoon.reflect.code
Interface CtLocalVariable<T>
-
- Type Parameters:
T
- type of the variable
- All Superinterfaces:
Cloneable
,CtCodeElement
,CtElement
,CtModifiable
,CtNamedElement
,CtQueryable
,CtRHSReceiver<T>
,CtStatement
,CtTypedElement<T>
,CtVariable<T>
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Implementing Classes:
CtLocalVariableImpl
public interface CtLocalVariable<T> extends CtStatement, CtVariable<T>, CtRHSReceiver<T>
This code element defines a local variable definition (within an executable body). Example:// defines a local variable x int x = 0;
With Java 10, the local variable inference is now authorized, then the following code is valid too in a block scope:// local variable in Java 10 var x = 0;
- See Also:
CtExecutable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CtLocalVariable<T>
clone()
Clone the element which calls this method in a new object.CtExpression<T>
getAssignment()
Useful proxy toCtVariable.getDefaultExpression()
.CtLocalVariableReference<T>
getReference()
Returns the corresponding reference.boolean
isInferred()
Return true if this variable's type is not explicitely defined in the source code, but was using the `var` keyword of Java 10.<U extends CtRHSReceiver<T>>
UsetAssignment(CtExpression<T> assignment)
Sets the right-hand side expression (RHS) of the "=" operator.<U extends CtLocalVariable<T>>
UsetInferred(boolean inferred)
Set true if the variable must be inferred.-
Methods inherited from interface spoon.reflect.code.CtCodeElement
partiallyEvaluate
-
Methods inherited from interface spoon.reflect.declaration.CtElement
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, updateAllParentsBelow
-
Methods inherited from interface spoon.reflect.declaration.CtModifiable
addModifier, getExtendedModifiers, getModifiers, getVisibility, hasModifier, isAbstract, isFinal, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVolatile, removeModifier, setExtendedModifiers, setModifiers, setVisibility
-
Methods inherited from interface spoon.reflect.declaration.CtNamedElement
getSimpleName, setSimpleName
-
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
-
Methods inherited from interface spoon.reflect.code.CtStatement
comment, getLabel, insertAfter, insertAfter, insertBefore, insertBefore, setLabel
-
Methods inherited from interface spoon.reflect.declaration.CtTypedElement
getType, setType
-
Methods inherited from interface spoon.reflect.declaration.CtVariable
getDefaultExpression, isPartOfJointDeclaration, setDefaultExpression
-
Methods inherited from interface spoon.reflect.visitor.CtVisitable
accept
-
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
-
-
-
Method Detail
-
getReference
CtLocalVariableReference<T> getReference()
Description copied from interface:CtNamedElement
Returns the corresponding reference.- Specified by:
getReference
in interfaceCtNamedElement
- Specified by:
getReference
in interfaceCtVariable<T>
-
getAssignment
CtExpression<T> getAssignment()
Useful proxy toCtVariable.getDefaultExpression()
.- Specified by:
getAssignment
in interfaceCtRHSReceiver<T>
-
clone
CtLocalVariable<T> clone()
Description copied from interface:CtElement
Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methodsRefactoring.copyType(CtType)
andRefactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.- Specified by:
clone
in interfaceCtCodeElement
- Specified by:
clone
in interfaceCtElement
- Specified by:
clone
in interfaceCtNamedElement
- Specified by:
clone
in interfaceCtStatement
-
setAssignment
<U extends CtRHSReceiver<T>> U setAssignment(CtExpression<T> assignment)
Description copied from interface:CtRHSReceiver
Sets the right-hand side expression (RHS) of the "=" operator.- Specified by:
setAssignment
in interfaceCtRHSReceiver<T>
-
isInferred
boolean isInferred()
Return true if this variable's type is not explicitely defined in the source code, but was using the `var` keyword of Java 10.
-
setInferred
<U extends CtLocalVariable<T>> U setInferred(boolean inferred)
Set true if the variable must be inferred. Warning: this method should only be used if compliance level is set to 10 or more.
-
-