So you're iterating over methods and check if there's a getter for current property extracted from current method. I prefer the name ifPropertyHasGetterMethod. Btw, we should also add forAllProperties/ifIsGetter/Setter and so on. So I think instead of putting these new methods in MethodTagsHandler it's better to define them in a new PropertyTagsHandler class along with the other property-oriented methods.
Ara. > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:xdoclet-devel- > [EMAIL PROTECTED]] On Behalf Of David Jencks > Sent: Wednesday, February 27, 2002 3:00 AM > To: xdoclet-devel > Subject: [Xdoclet-devel] Comments requested > > For the mbean stuff I am working on I need to find out if there are > getter/setter methods based on the current method name. I've written the > following additions to MethodTagsHandler and want to check that I'm not > breaking any conventions, rules, etc by adding these. Also if there is an > easier way to do this I'd like to know. > > thanks > david jencks > > Index: xdoclet/tags/MethodTagsHandler.java > =================================================================== > RCS file: > /cvsroot/xdoclet/xdoclet/core/src/xdoclet/tags/MethodTagsHandler.java,v > retrieving revision 1.23 > diff -u -r1.23 MethodTagsHandler.java > --- xdoclet/tags/MethodTagsHandler.java 26 Feb 2002 06:04:29 > -0000 1.23 > +++ xdoclet/tags/MethodTagsHandler.java 26 Feb 2002 23:22:58 -0000 > @@ -935,6 +935,72 @@ > } > > /** > + * The block tag <code>ifHasGetMethod</code> looks for a get > method based on > + * the attribute name from the current method, sets the current > method to that > + * get method, and applies the template if found. This is used to > look for > + * getters for mbean managed attributes. The get method found may > be the > + * current method. > + * > + * @param template a <code>String</code> value > + * @param attributes a <code>Properties</code> value > + * @exception XDocletException if an error occurs > + * @doc:tag type="block" > + */ > + public void ifHasGetMethod( String template, Properties attributes > ) throws XDocletException > + { > + MethodDoc get_method = getGetMethod(); > + > + if( get_method != null ) > + { > + MethodDoc old_method = getCurrentMethod(); > + > + setCurrentMethod( get_method ); > + try > + { > + generate( template ); > + } > + finally > + { > + setCurrentMethod( old_method ); > + } > + // end of try-catch > + } > + } > + > + /** > + * The block tag <code>ifHasSetMethod</code> looks for a set > method based on > + * the attribute name from the current method, sets the current > method to that > + * set method, and applies the template if found. This is used to > look for > + * setters for mbean managed attributes. The set method found may > be the > + * current method. > + * > + * @param template a <code>String</code> value > + * @param attributes a <code>Properties</code> value > + * @exception XDocletException if an error occurs > + * @doc:tag type="block" > + */ > + public void ifHasSetMethod( String template, Properties attributes > ) throws XDocletException > + { > + MethodDoc set_method = getSetMethod(); > + > + if( set_method != null ) > + { > + MethodDoc old_method = getCurrentMethod(); > + > + setCurrentMethod( set_method ); > + try > + { > + generate( template ); > + } > + finally > + { > + setCurrentMethod( old_method ); > + } > + // end of try-catch > + } > + } > + > + /** > * Searches for the MethodDoc of the method with name methodName > and returns > * it. > * > @@ -1037,6 +1103,47 @@ > cat.debug( "Method not found" ); > > return false; > + } > + > + private MethodDoc getGetMethod() throws XDocletException > + { > + MethodDoc current_method = getCurrentMethod(); > + > + if( current_method.name().startsWith( "get" ) || > current_method.name().startsWith( "is" ) ) > + { > + return current_method; > + } > + > + // end of if () > + > + String attributeName = getMethodNameWithoutPrefixFor( > current_method ); > + MethodDoc getter = getMethodDocForMethodName( "get" + > attributeName ); > + > + if( getter != null ) > + { > + return getter; > + } > + // end of if () > + getter = getMethodDocForMethodName( "is" + attributeName > ); > + //not too safe.. should check it's boolean. > + return getter; > + } > + > + private MethodDoc getSetMethod() throws XDocletException > + { > + MethodDoc current_method = getCurrentMethod(); > + > + if( current_method.name().startsWith( "set" ) ) > + { > + return current_method; > + } > + > + // end of if () > + > + String attributeName = getMethodNameWithoutPrefixFor( > current_method ); > + MethodDoc setter = getMethodDocForMethodName( "set" + > attributeName ); > + > + return setter; > } > > private boolean isInAppendExceptionsList( String > append_exceptions, String type ) > > _______________________________________________ > Xdoclet-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/xdoclet-devel _______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel
