Search in sources :

Example 96 with EClassifier

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());
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) Test(org.junit.Test)

Example 97 with EClassifier

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);
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) Test(org.junit.Test)

Example 98 with EClassifier

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));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 99 with EClassifier

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) CrossReference(org.eclipse.xtext.CrossReference) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet)

Example 100 with EClassifier

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());
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5