<commit_before>package fr.inria.diverse.melange.ui.menu

import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.commands.ExecutionException
import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.OperationCanceledException
import org.eclipse.core.runtime.Status
import org.eclipse.core.runtime.jobs.Job
import org.eclipse.jface.viewers.IStructuredSelection
import org.eclipse.ui.handlers.HandlerUtil

class CleanAll extends AbstractHandler {
	override execute(ExecutionEvent event) throws ExecutionException {
		new Job("Melange: Cleaning all generated artifacts") {
			override run(IProgressMonitor monitor) {
				try {
					monitor.beginTask("Cleaning all generated artifacts", IProgressMonitor.UNKNOWN)
					val sel = HandlerUtil.getActiveMenuSelection(event)
					val selection = sel as IStructuredSelection
					val resource = selection.firstElement as IResource
					val project = resource.project

					val srcGenFolder = project.getFolder("src-gen/")
					val modelGenFolder = project.getFolder("model-gen/")

					if (srcGenFolder.exists)
						srcGenFolder.members.forEach[delete(true, monitor)]
					if (modelGenFolder.exists)
						modelGenFolder.members.forEach[delete(true, monitor)]
				} catch (OperationCanceledException e) {
					return Status.CANCEL_STATUS
				} finally {
					monitor.done
				}

				return Status.OK_STATUS
			}
		}.schedule

		return null
	}
}<commit_msg>'CleanAll' action: also delete generated runtime projects of languages<commit_after>package fr.inria.diverse.melange.ui.menu

import com.google.inject.Inject
import fr.inria.diverse.melange.ast.LanguageExtensions
import fr.inria.diverse.melange.metamodel.melange.Language
import fr.inria.diverse.melange.metamodel.melange.ModelTypingSpace
import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.commands.ExecutionException
import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.OperationCanceledException
import org.eclipse.core.runtime.Status
import org.eclipse.core.runtime.jobs.Job
import org.eclipse.emf.common.util.URI
import org.eclipse.jface.viewers.IStructuredSelection
import org.eclipse.ui.handlers.HandlerUtil
import org.eclipse.xtext.resource.DerivedStateAwareResource
import org.eclipse.xtext.ui.resource.XtextResourceSetProvider

class CleanAll extends AbstractHandler {
	@Inject extension LanguageExtensions
	@Inject XtextResourceSetProvider rsProvider

	override execute(ExecutionEvent event) throws ExecutionException {
		new Job("Melange: Cleaning all generated artifacts") {
			override run(IProgressMonitor monitor) {
				try {
					monitor.beginTask("Cleaning all generated artifacts", IProgressMonitor.UNKNOWN)
					val sel = HandlerUtil.getActiveMenuSelection(event)
					val selection = sel as IStructuredSelection
					val resource = selection.firstElement as IResource
					val project = resource.project

					val srcGenFolder = project.getFolder("src-gen/")
					val modelGenFolder = project.getFolder("model-gen/")

					if (srcGenFolder.exists)
						srcGenFolder.members.forEach[delete(true, monitor)]
					if (modelGenFolder.exists)
						modelGenFolder.members.forEach[delete(true, monitor)]

					val rs = rsProvider.get(project)
					val res = rs.getResource(URI::createPlatformResourceURI(resource.fullPath.toString, true), true) as DerivedStateAwareResource
					val root = res.contents.head as ModelTypingSpace

					root.elements
					.filter(Language)
					.filter[generatedByMelange]
					.forEach[l |
						val runtimeName = l.externalRuntimeName
						val runtimeProject = project.workspace.root.getProject(runtimeName)
						runtimeProject.delete(true, true, monitor)
					]
				} catch (OperationCanceledException e) {
					return Status.CANCEL_STATUS
				} finally {
					monitor.done
				}

				return Status.OK_STATUS
			}
		}.schedule

		return null
	}
}
{'fraction_non_alphanumeric': 0.08409146791246619, 'fraction_numerical': 0.0, 'mean_word_length': 4.5271739130434785, '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': '4049989', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1123, 'n_words': 232}