<commit_before>/*
 * generated by Xtext
 */
package org.boomslang.dsl.feature.scoping

import com.google.inject.Inject
import com.wireframesketcher.model.Screen
import org.boomslang.dsl.feature.feature.BScenario
import org.boomslang.dsl.feature.feature.BWidgetWrapper
import org.boomslang.dsl.feature.feature.FeaturePackage
import org.boomslang.dsl.feature.services.WidgetTypeRefUtil
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.eclipse.xtext.scoping.impl.FilteringScope

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation.html#scoping
 * on how and when to use it 
 *
 */
class FeatureScopeProvider extends AbstractDeclarativeScopeProvider {

	@Inject extension WidgetTypeRefUtil

	def IScope scope_BStringOrParam_param(EObject ctx, EReference ref) {
		allowParamOfParentScenario(ctx, ref)
	}
	
	def IScope scope_BIntOrParam_param(EObject ctx, EReference ref) {
		allowParamOfParentScenario(ctx, ref)
	}

	def IScope scope_BIntOrStringOrParam_param(EObject ctx, EReference ref) {
		allowParamOfParentScenario(ctx, ref)
	}

	def IScope scope_BWidgetWrapper_widget(BWidgetWrapper ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}

	def IScope scope_BWidgetWrapper_widget(EObject ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}


	def IScope scope_BComboWrapper_list(EObject ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}
	
	def IScope scope_BTreeWrapper_tree(EObject ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}

	/**
	 * Elements in the DSL may 
	 * 1) be contained inside of BWidgetContainers and 
	 * 2) reference wireframe model elements
	 * If that is the case, only wireframe model elements of the WidgetContainer of the BWidgetContainer are allowed.
	 * If the BWidgetContainer does not reference any WidgetContainer, the BWidgetContainer of the BWidgetContainer
	 * will be checked (e.g. a BPostCondition (a BWidgetContainer) is contained in BTestCode (also a BWidgetContainer).
	 * 
	 * This method filters the default scope containing wireframe model elements so that only model elements are allowed 
	 * that have the same WidgetContainer as the given dslObject.
	 * Same
	 * @param dslObject - an object in the DSL that is contained (directly or indirectly) in a BWidgetContainer
	 * @param ref - the dslObject's reference to a wireframe model element
	 */
	def IScope allowElementsInItsBWidgetContainer(EObject dslObject, EReference ref) {
		val originalScope = delegateGetScope(dslObject, ref)
		
		//TODO make the widgetContainerOfNearestContext method return a list. 
		val allowedWidgetContainer = dslObject.widgetContainerOfNearestContext

		if (allowedWidgetContainer == null) {
			return IScope.NULLSCOPE
		}

		return new FilteringScope(originalScope,
			[ candidate |
				val objectOrProxy = candidate.EObjectOrProxy
				val EObject candidateEObject = if (objectOrProxy.eIsProxy) {
						EcoreUtil.resolve(objectOrProxy, dslObject);
					} else {
						objectOrProxy
					}
				val candidateContainer = EcoreUtil2.getContainerOfType(candidateEObject, Screen)
				return  allowedWidgetContainer.contains(candidateContainer)
			])<commit_msg>TODO to make widgetContainerOfNearestContext return a list done<commit_after>/*
 * generated by Xtext
 */
package org.boomslang.dsl.feature.scoping

import com.google.inject.Inject
import com.wireframesketcher.model.Screen
import org.boomslang.dsl.feature.feature.BScenario
import org.boomslang.dsl.feature.feature.BWidgetWrapper
import org.boomslang.dsl.feature.feature.FeaturePackage
import org.boomslang.dsl.feature.services.WidgetTypeRefUtil
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.eclipse.xtext.scoping.impl.FilteringScope

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation.html#scoping
 * on how and when to use it 
 *
 */
class FeatureScopeProvider extends AbstractDeclarativeScopeProvider {

	@Inject extension WidgetTypeRefUtil

	def IScope scope_BStringOrParam_param(EObject ctx, EReference ref) {
		allowParamOfParentScenario(ctx, ref)
	}
	
	def IScope scope_BIntOrParam_param(EObject ctx, EReference ref) {
		allowParamOfParentScenario(ctx, ref)
	}

	def IScope scope_BIntOrStringOrParam_param(EObject ctx, EReference ref) {
		allowParamOfParentScenario(ctx, ref)
	}

	def IScope scope_BWidgetWrapper_widget(BWidgetWrapper ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}

	def IScope scope_BWidgetWrapper_widget(EObject ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}


	def IScope scope_BComboWrapper_list(EObject ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}
	
	def IScope scope_BTreeWrapper_tree(EObject ctx, EReference ref) {
		allowElementsInItsBWidgetContainer(ctx, ref)
	}

	/**
	 * Elements in the DSL may 
	 * 1) be contained inside of BWidgetContainers and 
	 * 2) reference wireframe model elements
	 * If that is the case, only wireframe model elements of the WidgetContainer of the BWidgetContainer are allowed.
	 * If the BWidgetContainer does not reference any WidgetContainer, the BWidgetContainer of the BWidgetContainer
	 * will be checked (e.g. a BPostCondition (a BWidgetContainer) is contained in BTestCode (also a BWidgetContainer).
	 * 
	 * This method filters the default scope containing wireframe model elements so that only model elements are allowed 
	 * that have the same WidgetContainer as the given dslObject.
	 * Same
	 * @param dslObject - an object in the DSL that is contained (directly or indirectly) in a BWidgetContainer
	 * @param ref - the dslObject's reference to a wireframe model element
	 */
	def IScope allowElementsInItsBWidgetContainer(EObject dslObject, EReference ref) {
		val originalScope = delegateGetScope(dslObject, ref)
		
		val allowedWidgetContainer = dslObject.widgetContainerOfNearestContext

		if (allowedWidgetContainer == null) {
			return IScope.NULLSCOPE
		}

		return new FilteringScope(originalScope,
			[ candidate |
				val objectOrProxy = candidate.EObjectOrProxy
				val EObject candidateEObject = if (objectOrProxy.eIsProxy) {
						EcoreUtil.resolve(objectOrProxy, dslObject);
					} else {
						objectOrProxy
					}
				val candidateContainer = EcoreUtil2.getContainerOfType(candidateEObject, Screen)
				return  allowedWidgetContainer.contains(candidateContainer)
			])
{'fraction_non_alphanumeric': 0.0674793208532869, 'fraction_numerical': 0.0011609345523146133, 'mean_word_length': 5.066901408450704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6024348', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2027, 'n_words': 545}