OK that's easy to answer :-)

ifHasMethod checks current class to see if a method with the specified
name exists, it's not dependent on forAllMethod (it's not like a
hypothetical ifCurrentMethodNameEquals). So you loop over all methods
(which also traverses the superclass) and check n times for a method
called setValue and there's only one setValue method found obviously!

Take a look at entity-body.j, the way we use it is different, for
example:

<XDtEjbPersistent:forAllPersistentFields not-pk="true">
   <XDtMethod:ifHasMethod name="<XDtMethod:setterMethod/>"
parameters="<XDtMethod:methodType/>">
      <XDtMethod:setterMethod/>( dataHolder.<XDtMethod:getterMethod/>()
);
   </XDtMethod:ifHasMethod>
</XDtEjbPersistent:forAllPersistentFields>

We loop over all abstract getter methods here, and lets say come across
int getId() in this loop, we check if a method called setId(int) exists
and generate code for it. Note that setterMethod works because obviously
forAllPersistentFields updates currentMethod pointer in the loop.

ifHasMethod can be safely used outside forAllMethods (basically doesn't
use currentMethod pointer, just looks at currentClass, the class we're
parsing), but propertyName needs currentMethod because it strips set/get
from a method name to get the property name.

AFAIK what you're trying to accomplish is what you described in a
previous email, looping over all methods starts with a specific prefix.
Looping over all setter/getter methods is already easy, just do a
forAllMethods and check ifIsSetter (don't remember the exact name).

What if you don't want to do it in a forAllMethods/etc loop and just
want to check for a method and get its propertyName? It needs a bit more
coding but basically you do as below:

   <XDtMethod:ifHasMethod name="setValue">
        <XDtMethod:currentMethod name="setValue">
   </XDtMethod:ifHasMethod>

XDtMethod:currentMethod updates current method.

Certainly there's room for improvement, more generalization for purposes
other than the ones followed by ejbdoclet.

Cheers,
Ara.

> -----Original Message-----
> From: Erik Hatcher [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, February 17, 2002 7:22 PM
> To: Ara Abrahamian; [EMAIL PROTECTED]
> Subject: Re: [Xdoclet-user] XDtMethod:ifHasMethod ????
> 
> Sure, here's a complete example-
> 
> Template:
> <XDtMethod:forAllMethods>
> 
>   <XDtMethod:ifHasMethod name="setValue">
>     <XDtMethod:propertyName/> (without parameter)
>   </XDtMethod:ifHasMethod>
> 
>   <XDtMethod:ifHasMethod name="setValue"
parameters="java.lang.String">
>     <XDtMethod:propertyName/> (with parameter)
>   </XDtMethod:ifHasMethod>
> 
> </XDtMethod:forAllMethods>
> 
> Class:
> public class Test {
>     private String value;
> 
>     public void setValue (String value) {
>         this.value = value;
>     }
> }
> 
> Output:
>     value (with parameter)
>     <clinit> (with parameter)
>     clone (with parameter)
>     equals (with parameter)
>     finalize (with parameter)
>     class (with parameter)
>     hashCode (with parameter)
>     notify (with parameter)
>     notifyAll (with parameter)
>     registerNatives (with parameter)
>     toString (with parameter)
>     wait (with parameter)
>     wait (with parameter)
>     wait (with parameter)
> 
> Very bizarre.  Notice it only generates "value" with the ifHasMethod
> parameters specified.  But the even stranger thing is why did it
generate
> all those other methods in the output?
> 
> I'm using the latest HEAD version of XDoclet (as of yesterday).
> 
>     Erik
> 
> 
> ----- Original Message -----
> From: "Ara Abrahamian" <[EMAIL PROTECTED]>
> To: "'Erik Hatcher'" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Sunday, February 17, 2002 10:04 AM
> Subject: RE: [Xdoclet-user] XDtMethod:ifHasMethod ????
> 
> 
> > I have no idea about it, it should work fine! Can you show me the
rest
> > of the template and the class you're running it on?
> >
> > Ara.
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
[mailto:xdoclet-user-
> > > [EMAIL PROTECTED]] On Behalf Of Erik Hatcher
> > > Sent: Sunday, February 17, 2002 5:45 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [Xdoclet-user] XDtMethod:ifHasMethod ????
> > >
> > > I've even tried hardcoding it:
> > >
> > > <XDtMethod:ifHasMethod name="setXyz">
> > >   has method
> > > </XDtMethod:ifHasMethod>
> > >
> > > And it still did not output "has method".
> > >
> > > Help!
> > >
> > > Thanks,
> > >     Erik
> > >
> > >
> > > ----- Original Message -----
> > > From: "Erik Hatcher" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Saturday, February 16, 2002 8:15 PM
> > > Subject: [Xdoclet-user] XDtMethod:ifHasMethod ????
> > >
> > >
> > > > I have a class that has:
> > > >
> > > >     public void setXyz (String xyz)
> > > >
> > > > And I'm using this in a custom template:
> > > >
> > > > setter method = <XDtMethod:setterMethod/>
> > > > <XDtMethod:ifHasMethod name="<XDtMethod:setterMethod/>">
> > > >   has method
> > > > </XDtMethod:ifHasMethod>
> > > >
> > > >
> > > > And it outputs:
> > > >
> > > > setter method = setXyz
> > > >
> > > > but does not output "has method".
> > > >
> > > > Am I missing something basic here?
> > > >
> > > > I've seen the syntax:
> > > > <XDtMethod:ifHasMethod name="<XDtMethod:setterMethod/>"
> > > > parameters="<XDtMethod:methodType/>">
> > > >
> > > > used to find getters (right?), but how do I find and process
> > setters?
> > > (my
> > > > class does not have getters, only setters).
> > > >
> > > > Thanks,
> > > >     Erik
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > Xdoclet-user mailing list
> > > > [EMAIL PROTECTED]
> > > > https://lists.sourceforge.net/lists/listinfo/xdoclet-user
> > > >
> > >
> > >
> > > _______________________________________________
> > > Xdoclet-user mailing list
> > > [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/xdoclet-user
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> > _______________________________________________
> > Xdoclet-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/xdoclet-user
> >


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
Xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to