use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class NamesAreUniqueValidationHelperTest method testCreatedErrors_02.
@SuppressWarnings("deprecation")
@Test
public void testCreatedErrors_02() {
maxCallCount = 0;
ImmutableList<EClassifier> classifiers = ImmutableList.of(createEClass(), createEDataType());
for (EClassifier classifier : classifiers) {
classifier.setName("Same");
}
expected.addAll(classifiers);
helper.checkUniqueNames(Scopes.scopedElementsFor(classifiers), this, this);
assertEquals(classifiers.size(), callCount);
assertTrue(expected.isEmpty());
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class EcoreGenericsTest method testReferenceType.
@Test
public void testReferenceType() throws Exception {
EcoreGenericsUtil ecoreGenericsUtil = new EcoreGenericsUtil();
EClassifier referenceType = ecoreGenericsUtil.getReferenceType(GenericTestPackage.Literals.A__SOME_REFERENCE, GenericTestPackage.Literals.D);
assertEquals(GenericTestPackage.Literals.SOME_TYPE, referenceType);
referenceType = ecoreGenericsUtil.getReferenceType(GenericTestPackage.Literals.A__SOME_REFERENCE1, GenericTestPackage.Literals.D);
assertEquals(GenericTestPackage.Literals.SOME_TYPE, referenceType);
referenceType = ecoreGenericsUtil.getReferenceType(GenericTestPackage.Literals.B__OTHER_REFERENCE, GenericTestPackage.Literals.D);
assertEquals(GenericTestPackage.Literals.OTHER_TYPE, referenceType);
referenceType = ecoreGenericsUtil.getReferenceType(GenericTestPackage.Literals.B__OTHER_REFERENCE1, GenericTestPackage.Literals.D);
assertEquals(GenericTestPackage.Literals.A, referenceType);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class DeclarativeScopeProviderTest method testScopeByType.
@SuppressWarnings("unused")
@Test
public void testScopeByType() throws Exception {
final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
private IScope scope_EClass(EClassifier clazz, EReference ref) {
return a;
}
private IScope scope_EClass(EClass clazz, EReference ref) {
return b;
}
private IScope scope_EClass(EReference ctx, EReference ref) {
return c;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
assertEquals(a, provider.getScope(EcorePackage.eINSTANCE.getEShort(), details));
assertEquals(b, provider.getScope(details.getEContainingClass(), details));
assertEquals(c, provider.getScope(details, details));
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class AbstractElementFinder method findCrossReferences.
public List<CrossReference> findCrossReferences(EClassifier... targetEClassifiers) {
Set<EClassifier> classifiers = new HashSet<EClassifier>(Arrays.asList(targetEClassifiers));
Collection<EClass> classes = Lists.newArrayList(Iterables.filter(classifiers, EClass.class));
ArrayList<CrossReference> r = new ArrayList<CrossReference>();
for (AbstractRule ar : getRules()) {
TreeIterator<EObject> i = ar.eAllContents();
while (i.hasNext()) {
EObject o = i.next();
if (o instanceof CrossReference) {
CrossReference c = (CrossReference) o;
if (classifiers.contains(c.getType().getClassifier()))
r.add(c);
else if (c.getType().getClassifier() instanceof EClass)
for (EClass cls : classes) if (EcoreUtil2.isAssignableFrom(cls, (EClass) c.getType().getClassifier())) {
r.add(c);
break;
}
i.prune();
}
}
}
return r;
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_04.
@Test
public void testFindCurrentType_04() throws Exception {
with(XtextStandaloneSetup.class);
String model = "grammar myLang with org.eclipse.xtext.common.Terminals\n" + "generate g 'http://1'\n" + "Rule:\n" + " Fragment;\n" + "fragment Fragment: name=ID SecondFragment?;\n" + "fragment SecondFragment: {SubRule.named=current} value=ID;\n";
XtextResource r = getResourceFromString(model);
Grammar grammar = (Grammar) r.getContents().get(0);
AbstractRule rule = Iterables.getFirst(grammar.getRules(), null);
AbstractElement fragmentCall = rule.getAlternatives();
EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("Rule", currentType.getName());
}
Aggregations