Search in sources :

Example 31 with EClassifier

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

the class ChangeSerializerWithEmfTest method testChangeRefToXML.

@Test
public void testChangeRefToXML() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#21 MyPackage.MyClass1");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder_1.newLine();
    _builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"#//MyClass2\"/>");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass2\"/>");
    _builder_1.newLine();
    _builder_1.append("</ecore:EPackage>");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final EClassRef model = this._changeSerializerTestHelper.<EClassRef>contents(rs, "inmemory:/file1.pstl", EClassRef.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<EClassRef> _function = (EClassRef it) -> {
        EClassifier _get = model.getRef().getEPackage().getEClassifiers().get(1);
        model.setRef(((EClass) _get));
    };
    serializer.<EClassRef>addModification(model, _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#21 <4:18|MyPackage.MyClass2>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.MyClass2\"");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : EClassRef(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.EClassRef) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 32 with EClassifier

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

the class ChangeSerializerWithEmfTest method testChangeInXML.

@Test
public void testChangeInXML() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#21 MyPackage.MyClass1");
    Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder_1.newLine();
    _builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\"/>");
    _builder_1.newLine();
    _builder_1.append("</ecore:EPackage>");
    _builder_1.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
    this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
    final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
    final EPackage model = this._changeSerializerTestHelper.<EPackage>contents(rs, "inmemory:/file2.ecore", EPackage.class);
    final ChangeSerializer serializer = this.serializerProvider.get();
    final IChangeSerializer.IModification<EPackage> _function = (EPackage it) -> {
        EClassifier _head = IterableExtensions.<EClassifier>head(model.getEClassifiers());
        ((EClass) _head).setName("NewClass");
    };
    serializer.<EPackage>addModification(model, _function);
    Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("---------------------------- inmemory:/file2.ecore -----------------------------");
    _builder_2.newLine();
    _builder_2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder_2.newLine();
    _builder_2.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
    _builder_2.newLine();
    _builder_2.append("    ");
    _builder_2.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
    _builder_2.newLine();
    _builder_2.append("  ");
    _builder_2.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"NewClass\"/>");
    _builder_2.newLine();
    _builder_2.append("</ecore:EPackage>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
    _builder_2.newLine();
    _builder_2.append("#21 <4:18|MyPackage.NewClass>");
    _builder_2.newLine();
    _builder_2.append("--------------------------------------------------------------------------------");
    _builder_2.newLine();
    _builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.NewClass\"");
    _builder_2.newLine();
    this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EClassifier(org.eclipse.emf.ecore.EClassifier) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EPackage(org.eclipse.emf.ecore.EPackage) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 33 with EClassifier

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

the class XtextReferableElementsUnloader method caseEPackage.

private void caseEPackage(EPackage ePackage) {
    // guard against infinite recursion
    // EPackage.eSetProxyURI and friends tries to be smart thus
    // we have to make sure to compute all URIs before they are
    // set
    Resource resource = ePackage.eResource();
    URI resourceURI = resource.getURI();
    List<EClassifier> classifiers = ePackage.getEClassifiers();
    List<URI> uris = new ArrayList<URI>(classifiers.size());
    for (int i = 0, size = classifiers.size(); i < size; i++) {
        uris.add(resourceURI.appendFragment(resource.getURIFragment(classifiers.get(i))));
    }
    // and we have to set them in a proper order
    unload(ePackage);
    for (int i = 0, size = classifiers.size(); i < size; i++) {
        InternalEObject classifier = (InternalEObject) classifiers.get(i);
        classifier.eSetProxyURI(uris.get(i));
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) URI(org.eclipse.emf.common.util.URI) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 34 with EClassifier

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

the class EClassifierInfos method getCompatibleTypeNameOf.

public EClassifier getCompatibleTypeNameOf(Collection<EClassifier> classifiers, boolean useParent) {
    final Collection<EClassifierInfo> types = Sets.newLinkedHashSet();
    for (EClassifier classifier : classifiers) {
        final EClassifierInfo info = getInfoOrNull(classifier);
        if (info == null)
            return null;
        types.add(info);
    }
    final EClassifierInfo compatibleType = getCompatibleTypeOf(types);
    if (compatibleType != null)
        return compatibleType.getEClassifier();
    return GrammarUtil.findEObject(grammar);
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 35 with EClassifier

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

the class TypeHierarchyHelper method pushFeaturesUp.

private void pushFeaturesUp(EClassInfo info, Collection<EClass> traversedClasses) {
    EClass eClass = info.getEClass();
    if (info.isGenerated()) {
        if (traversedClasses.add(eClass)) {
            if (eClass.getESuperTypes().isEmpty())
                return;
            for (EClass superType : eClass.getESuperTypes()) {
                EClassInfo superInfo = (EClassInfo) infos.getInfoOrNull(superType);
                pushFeaturesUp(superInfo, traversedClasses);
            }
            Map<String, EStructuralFeature> allFeatures = Maps.newLinkedHashMap();
            Set<String> skippedNames = Sets.newLinkedHashSet();
            for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
                if (feature.getEContainingClass() != eClass) {
                    if (allFeatures.containsKey(feature.getName())) {
                        allFeatures.remove(feature.getName());
                    } else if (skippedNames.add(feature.getName())) {
                        allFeatures.put(feature.getName(), feature);
                    }
                }
            }
            Iterator<EStructuralFeature> iter = eClass.getEStructuralFeatures().iterator();
            while (iter.hasNext()) {
                EStructuralFeature declared = iter.next();
                EStructuralFeature existing = allFeatures.get(declared.getName());
                if (existing != null) {
                    EClassifier compatibleType = EcoreUtil2.getCompatibleType(declared.getEType(), existing.getEType(), grammar);
                    if (compatibleType != null) {
                        iter.remove();
                        existing.setEType(compatibleType);
                    }
                }
            }
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)192 EClass (org.eclipse.emf.ecore.EClass)132 Test (org.junit.Test)81 EPackage (org.eclipse.emf.ecore.EPackage)75 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)61 EObject (org.eclipse.emf.ecore.EObject)23 EReference (org.eclipse.emf.ecore.EReference)21 AbstractRule (org.eclipse.xtext.AbstractRule)19 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)18 Grammar (org.eclipse.xtext.Grammar)16 EDataType (org.eclipse.emf.ecore.EDataType)13 XtextResource (org.eclipse.xtext.resource.XtextResource)12 AbstractElement (org.eclipse.xtext.AbstractElement)11 EEnum (org.eclipse.emf.ecore.EEnum)8 ParserRule (org.eclipse.xtext.ParserRule)8 EAttribute (org.eclipse.emf.ecore.EAttribute)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 Assignment (org.eclipse.xtext.Assignment)7 ArrayList (java.util.ArrayList)6