public class CodeFactory extends SubFactory
Template
.factory
Constructor and Description |
---|
CodeFactory(Factory factory)
Creates a
CtCodeElement sub-factory. |
Modifier and Type | Method and Description |
---|---|
<A extends java.lang.annotation.Annotation> |
createAnnotation(CtTypeReference<A> annotationType)
Creates an annotation.
|
<T> CtBinaryOperator<T> |
createBinaryOperator(CtExpression<?> left,
CtExpression<?> right,
BinaryOperatorKind kind)
Creates a binary operator.
|
<T> CtCatchVariable<T> |
createCatchVariable(CtTypeReference<T> type,
java.lang.String name,
ModifierKind... modifierKinds)
Creates a catch variable declaration.
|
<T> CtCatchVariableReference<T> |
createCatchVariableReference(CtCatchVariable<T> catchVariable)
Creates a catch variable reference that points to an existing catch
variable (strong referencing).
|
<T> CtFieldAccess<java.lang.Class<T>> |
createClassAccess(CtTypeReference<T> type)
Creates a class access expression of the form
C.class . |
<T> CtCodeSnippetExpression<T> |
createCodeSnippetExpression(java.lang.String expression)
Creates a Code Snippet expression.
|
CtCodeSnippetStatement |
createCodeSnippetStatement(java.lang.String statement)
Creates a Code Snippet statement.
|
CtComment |
createComment(java.lang.String content,
CtComment.CommentType type)
Creates a comment
|
<T> CtConstructorCall<T> |
createConstructorCall(CtTypeReference<T> type,
CtExpression<?>... parameters)
Creates a constructor call.
|
<T extends CtStatement> |
createCtBlock(T element)
Creates a block.
|
CtCatch |
createCtCatch(java.lang.String nameCatch,
java.lang.Class<? extends java.lang.Throwable> exception,
CtBlock<?> ctBlock)
Creates a catch element.
|
<T> CtField<T> |
createCtField(java.lang.String name,
CtTypeReference<T> type,
java.lang.String exp,
ModifierKind... visibilities)
Creates a field.
|
CtPackageReference |
createCtPackageReference(java.lang.Package originalPackage)
Creates a package reference.
|
CtThrow |
createCtThrow(java.lang.String thrownExp)
Creates a throw.
|
<T> CtTypeReference<T> |
createCtTypeReference(java.lang.Class<?> originalClass)
Creates a type reference.
|
CtComment |
createInlineComment(java.lang.String content)
Creates an inline comment
|
<T> CtInvocation<T> |
createInvocation(CtExpression<?> target,
CtExecutableReference<T> executable,
CtExpression<?>... arguments)
Creates an invocation (can be a statement or an expression).
|
<T> CtInvocation<T> |
createInvocation(CtExpression<?> target,
CtExecutableReference<T> executable,
java.util.List<CtExpression<?>> arguments)
Creates an invocation (can be a statement or an expression).
|
CtJavaDocTag |
createJavaDocTag(java.lang.String content,
CtJavaDocTag.TagType type)
Creates a javadoc tag
|
CtJavaDocTag |
createJavaDocTag(java.lang.String content,
CtJavaDocTag.TagType type,
java.lang.String realName)
Creates a javadoc tag
|
<T> CtLiteral<T> |
createLiteral(T value)
Creates a literal with a given value.
|
<T> CtNewArray<T[]> |
createLiteralArray(T[] value)
Creates a one-dimension array that must only contain literals.
|
<T> CtLocalVariable<T> |
createLocalVariable(CtTypeReference<T> type,
java.lang.String name,
CtExpression<T> defaultExpression)
Creates a local variable declaration.
|
<T> CtLocalVariableReference<T> |
createLocalVariableReference(CtLocalVariable<T> localVariable)
Creates a local variable reference that points to an existing local
variable (strong referencing).
|
<T> CtLocalVariableReference<T> |
createLocalVariableReference(CtTypeReference<T> type,
java.lang.String name)
Creates a local variable reference with its name an type (weak
referencing).
|
<T> CtNewClass<T> |
createNewClass(CtType<T> superClass,
CtExpression<?>... parameters)
Creates a new anonymous class.
|
<R> CtStatementList |
createStatementList(CtBlock<R> block)
Creates a new statement list from an existing block.
|
CtTextBlock |
createTextBlock(java.lang.String value)
Creates a TextBlock with the given string value.
|
<T> CtThisAccess<T> |
createThisAccess(CtTypeReference<T> type)
Creates an explicit access to a
this variable (of the form
type.this ). |
<T> CtThisAccess<T> |
createThisAccess(CtTypeReference<T> type,
boolean isImplicit)
Creates an access to a
this variable (of the form
type.this ). |
<T> CtTypeAccess<T> |
createTypeAccess(CtTypeReference<T> accessedType)
Creates a accessed type.
|
<T> CtTypeAccess<T> |
createTypeAccess(CtTypeReference<T> accessedType,
boolean isImplicit)
Creates a accessed type.
|
<T> CtTypeAccess<T> |
createTypeAccessWithoutCloningReference(CtTypeReference<T> accessedType)
Creates a accessed type, see
createTypeAccess(CtTypeReference) for details. |
<A,T extends A> |
createVariableAssignment(CtVariableReference<A> variable,
boolean isStatic,
CtExpression<T> expression)
Creates a variable assignment (can be an expression or a statement).
|
<T> CtStatementList |
createVariableAssignments(java.util.List<? extends CtVariable<T>> variables,
java.util.List<? extends CtExpression<T>> expressions)
Creates a list of statements that contains the assignments of a set of
variables.
|
<T> CtVariableAccess<T> |
createVariableRead(CtVariableReference<T> variable,
boolean isStatic)
Creates a variable access for read.
|
java.util.List<CtExpression<?>> |
createVariableReads(java.util.List<? extends CtVariable<?>> variables)
Creates a list of variable accesses for read.
|
<T> CtVariableAccess<T> |
createVariableWrite(CtVariableReference<T> variable,
boolean isStatic)
Creates a variable access for write.
|
<T extends CtStatement> |
getOrCreateCtBlock(T element)
Accepts instance of CtStatement or CtBlock.
|
<R extends CtReference,E extends CtNamedElement> |
getReferences(java.util.List<E> elements)
Gets a list of references from a list of elements.
|
java.util.Set<ModifierKind> |
modifiers(ModifierKind... modifiers)
Creates a modifier set.
|
public CodeFactory(Factory factory)
CtCodeElement
sub-factory.public <T> CtBinaryOperator<T> createBinaryOperator(CtExpression<?> left, CtExpression<?> right, BinaryOperatorKind kind)
T
- the type of the expressionleft
- the left operandright
- the right operandkind
- the operator kindpublic <T> CtTypeAccess<T> createTypeAccess(CtTypeReference<T> accessedType)
This method sets a clone of the given accessedType
object to the
accessedType field of the returned CtTypeAccess
. If the
given accessedType
is unique and cloning is not needed, use
createTypeAccessWithoutCloningReference(CtTypeReference)
instead of this method.
T
- the type of the expression.accessedType
- a type reference to the accessed type.public <T> CtTypeAccess<T> createTypeAccess(CtTypeReference<T> accessedType, boolean isImplicit)
This method sets a clone of the given accessedType
object to the
accessedType field of the returned CtTypeAccess
. If the
given accessedType
is unique and cloning is not needed, use
createTypeAccessWithoutCloningReference(CtTypeReference)
instead of this method.
T
- the type of the expression.accessedType
- a type reference to the accessed type.isImplicit
- type of the type access is implicit or not.public <T> CtTypeAccess<T> createTypeAccessWithoutCloningReference(CtTypeReference<T> accessedType)
createTypeAccess(CtTypeReference)
for details.T
- the type of the expression.accessedType
- a type reference to the accessed type.public <T> CtFieldAccess<java.lang.Class<T>> createClassAccess(CtTypeReference<T> type)
C.class
.T
- the actual type of the accessed class if availabletype
- a type reference to the accessed classpublic <T> CtConstructorCall<T> createConstructorCall(CtTypeReference<T> type, CtExpression<?>... parameters)
T
- the actual type of the decelerating type of the constructor if availabletype
- the decelerating type of the constructorparameters
- the arguments of the constructor callpublic <T> CtNewClass<T> createNewClass(CtType<T> superClass, CtExpression<?>... parameters)
public <T> CtInvocation<T> createInvocation(CtExpression<?> target, CtExecutableReference<T> executable, CtExpression<?>... arguments)
T
- the return type of the invoked methodtarget
- the target expressionexecutable
- the invoked executablearguments
- the argument listpublic <T> CtInvocation<T> createInvocation(CtExpression<?> target, CtExecutableReference<T> executable, java.util.List<CtExpression<?>> arguments)
T
- the return type of the invoked methodtarget
- the target expression (may be null for static methods)executable
- the invoked executablearguments
- the argument listpublic <T> CtLiteral<T> createLiteral(T value)
T
- the type of the literalvalue
- the value of the literalpublic CtTextBlock createTextBlock(java.lang.String value)
value
- the string value of the literalpublic <T> CtNewArray<T[]> createLiteralArray(T[] value)
public <T> CtLocalVariable<T> createLocalVariable(CtTypeReference<T> type, java.lang.String name, CtExpression<T> defaultExpression)
T
- the local variable typetype
- the reference to the typename
- the name of the variabledefaultExpression
- the assigned default expressionpublic <T> CtLocalVariableReference<T> createLocalVariableReference(CtLocalVariable<T> localVariable)
public <T> CtLocalVariableReference<T> createLocalVariableReference(CtTypeReference<T> type, java.lang.String name)
public <T> CtCatchVariable<T> createCatchVariable(CtTypeReference<T> type, java.lang.String name, ModifierKind... modifierKinds)
T
- the catch variable typetype
- the reference to the typename
- the name of the variablemodifierKinds
- Modifiers of the catch variablepublic <T> CtCatchVariableReference<T> createCatchVariableReference(CtCatchVariable<T> catchVariable)
public <R> CtStatementList createStatementList(CtBlock<R> block)
public <T> CtThisAccess<T> createThisAccess(CtTypeReference<T> type)
this
variable (of the form
type.this
).T
- the actual type of this
type
- the reference to the type that holds the this
variabletype.this
expressionpublic <T> CtThisAccess<T> createThisAccess(CtTypeReference<T> type, boolean isImplicit)
this
variable (of the form
type.this
).T
- the actual type of this
type
- the reference to the type that holds the this
variableisImplicit
- type of the this access is implicit or not.type.this
expressionpublic <T> CtVariableAccess<T> createVariableRead(CtVariableReference<T> variable, boolean isStatic)
public java.util.List<CtExpression<?>> createVariableReads(java.util.List<? extends CtVariable<?>> variables)
variables
- the variables to be accessedpublic <T> CtVariableAccess<T> createVariableWrite(CtVariableReference<T> variable, boolean isStatic)
public <A,T extends A> CtAssignment<A,T> createVariableAssignment(CtVariableReference<A> variable, boolean isStatic, CtExpression<T> expression)
T
- the type of the assigned variablevariable
- a reference to the assigned variableisStatic
- tells if the assigned variable is static or notexpression
- the assigned expressionpublic <T> CtStatementList createVariableAssignments(java.util.List<? extends CtVariable<T>> variables, java.util.List<? extends CtExpression<T>> expressions)
variables
- the variables to be assignedexpressions
- the assigned expressionspublic <T> CtField<T> createCtField(java.lang.String name, CtTypeReference<T> type, java.lang.String exp, ModifierKind... visibilities)
T
- Generic type for the type of the field.name
- Name of the field.type
- Type of the field.exp
- Default expression of the field.visibilities
- All visibilities of the field.public <T extends CtStatement> CtBlock<?> createCtBlock(T element)
T
- Subclasses of CtStatement.element
- Statement of the block.public <T extends CtStatement> CtBlock<?> getOrCreateCtBlock(T element)
element
- public CtThrow createCtThrow(java.lang.String thrownExp)
thrownExp
- Expression of the throw.public CtCatch createCtCatch(java.lang.String nameCatch, java.lang.Class<? extends java.lang.Throwable> exception, CtBlock<?> ctBlock)
nameCatch
- Name of the variable in the catch.exception
- Type of the exception.ctBlock
- Content of the catch.public <T> CtTypeReference<T> createCtTypeReference(java.lang.Class<?> originalClass)
T
- Type of the reference.originalClass
- Original class of the reference.public CtPackageReference createCtPackageReference(java.lang.Package originalPackage)
originalPackage
- Original package of the reference.public <A extends java.lang.annotation.Annotation> CtAnnotation<A> createAnnotation(CtTypeReference<A> annotationType)
annotationType
- Type of the annotation.public <R extends CtReference,E extends CtNamedElement> java.util.List<R> getReferences(java.util.List<E> elements)
R
- the expected reference typeE
- the element typeelements
- the element listpublic java.util.Set<ModifierKind> modifiers(ModifierKind... modifiers)
modifiers
- to put in setpublic <T> CtCodeSnippetExpression<T> createCodeSnippetExpression(java.lang.String expression)
T
- The type of the expression represented by the CodeSnippetexpression
- The string that contains the expression.public CtCodeSnippetStatement createCodeSnippetStatement(java.lang.String statement)
statement
- The String containing the statement.public CtComment createComment(java.lang.String content, CtComment.CommentType type)
content
- The content of the commenttype
- The comment typepublic CtComment createInlineComment(java.lang.String content)
content
- The content of the commentpublic CtJavaDocTag createJavaDocTag(java.lang.String content, CtJavaDocTag.TagType type)
content
- The content of the javadoc tag with a possible paramatertype
- The tag typepublic CtJavaDocTag createJavaDocTag(java.lang.String content, CtJavaDocTag.TagType type, java.lang.String realName)
content
- The content of the javadoc tag with a possible paramatertype
- The tag typerealName
- The real name of the tagCopyright © 2007–2021 Inria. All rights reserved.