Q: When I open the dictionary for my Java application using the scriptable text editor, the 'aete' is very untidy. It looks
something like this:
Salad:
toss: public void Salad.toss(int)
toss reference
parameters int |
I know that I can make this more readable by editing my 'aete' by hand, but that's a bit of a pain. Is there any way I can specify how this information is generated?
A: Yes. Event, class, method, and parameter information are generated by introspecting the java classes. You can make a BeanInfo for your classes in order to provide a more human-readable terminology.
Specifically, you can use java.beans.MethodDescriptor to specify parameter descriptions and method descriptors for your classes.
Given the class Salad.java:
public class Salad
{
public void toss( int howHigh ){ ... }
}
|
You can make a SaladBeanInfo.java :
import
java.beans.*;
import java.lang.reflect.*;
public class
SaladBeanInfo extends SimpleBeanInfo
{
public MethodDescriptor[ ] getMethodDescriptors()
{
MethodDescriptor md[ ] = new MethodDescriptor[1];
try
{
ParameterDescriptor[ ] pd = new ParameterDescriptor[1];
pd[0] = new ParameterDescriptor();
pd[0].setShortDescription( "Number of inches to toss" );
pd[0].setName( "height" );
md[0] = new MethodDescriptor( getMethod( Salad.class,
"toss" ), pd );
md[0].setShortDescription( "Toss the salad vigorously." );
return md;
}
catch ( IntrospectionException e )
{
e.printStackTrace();
}
return null;
}
Method getMethod(
Class c, String methodName ) throws IntrospectionException
{
Method methods[ ][ ] = c.getMethods();
for ( int i = 0; i < methods.length; i++ )
{
if ( methods[i].getName().equals( methodName ))
{
return methods[i];
}
}
throw new IntrospectionException(
"No such method \"" + methodName + "\"" );
}
}
|
There are two points of note here. The first is the specification of the
method descriptor where we set the short description (this will
replace the method signature which is the default generation behavior of the 'aete' ). The second is the specification of a parameter descriptor. This is highly useful because it allows the scriptor to avoid the cumbersome "method object parameter { ... }" syntax common to applications that use the default 'aete'
generation behavior. Instead we can use:
toss of Salad "Green
Salad" height 10
This is a lot easier to understand than:
toss of Salad "Green
Salad" parameters { 10 }
|