<commit_before>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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
 *
 *******************************************************************************/
package org.eclipse.xtext.scoping;

import java.util.Collections;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtext.junit.AbstractXtextTests;
import org.eclipse.xtext.linking.lazy.LazyLinkingTestLanguageStandaloneSetup;
import org.eclipse.xtext.linking.lazy.lazyLinking.LazyLinkingPackage;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import org.eclipse.xtext.scoping.impl.DefaultScopeProvider;
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
import org.eclipse.xtext.scoping.impl.SimpleScope;

/**
 * @author <NAME> - Initial contribution and API
 * 
 */
public class DeclarativeScopeProviderTest extends AbstractXtextTests {
	@SuppressWarnings("unused")
	public void testSimple() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return a;
			}
		};

		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(a, provider.getScope(details, details));
	}
	
	
	public void testFallBack() throws Exception {
		with(new LazyLinkingTestLanguageStandaloneSetup());
		EObject model = getModelAndExpect("type Foo", 1);
		IScopeProvider provider = getScopeProvider();
		IScope scope = provider.getScope(model, LazyLinkingPackage.eINSTANCE.getType());
		assertEquals("Foo",scope.getAllContents().iterator().next().name());
	}

	@SuppressWarnings("unused")
	public void testNested() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());

		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return a;
			}

			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};

		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(b, provider.getScope(details, details));
		assertEquals(a, provider.getScope(details.getEContainingClass(), details));
	}

	@SuppressWarnings("unused")
	public void testPolymorphic() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());

		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClassifier clazz, EClass ref) {
				return a;
			}

			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}

			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};

		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(b, provider.getScope(details, details));
		assertEquals(c, provider.getScope(details.getEContainingClass(), details));
	}

	@SuppressWarnings("unused")
	public void testScopeByType() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClassifier clazz, EClass ref) {
				return a;
			}

			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}

			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};
		DefaultScopeProvider defaultScopeProvider = new DefaultScopeProvider();
		defaultScopeProvider.setImportUriResolver(new ImportUriResolver());
		provider.setGenericFallBack(defaultScopeProvider);
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource res = new XMIResourceFactoryImpl().createResource(URI.createURI("test.uri"));
		resourceSet.getResources().add(res);
		EReference details = EcoreUtil.copy(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
		res.getContents().add(details);
		assertNotNull(provider.getScope(details, details.eClass()));
	}
	
	@SuppressWarnings("unused")
	public void testScopeByReference() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
				return a;
			}
			
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}
			
			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};
		
		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(a, provider.getScope(details, details));
		assertEquals(a, provider.getScope(details.getEContainingClass(), details));
	}
	
	@SuppressWarnings("unused")
	public void testScopeByReference2() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClassifier clazz, EReference ref) {
				return a;
			}
			
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}
			
			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};
		
		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(b, provider.getScope(details, details));
		assertEquals(c, provider.getScope(details.getEContainingClass(), details));
	}
}
<commit_msg>Fix: Compiled accidently against a newer version of EMF<commit_after>/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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
 *
 *******************************************************************************/
package org.eclipse.xtext.scoping;

import java.util.Collections;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtext.junit.AbstractXtextTests;
import org.eclipse.xtext.linking.lazy.LazyLinkingTestLanguageStandaloneSetup;
import org.eclipse.xtext.linking.lazy.lazyLinking.LazyLinkingPackage;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import org.eclipse.xtext.scoping.impl.DefaultScopeProvider;
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
import org.eclipse.xtext.scoping.impl.SimpleScope;

/**
 * @author <NAME> - Initial contribution and API
 * 
 */
public class DeclarativeScopeProviderTest extends AbstractXtextTests {
	@SuppressWarnings("unused")
	public void testSimple() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return a;
			}
		};

		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(a, provider.getScope(details, details));
	}
	
	
	public void testFallBack() throws Exception {
		with(new LazyLinkingTestLanguageStandaloneSetup());
		EObject model = getModelAndExpect("type Foo", 1);
		IScopeProvider provider = getScopeProvider();
		IScope scope = provider.getScope(model, LazyLinkingPackage.eINSTANCE.getType());
		assertEquals("Foo",scope.getAllContents().iterator().next().name());
	}

	@SuppressWarnings("unused")
	public void testNested() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());

		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return a;
			}

			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};

		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(b, provider.getScope(details, details));
		assertEquals(a, provider.getScope(details.getEContainingClass(), details));
	}

	@SuppressWarnings("unused")
	public void testPolymorphic() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());

		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClassifier clazz, EClass ref) {
				return a;
			}

			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}

			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};

		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(b, provider.getScope(details, details));
		assertEquals(c, provider.getScope(details.getEContainingClass(), details));
	}

	@SuppressWarnings("unused")
	public void testScopeByType() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClassifier clazz, EClass ref) {
				return a;
			}

			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}

			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};
		DefaultScopeProvider defaultScopeProvider = new DefaultScopeProvider();
		defaultScopeProvider.setImportUriResolver(new ImportUriResolver());
		provider.setGenericFallBack(defaultScopeProvider);
		ResourceSet resourceSet = new ResourceSetImpl();
		Resource res = new XMIResourceFactoryImpl().createResource(URI.createURI("test.uri"));
		resourceSet.getResources().add(res);
		EReference details = (EReference) EcoreUtil.copy(EcorePackage.eINSTANCE.getEClass_ESuperTypes());
		res.getContents().add(details);
		assertNotNull(provider.getScope(details, details.eClass()));
	}
	
	@SuppressWarnings("unused")
	public void testScopeByReference() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
				return a;
			}
			
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}
			
			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};
		
		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(a, provider.getScope(details, details));
		assertEquals(a, provider.getScope(details.getEContainingClass(), details));
	}
	
	@SuppressWarnings("unused")
	public void testScopeByReference2() throws Exception {
		final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IScopedElement> emptySet());
		AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
			private IScope scope_EClass(EClassifier clazz, EReference ref) {
				return a;
			}
			
			private IScope scope_EClass(EClass clazz, EClass ref) {
				return c;
			}
			
			private IScope scope_EClass(EReference ctx, EClass ref) {
				return b;
			}
		};
		
		EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
		assertEquals(b, provider.getScope(details, details));
		assertEquals(c, provider.getScope(details.getEContainingClass(), details));
	}
}

{'fraction_non_alphanumeric': 0.12205508620097534, 'fraction_numerical': 0.0013737207225771, 'mean_word_length': 5.678899082568807, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '685620', 'n_tokens_mistral': 4724, 'n_tokens_neox': 4405, 'n_words': 927}