Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » VE Code Generation: Who generates global variable declarations?
VE Code Generation: Who generates global variable declarations? [message #485107] Thu, 10 September 2009 14:38 Go to next message
Kaspar  von Gunten is currently offline Kaspar von Gunten
Messages: 21
Registered: July 2009
Junior Member
Hi all

another question.

We use "Choose Bean" to drop some other visual components of special type
onto a VE visual bean class. In the general case, this generates the
following code:

import x.y.z.SomeSpecialPanel;
...
private SomeSpecialPanel myPanel = null;
...
/**
* This method initializes myPanel
* @return x.y.z.SomeSpecialPanel
*/
private SomeSpecialPanel getMyPanel() {
if (myPanel == null) {
myPanel = new SomeSpecialPanel();
}
return myPanel;
}

What we would like to do, is generate the following code:

import x.y.z.SomeSpecialPanel;
import x.y.z.AbstractPanel
import x.y.z.SpecialAnnotation
...
private @SpecialAnnotation AbstractPanel myPanel = null;
...
/**
* This method initializes myPanel
* @return x.y.z.AbstractPanel
*/
private AbstractPanel getMyPanel() {
if (myPanel == null) {
myPanel = SpecialPanelFactory.create(SomeSpecialPanel.class);
}
return myPanel;
}

Three things should change:
1) Instance variable type (and return type of getter) should be of type
AbstractPanel
2) Instance variable should receive an annotation marking it as special
3) Instead of "new" a factory should be invoked with the panel class

I managed to achieve 3) by installing Decoder and DecoderHelper for
AbstractPanel type (of which special panel is a subtype of) and overriding
the generate/decode methods.

But for 1) and 2) I didn't manage to find a hook. Where I can install my
own Decoder for the instance variable code generation and for the
getter/initialize method, or who is responsible for encoding those
expressions?

Any pointers/hints?

Help would be greatly appreciated,
Kaspar
Re: VE Code Generation: Who generates global variable declarations? [message #485139 is a reply to message #485107] Thu, 10 September 2009 15:27 Go to previous message
Kaspar  von Gunten is currently offline Kaspar von Gunten
Messages: 21
Registered: July 2009
Junior Member
Ok, so I found this:

http://www.eclipsezone.com/eclipse/forums/t43277.html

which tells me how to generate my own getter method (with correct return
type).

But I still don't know how I can influence the generation of the instance
variable. Looking at the code in BeanPartFactory.generateInstanceDecl(..)
did not reveal any (obvious) hooks that Icould use. I guess that it would
be needed to provide an own InstanceVariableTemplate there, but since this
is not created through a factory, chances seem slim to do so.

So the question remains, how I can generate:

private @SpecialAnnotation AbstractPanel myPanel = null;

instead of:

private SomeSpecialPanel myPanel = null;

If a SomeSpecialPanel is dropped in the editor.

Thanks,
Kaspar

PS: Patching BeanPartFactory would be a solution, I guess, but obviously
not a nice one...
Re: VE Code Generation: Who generates global variable declarations? [message #617417 is a reply to message #485107] Thu, 10 September 2009 15:27 Go to previous message
Kaspar  von Gunten is currently offline Kaspar von Gunten
Messages: 21
Registered: July 2009
Junior Member
Ok, so I found this:

http://www.eclipsezone.com/eclipse/forums/t43277.html

which tells me how to generate my own getter method (with correct return
type).

But I still don't know how I can influence the generation of the instance
variable. Looking at the code in BeanPartFactory.generateInstanceDecl(..)
did not reveal any (obvious) hooks that Icould use. I guess that it would
be needed to provide an own InstanceVariableTemplate there, but since this
is not created through a factory, chances seem slim to do so.

So the question remains, how I can generate:

private @SpecialAnnotation AbstractPanel myPanel = null;

instead of:

private SomeSpecialPanel myPanel = null;

If a SomeSpecialPanel is dropped in the editor.

Thanks,
Kaspar

PS: Patching BeanPartFactory would be a solution, I guess, but obviously
not a nice one...
Previous Topic:VE Code Generation: Who generates global variable declarations?
Next Topic:possible VE involvement?
Goto Forum:
  


Current Time: Fri Oct 31 04:07:32 GMT 2014

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

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