WARNING: The Page is deprecated because I have moved the project to the GoogleCode http://java-comment-preprocessor.googlecode.com

Java Comment Preprocessor

Some examples of the preprocessor usage you can see below

//#local TESTVAR="TEST LOCAL VARIABLE"
//#assert "TESTVAR="+/*$TESTVAR$*/
//#include ".//test//_MainProcedure.java"

public static final void testproc()
{
System.out.println(/*$VARHELLO$*/);
System.out.println("// Hello commentaries");
//#local counter=10
//#while counter!=0
System.out.println("Number /*$counter$*/");
//#local counter=counter-1
//#end
System.out.println("Current file name is /*$SRV_CUR_FILE$*/");
System.out.println("Output dir is /*$SRV_OUT_DIR$*/");
//#if strhas("Hello","Hello world")
System.out.println("Substring found");
//#endif
}

The information below is not completed

Directive list

Directive Reference
//#action EXPR0,EXPR1...EXPRn It makes an action event and preprocessor calls a preprocessor extension to preprocess it
//#global NAME=EXPR It defines a global variable (the variable is globally visibiled from all preprocessed files)
//#local NAME=EXPR It defines a local variable (the variable will be visibled only in the current preprocessing file and included files)
//#define NAME It defines a local variable with the TRUE value (it works as //#local NAME=true)
//#if BOOLEAN_EXPR It begins a #if..#else..#endif block
//#ifdefined VARIABLE_NAME It works similar #if and makes #ifdefined..#else..#endif block, TRUE if the variable is exists else FALSE
//#else It inverts the current flag of  #if or #ifdefined blocks
//#endif It ends current #if or #ifdefined blocks
//#include STRING_EXPR It allows to include and preprocess another source file, its name and path will be obtained through the string expression
//#excludeif BOOLEAN_EXPR It excludes the current preprocessing file from the preprocessor output list if the expression is true
//#exit It interrupts preprocessing of the current file immediately 
//#exitif BOOLEAN_EXPR It works like #exit but it will interrupt the preprocessing only if the expression result is true
//#while BOOLEAN_EXPR It starts a //#while..//#end block
//#break It breaks the current //#while..//#end block
//#continue It begins the new iteration in the current //#while..//#end block
//#end It ends the current //#while..//#end construction
//#// It makes the preprocessor to comment the next string in the preprocessing file (the '//' will be used as the comment prefix)
/*-*/ It gives up the rest of the string just after the directive (and the directive too of course)
/*$EXPR$*/ This directive will be replaced by a string representation of the expression result
//#- It turns off the output of preprocessed data into the output stream
//#+ It turns on the output of preprocessed data into the output stream
//$ It writes the string rest (just after this directive) into the output stream without comments "//$Hello"==>"Hello"
//$$ It writes the string rest (just after this directive) into the output stream without comments and without (!) processing macroses in /*$..$*/ directives
//#assert STR_EXPR It asserts some information on the current console (usually I use it for information messages and for some debugging)
//#prefix+ All strings after the directive will be added at the start of the result file (it is very useful to form an "import" list for Java sources)
//#prefix- It resets the prefix output mode
//#postfix+ All strings after the directive will be added at the end of the result file
//#postfix- It resets the postfix output mode
//#outdir STRING_EXPR It sets the destination directory for the current preprocessing file
//#outname STRING_EXPR It sets the name for the current preprocessing file
//#flush It flushes all inside buffers in the result file and reset inside buffers
//#_if BOOLEAN_EXPR It starts a #_if..#_else..#_endif block (it will be processed only during the "first" global pass)
//#_else It changes the flag for the current #_if block
//#_endif It ends the current #_if block

Expression operators

Arithmetic *, /, +, %
Logical && (and)
|| (or)
! (not)
^ (xor)
Comparison ==,!=,<,>,>=,<=
Brakes (,)

Examples

You can take a look at two java files below which actively use preprocessor and I used them in mobile developments.

LoadingThread.java, SoundManager.java


2003-2011 Igor A. Maznitsa. All Rights reserved.