Skip to content
Snippets Groups Projects
Commit 992396e9 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

first synthesis works

parent f9cfd194
Branches
Tags
No related merge requests found
Pipeline #
......@@ -22,6 +22,8 @@ Require-Bundle: javax.inject,
org.eclipse.ui.navigator.resources,
org.eclipse.ui.views.log,
org.eclipse.core.resources,
org.eclipse.emf
Import-Package: teetime.configuration.dsl.config
org.eclipse.emf,
org.eclipse.xtext.ui
Import-Package: org.eclipse.xtext.ui.editor.utils,
teetime.configuration.dsl.config
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
......@@ -37,7 +37,8 @@ class ConfigurationDiagramSynthesis extends AbstractDiagramSynthesis<Configurati
// Your dsl element <-> diagram figure mapping goes here!!
for(ConfigurationElement ce : model.elements){
if(ce instanceof Stage){
ce.transformStage(model)
System::err.println(ce)
root.children += ce.transformStage(model)
}
}
return root;
......
......@@ -11,10 +11,15 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.statushandlers.StatusManager;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import de.cau.cs.kieler.klighd.ui.DiagramViewManager;
import de.cau.cs.kieler.klighd.util.KlighdSynthesisProperties;
......@@ -36,26 +41,33 @@ public class OpenDiagramHandler extends AbstractHandler {
try {
IFile f = (IFile) sSelection.getFirstElement();
ResourceSet rs = new ResourceSetImpl();
Resource r =
rs.getResource(URI.createFileURI(f.getFullPath().toString()), true);
Resource r = rs.getResource(URI.createFileURI(f.getFullPath().toString()), true);
if (r.getContents().size() > 0) {
model = r.getContents().get(0);
}
} catch (Exception e) {
StatusManager.getManager().handle(
new Status(IStatus.ERROR, this.getClass().getCanonicalName(),
StatusManager.getManager().handle(new Status(IStatus.ERROR, this.getClass().getCanonicalName(),
"Could not load selected file.", e), StatusManager.SHOW);
}
} else {
model = sSelection.getFirstElement();
}
DiagramViewManager.createView(
"teetime.configuration.dsl.klighd.ConfigurationDiagram", "Configuration Diagram", model, KlighdSynthesisProperties.create());
DiagramViewManager.createView("teetime.configuration.dsl.klighd.ConfigurationDiagram",
"Configuration Diagram", model, KlighdSynthesisProperties.create());
} else if (selection instanceof ITextSelection) {
IXtextDocument xtextDocument = EditorUtils.getActiveXtextEditor().getDocument();
xtextDocument.readOnly(new IUnitOfWork<XtextResource, XtextResource>() {
public XtextResource exec(XtextResource state) throws Exception {
DiagramViewManager.createView("teetime.configuration.dsl.klighd.ConfigurationDiagram",
"Configuration Diagram", state.getContents().get(0), KlighdSynthesisProperties.create());
return state;
}
});
} else {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Unsupported element",
"KLighD diagram synthesis is unsupported for the current selection "
+ selection.toString() + ".");
"KLighD diagram synthesis is unsupported for the current selection " + selection.toString() + ".");
}
return null;
}
......
......@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.xtext,
org.antlr.runtime,
org.eclipse.xtext.util,
org.eclipse.xtend.lib,
org.eclipse.emf.common
org.eclipse.emf.common,
org.eclipse.ui;bundle-version="3.107.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: teetime.configuration.dsl,
teetime.configuration.dsl.scoping,
......
......@@ -6,18 +6,20 @@ package teetime.configuration.dsl.generator
import java.util.ArrayList
import java.util.Collections
import java.util.HashSet
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.ui.PlatformUI
import org.eclipse.ui.commands.ICommandService
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import teetime.configuration.dsl.config.ArgumentDeclaration
import teetime.configuration.dsl.config.Configuration
//import teetime.configuration.dsl.config.ConnectionLongForm
//import teetime.configuration.dsl.config.ConnectionShortForm
import teetime.configuration.dsl.config.Connection
import teetime.configuration.dsl.config.ImportDeclaration
import teetime.configuration.dsl.config.QualifiedNameList
import teetime.configuration.dsl.config.Stage
import teetime.configuration.dsl.config.Connection
import org.eclipse.core.commands.ParameterizedCommand
/**
* Generates code from your model files on save.
......@@ -25,10 +27,14 @@ import teetime.configuration.dsl.config.Connection
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class ConfigGenerator extends AbstractGenerator {
private static final String SYNTHESIZE_DIAGRAM = "teetime.configuration.dsl.klighd.openConfigurationDiagram";
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
var Configuration model;
for (c : resource.allContents.toIterable.filter(Configuration)) {
model = c
if (c.package != null) {
// the replacement is for placing the generated class in the correct directory
fsa.generateFile(c.package.replaceAll("\\.", "/") + "/" + c.type + ".java", c.compileConfig)
......@@ -240,7 +246,6 @@ class ConfigGenerator extends AbstractGenerator {
// b.append("());");
// return b.toString();
// }
/*** compiles connection defs like a->b->c->d */
def compileConnectionShort(Connection con) '''
««« connectPorts(«con.startStage».getOutputPort(), «con.idi».getInputPort());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment