Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Problem in resolving cross-reference between kdm fragments and java models.
Problem in resolving cross-reference between kdm fragments and java models. [message #1822185] Sat, 29 February 2020 04:07 Go to next message
Elder Rodrigues is currently offline Elder RodriguesFriend
Messages: 7
Registered: June 2019
Junior Member
Hello all,

I am having a problem about resolving crossreference between kdmfragments model and java models. What I want to do is get the line numbers of some java models, i.e., from a set of ASTNode's I want to get their corresponding line numbers in the source code.

Bellow is a simple example what I am trying to do:
//Registry JavaPackage and JavaapplicationPackage
EPackage.Registry.INSTANCE.put(JavaPackage.eNS_URI, JavaPackage.eINSTANCE);
EPackage.Registry.INSTANCE.put(JavaapplicationPackage.eNS_URI, JavaapplicationPackage.eINSTANCE);

//Initialize a resource set
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());

//Get resource of some xmi java model
Resource modismoModelResource = rs.getResource(URI.createURI("..._java.xmi"));

//Get the resource of the corresponding Java2File instances of the defaultPackage (for the sake of simplification let's stay there are just a default package to be analyzed)
Resource defaultPackageResource = rs.getResource(URI.createURI("..."), true);

EList<?> fooMethods = .... (application of an OCL query to get elements in the modiscoModelResource, e.g., "MethodDeclaration.allInstances()->select(m | m.name = 'foo')")

/*
  Now I need to inspect fooMethods list and get the crossreference objects in the defaultPackageResource in order to get their file numbers, how can I do it?
*/


(edited)
I have tried something like:
MethodDeclaration m;
for(Object obj: fooMethods) {
  m  = (MethodDeclaration) obj;
  EcoreUtil.UsageCrossReferencer.find(inv, defaultPackageResource); 
}


However, in the line EcoreUtil.UsageCrossReferencer.find(inv, defaultPackageResource) I got an exception:
class org.eclipse.emf.ecore.impl.EObjectImpl cannot be cast to class org.eclipse.gmt.modisco.java.CompilationUnit (org.eclipse.emf.ecore.impl.EObjectImpl and org.eclipse.gmt.modisco.java.CompilationUnit are in unnamed module of loader 'app')

My guess is that the resolving is not working. Therefore, in some part of the code there is a cast between EObjectImpl and CompilationUnit. However, as the resolving is not working, the cast is invalid.

Bellow there is a fragment of my xmi file that refers to java models.
<?xml version="1.0" encoding="ASCII"?>
<javaapplication:Java2File xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:javaapplication="http://www.eclipse.org/MoDisco/Java/Composition/0.1.incubation/javaApplication">
  <file href="../SampleProject_kdm.xmi#//@model.0/@inventoryElement.0/@inventoryElement.6/@inventoryElement.0"/>
  <children xsi:type="javaapplication:JavaNodeSourceRegion" startLine="2" startPosition="2" endLine="7" endPosition="106">
    <node href="../SampleProject_java.xmi#//@ownedElements.0/@ownedElements.0"/>
  </children>

[Updated on: Sat, 29 February 2020 13:19]

Report message to a moderator

Re: Problem in resolving cross-reference between kdm fragments and java models. [message #1822196 is a reply to message #1822185] Sat, 29 February 2020 16:59 Go to previous message
Elder Rodrigues is currently offline Elder RodriguesFriend
Messages: 7
Registered: June 2019
Junior Member
The problem with the exception has been fixed by using URI.createFileURI instead of URI.createURI and the resolving is now working.

Now I'm wondering how can I inspect the fooMethods list and get the respective regions of each element.
Previous Topic:Announcing MoDisco 1.5.0M3
Next Topic:Static/initialization blocks in BlockUnit
Goto Forum:
  


Current Time: Tue Nov 24 02:02:37 GMT 2020

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

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

Back to the top