io.sarl.lang.extralanguage.compiler
Class AbstractExtraLanguageGenerator
All Superinterfaces:
IRootGenerator, org.eclipse.xtext.generator.IGenerator2
All Known Subclasses:
PyGenerator
abstract class AbstractExtraLanguageGenerator
extends java.lang.Object
implements IRootGenerator
Abstract implementation for the generator from SARL to an extra language.
Maven Group Identifier:
io.sarl.lang
Maven Artifact Identifier:
compiler
Since:
0.6
Property Summary
Modifier and type Property and description
IActionPrototypeProvider actionPrototypeProvider
Replies the provider of action prototype.
org.eclipse.xtext.xbase.controlflow.IEarlyExitComputer earlyExitComputer
Replies the early exit computer.
IExpressionGenerator expressionGenerator
Replies the generator dedicated to the expressions.
protected java.lang.String filenameExtension
Replies the filename extension.
protected com.google.inject.Injector injector
Replies the injector.
SarlJvmModelAssociations jvmModelAssociations
Replies the associations between the SARL elements and the JVM elements.
protected java.lang.String outputConfigurationName
Replies the name of the output configuration to be used.
protected java.lang.String preferenceID
Replies the identifier of the container of the generator's preferences.
org.eclipse.xtext.naming.IQualifiedNameConverter qualifiedNameConverter
Replies the converter of qualified name.
org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider
Replies the provider of qualified name.
org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder typeBuilder
Replies the type builder.
org.eclipse.xtext.xbase.jvmmodel.JvmTypeExtensions typeExtensions
Replies the type extension provider.
org.eclipse.xtext.common.types.util.TypeReferences typeReferences
Replies the type reference finder.
org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver typeResolver
Replies the type resolver for expressions.
Constructor Summary
Constructor and description
new
Construct the generator.
Action Summary
Modifier and type Action and description
protected void _generate(SarlScript,IExtraLanguageGeneratorContext)
Generate the given script.
protected void after(EObject,IExtraLanguageGeneratorContext)
Do something after the generation of the given object.
void afterGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
protected void before(EObject,IExtraLanguageGeneratorContext)
Do something before the generation of the given object.
void beforeGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
protected boolean canGenerateFor(EObject)
Replies if this generator can generate resources from the given element.
protected abstract ExtraLanguageAppendable createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext)
Create the appendable object.
protected IExtraLanguageGeneratorContext createGeneratorContext(IFileSystemAccess2,IGeneratorContext,Resource)
Create the generator context for this generator.
void doGenerate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
void doGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
protected void generate(EObject,IExtraLanguageGeneratorContext)
Generate the given object.
protected void generate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void generate(XExpression,LightweightTypeReference,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
protected void generateFileHeader(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the header of the file..
protected void generateImportStatement(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the import for the given name.
protected boolean generateJvmMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the members (except constructors) for a Python class.
protected boolean generateSarlMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the members (except constructors) for a Python class.
IActionPrototypeProvider getActionPrototypeProvider
Replies the provider of action prototype.
protected org.eclipse.xtext.xbase.XExpression getAssociatedExpression(JvmMember)
Replies the expression associated to the given object.
org.eclipse.xtext.xbase.controlflow.IEarlyExitComputer getEarlyExitComputer
Replies the early exit computer.
protected org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference getExpectedType(XExpression)
Compute the expected type of the given expression.
protected org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference getExpectedType(XtendExecutable,JvmTypeReference)
Replies the expected type of the given executable.
abstract IExpressionGenerator getExpressionGenerator
Replies the generator dedicated to the expressions.
ExtraLanguageFeatureNameConverter getFeatureNameConverter(IExtraLanguageGeneratorContext)
Replies the converter of feature names.
protected abstract java.lang.String getFilenameExtension
Replies the filename extension.
protected com.google.inject.Injector getInjector
Replies the injector.
SarlJvmModelAssociations getJvmModelAssociations
Replies the associations between the SARL elements and the JVM elements.
protected abstract java.lang.String getOutputConfigurationName
Replies the name of the output configuration to be used.
protected abstract java.lang.String getPreferenceID
Replies the identifier of the container of the generator's preferences.
org.eclipse.xtext.naming.IQualifiedNameConverter getQualifiedNameConverter
Replies the converter of qualified name.
org.eclipse.xtext.naming.IQualifiedNameProvider getQualifiedNameProvider
Replies the provider of qualified name.
protected static java.util.List<E> getSuperTypes(JvmTypeReference,List<E>)
Replies the merged list with the extended and implemented types.
org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder getTypeBuilder
Replies the type builder.
ExtraLanguageTypeConverter getTypeConverter(IExtraLanguageGeneratorContext)
Replies the type converter.
org.eclipse.xtext.xbase.jvmmodel.JvmTypeExtensions getTypeExtensions
Replies the type extension provider.
org.eclipse.xtext.common.types.util.TypeReferences getTypeReferences
Replies the type reference finder.
org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver getTypeResolver
Replies the type resolver for expressions.
protected void initializeContext(IExtraLanguageGeneratorContext)
Initialize the given context.
static java.util.List<E> loadPropertyFile(String,Plugin,Class<T>,Function1<Param,Result>)
Load a property file from the resources.
void setActionPrototypeProvider(IActionPrototypeProvider)
Change the provider of action prototype.
void setCommonTypeComputationServices(CommonTypeComputationServices)
Change the common type service.
void setEarlyExitComputer(IEarlyExitComputer)
Change the early exit computer.
void setInjector(Injector)
Change the injector.
void setJvmModelAssociations(SarlJvmModelAssociations)
Change the associations between the SARL elements and the JVM elements.
void setLogicalContainerProvider(IActionPrototypeProvider)
Change the provider of action prototype.
void setQualifiedNameConverter(IQualifiedNameConverter)
Change the converter of qualified name.
void setQualifiedNameProvider(IQualifiedNameProvider)
Change the provider of qualified name.
void setTypeBuilder(JvmTypesBuilder)
Change the type builder.
void setTypeExtensions(JvmTypeExtensions)
Change the type extension provider.
void setTypeReferences(TypeReferences)
Change the type reference finder.
void setTypeResolver(IBatchTypeResolver)
Change the type resolver for expressions.
protected java.lang.String toFilename(QualifiedName)
Replies the filename for the qualified name.
protected java.lang.String toFilename(QualifiedName,String)
Replies the filename for the qualified name.
protected boolean writeFile(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Write the given file.
Property Details
actionPrototypeProvider
var actionPrototypeProvider : IActionPrototypeProvider
Replies the provider of action prototype.

This property is an alias for the action: getActionPrototypeProvider

Returns:
the action prototype provider.
earlyExitComputer
var earlyExitComputer : org.eclipse.xtext.xbase.controlflow.IEarlyExitComputer
Replies the early exit computer.

This property is an alias for the action: getEarlyExitComputer

Returns:
the early exit computer.
expressionGenerator
val expressionGenerator : IExpressionGenerator
Replies the generator dedicated to the expressions.

This property is an alias for the action: getExpressionGenerator

Returns:
the generator for expressions.
filenameExtension
protected val filenameExtension : java.lang.String
Replies the filename extension.

This property is an alias for the action: getFilenameExtension

Returns:
the extension.
injector
protected var injector : com.google.inject.Injector
Replies the injector.

This property is an alias for the action: getInjector

Returns:
the injector.
jvmModelAssociations
var jvmModelAssociations : SarlJvmModelAssociations
Replies the associations between the SARL elements and the JVM elements.

This property is an alias for the action: getJvmModelAssociations

Returns:
the associations.
outputConfigurationName
protected val outputConfigurationName : java.lang.String
Replies the name of the output configuration to be used.

This property is an alias for the action: getOutputConfigurationName

Returns:
the name of the output configuration.
preferenceID
protected val preferenceID : java.lang.String
Replies the identifier of the container of the generator's preferences.

This property is an alias for the action: getPreferenceID

Returns:
the identifier.
qualifiedNameConverter
var qualifiedNameConverter : org.eclipse.xtext.naming.IQualifiedNameConverter
Replies the converter of qualified name.

This property is an alias for the action: getQualifiedNameConverter

Returns:
the converer.
qualifiedNameProvider
var qualifiedNameProvider : org.eclipse.xtext.naming.IQualifiedNameProvider
Replies the provider of qualified name.

This property is an alias for the action: getQualifiedNameProvider

Returns:
the provider.
typeBuilder
var typeBuilder : org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
Replies the type builder.

This property is an alias for the action: getTypeBuilder

Returns:
the builder.
typeExtensions
var typeExtensions : org.eclipse.xtext.xbase.jvmmodel.JvmTypeExtensions
Replies the type extension provider.

This property is an alias for the action: getTypeExtensions

Returns:
the type extension provider.
typeReferences
var typeReferences : org.eclipse.xtext.common.types.util.TypeReferences
Replies the type reference finder.

This property is an alias for the action: getTypeReferences

Returns:
the type reference finder.
typeResolver
var typeResolver : org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver
Replies the type resolver for expressions.

This property is an alias for the action: getTypeResolver

Returns:
the batch type resolver.
Constructor Details
new
new
Construct the generator.
Action Details
_generate(SarlScript,IExtraLanguageGeneratorContext)
protected def _generate(SarlScript,IExtraLanguageGeneratorContext)
Generate the given script.
Parameters:
script - the script.
context - the context.
after(EObject,IExtraLanguageGeneratorContext)
protected def after(EObject,IExtraLanguageGeneratorContext)
Do something after the generation of the given object.
Parameters:
object - the object.
context - the context.
afterGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
def afterGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
before(EObject,IExtraLanguageGeneratorContext)
protected def before(EObject,IExtraLanguageGeneratorContext)
Do something before the generation of the given object.
Parameters:
object - the object.
context - the context.
beforeGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
def beforeGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
canGenerateFor(EObject)
protected def canGenerateFor(EObject) : boolean
Replies if this generator can generate resources from the given element.
Parameters:
object - the object for which the generation was queried.
Returns:
true for generating the resources, false for ignoring the object.
createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext)
protected def createAppendable(JvmDeclaredType,IExtraLanguageGeneratorContext) : ExtraLanguageAppendable
Create the appendable object.
Parameters:
thisType - the current type for which the appendable should be created. If it is null, the import manager of the appendable is not associated to a "this" type.
context - the generation context.
Returns:
the appendable object.
createGeneratorContext(IFileSystemAccess2,IGeneratorContext,Resource)
protected def createGeneratorContext(IFileSystemAccess2,IGeneratorContext,Resource) : IExtraLanguageGeneratorContext
Create the generator context for this generator.
Parameters:
fsa - the file system access.
context - the global context.
resource - the resource.
Returns:
the context.
doGenerate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
def doGenerate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the given object.

This function calls the before(EObject, IExtraLanguageGeneratorContext), generate(EObject, ExtraLanguageAppendable, IExtraLanguageGeneratorContext), and after(EObject, IExtraLanguageGeneratorContext) functions.
Parameters:
object - the object.
appendable - the target for the generated content.
context - the context.
doGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
def doGenerate(Resource,IFileSystemAccess2,IGeneratorContext)
generate(EObject,IExtraLanguageGeneratorContext)
protected def generate(EObject,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
object - the object.
context - the context.
generate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generate(EObject,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
object - the object.
appendable - the target for the generated content.
context - the context.
generate(XExpression,LightweightTypeReference,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generate(XExpression,LightweightTypeReference,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the given object.
Parameters:
expression - the expression to be generated.
needReturn - the type of the expression in the context of a returned expression from a function.
appendable - the target for the generated content.
context - the context.
generateFileHeader(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generateFileHeader(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the header of the file..
Parameters:
qualifiedName - the name of the type for which the file was created.
appendable - the appendable.
context - the context.
generateImportStatement(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generateImportStatement(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
Generate the import for the given name.
Parameters:
importedQualifiedName - the imported name.
appendable - the appendable.
context - the context.
generateJvmMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generateJvmMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext) : boolean
Generate the members (except constructors) for a Python class.
Parameters:
members - the members to be added.
it - the output.
context - the generation context.
Returns:
true if a member was generated. false if no member was generated.
generateSarlMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def generateSarlMembers(List<E>,ExtraLanguageAppendable,IExtraLanguageGeneratorContext) : boolean
Generate the members (except constructors) for a Python class.
Parameters:
members - the members to be added.
it - the output.
context - the generation context.
Returns:
true if a member was generated. false if no member was generated.
getActionPrototypeProvider
def getActionPrototypeProvider : IActionPrototypeProvider
Replies the provider of action prototype.
Returns:
the action prototype provider.
getAssociatedExpression(JvmMember)
protected def getAssociatedExpression(JvmMember) : org.eclipse.xtext.xbase.XExpression
Replies the expression associated to the given object. Usually, the expression is inside the given object.
Parameters:
object - the object.
Returns:
the expression, or null if none.
getEarlyExitComputer
def getEarlyExitComputer : org.eclipse.xtext.xbase.controlflow.IEarlyExitComputer
Replies the early exit computer.
Returns:
the early exit computer.
getExpectedType(XExpression)
protected def getExpectedType(XExpression) : org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
Compute the expected type of the given expression.
Parameters:
expr - the expression.
Returns:
the expected type of the argument.
getExpectedType(XtendExecutable,JvmTypeReference)
protected def getExpectedType(XtendExecutable,JvmTypeReference) : org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
Replies the expected type of the given executable.
Parameters:
executable - the executable.
declaredReturnType - the declared return type, if one.
Returns:
the expected type or null if none ( void ).
getExpressionGenerator
def getExpressionGenerator : IExpressionGenerator
Replies the generator dedicated to the expressions.
Returns:
the generator for expressions.
getFeatureNameConverter(IExtraLanguageGeneratorContext)
def getFeatureNameConverter(IExtraLanguageGeneratorContext) : ExtraLanguageFeatureNameConverter
Replies the converter of feature names.
Parameters:
context - the context of the generation.
Returns:
the converter.
getFilenameExtension
protected def getFilenameExtension : java.lang.String
Replies the filename extension.
Returns:
the extension.
getInjector
protected def getInjector : com.google.inject.Injector
Replies the injector.
Returns:
the injector.
getJvmModelAssociations
def getJvmModelAssociations : SarlJvmModelAssociations
Replies the associations between the SARL elements and the JVM elements.
Returns:
the associations.
getOutputConfigurationName
protected def getOutputConfigurationName : java.lang.String
Replies the name of the output configuration to be used.
Returns:
the name of the output configuration.
getPreferenceID
protected def getPreferenceID : java.lang.String
Replies the identifier of the container of the generator's preferences.
Returns:
the identifier.
getQualifiedNameConverter
def getQualifiedNameConverter : org.eclipse.xtext.naming.IQualifiedNameConverter
Replies the converter of qualified name.
Returns:
the converer.
getQualifiedNameProvider
def getQualifiedNameProvider : org.eclipse.xtext.naming.IQualifiedNameProvider
Replies the provider of qualified name.
Returns:
the provider.
getSuperTypes(JvmTypeReference,List<E>)
protected def getSuperTypes(JvmTypeReference,List<E>) : java.util.List<E>
Replies the merged list with the extended and implemented types.
Parameters:
extension - the extended type.
implemented - the implemented types.
Returns:
the super types.
getTypeBuilder
def getTypeBuilder : org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
Replies the type builder.
Returns:
the builder.
getTypeConverter(IExtraLanguageGeneratorContext)
def getTypeConverter(IExtraLanguageGeneratorContext) : ExtraLanguageTypeConverter
Replies the type converter.
Parameters:
context - the context of the generation.
Returns:
the converter.
getTypeExtensions
def getTypeExtensions : org.eclipse.xtext.xbase.jvmmodel.JvmTypeExtensions
Replies the type extension provider.
Returns:
the type extension provider.
getTypeReferences
def getTypeReferences : org.eclipse.xtext.common.types.util.TypeReferences
Replies the type reference finder.
Returns:
the type reference finder.
getTypeResolver
def getTypeResolver : org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver
Replies the type resolver for expressions.
Returns:
the batch type resolver.
initializeContext(IExtraLanguageGeneratorContext)
protected def initializeContext(IExtraLanguageGeneratorContext)
Initialize the given context. This function in invoked when the generator is called with a resource and before the generation on the resource's content is started.
Parameters:
generatorContext - the context to initialize.
Since:
0.8
loadPropertyFile(String,Plugin,Class<T>,Function1<Param,Result>)
def loadPropertyFile(String,Plugin,Class<T>,Function1<Param,Result>) : java.util.List<E>
Load a property file from the resources. This function is able to get the resource from an OSGi bundles if it is specified, or from the application classpath.
Parameters:
filename - the name of the resource, without the starting slash character.
bundledPlugin - the plugin that is able to provide the bundle that contains the resources, or null to use the application classpath.
readerClass - the class that has called this function. It is used for obtaining the resource if the bundled plugin is not provided.
statusBuilder - the builder of a status that takes the exception as parameter and creates a status object. This builder is used only if the bundledPlugin is not null.
Returns:
the loaded resources.
setActionPrototypeProvider(IActionPrototypeProvider)
def setActionPrototypeProvider(IActionPrototypeProvider)
Change the provider of action prototype.
Parameters:
provider - the action prototype provider.
setCommonTypeComputationServices(CommonTypeComputationServices)
def setCommonTypeComputationServices(CommonTypeComputationServices)
Change the common type service.
Parameters:
services - the service.
setEarlyExitComputer(IEarlyExitComputer)
def setEarlyExitComputer(IEarlyExitComputer)
Change the early exit computer.
Parameters:
computer - the early exit computer.
setInjector(Injector)
def setInjector(Injector)
Change the injector.
Parameters:
injector - the injector.
setJvmModelAssociations(SarlJvmModelAssociations)
def setJvmModelAssociations(SarlJvmModelAssociations)
Change the associations between the SARL elements and the JVM elements.
Parameters:
associations - the associations.
setLogicalContainerProvider(IActionPrototypeProvider)
def setLogicalContainerProvider(IActionPrototypeProvider)
Change the provider of action prototype.
Parameters:
provider - the action prototype provider.
setQualifiedNameConverter(IQualifiedNameConverter)
def setQualifiedNameConverter(IQualifiedNameConverter)
Change the converter of qualified name.
Parameters:
converter - the converter.
setQualifiedNameProvider(IQualifiedNameProvider)
def setQualifiedNameProvider(IQualifiedNameProvider)
Change the provider of qualified name.
Parameters:
provider - the provider.
setTypeBuilder(JvmTypesBuilder)
def setTypeBuilder(JvmTypesBuilder)
Change the type builder.
Parameters:
builder - the builder.
setTypeExtensions(JvmTypeExtensions)
def setTypeExtensions(JvmTypeExtensions)
Change the type extension provider.
Parameters:
provider - the type extension provider.
setTypeReferences(TypeReferences)
def setTypeReferences(TypeReferences)
Change the type reference finder.
Parameters:
finder - the type reference finder.
setTypeResolver(IBatchTypeResolver)
def setTypeResolver(IBatchTypeResolver)
Change the type resolver for expressions.
Parameters:
resolver - the batch type resolver.
toFilename(QualifiedName)
protected def toFilename(QualifiedName) : java.lang.String
Replies the filename for the qualified name.
Parameters:
name - the qualified name.
Returns:
the filename.
toFilename(QualifiedName,String)
protected def toFilename(QualifiedName,String) : java.lang.String
Replies the filename for the qualified name.
Parameters:
name - the qualified name.
separator - the filename separator.
Returns:
the filename.
writeFile(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext)
protected def writeFile(QualifiedName,ExtraLanguageAppendable,IExtraLanguageGeneratorContext) : boolean
Write the given file.
Parameters:
name - the name of the type to write.
appendable - the content to be written.
context - the generator context.
Returns:
true if the file was written.