Search in sources :

Example 51 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class GrammarUtilTest method testFindCurrentType_06.

@Test
public void testFindCurrentType_06() 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 returns Rule:\n" + "    name=ID Fragment?\n" + ";\n";
    XtextResource r = getResourceFromString(model);
    Grammar grammar = (Grammar) r.getContents().get(0);
    AbstractRule rule = Iterables.getLast(grammar.getRules());
    AbstractElement fragmentCall = Iterables.getLast(((Group) rule.getAlternatives()).getElements());
    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)

Example 52 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class GrammarUtilTest method testFindCurrentType_03.

@Test
public void testFindCurrentType_03() 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("SubRule", currentType.getName());
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 53 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class GrammarUtilTest method testFindCurrentType_01.

@Test
public void testFindCurrentType_01() 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;\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)

Example 54 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class TypeRefImpl method setClassifier.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setClassifier(EClassifier newClassifier) {
    EClassifier oldClassifier = classifier;
    classifier = newClassifier;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, XtextTestPackage.TYPE_REF__CLASSIFIER, oldClassifier, classifier));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 55 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class EMFGeneratorFragment2 method findAllUsedEPackages.

private Map<String, EPackage> findAllUsedEPackages(final List<EPackage> generatedPackages) {
    final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap();
    final TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
    while (packageContentIterator.hasNext()) {
        {
            final EObject current = packageContentIterator.next();
            EList<EObject> _eCrossReferences = current.eCrossReferences();
            for (final EObject referenced : _eCrossReferences) {
                {
                    boolean _eIsProxy = referenced.eIsProxy();
                    if (_eIsProxy) {
                        throw new RuntimeException(((("Unresolved proxy: " + referenced) + " in ") + current));
                    }
                    if ((referenced instanceof EClassifier)) {
                        final EPackage referencedPackage = ((EClassifier) referenced).getEPackage();
                        boolean _contains = generatedPackages.contains(referencedPackage);
                        boolean _not = (!_contains);
                        if (_not) {
                            result.put(referencedPackage.getNsURI(), referencedPackage);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

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