<commit_before>package fr.inria.diverse.trace.gemoc.ui.commands

import fr.inria.diverse.melange.metamodel.melange.Language
import fr.inria.diverse.trace.gemoc.generator.GenericEngineTraceAddonGeneratorHelper
import java.io.PrintWriter
import java.io.StringWriter
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.commands.ExecutionException
import org.eclipse.core.commands.IHandler
import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IProject
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.Status
import org.eclipse.core.runtime.jobs.Job
import org.gemoc.xdsmlframework.ide.ui.commands.AbstractMelangeSelectHandler

import static fr.inria.diverse.trace.gemoc.ui.commands.XDSMLProject2TraceAddonHandler.*
import org.eclipse.jface.dialogs.InputDialog
import org.eclipse.swt.widgets.Shell
import org.eclipse.jface.window.Window
import org.gemoc.xdsmlframework.ide.ui.xdsml.wizards.MelangeXDSMLProjectHelper

/**
 * Handler that allows to get an XDSML project (containing a melange file) 
 * and will ask for selection of the language (if necessary) and launch the generation
 */
class XDSMLProject2TraceAddonHandler extends AbstractMelangeSelectHandler implements IHandler {
	val static String pluginId = "fr.inria.diverse.trace.gemoc.ui"

	override Object executeForSelectedLanguage(ExecutionEvent event, IProject updatedGemocLanguageProject,
		Language language) throws ExecutionException {

		val IFile melangeFile = getMelangeIFile(event, language)
		val suggestedPluginName = MelangeXDSMLProjectHelper.baseProjectName(melangeFile.project) + "." +
			language.name.toLowerCase + ".trace"
		val org.eclipse.jface.dialogs.InputDialog inputDialog = new InputDialog(new Shell(), "Create MultiDimensional Trace addon for language "+language.getName(),
            "Enter project name ", suggestedPluginName, null)
		inputDialog.open();
    	if (inputDialog.getReturnCode() == Window.OK ) {
        	val String projectName = inputDialog.getValue();
        	val Job j = new Job("Generating trace addon plugin for " + melangeFile.toString) {
			override protected run(IProgressMonitor monitor) {
				try {

					GenericEngineTraceAddonGeneratorHelper.generateAddon(melangeFile, language.name, projectName, true, monitor)

				} catch (Exception e) {
					val StringWriter sw = new StringWriter();
					e.printStackTrace(new PrintWriter(sw));
					val String exceptionAsString = sw.toString();
					return new Status(Status.ERROR, pluginId, exceptionAsString)
				}
				return new Status(Status.OK, pluginId, "Multidimensional Trace addon plugin generated.")
			}
		}
		// And we start the job<commit_msg>Fix the trace addon project name suggestion with 2x the language name<commit_after>package fr.inria.diverse.trace.gemoc.ui.commands

import fr.inria.diverse.melange.metamodel.melange.Language
import fr.inria.diverse.trace.gemoc.generator.GenericEngineTraceAddonGeneratorHelper
import java.io.PrintWriter
import java.io.StringWriter
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.commands.ExecutionException
import org.eclipse.core.commands.IHandler
import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IProject
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.Status
import org.eclipse.core.runtime.jobs.Job
import org.gemoc.xdsmlframework.ide.ui.commands.AbstractMelangeSelectHandler

import static fr.inria.diverse.trace.gemoc.ui.commands.XDSMLProject2TraceAddonHandler.*
import org.eclipse.jface.dialogs.InputDialog
import org.eclipse.swt.widgets.Shell
import org.eclipse.jface.window.Window
import org.gemoc.xdsmlframework.ide.ui.xdsml.wizards.MelangeXDSMLProjectHelper

/**
 * Handler that allows to get an XDSML project (containing a melange file) 
 * and will ask for selection of the language (if necessary) and launch the generation
 */
class XDSMLProject2TraceAddonHandler extends AbstractMelangeSelectHandler implements IHandler {
	val static String pluginId = "fr.inria.diverse.trace.gemoc.ui"

	override Object executeForSelectedLanguage(ExecutionEvent event, IProject updatedGemocLanguageProject,
		Language language) throws ExecutionException {

		val IFile melangeFile = getMelangeIFile(event, language)
		val baseProjectName = MelangeXDSMLProjectHelper.baseProjectName(melangeFile.project)
			
		// If the base project name doesn't end with the language name, we suggest it		
		val suggestedBasePluginName = if (baseProjectName.endsWith(language.name.toLowerCase))
				baseProjectName
			else
				baseProjectName + "." language.name.toLowerCase
		val suggestedPluginName = suggestedBasePluginName + ".trace"
			
		val org.eclipse.jface.dialogs.InputDialog inputDialog = new InputDialog(new Shell(), "Create MultiDimensional Trace addon for language "+language.getName(),
            "Enter project name ", suggestedPluginName, null)
		inputDialog.open();
    	if (inputDialog.getReturnCode() == Window.OK ) {
        	val String projectName = inputDialog.getValue();
        	val Job j = new Job("Generating trace addon plugin for " + melangeFile.toString) {
			override protected run(IProgressMonitor monitor) {
				try {

					GenericEngineTraceAddonGeneratorHelper.generateAddon(melangeFile, language.name, projectName, true, monitor)

				} catch (Exception e) {
					val StringWriter sw = new StringWriter();
					e.printStackTrace(new PrintWriter(sw));
					val String exceptionAsString = sw.toString();
					return new Status(Status.ERROR, pluginId, exceptionAsString)
				}
				return new Status(Status.OK, pluginId, "Multidimensional Trace addon plugin generated.")
			}
		}
		// And we start the job
{'fraction_non_alphanumeric': 0.08412530799014431, 'fraction_numerical': 0.0008799718409010912, 'mean_word_length': 5.013756613756613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '266188', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1577, 'n_words': 384}