Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » getCanGenerateParent() in the Generator Extension Example
getCanGenerateParent() in the Generator Extension Example [message #428953] Sat, 04 April 2009 06:26 Go to next message
Eclipse UserFriend
Originally posted by: tim.baumgartner.gmx.de

Hi,

I've written a generator extension using
org.eclipse.emf.examples.generator.validator as a starting point.
I implemented GenClassValidatorGeneratorAdapter#getCanGenerateParent(),
but it is never called. Prior to this, I understood the API the
following way:
- for each object the corresponding GeneratorAdapter checks if the
object's attributes are OK
- if attributes of additional objects have to be checked, the
GeneratorAdapter specifies them by overriding getCanGenerateParent() and
getCanGenerateChildren()

Assuming I have not found a bug, I must be wrong. Can someone explain me
why and how to use the API instead?

To give you some more details: Each of my GeneratorAdapters checks for a
certain GenAnnotation at the object. If a GenPackage has a GenAnnotation
specifying it should *not* be generated, then none of it's GenClasses
should be generated either, even if they are annotated that they should.

Thanks,
Tim
Re: getCanGenerateParent() in the Generator Extension Example [message #428954 is a reply to message #428953] Sat, 04 April 2009 13:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030704020005040802040306
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Tim,

It's called in this method in
org.eclipse.emf.codegen.ecore.generator.Generator, so you could try
setting a breakpoint here to see why it doesn't seem to get called.

private List<GeneratorData> getGeneratorData(Object object, Object
projectType, boolean forGenerate, boolean forChildren, boolean
skipFirst, Set<Object> objects)
{
List<Object> result = new ArrayList<Object>();
result.add(object);

for (int i = 0; i < result.size(); skipFirst = false)
{
Object o = result.get(i);

Collection<GeneratorAdapter> adapters = getAdapters(o);
result.remove(i);
if (!adapters.isEmpty())
{
for (GeneratorAdapter adapter : adapters)
{
if (forChildren)
{
Collection<?> children = forGenerate ?
adapter.getGenerateChildren(o, projectType) :
adapter.getCanGenerateChildren(o, projectType);
for (Object child : children)
{
if (objects.add(child))
{
result.add(child);
}
}
}
else
{
Object parent = forGenerate ?
adapter.getGenerateParent(o, projectType) :
adapter.*getCanGenerateParent*(o, projectType);
if (parent != null && objects.add(parent))
{
result.add(parent);
}
}

if (!skipFirst)
{
result.add(i++, new GeneratorData(o, adapter));
}
}
}
}

@SuppressWarnings({"cast","unchecked"})
List<GeneratorData> list = (List<GeneratorData>)(List)result;
return list;
}

Without looking closely, it seems to me it will only get called in you
try to invoke generate directly on an intermediate node. If you start
at the root, it won't get called because you'll never walk deeper than a
node that refused to generated...


Tim Baumgartner wrote:
> Hi,
>
> I've written a generator extension using
> org.eclipse.emf.examples.generator.validator as a starting point.
> I implemented
> GenClassValidatorGeneratorAdapter#getCanGenerateParent(), but it is
> never called. Prior to this, I understood the API the following way:
> - for each object the corresponding GeneratorAdapter checks if the
> object's attributes are OK
> - if attributes of additional objects have to be checked, the
> GeneratorAdapter specifies them by overriding getCanGenerateParent()
> and getCanGenerateChildren()
>
> Assuming I have not found a bug, I must be wrong. Can someone explain
> me why and how to use the API instead?
>
> To give you some more details: Each of my GeneratorAdapters checks for
> a certain GenAnnotation at the object. If a GenPackage has a
> GenAnnotation specifying it should *not* be generated, then none of
> it's GenClasses should be generated either, even if they are annotated
> that they should.
>
> Thanks,
> Tim

--------------030704020005040802040306
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tim,<br>
<br>
It's called in this method in
org.eclipse.emf.codegen.ecore.generator.Generator, so you could try
setting a breakpoint here to see why it doesn't seem to get called.<br>
<small><br>
</small>
<blockquote><small>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: getCanGenerateParent() in the Generator Extension Example [message #428957 is a reply to message #428954] Sat, 04 April 2009 19:57 Go to previous message
Eclipse UserFriend
Originally posted by: tim.baumgartner.gmx.de

Hey Ed,

thanks a lot. I will simply check the parent myself. Besides that, I
like the concept of using an AdapterFactory for code generation.

Tim
Previous Topic:[Teneo] Discontinue Jpox support in Teneo 1.1 (Eclipse 3.5/EMF 2.5)?
Next Topic:explicite bidirectional containment references
Goto Forum:
  


Current Time: Fri Apr 19 21:37:44 GMT 2024

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

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

Back to the top