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

import org.eclipse.emf.ecore.EReference
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.impl.ScopeBasedSelectable
import org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider
import org.testeditor.tcl.TclModel

public class TclDelegateScopeProvider extends XImportSectionNamespaceScopeProvider {

	override getResourceScope(IScope globalScope, Resource resource, EReference reference) {
		var IScope result = globalScope
		val globalScopeSelectable = new ScopeBasedSelectable(result)
		val normalizers = getImplicitImports(isIgnoreCase(reference))

		// Custom code START
		val head = resource.contents.head
		if (head instanceof TclModel) {
			normalizers += doCreateImportNormalizer(head.qualifiedNameOfLocalElement, true, false)
		}
		// Custom code END
		if (!normalizers.isEmpty()) {
			result = createImportScope(result, normalizers, globalScopeSelectable, reference.getEReferenceType(),
				isIgnoreCase(reference))
		}<commit_msg>TE-413 Set package declaration from file structure<commit_after>package org.testeditor.tcl.dsl.scoping

import org.eclipse.emf.ecore.EReference
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.impl.ScopeBasedSelectable
import org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider
import org.testeditor.tcl.TclModel
import javax.inject.Inject
import org.testeditor.dsl.common.util.ClasspathUtil

public class TclDelegateScopeProvider extends XImportSectionNamespaceScopeProvider {

	@Inject ClasspathUtil classpathUtil

	override getResourceScope(IScope globalScope, Resource resource, EReference reference) {
		var IScope result = globalScope
		val globalScopeSelectable = new ScopeBasedSelectable(result)
		val normalizers = getImplicitImports(isIgnoreCase(reference))

		// Custom code START
		val head = resource.contents.head
		if (head instanceof TclModel) {
			if(head.package == null){
				head.package = classpathUtil.inferPackage(head)
			} 
			normalizers += doCreateImportNormalizer(head.qualifiedNameOfLocalElement, true, false)
		}
		// Custom code END
		if (!normalizers.isEmpty()) {
			result = createImportScope(result, normalizers, globalScopeSelectable, reference.getEReferenceType(),
				isIgnoreCase(reference))
		}
{'fraction_non_alphanumeric': 0.08038317367763433, 'fraction_numerical': 0.0012494793835901709, 'mean_word_length': 6.002915451895044, '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': '2282046', 'n_tokens_mistral': 737, 'n_tokens_neox': 690, 'n_words': 141}