Invalid type for iteration Error [message #1763791] |
Fri, 19 May 2017 16:54 |
Nicholas Johnson 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:
- ojss
- 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 #1765952 is a reply to message #1764004] |
Wed, 14 June 2017 14:53 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.25864 seconds