Declarations

Description Declarations of instance variables, methods, and other class-level declarations are used to provide control over the class. The example shows a declaration of an instance variable count and a method called transform. The combination translates every odd numbered word to upper case.
Simple Form
#declarations java-declarations #
XML Form
<declarations> java-declarations </declarations>
Translation to Java
java-declarations (inserted at the class level,
	rather than the generate method)
Example Template Dict.template

#declarations

int count = 0;

void transform(String s, ProgramWriter out) {
	++count;
	if (count%2==0) {
		out.print(s);
	} else {
		out.print(s.toUpperCase());
	}
}

#

public class test {

	String[] words = {
	#for "//word"#
		"# transform(context.evalString("."), out); #",
	#end#
	};
}

Example Spec words.xml

<?xml version="1.0"?>
<words>
  <word>hill</word>
  <word>fetch</word>
  <word>pail</word>
  <word>water</word>
  <word>up</word>
  <word>down</word>
  <word>crown</word>
</words>
Generated Output Dict.java


public class test {

	String[] words = {
		"HILL",
		"fetch",
		"PAIL",
		"water",
		"UP",
		"down",
		"CROWN",
	};
}