Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 332d10af rédigé par Gerson Sunyé's avatar Gerson Sunyé
Parcourir les fichiers

Migrate exercises to project mde/tutorial

parent 95091c42
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 2 ajouts et 306 suppressions
......@@ -19,6 +19,8 @@
[source,sh]
----
git clone https://gitlab.univ-nantes.fr/naomod/mde/slides.git
cd slides
bundle install
----
......
exercises/codegen/code.png

46,3 ko

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="xtend-gen">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>fr.univnantes.idm.robotdsl.codegen.examples</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: fr.univnantes.idm.robotdsl.codegen.examples
Bundle-SymbolicName: fr.univnantes.idm.robotdsl.codegen.examples
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: fr.univnantes.idm.robotdsl.codegen.test
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: fr.univnantes.idm.robotdsl.xtext,
fr.univnantes.idm.robotdsl.abstractsyntax,
org.junit.jupiter.api;bundle-version="[5.0.0,6.0.0)",
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing,
org.eclipse.xtext.xbase.lib;bundle-version="2.14.0",
fr.univnantes.idm.robotdsl.xtext.tests;bundle-version="1.0.0",
fr.univnantes.idm.robotdsl.codegen;bundle-version="1.0.0"
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
package fr.univnantes.idm.robotdsl.codegen.examples
import com.google.inject.Inject
import fr.univnantes.idm.robotdsl.abstractsyntax.robotdsl.RobotSimulation
import fr.univnantes.idm.robotdsl.codegen.RobotDSLCodeGenerator
import fr.univnantes.idm.tests.RobotDSLInjectorProvider
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith
@ExtendWith(InjectionExtension)
@InjectWith(RobotDSLInjectorProvider)
class RobotDSLCodeGeneratorTest {
@Inject
ParseHelper<RobotSimulation> parseHelper
/**
* Loads the model provided in its textual concrete syntax representation
* (ie. as defined by the Xtext grammar)
*/
def RobotSimulation loadModel(String modelAsText) {
val result = parseHelper.parse(modelAsText)
Assertions.assertNotNull(result)
val errors = result.eResource.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
return result
}
/**
* Generates Java code for a model provided in its textual concrete syntax representation,
* and print the generated code in the console.
*/
def generateAndPrintCode(String modelAsText) {
val loadedModel1 = loadModel(modelAsText)
val generatedCode = RobotDSLCodeGenerator::generateCode(loadedModel1)
println("-------------------------------------")
println(generatedCode)
}
@Test
def void testModel1() {
generateAndPrintCode('''
simulation s1 {
robot r1 {
motor m1 (3)
}
program p1 for r1 {
moveForward 12;
}
}
''')
}
@Test
def void testModel2() {
generateAndPrintCode('''
simulation s2 {
robot r2 {
light l1,
light l2,
light l3,
motor m1 (12),
motor m2 (13)
}
program p2 for r2 {
moveForward 12;
setLightColor of l1 to YELLOW;
rotate 180;
moveForward 15;
},
program p3 for r2 {
rotate 45;
moveForward 50;
setLightColor of l1 to RED;
moveForward 15;
setLightColor of l2 to BLUE;
}
}
''')
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>fr.univnantes.idm.robotdsl.codegen</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: fr.univnantes.idm.robotdsl.codegen
Bundle-SymbolicName: fr.univnantes.idm.robotdsl.codegen
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: fr.univnantes.idm.robotdsl.codegen
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: com.google.guava,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtend.lib,
org.eclipse.xtend.lib.macro,
fr.univnantes.idm.robotdsl.abstractsyntax;bundle-version="0.1.0"
Export-Package: fr.univnantes.idm.robotdsl.codegen
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
package fr.univnantes.idm.robotdsl.codegen
import fr.univnantes.idm.robotdsl.abstractsyntax.robotdsl.RobotSimulation
class RobotDSLCodeGenerator {
static def String generateCode(RobotSimulation simulation) {
return ''''''
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>fr.univnantes.idm.robotdsl.lib</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: fr.univnantes.idm.robotdsl.lib
Bundle-SymbolicName: fr.univnantes.idm.robotdsl.lib
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: fr.univnantes.idm.robotdsl.lib
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
package fr.univnantes.idm.robotdsl.lib;
public enum Color {
GREEN,
RED,
YELLOW,
BLUE
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter