Commit 72dfe2d2 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+migrated current versions of TDL mapping to TTCN-3 (core + ui)



Change-Id: Ib446cfc2579b74a9a6b2fb507def04946f436e00
Signed-off-by: Philip Makedonski's avatarmakedonski <makedonski@informatik.uni-goettingen.de>
parent d27428a5
<?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.7"/>
<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>org.etsi.mts.tdl.ttcn3.ui</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.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: org.etsi.mts.tdl.ttcn3.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.etsi.mts.tdl.ttcn3.ui.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.0",
org.eclipse.ui.workbench,
org.eclipse.emf.common,
org.eclipse.emf.ecore,
org.eclipse.xtext,
org.eclipse.xtext.ui,
org.etsi.mts.tdl.ttcn3,
de.ugoe.cs.swe.TTCN3
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="TDL"
id="org.etsi.mts.tdl.ttcn3.ui.commands.category">
</category>
<command
categoryId="org.etsi.mts.tdl.ttcn3.ui.commands.category"
id="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
name="Transform TDL model to TTCN-3">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
class="org.etsi.mts.tdl.ttcn3.ui.handlers.TransformationHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="TDL"
mnemonic="T"
id="org.etsi.mts.tdl.tools.menus.TDLMenu">
<command
commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
mnemonic="3"
id="org.etsi.mts.tdl.ttcn3.ui.menus.trasnformCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="org.etsi.mts.tdl.ttcn3.ui.toolbars.transform">
<command
commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
icon="icons/TransformIcon.png"
tooltip="Transform TDL model to TTCN-3"
id="org.etsi.mts.tdl.ttcn3.ui.toolbars.transformCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
package org.etsi.mts.tdl.ttcn3.ui;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.etsi.mts.tdl.ttcn3.ui"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
<?xml version="1.0" encoding="UTF-8"?><projectDescription><name>DUMMY</name><comment></comment><projects></projects><buildSpec></buildSpec><natures></natures></projectDescription>
\ No newline at end of file
package org.etsi.mts.tdl.ttcn3.ui.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.URI;
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.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
import org.etsi.mts.tdl.ttcn3.Transform;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
*/
public class TransformationHandler extends AbstractHandler {
@Inject
IResourceSetProvider resourceSetProvider;
private IWorkbenchWindow window;
/**
* The constructor.
*/
public TransformationHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
IFile file = null;
IProject project = null;
if (input != null && input instanceof FileEditorInput) {
file = ((FileEditorInput) input).getFile();
project = file.getProject();
} else if (selection !=null && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
file = (IFile) firstElement;
project = file.getProject();
}
}
try {
if (file !=null && (file.getName().endsWith(".tdl") || file.getName().endsWith(".tdlan2"))) {
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.getResource(uri, true);
Transform transformer = new Transform();
URI interimURI = URI.createURI(uri.toString()+".ttcn3m");
Resource ir = rs.createResource(interimURI);
transformer.transform(r, ir);
URI targetURI = URI.createURI(uri.toString()+".ttcn3");
Injector injector = Guice.createInjector(new de.ugoe.cs.swe.TTCN3RuntimeModule());
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource tr = resourceSet.createResource(targetURI);
transformer.transform(r, tr);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void init(IWorkbenchWindow window) {
this.window = window;
}
@Override
public boolean isEnabled() {
return true;
}
}
<?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>org.etsi.mts.tdl.ttcn3</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: TDL to TTCN-3 Core
Bundle-SymbolicName: org.etsi.mts.tdl.ttcn3
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.etsi.mts.tdl.ttcn3
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.emf.common,
org.eclipse.core.runtime,
org.eclipse.emf.ecore,
org.eclipse.osgi,
de.ugoe.cs.swe.TTCN3,
org.etsi.mts.tdl.model,
org.eclipse.epsilon.common,
org.eclipse.epsilon.emc.emf,
org.eclipse.epsilon.eol.engine,
org.eclipse.epsilon.etl.engine
Export-Package: org.etsi.mts.tdl.ttcn3
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
package org.etsi.mts.tdl.ttcn3;
import java.io.File;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.epsilon.common.parse.problem.ParseProblem;
import org.eclipse.epsilon.emc.emf.EmfModel;
import org.eclipse.epsilon.emc.emf.InMemoryEmfModel;
import org.eclipse.epsilon.eol.EolModule;
import org.eclipse.epsilon.eol.IEolExecutableModule;
import org.eclipse.epsilon.eol.models.IModel;
import org.eclipse.epsilon.etl.EtlModule;
import org.etsi.mts.tdl.tdlPackage;
import org.osgi.framework.Bundle;
import de.ugoe.cs.swe.tTCN3.TTCN3Package;
public class Transform {
public void transform(Resource r, Resource tr) {
try {
String source = "src/org/etsi/mts/tdl/ttcn3/epsilon/ttcn3mapping.etl";
Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.ttcn3");
String moduleSource = bundle.getLocation().substring(15)+source;
IEolExecutableModule module = loadModule(moduleSource);
IModel tdlModel = getTDLModel(r, true, false);
IModel ttcnModel = getTTCNModel(tr, false, true);
tdlModel.load();
ttcnModel.load();
module.getContext().getModelRepository().addModel(tdlModel);
module.getContext().getModelRepository().addModel(ttcnModel);
//execute
module.execute();
tdlModel.dispose();
ttcnModel.dispose();
module.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
//TODO: extract to shared library
private IEolExecutableModule loadModule(String source) throws Exception, URISyntaxException {
IEolExecutableModule module = null;
if (source.endsWith("etl")) {
module = new EtlModule();
} else if (source.endsWith("eol")) {
module = new EolModule();
// } else if (source.endsWith("evl")) {
// module = new EvlModule();
} else {
}
module.parse(new File(source));
if (module.getParseProblems().size() > 0) {
System.err.println("Parse errors occured...");
for (ParseProblem problem : module.getParseProblems()) {
System.err.println(problem.toString());
}
}
return module;
}
public IModel getTDLModel(Resource resource, boolean read, boolean write) throws Exception {
EmfModel model;
model = new InMemoryEmfModel("TDL", resource, tdlPackage.eINSTANCE);
model.setStoredOnDisposal(write);
model.setReadOnLoad(read);
model.setCachingEnabled(true);
return model;
}
public IModel getTTCNModel(Resource resource, boolean read, boolean write) throws Exception {
EmfModel model;
model = new InMemoryEmfModel("TTCN", resource, TTCN3Package.eINSTANCE);
model.setStoredOnDisposal(write);
model.setReadOnLoad(read);
model.setCachingEnabled(true);
return model;
}
}
//Supporting operation aliases for OCL
operation Any oclIsUndefined() : Boolean {
return self.isUndefined();
}
operation Any oclIsTypeOf(t:Any) : Boolean {
return self.isTypeOf(t);
}
operation Any oclIsKindOf(t:Any) : Boolean {
return self.isKindOf(t);
}
operation Any oclAsType(t:Any) : Any {
return self;
}
operation Any notEmpty() : Boolean {
return not self.isEmpty();
}
operation Any container() : Any {
return self.eContainer;
}
operation String size() : Integer {
return self.length();
}
//Supporting operations
operation Any getTestDescription() : Any {
if (self.eContainer.isDefined()) {
if (not self.eContainer.isKindOf(TestDescription)) {
return self.eContainer.getTestDescription();
} else {
return self.eContainer;
}
}
}
operation Any getTestObjective() : Any {
if (self.eContainer.isDefined()) {
if (not self.eContainer.isKindOf(StructuredTestObjective)) {
return self.eContainer.getTestObjective();
} else {
return self.eContainer;
}
}
}
operation Any contains(object : Any) : Boolean {
return self.eAllContents().includes(object);
}
operation TDL!StructuredTestObjective indexOf(object : Any) : Integer {
return self.eAllContents().indexOf(object);
}
//QualifiedNames
operation Any qualifiedName() : String {
var p = self.getNamedParent();
if (p.isDefined()) {
return p.qualifiedName()+"::"+self.name;
} else {
return self.name;
}
}
operation Any getNamedParent() : Any {
if (self.eContainer.isDefined()) {
if (not self.eContainer.isKindOf(NamedElement)) {
return self.eContainer.getNamedParent();
} else {
return self.eContainer;
}
}
}
//Get Data Type
//TODO: add support for reduction..
//TODO: check for reduction too once support is added
operation TDL!DataInstanceUse getDataType() : Any {
if (not self.dataInstance.oclIsUndefined()) {
return self.dataInstance.dataType;
} else if (not self.dataType.oclIsUndefined()) {
return self.dataType;
} else {
if (self.container().oclIsTypeOf(MemberAssignment)) {
return self.container().member.dataType;
} else if (self.container().oclIsTypeOf(ParameterBinding)) {
return self.container().parameter.dataType;
} else {
(self.container().type.name+".getDataType() not yet defined").println();
}
}
}
operation TDL!FunctionCall getDataType() : Any {
return self.`function`.returnType;
}
operation TDL!VariableUse getDataType() : Any {
return self.variable.dataType;
}
operation TDL!TimeLabelUse getDataType() : Any {
return Time.allInstances().first();
}
operation TDL!FormalParameterUse getDataType() : Any {
return self.parameter.dataType;
}