Re: How to strip comments out of code
On 31 oct, 05:43, Lew <l...@lewscanon.com> wrote:
silviocor...@yahoo.com wrote:
I need to write a class that will take a java file as input, strip all
the comments out, and save thre result in a different file....
Why not just decompile the bytecode?
Because decompilers change the syntax. Sometimes making it hard to
understand, sometimes easier, but changed anyway.
For instance
public String toString() {
String myname = this.getName();
return("#<"
+ (myname!=null ? (" " + myname) : "" )
+ ">");
}
becomes (with jad)
public String toString()
{
String myname = getName();
return (new StringBuilder()).append("#<").append(myname ==
null ? "" : (new StringBuilder()).append("
").append(myname).toString()).append(">").toString();
}
Also, decompilers have problems, in particular with inline functions
or static declarations (see for instance http://www.kpdus.com/jad.html#bugs,
and JAD is one of the best AFAIK).
So, it was a nice idea, but does not provide a good answer to the
need. I like the idea of using a C/C++ preprocessor (even though there
might be side effects, too).
--
R=E9gis