Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Invalid type for iteration Error
Invalid type for iteration Error [message #1763791] Fri, 19 May 2017 16:54 Go to next message
Nicholas Johnson is currently offline Nicholas JohnsonFriend
Messages: 12
Registered: March 2017
Junior Member
I'm fairly new to EMF and Acceleo 3.x and I'm trying to figure out why I get the following error when I try to iterate through a list:

Invalid type for iteration at line 15 in Module genClass for block for (aComponent.implements). org.openjaus.ojss.model.impl.ServiceImpl was not an instanceof null.


I have two metamodels:


  1. ojss
  2. skeleton


Each metamodel is in a separate eclipse plugin/project.

The Component EClass in the skeleton metamodel has a list of references (implements) to the Service EClass in the ojss metamodel. I have instances of both metamodels: My.skeleton and My.ojss such that My.skeleton references objects in My.ojss.

I'm running Acceleo from the same Eclipse instance that I'm doing the development using a Launch Configuration and set to run as a Java Application. I register the packages in the registerPackages method:

if (!isInWorkspace(SkeletonPackage.class))
{
        resourceSet.getPackageRegistry().put(SkeletonPackage.eNS_URI, SkeletonPackage.eINSTANCE);
}

if (!isInWorkspace(ModelPackage.class))
{
        resourceSet.getPackageRegistry().put(ModelPackage.eNS_URI, ModelPackage.eINSTANCE);
}


and I figured out that I needed/how to register the resource factories in the registerResourceFactories method:

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("skeleton", new SkeletonResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ojss", new ModelResourceFactoryImpl());


All the proxies seem to resolve fine and if I just print the Component.implements list it lists the Service information as I would expect:

[aComponent.implements/] --> org.openjaus.ojss.model.impl.ServiceImpl@72e5a8e (name: Transport, ... )


However, when I try to iterate over the component.implements list I get the error listed above. Here is the code I'm using to iterate over the list.
[for (aService : Service | aComponent.implements)]
    + block_expression
[/for]


I've tested manually loading the model(s) and iterating over the list using the following code and it seems to work fine. This seems to imply it's an Acceleo problem.
        // Initialize the model
        SkeletonPackage.eINSTANCE.eClass();

        // Register the XMI resource factory for the .website extension

        Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
        Map<String, Object> m = reg.getExtensionToFactoryMap();
        m.put("skeleton", new SkeletonResourceFactoryImpl());
        m.put("ojss", new ModelResourceFactoryImpl());

        // Obtain a new resource set
        ResourceSet resSet = new ResourceSetImpl();

        // Get the resource
        String filePath = "C:\\openjaus\\ojssdev\\runtime-EclipseApplication\\skeletons\\openjaus.skeleton";
        URI fileURI = URI.createFileURI(filePath);
        Resource resource = resSet.getResource(fileURI, true);

        // Get the first model element and cast it to the right type, in my
        // example everything is hierarchical included in this first node
        Project myProject = (Project)resource.getContents().get(0);
        print(myProject);


Anyone have any suggestions on where to look / how to fix?

I'm using Eclipse Neon 4.6.0, Acceleo 3.6.6, and EMF 2.12.0

Thanks.

[Updated on: Fri, 19 May 2017 16:57]

Report message to a moderator

Re: Invalid type for iteration Error [message #1763792 is a reply to message #1763791] Fri, 19 May 2017 17:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you can't figure it out, there is rather less chance that we can since you have the code to debug and we don't.

I might guess that you iterating over a non-collection, but cannot be more helpful.

You need to post a repro.

Regards

Ed Willink
Re: Invalid type for iteration Error [message #1764004 is a reply to message #1763792] Tue, 23 May 2017 20:58 Go to previous messageGo to next message
Nicholas Johnson is currently offline Nicholas JohnsonFriend
Messages: 12
Registered: March 2017
Junior Member
I tried to re-create the problem using a different project that I could share and can't get the problem to duplicate with that project.

*sigh*

I'm trying to see if that gives me any insight into what I'm doing wrong. I'll post if I make some progress / figure out the problem.
Re: Invalid type for iteration Error [message #1765952 is a reply to message #1764004] Wed, 14 June 2017 14:53 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi Nicholas,

This error message seems very strange to me (not an instanceof null?). Could you try printing the following to see if this can help?

[aComponent.implements/]
[aComponent.implements->size()/]
[for (aService : OclAny | aComponent.implements->asSequence())]
    [aService/]
[/for]


Laurent Goubet
Obeo
Previous Topic:Post trim not working
Next Topic:Question for export a project
Goto Forum:
  


Current Time: Thu Apr 25 23:28:27 GMT 2024

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

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

Back to the top