Search in sources :

Example 76 with EClass

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

the class Xtext2EcoreTransformerTest method testBug346685_b01.

@Test
public void testBug346685_b01() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\'");
    String grammar = _builder.toString();
    String _grammar = grammar;
    grammar = (_grammar + " Model: A ({D.a = current} b = B)? c=C? ;\n");
    String _grammar_1 = grammar;
    grammar = (_grammar_1 + " A: {A} \'a\';\n");
    String _grammar_2 = grammar;
    grammar = (_grammar_2 + " B: {B} \'c\';\n");
    String _grammar_3 = grammar;
    grammar = (_grammar_3 + " C: {C} \'b\';\n");
    EPackage ePackage = this.getEPackageFromGrammar(grammar);
    Assert.assertEquals(5, ePackage.getEClassifiers().size());
    EClassifier _type = this.<EClassifier>type(ePackage, "Model");
    EClass typeModel = ((EClass) _type);
    Assert.assertNotNull(typeModel);
    Assert.assertNotNull(this.<EStructuralFeature>feature(typeModel, "c"));
    Assert.assertEquals(1, this.features(typeModel).size());
    EClassifier _type_1 = this.<EClassifier>type(ePackage, "A");
    EClass typeA = ((EClass) _type_1);
    Assert.assertNotNull(typeA);
    Assert.assertTrue(this.features(typeA).isEmpty());
    Assert.assertEquals(1, typeA.getESuperTypes().size());
    Assert.assertSame(typeModel, IterableExtensions.<EClass>head(typeA.getESuperTypes()));
    EClassifier _type_2 = this.<EClassifier>type(ePackage, "B");
    EClass typeB = ((EClass) _type_2);
    Assert.assertNotNull(typeB);
    Assert.assertTrue(this.features(typeB).isEmpty());
    EClassifier _type_3 = this.<EClassifier>type(ePackage, "C");
    EClass typeC = ((EClass) _type_3);
    Assert.assertNotNull(typeC);
    Assert.assertTrue(this.features(typeC).isEmpty());
    EClassifier _type_4 = this.<EClassifier>type(ePackage, "D");
    EClass typeD = ((EClass) _type_4);
    Assert.assertNotNull(typeD);
    Assert.assertNotNull(this.<EStructuralFeature>feature(typeD, "a"));
    Assert.assertNotNull(this.<EStructuralFeature>feature(typeD, "b"));
    Assert.assertEquals(2, this.features(typeD).size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 77 with EClass

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

the class EcoreGenericsUtil method getReferenceType.

public EClass getReferenceType(EReference reference, EClass context) {
    EGenericType genericType = reference.getEGenericType();
    if (genericType == null) {
        return reference.getEReferenceType();
    }
    EGenericType boundGenericType = getBoundGenericType(genericType, context);
    if (boundGenericType.getEClassifier() == null) {
        throw new IllegalStateException("Either typeParameter or eRawType must be set in EGenericType " + genericType);
    }
    return (EClass) boundGenericType.getEClassifier();
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EGenericType(org.eclipse.emf.ecore.EGenericType)

Example 78 with EClass

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

the class Formatter2Fragment2 method doGenerateStubFile.

protected void doGenerateStubFile() {
    boolean _isGenerateStub = this.isGenerateStub();
    boolean _not = (!_isGenerateStub);
    if (_not) {
        return;
    }
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
        final XtendFileAccess xtendFile = this.fileAccessFactory.createXtendFile(this.getFormatter2Stub(this.getGrammar()));
        xtendFile.setResourceSet(this.getLanguage().getResourceSet());
        final LinkedHashMultimap<EClass, EReference> type2ref = LinkedHashMultimap.<EClass, EReference>create();
        this.getLocallyAssignedContainmentReferences(this.getLanguage().getGrammar(), type2ref);
        final LinkedHashMultimap<EClass, EReference> inheritedTypes = LinkedHashMultimap.<EClass, EReference>create();
        this.getInheritedContainmentReferences(this.getLanguage().getGrammar(), inheritedTypes, CollectionLiterals.<Grammar>newHashSet());
        final Set<EClass> types = type2ref.keySet();
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("class ");
                String _simpleName = Formatter2Fragment2.this.getFormatter2Stub(Formatter2Fragment2.this.getGrammar()).getSimpleName();
                _builder.append(_simpleName);
                _builder.append(" extends ");
                TypeReference _stubSuperClass = Formatter2Fragment2.this.getStubSuperClass();
                _builder.append(_stubSuperClass);
                _builder.append(" {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("@");
                _builder.append(Inject.class, "\t");
                _builder.append(" extension ");
                TypeReference _grammarAccess = Formatter2Fragment2.this._grammarAccessExtensions.getGrammarAccess(Formatter2Fragment2.this.getGrammar());
                _builder.append(_grammarAccess, "\t");
                _builder.newLineIfNotEmpty();
                {
                    Iterable<EClass> _take = IterableExtensions.<EClass>take(types, 2);
                    for (final EClass type : _take) {
                        _builder.newLine();
                        _builder.append("\t");
                        StringConcatenationClient _generateFormatMethod = Formatter2Fragment2.this.generateFormatMethod(type, type2ref.get(type), inheritedTypes.containsKey(type));
                        _builder.append(_generateFormatMethod, "\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("// TODO: implement for ");
                final Function1<EClass, String> _function = (EClass it) -> {
                    return it.getName();
                };
                String _join = IterableExtensions.join(IterableExtensions.<EClass, String>map(IterableExtensions.<EClass>drop(types, 2), _function), ", ");
                _builder.append(_join, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
            }
        };
        xtendFile.setContent(_client);
        xtendFile.writeTo(this.getProjectConfig().getRuntime().getSrc());
    } else {
        String _name = this.getClass().getName();
        String _plus = (_name + " has been configured to generate a Java stub, but that\'s not yet supported. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=481563");
        Formatter2Fragment2.LOG.error(_plus);
    }
}
Also used : XtendFileAccess(org.eclipse.xtext.xtext.generator.model.XtendFileAccess) EClass(org.eclipse.emf.ecore.EClass) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) EReference(org.eclipse.emf.ecore.EReference)

Example 79 with EClass

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

the class Ecore2XtextExtensions method subClasses.

public static Iterable<EClass> subClasses(final EClass it) {
    Iterable<EClass> _xifexpression = null;
    EPackage _ePackage = it.getEPackage();
    boolean _tripleEquals = (_ePackage == null);
    if (_tripleEquals) {
        _xifexpression = CollectionLiterals.<EClass>emptyList();
    } else {
        final Function1<EClass, Boolean> _function = (EClass c) -> {
            return Boolean.valueOf(c.getEAllSuperTypes().contains(it));
        };
        _xifexpression = IterableExtensions.<EClass>filter(Iterables.<EClass>filter(it.getEPackage().getEClassifiers(), EClass.class), _function);
    }
    return _xifexpression;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EPackage(org.eclipse.emf.ecore.EPackage)

Example 80 with EClass

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

the class Ecore2XtextExtensions method allConcreteRuleClassifiers.

public static Iterable<EClassifier> allConcreteRuleClassifiers(final Ecore2XtextConfiguration it) {
    Iterable<EClassifier> _xifexpression = null;
    EClass _rootElementClass = it.getRootElementClass();
    boolean _tripleEquals = (_rootElementClass == null);
    if (_tripleEquals) {
        final Function1<EPackageInfo, Set<EClassifier>> _function = (EPackageInfo it_1) -> {
            return Ecore2XtextExtensions.allReferencedClassifiers(it_1.getEPackage(), false);
        };
        final Function1<EClassifier, Boolean> _function_1 = (EClassifier it_1) -> {
            return Boolean.valueOf(Ecore2XtextExtensions.needsConcreteRule(it_1));
        };
        _xifexpression = IterableExtensions.<EClassifier>filter(IterableExtensions.<EClassifier>toSet(Iterables.<EClassifier>concat(IterableExtensions.<EPackageInfo, Set<EClassifier>>map(it.getEPackageInfos(), _function))), _function_1);
    } else {
        Set<EClassifier> _xblockexpression = null;
        {
            final ArrayList<EClassifier> c = CollectionLiterals.<EClassifier>newArrayList(EClassifier.class.cast(it.getRootElementClass()));
            Ecore2XtextExtensions.allAssignedClassifiers(it.getRootElementClass(), c);
            final Function1<EClassifier, Boolean> _function_2 = (EClassifier cl) -> {
                return Boolean.valueOf(Ecore2XtextExtensions.needsConcreteRule(cl));
            };
            _xblockexpression = IterableExtensions.<EClassifier>toSet(IterableExtensions.<EClassifier>filter(c, _function_2));
        }
        _xifexpression = _xblockexpression;
    }
    return _xifexpression;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) Set(java.util.Set) ArrayList(java.util.ArrayList) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackageInfo(org.eclipse.xtext.xtext.wizard.EPackageInfo)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)205 Test (org.junit.Test)99 EPackage (org.eclipse.emf.ecore.EPackage)70 EClassifier (org.eclipse.emf.ecore.EClassifier)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)43 EObject (org.eclipse.emf.ecore.EObject)35 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)27 Resource (org.eclipse.emf.ecore.resource.Resource)23 EReference (org.eclipse.emf.ecore.EReference)22 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)16 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)13 ParserRule (org.eclipse.xtext.ParserRule)12 QualifiedName (org.eclipse.xtext.naming.QualifiedName)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)11 IScope (org.eclipse.xtext.scoping.IScope)11 ArrayList (java.util.ArrayList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 List (java.util.List)9 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9