public class ClassGeneratorHelper extends Object
After construction:
getITraitsVisitor()
and visiting each trait to be added.getCTraitsVisitor()
and visiting each trait to be added.addITraitsMethod(Name, Collection, Name, Collection, boolean, boolean, boolean, InstructionList)
.
After all the trait's and instructions have been added to the class, either
finishClass(InstructionList)
or finishScript()
must be
called.
Constructor and Description |
---|
ClassGeneratorHelper(ICompilerProject project,
IABCVisitor visitor,
Name className,
ClassDefinition baseClass,
Collection<Name> implementedInterfaces,
Collection<Name> constructorParamTypes,
InstructionList constructorInstructions,
boolean hasProtectedMembers)
Generate an ABC class with constructor instructions.
|
ClassGeneratorHelper(ICompilerProject project,
IABCVisitor visitor,
Name className,
ClassDefinition baseClass,
Collection<Name> implementedInterfaces,
Collection<Name> iinitParameterTypes,
InstructionList iinitInstructions,
InstructionList cinitInstructions,
boolean hasProtectedMembers)
Constructor
|
ClassGeneratorHelper(ICompilerProject project,
IABCVisitor visitor,
Name className,
ClassDefinition baseClass,
Collection<Name> implementedInterfaces,
InstructionList constructorInstructions)
|
ClassGeneratorHelper(ICompilerProject project,
IABCVisitor visitor,
Name className,
ClassDefinition baseClass,
InstructionList constructorInstructions)
|
Modifier and Type | Method and Description |
---|---|
void |
addCTraitsGetter(Name getterName,
Name returnType,
InstructionList body)
Utility method to add a static getter to the generated class.
|
void |
addCTraitsMethod(Name methodName,
Collection<Name> parameterTypes,
Name returnType,
Collection<Object> defaultParameterValues,
boolean needsRest,
InstructionList body)
Utility method to add a static method to the generated class.
|
void |
addITraitsGetter(Name getterName,
Name returnType,
InstructionList body)
Utility method to add an instance getter to the generated class.
|
void |
addITraitsMethod(Name methodName,
Collection<Name> parameterTypes,
Name returnType,
Collection<Object> defaultParameterValues,
boolean needsRest,
boolean isFinal,
boolean isOverride,
InstructionList body)
Utility method to add an instance method to the generated class.
|
void |
addITraitsMethod(Name methodName,
Collection<Name> parameterTypes,
Name returnType,
Collection<Object> defaultParameterValues,
boolean needsRest,
boolean isFinal,
boolean isOverride,
InstructionList body,
int functionKindTrait)
Utility method to add an instance method to the generated class.
|
void |
addMemberVariable(Name variableName,
Name type)
Utility method to add a member variable to a class.
|
void |
finishClass(InstructionList scriptInitInstructions)
Generates the instructions to create the class closure and adds them to
the specified
InstructionList . |
void |
finishScript()
Adds a new script to the ABC with a trait for the class closure and an
init with instructions to create the class closure for the generated
class.
|
ITraitsVisitor |
getCTraitsVisitor() |
ITraitsVisitor |
getITraitsVisitor() |
Namespace |
getProtectedNamespace() |
static InstructionList |
returnVoid() |
public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, InstructionList constructorInstructions)
ClassGeneratorHelper(ICompilerProject, IABCVisitor, Name, ClassDefinition, Collection, Collection, InstructionList, boolean)
.project
- A compiler project.visitor
- An ABC visitor.className
- The ABC name of the new class.baseClass
- The definition of the class being extended.public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, Collection<Name> implementedInterfaces, InstructionList constructorInstructions)
ClassGeneratorHelper(ICompilerProject, IABCVisitor, Name, ClassDefinition, Collection, Collection, InstructionList, boolean)
.project
- A compiler project.visitor
- An ABC visitor.className
- The ABC name of the new class.baseClass
- The definition of the class being extended.implementedInterfaces
- The ABC name of the interfaces being implemented.public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, Collection<Name> implementedInterfaces, Collection<Name> constructorParamTypes, InstructionList constructorInstructions, boolean hasProtectedMembers)
public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, Collection<Name> implementedInterfaces, Collection<Name> iinitParameterTypes, InstructionList iinitInstructions, InstructionList cinitInstructions, boolean hasProtectedMembers)
project
- ICompilerProject
project for which ABC is being
generated.visitor
- IABCVisitor
to write the new class into.className
- Name
of the class to generatebaseClass
- ClassDefinition
for the base class the generated
class extends.implementedInterfaces
- Collection of Name
's that at runtime
will refer to interfaces the generated class implement.iinitParameterTypes
- Collection of Name
's that at runtime
will refer to the types of the constructor arguments.iinitInstructions
- Instructions for the constructor.cinitInstructions
- Instructions for the cinit()
method.hasProtectedMembers
- whether or not this class has protected members
There must be one returnvoid
instruction.public static InstructionList returnVoid()
public void finishScript()
After this method is called no other methods on this class should be called.
public void finishClass(InstructionList scriptInitInstructions)
InstructionList
.scriptInitInstructions
- InstructionList
to add the
instructions that create the class closure to.public ITraitsVisitor getITraitsVisitor()
ITraitsVisitor
for the instance trait's of the generated class.public ITraitsVisitor getCTraitsVisitor()
ITraitsVisitor
for the class trait's of the generated class.public void addITraitsMethod(Name methodName, Collection<Name> parameterTypes, Name returnType, Collection<Object> defaultParameterValues, boolean needsRest, boolean isFinal, boolean isOverride, InstructionList body)
methodName
- Name
of the method to add.parameterTypes
- Collection of Name
's of the parameters to
the method.returnType
- Name
of the return type of the method.defaultParameterValues
- Collection of object's that can be
converted to ABC constants for the default values of parameters.needsRest
- true if the method needs the rest parameter, false otherwiseisFinal
- true if the method is final, false otherwiseisOverride
- true if the method is an override of another method, false otherwisebody
- An InstructionList
for the body of the method.public void addITraitsMethod(Name methodName, Collection<Name> parameterTypes, Name returnType, Collection<Object> defaultParameterValues, boolean needsRest, boolean isFinal, boolean isOverride, InstructionList body, int functionKindTrait)
methodName
- Name
of the method to add.parameterTypes
- Collection of Name
's of the parameters to
the method.returnType
- Name
of the return type of the method.defaultParameterValues
- Collection of object's that can be
converted to ABC constants for the default values of parameters.needsRest
- true if the method needs the rest parameter, false otherwiseisFinal
- true if the method is final, false otherwiseisOverride
- true if the method is an override of another method, false otherwisebody
- An InstructionList
for the body of the method.functionKindTrait
- One of ABCConstants, TRAIT_Method, TRAIT_Getter,
TRAIT_Setter.public void addCTraitsMethod(Name methodName, Collection<Name> parameterTypes, Name returnType, Collection<Object> defaultParameterValues, boolean needsRest, InstructionList body)
methodName
- Name
of the method to add.parameterTypes
- Collection of Name
's of the parameters to
the method.returnType
- Name
of the return type of the method.defaultParameterValues
- Collection of object's that can be
converted to ABC constants for the default values of parameters.needsRest
- true if the method needs the rest parameter, false otherwisebody
- An InstructionList
for the body of the method.public void addITraitsGetter(Name getterName, Name returnType, InstructionList body)
getterName
- Name
of the method to add.returnType
- Name
of the return type of the method.body
- An InstructionList
for the body of the method.public void addCTraitsGetter(Name getterName, Name returnType, InstructionList body)
getterName
- Name
of the method to add.returnType
- Name
of the return type of the method.body
- An InstructionList
for the body of the method.public void addMemberVariable(Name variableName, Name type)
variableName
- Name
of the member variable to add.public Namespace getProtectedNamespace()
Copyright © 2016 The Apache Software Foundation. All rights reserved.