io.sarl.lang.pythongenerator.generator
Class PyGenerator
All Superinterfaces:
IRootGenerator, org.eclipse.xtext.generator.IGenerator2
class PyGenerator
extends AbstractExtraLanguageGenerator
The generator from SARL to the Python language.
Maven Group Identifier:
io.sarl.lang
Maven Artifact Identifier:
pythongenerator
Since:
0.6
Property Summary
Modifier and type Property and description
PyExpressionGenerator expressionGenerator
Replies the generator of XExpression.
protected java.lang.String filenameExtension
protected java.lang.String outputConfigurationName
protected java.lang.String preferenceID
Field Summary
Modifier and type Field and description
public static val java.lang.String PYTHON_FILE_HEADER
Header for a Python file.
Constructor Summary
Constructor and description
new
Action Summary
Modifier and type Action and description
protected void _before(SarlCapacityUses,IExtraLanguageGeneratorContext)
Mark the functions of the used capacities in order to have a valid feature call within the code.
protected void _generate(SarlAgent,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlAnnotationType,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlBehavior,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlCapacity,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlClass,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlEnumeration,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlEvent,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlInterface,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlSkill,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlAction,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlAnnotationType,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlBehaviorUnit,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlCapacityUses,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlClass,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlConstructor,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlEnumeration,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlField,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void _generate(SarlInterface,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected PyAppendable createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext)
protected static boolean generateBlockComment(String,PyAppendable)
Generate a Python block comment with the given comment.
protected static boolean generateDocString(String,PyAppendable)
Generate a Python docstring with the given comment.
protected boolean generateEnumerationDeclaration(SarlEnumeration,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given enumeration declaration.
protected void generateExecutable(String,XtendExecutable,boolean,boolean,JvmTypeReference,String,PyAppendable,IExtraLanguageGeneratorContext)
Generate the Python code for an executable statement.
protected void generateFileHeader(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected void generateGuardEvaluators(String,PyAppendable,IExtraLanguageGeneratorContext)
Generate the memorized guard evaluators.
protected void generateImportStatement(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected boolean generatePythonClassDeclaration(String,boolean,List<E>,String,boolean,PyAppendable,IExtraLanguageGeneratorContext)
Generate the type declaration for a Python class.
protected boolean generatePythonConstructors(String,List<E>,PyAppendable,IExtraLanguageGeneratorContext)
Generate the constructors for a Python class.
protected void generatePythonField(SarlField,PyAppendable,IExtraLanguageGeneratorContext)
Create a field declaration.
protected boolean generateTypeDeclaration(String,String,boolean,List<E>,String,boolean,List<E>,PyAppendable,IExtraLanguageGeneratorContext,Procedure2<P1,P2>)
Generate the given type.
PyExpressionGenerator getExpressionGenerator
Replies the generator of XExpression.
protected java.lang.String getFilenameExtension
protected java.lang.String getGenerationComment(IExtraLanguageGeneratorContext)
Replies a string representing a comment with the generation information.
protected java.lang.String getOutputConfigurationName
protected java.lang.String getPreferenceID
protected void initializeContext(IExtraLanguageGeneratorContext)
protected org.eclipse.xtext.common.types.JvmType newType(String)
Create a JvmType for a Python type.
void setExpressionGenerator(PyExpressionGenerator)
Change the generator of XExpression.
void setPyGeneratorConfigurationProvider(IPyGeneratorConfigurationProvider)
Change the provider of the generator's configuration.
protected boolean writeFile(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected void writePackageFiles(QualifiedName,String,IExtraLanguageGeneratorContext)
Generate the Python package files.
Inherited: _generate(SarlScript,IExtraLanguageGeneratorContext), after(EObject,IExtraLanguageGeneratorContext), afterGenerate(Resource,IFileSystemAccess2,IGeneratorContext), before(EObject,IExtraLanguageGeneratorContext), beforeGenerate(Resource,IFileSystemAccess2,IGeneratorContext), canGenerateFor(EObject), createGeneratorContext(IFileSystemAccess2,IGeneratorContext,Resource), doGenerate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext), doGenerate(Resource,IFileSystemAccess2,IGeneratorContext), generate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext), generate(EObject,IExtraLanguageGeneratorContext), generate(XExpression,LightweightTypeReference,ExtraLanguageAppendable,IExtraLanguageGeneratorContext), generateJvmMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext), generateSarlMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext), getActionPrototypeProvider, getAssociatedExpression(JvmMember), getEarlyExitComputer, getExpectedType(XExpression), getExpectedType(XtendExecutable,JvmTypeReference), getFeatureNameConverter(IExtraLanguageGeneratorContext), getInjector, getJvmModelAssociations, getQualifiedNameConverter, getQualifiedNameProvider, getSuperTypes(JvmTypeReference,List<E>), getTypeBuilder, getTypeConverter(IExtraLanguageGeneratorContext), getTypeExtensions, getTypeReferences, getTypeResolver, loadPropertyFile(String,Plugin,Class<T>,Function1<Param,Result>), setActionPrototypeProvider(IActionPrototypeProvider), setCommonTypeComputationServices(CommonTypeComputationServices), setEarlyExitComputer(IEarlyExitComputer), setInjector(Injector), setJvmModelAssociations(SarlJvmModelAssociations), setLogicalContainerProvider(IActionPrototypeProvider), setQualifiedNameConverter(IQualifiedNameConverter), setQualifiedNameProvider(IQualifiedNameProvider), setTypeBuilder(JvmTypesBuilder), setTypeExtensions(JvmTypeExtensions), setTypeReferences(TypeReferences), setTypeResolver(IBatchTypeResolver), toFilename(QualifiedName), toFilename(QualifiedName,String)
Property Details
expressionGenerator
var expressionGenerator : PyExpressionGenerator
Replies the generator of XExpression.

This property is an alias for the action: getExpressionGenerator

Returns:
the generator.
filenameExtension
protected val filenameExtension : java.lang.String

This property is an alias for the action: getFilenameExtension

outputConfigurationName
protected val outputConfigurationName : java.lang.String

This property is an alias for the action: getOutputConfigurationName

preferenceID
protected val preferenceID : java.lang.String

This property is an alias for the action: getPreferenceID

Field Details
PYTHON_FILE_HEADER
public static val PYTHON_FILE_HEADER : java.lang.String = "#!/usr/bin/env python3"
Header for a Python file.
Constructor Details
new
new
Action Details
_before(SarlCapacityUses,IExtraLanguageGeneratorContext)
protected def _before(SarlCapacityUses,IExtraLanguageGeneratorContext)
Mark the functions of the used capacities in order to have a valid feature call within the code.
Parameters:
uses - the capacity uses.
context - the context.
_generate(SarlAgent,IExtraLanguageGeneratorContext)
protected def _generate(SarlAgent,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
agent - the agent.
context - the context.
_generate(SarlAnnotationType,IExtraLanguageGeneratorContext)
protected def _generate(SarlAnnotationType,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
annotation - the annotation.
context - the context.
_generate(SarlBehavior,IExtraLanguageGeneratorContext)
protected def _generate(SarlBehavior,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
behavior - the behavior.
context - the context.
_generate(SarlCapacity,IExtraLanguageGeneratorContext)
protected def _generate(SarlCapacity,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
capacity - the capacity.
context - the context.
_generate(SarlClass,IExtraLanguageGeneratorContext)
protected def _generate(SarlClass,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
clazz - the class.
context - the context.
_generate(SarlEnumeration,IExtraLanguageGeneratorContext)
protected def _generate(SarlEnumeration,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
enumeration - the enumeration.
context - the context.
_generate(SarlEvent,IExtraLanguageGeneratorContext)
protected def _generate(SarlEvent,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
event - the event.
context - the context.
_generate(SarlInterface,IExtraLanguageGeneratorContext)
protected def _generate(SarlInterface,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
interf - the interface.
context - the context.
_generate(SarlSkill,IExtraLanguageGeneratorContext)
protected def _generate(SarlSkill,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
skill - the skill.
context - the context.
_generate(SarlAction,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlAction,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
action - the action.
it - the target for the generated content.
context - the context.
_generate(SarlAnnotationType,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlAnnotationType,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
annotation - the annotation.
it - the target for the generated content.
context - the context.
_generate(SarlBehaviorUnit,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlBehaviorUnit,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
handler - the behavior unit.
it - the target for the generated content.
context - the context.
_generate(SarlCapacityUses,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlCapacityUses,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
uses - the capacity uses.
it - the target for the generated content.
context - the context.
See:
computeCapacityFunctionMarkers(JvmDeclaredType) , markCapacityFunctions(PyAppendable) , _before(SarlCapacityUses,IExtraLanguageGeneratorContext) , createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext)
_generate(SarlClass,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlClass,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
clazz - the class.
it - the target for the generated content.
context - the context.
_generate(SarlConstructor,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlConstructor,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
constructor - the constructor.
it - the target for the generated content.
context - the context.
_generate(SarlEnumeration,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlEnumeration,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
enumeration - the enumeration.
it - the target for the generated content.
context - the context.
_generate(SarlField,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlField,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
field - the fields.
it - the target for the generated content.
context - the context.
_generate(SarlInterface,PyAppendable,IExtraLanguageGeneratorContext)
protected def _generate(SarlInterface,PyAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
interf - the interface.
it - the target for the generated content.
context - the context.
createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext)
protected def createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext) : PyAppendable
generateBlockComment(String,PyAppendable)
protected def generateBlockComment(String,PyAppendable) : boolean
Generate a Python block comment with the given comment.
Parameters:
comment - the comment.
it - the receiver of the block comment.
Returns:
true if the block comment is added, false otherwise.
generateDocString(String,PyAppendable)
protected def generateDocString(String,PyAppendable) : boolean
Generate a Python docstring with the given comment.
Parameters:
comment - the comment.
it - the receiver of the docstring.
Returns:
true if the docstring is added, false otherwise.
generateEnumerationDeclaration(SarlEnumeration,PyAppendable,IExtraLanguageGeneratorContext)
protected def generateEnumerationDeclaration(SarlEnumeration,PyAppendable,IExtraLanguageGeneratorContext) : boolean
Generate the given enumeration declaration.
Parameters:
enumeration - the enumeration.
it - the receiver of the generated code.
context - the context.
Returns:
true if a declaration was generated. false if no enumeration was generated.
Since:
0.8
generateExecutable(String,XtendExecutable,boolean,boolean,JvmTypeReference,String,PyAppendable,IExtraLanguageGeneratorContext)
protected def generateExecutable(String,XtendExecutable,boolean,boolean,JvmTypeReference,String,PyAppendable,IExtraLanguageGeneratorContext)
Generate the Python code for an executable statement.
Parameters:
name - the name of the executable.
executable - the executable statement.
appendSelf - indicates if the "self" parameter should be added.
isAbstract - indicates if the executable is abstract.
returnType - the type of the value to be returned, or null if void.
comment - the comment associated to the function.
it - the target for the generated content.
context - the context.
generateFileHeader(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generateFileHeader(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
generateGuardEvaluators(String,PyAppendable,IExtraLanguageGeneratorContext)
protected def generateGuardEvaluators(String,PyAppendable,IExtraLanguageGeneratorContext)
Generate the memorized guard evaluators.
Parameters:
container - the fully qualified name of the container of the guards.
it - the output.
context - the generation context.
generateImportStatement(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generateImportStatement(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
generatePythonClassDeclaration(String,boolean,List<E>,String,boolean,PyAppendable,IExtraLanguageGeneratorContext)
protected def generatePythonClassDeclaration(String,boolean,List<E>,String,boolean,PyAppendable,IExtraLanguageGeneratorContext) : boolean
Generate the type declaration for a Python class.
Parameters:
typeName - name of the type.
isAbstract - indicates if the type is abstract (interface included).
superTypes - the super types.
comment - the type declaration's comment.
ignoreObjectType - ignores the "Object" type if the super types.
it - the output.
context - the generation context.
Returns:
true if the declaration was generated. false if the declaration was not generated.
generatePythonConstructors(String,List<E>,PyAppendable,IExtraLanguageGeneratorContext)
protected def generatePythonConstructors(String,List<E>,PyAppendable,IExtraLanguageGeneratorContext) : boolean
Generate the constructors for a Python class.
Parameters:
container - the fully qualified name of the container.
members - the members to be added.
it - the output.
context - the generation context.
Returns:
true if a constructor was generated. false if no constructor was generated.
generatePythonField(SarlField,PyAppendable,IExtraLanguageGeneratorContext)
protected def generatePythonField(SarlField,PyAppendable,IExtraLanguageGeneratorContext)
Create a field declaration.
Parameters:
field - the field to generate.
it - the output
context - the generation context.
generateTypeDeclaration(String,String,boolean,List<E>,String,boolean,List<E>,PyAppendable,IExtraLanguageGeneratorContext,Procedure2<P1,P2>)
protected def generateTypeDeclaration(String,String,boolean,List<E>,String,boolean,List<E>,PyAppendable,IExtraLanguageGeneratorContext,Procedure2<P1,P2>) : boolean
Generate the given type.
Parameters:
fullyQualifiedName - the fully qualified name of the type.
name - the name of the type.
isAbstract - indicates if the type is abstract.
superTypes - the super types.
comment - the comment.
ignoreObjectType - ignores the "Object" type if the super types.
members - the members.
it - the output.
context - the context.
memberGenerator - the generator of members.
Returns:
true if the type declaration was generated.
getExpressionGenerator
def getExpressionGenerator : PyExpressionGenerator
Replies the generator of XExpression.
Returns:
the generator.
getFilenameExtension
protected def getFilenameExtension : java.lang.String
getGenerationComment(IExtraLanguageGeneratorContext)
protected def getGenerationComment(IExtraLanguageGeneratorContext) : java.lang.String
Replies a string representing a comment with the generation information.
Parameters:
context - the generation context.
Returns:
the comment text.
getOutputConfigurationName
protected def getOutputConfigurationName : java.lang.String
getPreferenceID
protected def getPreferenceID : java.lang.String
initializeContext(IExtraLanguageGeneratorContext)
protected def initializeContext(IExtraLanguageGeneratorContext)
newType(String)
protected def newType(String) : org.eclipse.xtext.common.types.JvmType
Create a JvmType for a Python type.
Parameters:
pythonName - the python type name.
Returns:
the type.
setExpressionGenerator(PyExpressionGenerator)
def setExpressionGenerator(PyExpressionGenerator)
Change the generator of XExpression.
Parameters:
generator - the generator.
setPyGeneratorConfigurationProvider(IPyGeneratorConfigurationProvider)
def setPyGeneratorConfigurationProvider(IPyGeneratorConfigurationProvider)
Change the provider of the generator's configuration.
Parameters:
provider - the provider.
writeFile(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def writeFile(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext) : boolean
writePackageFiles(QualifiedName,String,IExtraLanguageGeneratorContext)
protected def writePackageFiles(QualifiedName,String,IExtraLanguageGeneratorContext)
Generate the Python package files.

This function generates the "__init__.py" files for all the packages.
Parameters:
name - the name of the generated type.
lineSeparator - the line separator.
context - the generation context.