Skip to main content



      Home
Home » Modeling » EMF » How can I enumerate all of the generated classes?
How can I enumerate all of the generated classes? [message #901485] Mon, 13 August 2012 01:15 Go to next message
Eclipse UserFriend
In my RCP program, I'd like to enumerate all of its modeled classes' Class objects. Is there a reasonable way to do this?

Thanks,

Mike
Re: How can I enumerate all of the generated classes? [message #901489 is a reply to message #901485] Mon, 13 August 2012 02:08 Go to previous messageGo to next message
Eclipse UserFriend
Mike,

If you know the model, then XyzPackage.eINSTANCE.getEClassifiers()
returns all the classifiers of the model and from that you can filter to
give just the EClasses.

On 13/08/2012 7:15 AM, Michael Spertus wrote:
> In my RCP program, I'd like to enumerate all of its modeled classes'
> Class objects. Is there a reasonable way to do this?
>
> Thanks,
>
> Mike
Re: How can I enumerate all of the generated classes? [message #901491 is a reply to message #901489] Mon, 13 August 2012 03:03 Go to previous messageGo to next message
Eclipse UserFriend
Ed Merks wrote on Mon, 13 August 2012 02:08
Mike,

If you know the model, then XyzPackage.eINSTANCE.getEClassifiers()
returns all the classifiers of the model and from that you can filter to
give just the EClasses.

Thanks for the response Ed. Actually, I don't know the model, but you still gave me just what I need because
public static Collection<EClassifier> enumerateModeledClassifiers() {
  Collection<EClassifier> classifiers = new ArrayList<EClassifier>();
  try {
    IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.emf.ecore.generated_package");
    for(IConfigurationElement e : config) {
      String uri=e.getAttribute("uri")
      classifiers.addAll(EPackage.Registry.INSTANCE.getEPackage(e.getAttribute("uri")).getEClassifiers());
    }
  } catch (Exception ex) {
    System.out.println(ex.getMessage());
  }
  return classifiers;
}
 

and filtering does the trick.

Thanks again,

Mike
Quote:

On 13/08/2012 7:15 AM, Michael Spertus wrote:
> In my RCP program, I'd like to enumerate all of its modeled classes'
> Class objects. Is there a reasonable way to do this?
>
> Thanks,
>
> Mike

Re: How can I enumerate all of the generated classes? [message #901507 is a reply to message #901491] Mon, 13 August 2012 04:03 Go to previous messageGo to next message
Eclipse UserFriend
Michael,

You can iterate directly over the EPackage.Registry.INSTANCE's contents
given they're populated by consulting the configuration elements already.

On 13/08/2012 9:03 AM, Michael Spertus wrote:
> Ed Merks wrote on Mon, 13 August 2012 02:08
>> Mike,
>>
>> If you know the model, then XyzPackage.eINSTANCE.getEClassifiers()
>> returns all the classifiers of the model and from that you can filter
>> to give just the EClasses.
>
> Thanks for the response Ed. Actually, I don't know the model, but you
> still gave me just what I need because
> public static Collection<EClassifier> enumerateModeledClassifiers() {
> Collection<EClassifier> classifiers = new ArrayList<EClassifier>();
> try {
> IConfigurationElement[] config =
> Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.emf.ecore.generated_package");
> for(IConfigurationElement e : config) {
> String uri=e.getAttribute("uri")
> classifiers.addAll(EPackage.Registry.INSTANCE.getEPackage(e.getAttribute("uri")).getEClassifiers());
> }
> } catch (Exception ex) {
> System.out.println(ex.getMessage());
> }
> return classifiers;
> }
>
> and filtering does the trick.
>
> Thanks again,
>
> Mike
> Quote:
>> On 13/08/2012 7:15 AM, Michael Spertus wrote:
>> > In my RCP program, I'd like to enumerate all of its modeled
>> classes' > Class objects. Is there a reasonable way to do this?
>> >
>> > Thanks,
>> >
>> > Mike
>
>
Re: How can I enumerate all of the generated classes? [message #901581 is a reply to message #901507] Mon, 13 August 2012 10:13 Go to previous message
Eclipse UserFriend
Ed Merks wrote on Mon, 13 August 2012 04:03
Michael,

You can iterate directly over the EPackage.Registry.INSTANCE's contents
given they're populated by consulting the configuration elements already.

Much better. Thanks, Ed.

Mike
Previous Topic:What is the status of XSD roundtrip ?
Next Topic:EMF Compare - comparision throough emf compare failed [compare]
Goto Forum:
  


Current Time: Wed Jul 23 15:37:05 EDT 2025

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

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

Back to the top