Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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
Michael Spertus is currently offline Michael Spertus
Messages: 78
Registered: July 2009
Member
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
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
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
Michael Spertus is currently offline Michael Spertus
Messages: 78
Registered: July 2009
Member
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
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
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
Michael Spertus is currently offline Michael Spertus
Messages: 78
Registered: July 2009
Member
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: Fri Aug 29 16:21:49 EDT 2014

Powered by FUDForum. Page generated in 0.02465 seconds