|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jatha.Macro | +--macros.PROP
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 |
public PROP()
Method Detail |
public void expand(java.lang.String[] args, java.io.Writer out, Expander expander) throws java.io.IOException
expand
in class Macro
public static java.lang.String getNameOfParameter(java.lang.String type, java.lang.String propertyName)
public static java.lang.String getNameOfGetMethod(java.lang.String type, java.lang.String propertyName)
public static java.lang.String getNameOfMemberVariable(java.lang.String propertyName)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |