Commit 6df62ec0 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

* moved new TTCN-3 generation to ttcn3 plugins, removed legacy epsilon implementation, &27

parent 0772743d
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
@@ -17,11 +17,6 @@
            categoryId="org.etsi.mts.tdl.tools.rt.ui.commands.category"
            id="org.etsi.mts.tdl.tools.rt.ui.commands.tp2tdCommand">
      </command>
      <command
            name="Generate TTCN-3 code from TDL model"
            categoryId="org.etsi.mts.tdl.tools.rt.ui.commands.category"
            id="org.etsi.mts.tdl.tools.rt.ui.commands.translateTTCN3Command">
      </command>
      <command
            name="Activate TDL validation"
            categoryId="org.etsi.mts.tdl.tools.rt.ui.commands.category"
@@ -43,10 +38,6 @@
            commandId="org.etsi.mts.tdl.tools.rt.ui.commands.tp2tdCommand"
            class="org.etsi.mts.tdl.tools.rt.ui.handlers.TP2TDHandler">
      </handler>
      <handler
            commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateTTCN3Command"
            class="org.etsi.mts.tdl.tools.rt.ui.handlers.RendererHandler">
      </handler>
      <handler
            commandId="org.etsi.mts.tdl.tools.rt.ui.commands.toggleValidatorCommand"
            class="org.etsi.mts.tdl.tools.rt.ui.handlers.ToggleValidation">
@@ -87,17 +78,6 @@
                  id="org.etsi.mts.tdl.tools.rt.ui.menus.tp2tdCommand">
            </command>
         </menu>
         <menu
               label="TDL"
               mnemonic="T"
               id="org.etsi.mts.tdl.tools.menus.TDLMenu">
            <command
                  commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateTTCN3Command"
                  icon="icons/TransformIcon.png"
                  mnemonic="3"
                  id="org.etsi.mts.tdl.tools.rt.ui.menus.translateTTCN3Command">
            </command>
         </menu>
         <menu
               label="TDL"
               mnemonic="T"
@@ -126,12 +106,6 @@
                  icon="icons/TransformIcon.png"
                  tooltip="Transform TPs to TDs"
                  id="org.etsi.mts.tdl.tools.rt.ui.toolbars.tp2tdCommand">
            </command>
            <command
                  commandId="org.etsi.mts.tdl.tools.rt.ui.commands.translateTTCN3Command"
                  icon="icons/T3Icon.png"
                  tooltip="Generate TTCN-3 code from TDL model"
                  id="org.etsi.mts.tdl.tools.rt.ui.toolbars.translateTTCN3Command">
            </command>
	         <command
	              commandId="org.etsi.mts.tdl.tools.rt.ui.commands.toggleValidatorCommand"
+3 −6
Original line number Diff line number Diff line
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Automatic-Module-Name: org.etsi.mts.tdl.ttcn3.ui
Bundle-Name: Ui
Bundle-Name: TDL to TTCN-3 Generation 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
@@ -11,12 +11,9 @@ Require-Bundle: org.eclipse.ui,
 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,
 de.ugoe.cs.swe.TTCN3.ui
 org.etsi.mts.tdl.model,
 org.etsi.mts.tdl.ttcn3
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
+10 −10
Original line number Diff line number Diff line
@@ -9,22 +9,22 @@
            id="org.etsi.mts.tdl.ttcn3.ui.commands.category">
      </category>
      <command
            name="Generate TTCN-3 code from TDL model"
            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">
            id="org.etsi.mts.tdl.ttcn3.ui.commands.translateTTCN3Command">
      </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">
            commandId="org.etsi.mts.tdl.ttcn3.ui.commands.translateTTCN3Command"
            class="org.etsi.mts.tdl.ttcn3.ui.handlers.RendererHandler">
      </handler>
   </extension>
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
            commandId="org.etsi.mts.tdl.ttcn3.ui.commands.translateTTCN3Command"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+6"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
@@ -39,10 +39,10 @@
               mnemonic="T"
               id="org.etsi.mts.tdl.tools.menus.TDLMenu">
            <command
                  commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
                  commandId="org.etsi.mts.tdl.ttcn3.ui.commands.translateTTCN3Command"
                  icon="icons/T3Icon.png"
                  mnemonic="3"
                  id="org.etsi.mts.tdl.ttcn3.ui.menus.trasnformCommand">
                  id="org.etsi.mts.tdl.ttcn3.ui.menus.translateTTCN3Command">
            </command>
         </menu>
      </menuContribution>
@@ -51,10 +51,10 @@
         <toolbar
               id="org.etsi.mts.tdl.ttcn3.ui.toolbars.transform">
            <command
                  commandId="org.etsi.mts.tdl.ttcn3.ui.commands.transformCommand"
                  commandId="org.etsi.mts.tdl.ttcn3.ui.commands.translateTTCN3Command"
                  icon="icons/T3Icon.png"
                  tooltip="Transform TDL model to TTCN-3"
                  id="org.etsi.mts.tdl.ttcn3.ui.toolbars.transformCommand">
                  tooltip="Generate TTCN-3 code from TDL model"
                  id="org.etsi.mts.tdl.ttcn3.ui.toolbars.translateTTCN3Command">
            </command>
         </toolbar>
      </menuContribution>
+2 −3
Original line number Diff line number Diff line
package org.etsi.mts.tdl.tools.rt.ui.handlers;
package org.etsi.mts.tdl.ttcn3.ui.handlers;

import java.util.Arrays;
import java.util.LinkedHashMap;
@@ -29,9 +29,8 @@ import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.etsi.mts.tdl.ttcn3.TTCN3Renderer;
import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.tools.rt.renderers.TTCN3Renderer;

import com.google.inject.Guice;
import com.google.inject.Injector;

+0 −118
Original line number Diff line number Diff line
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.emf.ecore.util.EcoreUtil;
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;
import com.google.inject.Provider;

/**
 * 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 Injector injector;
	@Inject Provider<ResourceSet> rsp;
	@Inject Provider<XtextResourceSet> xrsp;

	
	@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;
		if (input != null && input instanceof FileEditorInput) {
			file = ((FileEditorInput) input).getFile();
		} else if (selection !=null && selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
			Object firstElement = structuredSelection.getFirstElement();
			if (firstElement instanceof IFile) {
				file = (IFile) firstElement;
			}
		}
		try {
			if (file !=null) {
				injector = Guice.createInjector();
				URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
				XtextResourceSet rs = injector.getInstance(XtextResourceSet.class);
				Resource r = rs.getResource(uri, true);
				EcoreUtil.resolveAll(r); //This is important otherwise weird problems occur if unresolved imported definitions are encountered
				if (file.getName().endsWith(".tdl")
						|| file.getName().endsWith(".tdlan2")
						|| file.getName().endsWith(".tdltx")
						|| file.getName().endsWith(".tdltxi")) {
					Transform transformer = new Transform();
					
					URI interimURI = URI.createURI(uri.toString()+"-generated.ttcn3m");
					Resource ir = rs.createResource(interimURI);
					transformer.transform(r, ir);
					//This is important otherwise ghost references may occur
					ir.unload();
					URI targetURI = URI.createURI(uri.toString()+"-generated.ttcn3");
					//				URI targetURI = URI.createPlatformResourceURI(file.getFullPath().toString()+".ttcn3", true);
					//				Injector injector = Guice.createInjector(new de.ugoe.cs.swe.TTCN3RuntimeModule());
					//				XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
					//				Resource tr = resourceSet.createResource(targetURI);
					Resource tr = rs.createResource(targetURI);
					transformer.transform(r, tr);
				} else if (file.getName().endsWith(".ttcn3")) {
					URI targetURI = URI.createURI(uri.toString()+".ttcn3m");
					Resource tr = rs.createResource(targetURI);
					tr.getContents().addAll(EcoreUtil.copyAll(r.getContents()));
					tr.save(null);
				} else if (file.getName().endsWith(".ttcn3m")) {
					URI targetURI = URI.createURI(uri.toString()+".ttcn3");
					Resource tr = rs.createResource(targetURI);
					tr.getContents().addAll(EcoreUtil.copyAll(r.getContents()));
					tr.save(null);
				}
				
			}
		} catch (Exception e) {
			System.err.println("  Transformation: "+e.getMessage());
			//TODO: add dialog
		}
		return null;
	}
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}
}
Loading