Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Load HUTN as ecore model
Load HUTN as ecore model [message #1845869] Fri, 08 October 2021 20:34 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

I want use HUTN to write unit tests. So I give a text snippet of the model and want to retrieve the EObject ...

    protected EObject loadHutn(final String content) throws Exception {
        final var ecoreResourceSet = new ResourceSetImpl();
        ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());
        ecoreResourceSet.getPackageRegistry().put(ImPackage.eINSTANCE.getNsURI(), ImPackage.eINSTANCE);

        try (var inModel = new HutnModel("name", content)) {
            // ... ?
            inModel.dispose();
            inModel.close();
        }
        return ecoreResourceSet.getContents().get(0);
    }


How do I get the HutnModel to push the content into the resource set, so I can retrieve the objects?

thanks Frank
Re: Load HUTN as ecore model [message #1846926 is a reply to message #1845869] Sat, 09 October 2021 08:06 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Frank,

inModel.allContents() should return all the EObjects in the HUTN model.

Best,
Dimitris
Re: Load HUTN as ecore model [message #1846928 is a reply to message #1846926] Sat, 09 October 2021 09:14 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
I try it like this, but the collection from allContents is empty:

    static final ImPackage PCK = ImPackage.eINSTANCE;

    protected EObject loadHutn(final String content) throws Exception {
        final var ecoreResourceSet = new ResourceSetImpl();
        ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
                PCK.getNsPrefix(),
                new XMIResourceFactoryImpl());
        ecoreResourceSet.getPackageRegistry().put(PCK.getNsURI(), PCK);

        EObject result = null;
        try (var inModel = new HutnModel("name.im", content)) {
            inModel.load();

            result = (EObject) inModel.allContents().iterator().next(); // java.util.NoSuchElementException here
            inModel.dispose();
        }
        return result;
    }

    @Test
    void testName() throws Exception {

        loadHutn(String.format("""
                @Spec {
                  metamodel "%s" {
                    nsUri: "%s"
                  }
                }

                ImModel {
                }
                """, PCK.getNsPrefix(), PCK.getNsURI()));
}


I expect, that it gives me 1 object back.
Also, when I try to put in child objects, I get parse errors.

Is the connection between my ImPackage and the HutnModel properly established?


[Updated on: Sat, 09 October 2021 09:15]

Report message to a moderator

Re: Load HUTN as ecore model [message #1846929 is a reply to message #1846928] Sat, 09 October 2021 09:16 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Frank,

Could you please share a minimal example [1] I can use to reproduce this?

Many thanks,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/
Re: Load HUTN as ecore model [message #1846945 is a reply to message #1846929] Sat, 09 October 2021 17:57 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Is there an example code which uses a generated ecore package java file and loads HUTN string to create a model?
If such an example exists, this might be more efficient for both of us.
Re: Load HUTN as ecore model [message #1846947 is a reply to message #1846945] Sat, 09 October 2021 19:26 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Frank,

Could you please have a look at the tests under https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/tests/org.eclipse.epsilon.hutn.test.unit?

Best,
Dimitris
Re: Load HUTN as ecore model [message #1847345 is a reply to message #1846947] Sun, 24 October 2021 08:35 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hello Dimitris,

sorry I don't find or understand where to find the useful information in the tests.
And I cannot create a minimal example, because I do not have a bug situation. I just don't know how to use the API or which API to use at all.

Given a metamodel:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Im" nsURI="https://www.acme.com/im" nsPrefix="Im">
  <eClassifiers xsi:type="ecore:EClass" name="Project">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
</ecore:EPackage>


From that, there exists a generated Java package with a Project interface and an implementation class ProjectImpl.


Now for testing, I want to use HUTN, because it can specify the types precisely ( which is missing in Flexmi?).

@Spec {
  metamodel "Im" {
    nsUri: "https://www.acme.com/im"
   }
}
Project {
  name: "MyProject"
}


How can I load that HUTN file using Java API, so that the result is an instance of the ProjectImpl class?

regards
Frank
Re: Load HUTN as ecore model [message #1847366 is a reply to message #1847345] Mon, 25 October 2021 12:24 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Frank,

The code below should do the trick.

public static void main(String[] args) throws Exception {

  EPackage.Registry.INSTANCE.put(ImPackage.eNS_URI, ImPackage.eINSTANCE);

  HutnModel model = new HutnModel();
  StringProperties properties = new StringProperties();
  properties.put(HutnModel.PROPERTY_SOURCE_FILE, new File("model.hutn").getAbsolutePath());
  properties.put(HutnModel.PROPERTY_READONLOAD, "true");
  model.load(properties);

  System.out.println(model.allContents());
}


I've also tweaked the HUTN source to add a container for the Project instance.

@Spec {
  metamodel "Im" {
    nsUri: "https://www.acme.com/im"
  }
}

im {
  Project {
    name: "MyProject"
  }
}


Best,
Dimitris

[Updated on: Mon, 25 October 2021 14:49]

Report message to a moderator

Re: Load HUTN as ecore model [message #1847919 is a reply to message #1847366] Fri, 12 November 2021 15:11 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Thanks, the surrounding package was my missing part.

When trying to use this HUTN parser, I see 2 problems:

1. There are lots of warnings in stdout:
Warning: The type 'XYZ' is ambiguous and could refer to any of the following: 'Intermediate!ClassObject' 'Metamodel!ClassObject'. The type 'Intermediate!ClassObject' has been assumed.
IMO: In general, no console printing should be done from inside a library.

2. If parsing fails, the thrown EolInternalException gives no hint. It just says: "No HUTN has been parsed."
This happens e.g. if the HUTN snippet has an empty object, but it requires a feature.
In parallel there is a lot of console printing,
See the printStacktrace in HutnModule:137
But also this printing gives no hint where in the passed text the problem might be located.


Re: Load HUTN as ecore model [message #1847941 is a reply to message #1847919] Sun, 14 November 2021 18:51 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Another problem...

3. My goal is to use HUTN for unit testing. To provide short snippets to create my model to be processed and then verified.
But it turns out, that parsing the simplest HUTN snippets takes minimum 200ms (ignoring the first test in a row, which might take >2000ms).
What a pity, this might be the killer.
Re: Load HUTN as ecore model [message #1847942 is a reply to message #1847941] Sun, 14 November 2021 19:08 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Frank,

The implementation of HUTN uses interpreted transformations and validation constraints under the hood so it's unlikely that it can get much faster without a substantial rewrite.

> Now for testing, I want to use HUTN, because it can specify the types precisely (which is missing in Flexmi?).

Could you please elaborate a bit on what you mean by "specify the types precisely"?

Best,
Dimitris
Re: Load HUTN as ecore model [message #1847962 is a reply to message #1847942] Mon, 15 November 2021 11:43 Go to previous message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hello Dimitris,

I think I missed something in the Flexmi doc. so I can specify both, the attribute to assign to and the explicit EClass to be used.

Trials with simplest Flexmi-Yaml snippets need less than 10ms to be processed.
So I guess, I will continue my evaluation with Flexmi/yaml

Thanks for your support
Frank
Previous Topic:EGL undesirable trim on return template operations
Next Topic:Loading a WSDL file with type information
Goto Forum:
  


Current Time: Sat Apr 27 06:33:32 GMT 2024

Powered by FUDForum. Page generated in 0.03777 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top