Delete the source code of Java comments

Source: Internet
Author: User

Delete the source code of Java comments
 
Import java. util. RegEx .*;
Import java. Io .*;
Import util9 .*;
// Some java files have too many comments, which affects readability. This class can solve this problem.
// Usage.
Public class delnoteinjavafile {
Static bufferedreader BR;
Static bufferedwriter bw;
Static string suffix = ". nonote. Java ";
Public delnoteinjavafile ()
{
String message = "input file name :";
String ret = read9.stringfromcontrol (Message );
If (injava (new file (RET) system. Out. println ("successed ");
Else system. Out. println ("failed ");
}
Public delnoteinjavafile (string F)
{
If (injava (new file (F) system. Out. println ("successed ");
Else system. Out. println ("failed ");
}
Public delnoteinjavafile (file F)
{
If (injava (F) system. Out. println ("successed ");
Else system. Out. println ("failed ");
}
Public static Boolean check (file F)
{
If (! F. exists ()){
System. Err. println ("wrong1.file not exists ");
Return false;
}
If (! F. isfile ()){
System. Err. println ("wrong2.abstract file is not a file ");
Return false;
}
Return true;
}
Public static Boolean injava (file F ){
If (check (f) = false) return false;
File FF = new file (F. getname () + suffix );
If (FF. exists ()){
System. Out. println ("wrong3 ");
Return false;
}
String S, SS;
Try {
Ff. createnewfile ();
BR = new bufferedreader (New filereader (f ));
BW = new bufferedwriter (New filewriter (ff ));
// The slash is Char '/', the star is Char '*'.
Pattern slash_star_start = pattern. Compile ("// *. *"); // just like :/*....
Pattern star_slash = pattern. Compile ("^ .*//*/");
Pattern slash_star_both = pattern. Compile ("///*.*//*/");
Pattern slash2 = pattern. Compile ("// s {0 ,}//");
// Pattern star = pattern. Compile ("// s {0 ,}//*");
Matcher MAT;
Int I = 0;
Boolean note = false;
While (S = Br. Readline ())! = NULL ){
// Deal with such string :.../*...*/....
If (S. Trim (). Length () = 0) continue;
S = S. replaceall (slash_star_both.pattern (),"");
// Deal :....//....
MAT = slash2.matcher (s );
If (mat. Find () & not; E = false ){
System. Out. println ("S1 =" + S );
S = S. substring (0, mat. Start ());
If (S. Trim (). Length () = 0) continue;
Bw. Write (s );
Bw. newline ();
Continue;
}
// Deal :...*/...
MAT = star_slash.matcher (s );
If (mat. Find ()){
Note = false;
System. Out. println ("S2 =" + S );
S = S. substring (mat. End ());

If (S. Trim (). Length () = 0 ){
Continue;
}
}
If (note = true ){
Continue;
}
// Deal :..../*....
MAT = slash_star_start.matcher (s );
If (mat. Find ()){
Note = true;
System. Out. println ("s =" + S );
S = S. substring (0, mat. Start ());
System. Out. println ("S1 =" + S + ", mat. Start () =" + mat. Start ());
If (S. Trim (). Length () = 0 ){
Continue;
}

}
Bw. Write (s );
Bw. newline ();
}
BR. Close ();
Bw. Close ();
/*
If (F. renameto (new file (FF. getname () + ". Bak "))){
System. Out. println ("backup file is:" + ff. getname () + ". Bak ");
If (FF. renameto (f ))
System. Out. println ("output file is:" + F. getname ());
Else {system. Out. println ("wrong53"); Return false ;}
}
Else {
System. Out. println ("wrong55 ");
Return false;
}
*/
}
Catch (ioexception e ){
E. getmessage ();
Return false;
}
Return true;
}

Public static Boolean injava (string s ){
Return injava (new file (s ));
}
Public static void main (string a [])
{If (A. Length = 0) New delnote9 ();
Else new delnoteinjavafile (A [0]);
}
}
 
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.