blob: 85a8425347da622e550ab58f1a0296cef65eaa53 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/**
* Copyright (c) 2011-2012 Eclipse contributors 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.emf.test.ecore.xcore.scoping;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
import org.eclipse.emf.test.ecore.xcore.legacy_xpect_runner.InjectParameter;
import org.eclipse.emf.test.ecore.xcore.legacy_xpect_runner.Offset;
import org.eclipse.emf.test.ecore.xcore.legacy_xpect_runner.ParameterSyntax;
import org.eclipse.emf.test.ecore.xcore.legacy_xpect_runner.ParameterizedXtextRunner;
import org.eclipse.emf.test.ecore.xcore.legacy_xpect_runner.ResourceURIs;
import org.eclipse.emf.test.ecore.xcore.legacy_xpect_runner.XpectCommaSeparatedValues;
import org.eclipse.xtext.junit4.InjectWith;
import org.eclipse.xtext.junit4.validation.ValidationTestHelper;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.IScopeProvider;
import org.eclipse.xtext.util.Pair;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
@InjectWith(XcoreInjectorProvider.class)
@RunWith(ParameterizedXtextRunner.class)
@ResourceURIs(baseDir = "test-models/org/eclipse/emf/test/ecore/xcore/scoping", fileExtensions = "xcore")
public class XcoreScopingTest
{
@InjectParameter
private XtextResource resource;
@InjectParameter
private Offset offset;
@Inject
private ValidationTestHelper validationHelper;
@Inject
private IScopeProvider scopeProvider;
@Test
public void noValidationIssues()
{
validationHelper.assertNoIssues(resource.getContents().get(0));
}
@XpectCommaSeparatedValues()
@ParameterSyntax("'at' offset=OFFSET")
public List<String> scopeAllElements()
{
Pair<EObject, EStructuralFeature> objAndFeature = offset.getEStructuralFeatureByParent();
Assert.assertTrue(objAndFeature.getSecond() instanceof EReference);
Assert.assertFalse(((EReference)objAndFeature.getSecond()).isContainment());
IScope scope = scopeProvider.getScope(objAndFeature.getFirst(), (EReference)objAndFeature.getSecond());
List<String> result = Lists.newArrayList();
for (IEObjectDescription desc : scope.getAllElements())
result.add(desc.getName().toString());
return result;
}
}
|