Search in sources :

Example 6 with GenModel

use of org.eclipse.emf.codegen.ecore.genmodel.GenModel in project xtext-core by eclipse.

the class AbstractPortableURIsTest method doTestResource.

protected void doTestResource(String platformPath, String... packageNames) {
    Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
    assertNotNull(resource);
    assertEquals(1, resource.getContents().size());
    EObject obj = resource.getContents().get(0);
    if (obj instanceof EPackage) {
        assertEquals(packageNames[0], ((EPackage) obj).getName());
    } else if (obj instanceof GenModel) {
        GenModel model = (GenModel) obj;
        List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
        assertEquals(packageNames.length, packages.size());
        ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {

            @Override
            public String apply(GenPackage p) {
                return p.getEcorePackage().getName();
            }
        });
        List<String> packageNamesList = Arrays.asList(packageNames);
        Collections.sort(packageNamesList);
        for (int i = 0; i < packageNamesList.size(); i++) {
            assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
        }
        IStatus status = model.validate();
        assertTrue(printLeafs(status), status.isOK());
        EObject orig = EcoreUtil.copy(obj);
        ((GenModel) obj).reconcile();
        if (!EcoreUtil.equals(orig, obj)) {
            Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {

                @Override
                public boolean apply(EStructuralFeature f) {
                    if (f instanceof EReference) {
                        EReference casted = (EReference) f;
                        return !casted.isContainment();
                    }
                    return false;
                }
            };
            String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
            String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
            throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
        }
    } else {
        fail("Unexpected root element type: " + obj.eClass().getName());
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) EPackage(org.eclipse.emf.ecore.EPackage) Predicate(com.google.common.base.Predicate) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) GenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with GenModel

use of org.eclipse.emf.codegen.ecore.genmodel.GenModel in project xtext-core by eclipse.

the class GenModelUtil2 method getGenPackage.

public static GenPackage getGenPackage(final EPackage pkg, final ResourceSet resourceSet) {
    final String nsURI = pkg.getNsURI();
    String location = null;
    Resource _eResource = pkg.eResource();
    URI _uRI = null;
    if (_eResource != null) {
        _uRI = _eResource.getURI();
    }
    boolean _tripleNotEquals = (_uRI != null);
    if (_tripleNotEquals) {
        location = pkg.eResource().getURI().toString();
    }
    final Resource genModelResource = GenModelUtil2.getGenModelResource(location, nsURI, resourceSet);
    if ((genModelResource != null)) {
        EList<EObject> _contents = genModelResource.getContents();
        for (final EObject model : _contents) {
            if ((model instanceof GenModel)) {
                final GenPackage genPkg = ((GenModel) model).findGenPackage(pkg);
                if ((genPkg != null)) {
                    genPkg.getEcorePackage().getEClassifiers();
                    return genPkg;
                }
            }
        }
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("No GenPackage for NsURI ");
        _builder.append(nsURI);
        _builder.append(" found in ");
        URI _uRI_1 = genModelResource.getURI();
        _builder.append(_uRI_1);
        throw new RuntimeException(_builder.toString());
    }
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("No GenPackage for NsURI ");
    _builder_1.append(nsURI);
    _builder_1.append(".");
    throw new RuntimeException(_builder_1.toString());
}
Also used : EObject(org.eclipse.emf.ecore.EObject) GenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel) Resource(org.eclipse.emf.ecore.resource.Resource) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) URI(org.eclipse.emf.common.util.URI)

Aggregations

GenModel (org.eclipse.emf.codegen.ecore.genmodel.GenModel)7 GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)7 EObject (org.eclipse.emf.ecore.EObject)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 EPackage (org.eclipse.emf.ecore.EPackage)4 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)4 URI (org.eclipse.emf.common.util.URI)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 Predicate (com.google.common.base.Predicate)2 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 EReference (org.eclipse.emf.ecore.EReference)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 ComparisonFailure (org.junit.ComparisonFailure)2 GenModelImpl (org.eclipse.emf.codegen.ecore.genmodel.impl.GenModelImpl)1 GenPackageImpl (org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 GenModelHelper (org.eclipse.emf.mwe.utils.GenModelHelper)1 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1