Skip to content

Commit f788849

Browse files
committed
Add generator example
1 parent a581259 commit f788849

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

plugins/eu.coresense.CognitiveModule.xtext/src/eu/coresense/cognitivemodule/generator/CogModGenerator.xtend

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ import org.eclipse.emf.ecore.resource.Resource
77
import org.eclipse.xtext.generator.AbstractGenerator
88
import org.eclipse.xtext.generator.IFileSystemAccess2
99
import org.eclipse.xtext.generator.IGeneratorContext
10+
import eu.coresense.CognitiveModule.CognitiveModule
11+
import com.google.inject.Inject
1012

1113
/**
1214
* Generates code from your model files on save.
1315
*
1416
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
1517
*/
1618
class CogModGenerator extends AbstractGenerator {
19+
20+
@Inject extension ReadmeCompiler
1721

18-
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
19-
// fsa.generateFile('greetings.txt', 'People to greet: ' +
20-
// resource.allContents
21-
// .filter(Greeting)
22-
// .map[name]
23-
// .join(', '))
24-
}
25-
}
22+
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context){
23+
for (cognitive_module : resource.allContents.toIterable.filter(CognitiveModule)){
24+
fsa.generateFile(
25+
cognitive_module.getName().toLowerCase+"/README.md",
26+
compile_toREADME(cognitive_module).toString().replace("\t"," ")
27+
)
28+
}}
29+
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package eu.coresense.cognitivemodule.generator
2+
3+
import eu.coresense.CognitiveModule.CognitiveModule
4+
5+
class ReadmeCompiler {
6+
7+
def compile_toREADME(CognitiveModule cogmod) '''
8+
# «cogmod.name»
9+
10+
This package has be created automatically using the [RosTooling](https://github.com/ipa320/RosTooling).
11+
12+
13+
This Cognitive Module has the following structure:
14+
15+
### Core
16+
«cogmod.core.name»
17+
18+
### Meta
19+
«cogmod.meta.name»
20+
21+
### Coupling
22+
«cogmod.coupling.name»
23+
24+
### Afferents
25+
«FOR af:cogmod.afferent»
26+
- «af.topic» [«af.type»]
27+
«ENDFOR»
28+
29+
### Efferents
30+
«FOR ef:cogmod.efferent»
31+
- «ef.topic» [«ef.type»]
32+
«ENDFOR»
33+
34+
'''}
35+
36+

0 commit comments

Comments
 (0)