<commit_before>/**
 * Copyright (c) 2013 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.simulation.core.launch;

import java.util.Collections;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.yakindu.sct.model.sgraph.Statechart;
import org.yakindu.sct.simulation.core.debugmodel.SCTDebugTarget;
import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
import org.yakindu.sct.simulation.core.util.ResourceUtil;

/**
 * 
 * @author <NAME> - Initial contribution and API
 * 
 */
public abstract class AbstractSCTLaunchConfigurationDelegate extends LaunchConfigurationDelegate implements
		ILaunchConfigurationDelegate {

	public String FILE_NAME = "filename";
	public String DEFAULT_FILE_NAME = "";

	protected abstract ISimulationEngine createExecutionContainer(ILaunch launch, Statechart statechart);

	@Override
	public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
			throws CoreException {
		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
		URI uri = URI.createPlatformResourceURI(filename, true);
		if (!URIConverter.INSTANCE.exists(uri, Collections.emptyMap()))
			return false;
		return super.preLaunchCheck(configuration, mode, monitor);
	}
	
	public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
			throws CoreException {
		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
		Statechart statechart = loadStatechart(filename);
		SCTDebugTarget target = createDebugTarget(launch, statechart);
		launch.addDebugTarget(target);
		target.init();
		target.start();
	}

	protected SCTDebugTarget createDebugTarget(ILaunch launch, Statechart statechart) throws CoreException {
		Assert.isNotNull(statechart);
		return new SCTDebugTarget(launch, statechart, createExecutionContainer(launch, statechart));
	}

	protected Statechart loadStatechart(String filename) {
		return ResourceUtil.loadStatechart(filename);
	}

	@Override
	protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode)
			throws CoreException {
		String filename = configuration.getAttribute(FILE_NAME, "");
		IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filename);
		return new IProject[] { resource.getProject() };

	}
	
	@Override
	public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
			throws CoreException {
		//Never build the workspace before simulation
		return false;
	}

}<commit_msg>Changed save prompt for "Run as..." option for a statechart project … (#1655)<commit_after>/**
 * Copyright (c) 2013 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.simulation.core.launch;

import java.util.Collections;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.yakindu.sct.model.sgraph.Statechart;
import org.yakindu.sct.simulation.core.debugmodel.SCTDebugTarget;
import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
import org.yakindu.sct.simulation.core.util.ResourceUtil;

/**
 * 
 * @author <NAME> - Initial contribution and API
 * 
 */
public abstract class AbstractSCTLaunchConfigurationDelegate extends LaunchConfigurationDelegate implements
			ILaunchConfigurationDelegate {

	public String FILE_NAME = "filename";
	public String DEFAULT_FILE_NAME = "";

	protected abstract ISimulationEngine createExecutionContainer(ILaunch launch, Statechart statechart);

	@Override
	public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
			throws CoreException {
		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
		URI uri = URI.createPlatformResourceURI(filename, true);
		if (!URIConverter.INSTANCE.exists(uri, Collections.emptyMap()))
			return false;
		return super.preLaunchCheck(configuration, mode, monitor);
	}

	public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
			throws CoreException {
		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
		Statechart statechart = loadStatechart(filename);
		SCTDebugTarget target = createDebugTarget(launch, statechart);
		launch.addDebugTarget(target);
		target.init();
		target.start();
	}

	protected SCTDebugTarget createDebugTarget(ILaunch launch, Statechart statechart) throws CoreException {
		Assert.isNotNull(statechart);
		return new SCTDebugTarget(launch, statechart, createExecutionContainer(launch, statechart));
	}

	protected Statechart loadStatechart(String filename) {
		return ResourceUtil.loadStatechart(filename);
	}

	@Override
	protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode)
			throws CoreException {
		String filename = configuration.getAttribute(FILE_NAME, "");
		IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filename);
		return new IProject[] { resource.getProject() };

	}

	@Override
	public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
			throws CoreException {
		// Never build the workspace before simulation
		return false;
	}

	@Override
	protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
		return getProjectsForProblemSearch(configuration, mode);
	}
}
{'fraction_non_alphanumeric': 0.08696261027867246, 'fraction_numerical': 0.0028007281893292256, 'mean_word_length': 6.078295341922696, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '266047', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1927, 'n_words': 472}