One technique I've used is to use m4 as a preprocessor for java files. You write your code in classname.java.m4
and use a Makefile or other build system rule to run m4:
%: %.m4
@echo "/* automatically generated from $< -- don not edit*/" >$@
m4 $< >>$@