ECore reflection and cross references

Manuel Leduc

To have a context, I am currently working on an ecore to java model transformation. Practically, I am reading some ecore file and generate a string which happens to be a valid java interface source code.

As a example, here is my code generation workflow.

projectA.ecore:

Defines an EClass 'A'

package projectA : projectA = 'http://www.example.org/projectA'
{
    class A;
}

projectB.ecore:

Defines an EClass 'B' which inherit from 'A' using cross-reference to a.ecore to get access to it.

import projectA : '../../projectA/model/projectA.ecore#/';

package projectB : projectB = 'http://www.example.org/projectB'
{
    class B extends projectA::A;
}

From those ecore I first generate an interface for projectA.ecore:

package projecta;

interface ProjectA<A> {
  // ...
}

And now I have want to do the same thing for projectB.ecore and obtains the following interface:

package projectb;

import projecta.ProjectA;

interface ProjectB<A,B> extends ProjectA<A> {
  // ...
}

To do so I need to detect that A is and EClass accessed using cross reference and do some analysis in projectA.ecore in order to generate a valid interface extension, packages imports...

I looked around in the ecore reflection API without finding a clean and obvious way to do so. Is this possible? It yes, how?

EDIT: Technical details

I'm loading the ecore using this kind of code :

final ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());
final Resource resource = resourceSet.getResource(uri, true);
final EPackage ePackage = (EPackage) resource.getContents().get(0);
final String fileContent = new GenerateAlgebra().process(ePackage);

GenerateAlgebra is the class dedicated to the .ecore to String transformation. Technically it is developed using Xtend (https://github.com/manuelleduc/ecore-oa/blob/master/fr.inria.diverse.ecorealgebragenerator/src/fr/inria/diverse/objectalgebragenerator/popup/actions/GenerateAlgebra.xtend).

Mad Matts

If you just want to get the file path to the ecore file in which the EClass is defined use the resource URI

try:

ePackage.eResource().getURI() which gives you the actual URI to the ecore file in which the package and all its EClasses are defined. something like: file:/Users/../../yourPath/projectA.ecore You can also use the getNsURI(), getName() to identify the two ecore files.

If you use a Resourceset, like you did, and you have cross references between several ecore files, then the set tries to load all of the other Resources aswell. Which means, by calling resourceSet.getResource(uri, true) the resourceset should contain both resources.

try iterating through resourceSet.getResources()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Renaming of cross references not happening if the cross references are cached

From Dev

Xtext multiple cross references

From Dev

java 8 Method References and Reflection

From Dev

Cross references in source code comments

From Dev

Cross-service references in DB

From Dev

Cross references in source code comments

From Dev

Cross-service references in DB

From Dev

Cross-Service references in OData

From Dev

Find all property references using reflection

From Dev

Cross-project references between two projects

From Dev

Pandas groupby add rows with cross references

From Dev

Get all cross references in word with VBA

From Dev

G++ ARM cross compiling: undefined references

From Dev

Cross references between slides and its content

From Dev

xsl cross references comparing one node with another

From Dev

Word: combining cross-references efficiently

From Dev

Cross-project references between two projects

From Dev

Get all cross references in word with VBA

From Dev

Postgresql cross-database references in Rails

From Dev

Cross references when using template parameters

From Dev

Dynamically add External (Cross-Workbook) references

From Dev

Boost undefined references cross compiling linux to windows

From Dev

Calling a dynamically loaded DLL method through reflection, but the target references a DLL

From Dev

Finding all references to a method called by using reflection in Visual Studio

From Dev

Ecore EClass inheritance in Xtext

From Dev

Assembly cross references lost when manually loading assembly

From Dev

Scribble documentation: cross-references between two simple files

From Dev

S4 class cross-references - what is appropriate syntax?

From Dev

How to properly write cross-references to external documentation with intersphinx?

Related Related

  1. 1

    Renaming of cross references not happening if the cross references are cached

  2. 2

    Xtext multiple cross references

  3. 3

    java 8 Method References and Reflection

  4. 4

    Cross references in source code comments

  5. 5

    Cross-service references in DB

  6. 6

    Cross references in source code comments

  7. 7

    Cross-service references in DB

  8. 8

    Cross-Service references in OData

  9. 9

    Find all property references using reflection

  10. 10

    Cross-project references between two projects

  11. 11

    Pandas groupby add rows with cross references

  12. 12

    Get all cross references in word with VBA

  13. 13

    G++ ARM cross compiling: undefined references

  14. 14

    Cross references between slides and its content

  15. 15

    xsl cross references comparing one node with another

  16. 16

    Word: combining cross-references efficiently

  17. 17

    Cross-project references between two projects

  18. 18

    Get all cross references in word with VBA

  19. 19

    Postgresql cross-database references in Rails

  20. 20

    Cross references when using template parameters

  21. 21

    Dynamically add External (Cross-Workbook) references

  22. 22

    Boost undefined references cross compiling linux to windows

  23. 23

    Calling a dynamically loaded DLL method through reflection, but the target references a DLL

  24. 24

    Finding all references to a method called by using reflection in Visual Studio

  25. 25

    Ecore EClass inheritance in Xtext

  26. 26

    Assembly cross references lost when manually loading assembly

  27. 27

    Scribble documentation: cross-references between two simple files

  28. 28

    S4 class cross-references - what is appropriate syntax?

  29. 29

    How to properly write cross-references to external documentation with intersphinx?

HotTag

Archive