macros
Class PROP

java.lang.Object
  |
  +--jatha.Macro
        |
        +--macros.PROP

public class PROP
extends Macro

PROP(type, name, [initial-value])

The PROP (short for property) macro declares a private member variable, a get-function, and a set-function. Example: @PROP(String, name) will generate code something like this:

 private String m_name;
 public String getName() { return m_name; }
 public void setName(String name) { m_name = name; }
 

The "m_" prefix is primarily to ensure that if you choose a name that happens to be a java reserved word (for example, "interface"), the name of the variable won't cause a compile error.

Note: if the type is "boolean", the get function uses a prefix of "is" instead of "get" (e.g. isHungry() instead of getHungry()).

Also note: the name of the property is automatically capitalized for the get/set functions. So @PROP(String, name) generates a function called getName(), not getname(). If you capitalize the name of the property, the only things affected will be the name of the member variable and the name of the parameter to the set function.

Also note: if you write your own macros, you should know that this macro leaves a message recording the type of any property it declares. For example, getMessage("PROP`typeof`myProperty") will return the String type of the "myProperty" property. Also, if you need to reference the member variable that stores a property's value, you shouldn't assume that it's simply "m_"+propertyName; instead, use getNameOfMemberForProperty().


Fields inherited from class jatha.Macro
util
 
Constructor Summary
PROP()
           
 
Method Summary
 void expand(java.lang.String[] args, java.io.Writer out, Expander expander)
          Expands the macro
static java.lang.String getNameOfGetMethod(java.lang.String type, java.lang.String propertyName)
          Returns the name of the get method for the given property name and type.
static java.lang.String getNameOfMemberVariable(java.lang.String propertyName)
          Returns the name of the member variable used to store the value of the given property.
static java.lang.String getNameOfParameter(java.lang.String type, java.lang.String propertyName)
          Returns an appropriate name for a method parameter, given the name and type of a property.
 
Methods inherited from class jatha.Macro
expand
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PROP

public PROP()
Method Detail

expand

public void expand(java.lang.String[] args,
                   java.io.Writer out,
                   Expander expander)
            throws java.io.IOException
Expands the macro
Overrides:
expand in class Macro

getNameOfParameter

public static java.lang.String getNameOfParameter(java.lang.String type,
                                                  java.lang.String propertyName)
Returns an appropriate name for a method parameter, given the name and type of a property. For example, a boolean property "foo" will return "isFoo". A property called "class" will return "theClass". Most parameter names, however, are the same as the property name -- an int property called "bar" will just return "bar".

getNameOfGetMethod

public static java.lang.String getNameOfGetMethod(java.lang.String type,
                                                  java.lang.String propertyName)
Returns the name of the get method for the given property name and type. If the type is boolean, the method will start with "is", otherwise, it starts with "get".

getNameOfMemberVariable

public static java.lang.String getNameOfMemberVariable(java.lang.String propertyName)
Returns the name of the member variable used to store the value of the given property.