<commit_before>package org.testeditor.tcl.dsl.validation

import org.eclipse.xtext.validation.Check
import org.testeditor.tcl.MacroCollection
import org.testeditor.tcl.TclModel
import org.testeditor.tcl.TestCase
import org.testeditor.tcl.TestConfiguration

import static org.testeditor.tcl.TclPackage.Literals.*

class FileExtensionValidator extends AbstractTclValidator {

	/**
	 * Checks that the contents of a {@link TclModel} match to the their corresponding
	 * file extension.
	 * 
	 * .tcl => only a {@link TestCase} is allowed
	 * .tml => only a {@link MacroCollection} is allowed
	 * .config => only a {@link TestConfiguration} is allowed
	 */
	@Check
	def void conentsMatchFileExtension(TclModel model) {
		val fileExtension = model.eResource.URI.fileExtension
		switch (fileExtension) {
			case "tcl": {
				model.verifyNoMacroCollection
				model.verifyNoTestConfiguration
			}
			case "tml": {
				model.verifyNoTestCase
				model.verifyNoTestConfiguration
			}
			case "config": {
				model.verifyNoTestCase
				model.verifyNoMacroCollection
			}
			default:
				throw new RuntimeException('''unknown file extension (fileExtensions='«fileExtension»')''')
		}
	}

	private def void verifyNoMacroCollection(TclModel model) {
		if (model.macroCollection != null) {
			error("this file type may only contain test cases but it contains macro definitions", model,
				TCL_MODEL__MACRO_COLLECTION)
		}
	}

	private def void verifyNoTestConfiguration(TclModel model) {
		if (model.config !== null) {
			error("this file type may only contain test cases but it contains a test configuration", model,
				TCL_MODEL__CONFIG)
		}
	}

	private def void verifyNoTestCase(TclModel model) {
		if (model.test != null) {
			error("this file type may only contain macro definitions but it contains test cases", model,
				TCL_MODEL__TEST)
		}
	}

}<commit_msg>get rid of import warnings - FileExtensionValidator should not inherit from XbaseValidator<commit_after>package org.testeditor.tcl.dsl.validation

import java.util.List
import org.eclipse.emf.ecore.EPackage
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
import org.eclipse.xtext.validation.Check
import org.testeditor.tcl.MacroCollection
import org.testeditor.tcl.TclModel
import org.testeditor.tcl.TclPackage
import org.testeditor.tcl.TestCase
import org.testeditor.tcl.TestConfiguration

import static org.testeditor.tcl.TclPackage.Literals.*

class FileExtensionValidator extends AbstractDeclarativeValidator {

	override protected List<EPackage> getEPackages() {
		return #[TclPackage.eINSTANCE]
	}

	/**
	 * Checks that the contents of a {@link TclModel} match to the their corresponding
	 * file extension.
	 * 
	 * .tcl => only a {@link TestCase} is allowed
	 * .tml => only a {@link MacroCollection} is allowed
	 * .config => only a {@link TestConfiguration} is allowed
	 */
	@Check
	def void conentsMatchFileExtension(TclModel model) {
		val fileExtension = model.eResource.URI.fileExtension
		switch (fileExtension) {
			case "tcl": {
				model.verifyNoMacroCollection
				model.verifyNoTestConfiguration
			}
			case "tml": {
				model.verifyNoTestCase
				model.verifyNoTestConfiguration
			}
			case "config": {
				model.verifyNoTestCase
				model.verifyNoMacroCollection
			}
			default:
				throw new RuntimeException('''unknown file extension (fileExtensions='«fileExtension»')''')
		}
	}

	private def void verifyNoMacroCollection(TclModel model) {
		if (model.macroCollection != null) {
			error("This file type may not contain macro collections.", model, TCL_MODEL__MACRO_COLLECTION)
		}
	}

	private def void verifyNoTestConfiguration(TclModel model) {
		if (model.config !== null) {
			error("This file type may not contain test configurations.", model, TCL_MODEL__CONFIG)
		}
	}

	private def void verifyNoTestCase(TclModel model) {
		if (model.test != null) {
			error("This file type may not contain test cases.", model, TCL_MODEL__TEST)
		}
	}

}
{'fraction_non_alphanumeric': 0.09100126742712294, 'fraction_numerical': 0.0, 'mean_word_length': 4.368707482993197, 'pattern_counts': {'":': 6, '<': 4, '<?xml version=': 0, '>': 10, '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': '4159084', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1160, 'n_words': 322}