Remove only comments with macros?
Lilianne-Blaze opened this issue · 4 comments
Lilianne-Blaze commented
Could you please add an option to Maven plugin that allows removing comments but only those that contain JCP macros? So that javadocs and code-explaining comments remain untouched?
raydac commented
if file preprocessed then such comments will be removed automatically and how to be if file not preprocessed but for instance such code snippet cleared of jcp comments?
//#if DEBUG
// Hello debug
System.out.println("Hello debug");
//#else
// No debug
System.out.println("No debug");
//#endif
we will get clean result
// Hello debug
System.out.println("Hello debug");
// No debug
System.out.println("No debug");
how to be in the case?
Lilianne-Blaze commented
Basically given that code:
public static long getMyPid() {
System.out.println("(getMyPid called)");
long retVal = 0;
// #if preprocess.java.version >= 9
// use new API
retVal = ProcessHandle.current().pid();
// #else
// use old MXBean hack
// $retVal = getMyPidOld();
// #endif
return retVal;
}
Normally I get this:
public static long getMyPid() {
System.out.println("(getMyPid called)");
long retVal = 0;
// JCP! if preprocess.java.version >= 9
// JCP> // use new API
// JCP> retVal = ProcessHandle.current().pid();
// JCP! else
// use old MXBean hack
retVal = getMyPidOld();
// JCP! endif
return retVal;
}
With keepComments=false I get this:
public static long getMyPid() {
System.out.println("(getMyPid called)");
long retVal = 0;
retVal = getMyPidOld();
return retVal;
}
I would like to get this:
public static long getMyPid() {
System.out.println("(getMyPid called)");
long retVal = 0;
// use old MXBean hack
retVal = getMyPidOld();
return retVal;
}
Something like keepNormalComments or keepNonmacroComments would be nice
raydac commented
ok, I will check
raydac commented
I've made some improvements and now keepComments allows such variants:
- true it works as previously and keeps all comments
- false it removes all java formatted comments
- keep_all it works as true
- remove_c_style it works as false
- remove_jcp_only removes only JCP directives
if you use gradle then just usekeepComments='remove_jcp_only'