vjame

          優(yōu)化代碼是無止境的
          隨筆 - 65, 文章 - 9, 評(píng)論 - 26, 引用 - 0
          數(shù)據(jù)加載中……

          代碼統(tǒng)計(jì)

          import java.io.BufferedReader;
          import java.io.File;
          import java.io.FileNotFoundException;
          import java.io.FileReader;
          import java.io.IOException;

          public class CodeCounter {
              
              
          static long normalLines = 0;
              
          static long commentLines = 0;
              
          static long whiteLines = 0;
              
              
          public static void main(String[] args) {
                  File f 
          = new File("D:\\share\\JavaProjects\\TankWar1.9.11\\src");
                  File[] codeFiles 
          = f.listFiles();
                  
          for(File child : codeFiles){
                      
          if(child.getName().matches(".*\\.java$")) {
                          parse(child);
                      }
                  }
                  
                  System.out.println(
          "normalLines:" + normalLines);
                  System.out.println(
          "commentLines:" + commentLines);
                  System.out.println(
          "whiteLines:" + whiteLines);
                  
              }

              
          private static void parse(File f) {
                  BufferedReader br 
          = null;
                  
          boolean comment = false;
                  
          try {
                      br 
          = new BufferedReader(new FileReader(f));
                      String line 
          = "";
                      
          while((line = br.readLine()) != null) {
                          line 
          = line.trim();
                          
          if(line.matches("^[\\s&&[^\\n]]*$")) {
                              whiteLines 
          ++;
                          } 
          else if (line.startsWith("/*"&& !line.endsWith("*/")) {
                              commentLines 
          ++;
                              comment 
          = true;    
                          } 
          else if (line.startsWith("/*"&& line.endsWith("*/")) {
                              commentLines 
          ++;
                          } 
          else if (true == comment) {
                              commentLines 
          ++;
                              
          if(line.endsWith("*/")) {
                                  comment 
          = false;
                              }
                          } 
          else if (line.startsWith("//")) {
                              commentLines 
          ++;
                          } 
          else {
                              normalLines 
          ++;
                          }
                      }
                  } 
          catch (FileNotFoundException e) {
                      e.printStackTrace();
                  } 
          catch (IOException e) {
                      e.printStackTrace();
                  } 
          finally {
                      
          if(br != null) {
                          
          try {
                              br.close();
                              br 
          = null;
                          } 
          catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  }
              }

          }

          posted on 2009-02-09 13:23 lanjh 閱讀(479) 評(píng)論(5)  編輯  收藏 所屬分類: Java App

          評(píng)論

          # re: 代碼統(tǒng)計(jì)  回復(fù)  更多評(píng)論   

          這個(gè)算法比較簡(jiǎn)單,而且沒有考慮折行的問題,難能可貴的是是自己實(shí)現(xiàn)這個(gè)算法,鼓勵(lì)了
          2009-02-10 11:13 | jeasonzhao

          # Pharmacy  回復(fù)  更多評(píng)論   

          Hi. In the future I'm going to keep here links to their sites. But I do not worry about the sites where my link is removed. So if you do not want to see a mountain of links, simply delete this message. After 2 weeks, I will come back and check.
          2009-05-12 01:53 | Taddeo

          # Wall clock  回復(fù)  更多評(píng)論   

          Hello everyone. Speak when you are angry--and you will make the best speech you'll ever regret.
          I am from Egypt and learning to write in English, please tell me right I wrote the following sentence: "Synthroid and phentermine, tramadol cheap price, phentermine with vit injection, phentermine no prescription online consultation, addition in order phentermine."

          Thank you so much for your future answers :-(. Zaccheus.
          2009-05-15 19:25 | Zaccheus

          # Payday LOan  回復(fù)  更多評(píng)論   

          Give please. Use what you have to run toward your best - that's how I now live my life.
          I am from Czech and also now'm speaking English, give please true I wrote the following sentence: "Progesterone, synthroid, flagyli I pulses azith m w f sun, estriol, progesterone, synthroid, and pulsing w flagyli."

          Thanks for the help 8), Doreen.
          2009-05-19 11:45 | Doreen

          # Turbo Tax  回復(fù)  更多評(píng)論   

          Hi everyone. I love you so much. Great place to visit. Help me! Can not find sites on the: Turbo Tax. I found only this - <a href="http://turbo-tax.biz">turbo tax</a>. Buy cytomel liothyronine sodium online. Synthroid too high synthroid and cholesterol soon after starting synthroid taken with adderall tramadol, he began to. With respect ;-), Rosalyn from Jamaica.
          2009-05-24 18:55 | Rosalyn
          主站蜘蛛池模板: 镇赉县| 普兰店市| 金秀| 称多县| 兴安县| 民乐县| 霍城县| 吕梁市| 义马市| 海口市| 泸溪县| 达日县| 渝中区| 绵竹市| 炎陵县| 枞阳县| 萝北县| 同仁县| 桑植县| 江华| 乐昌市| 桦川县| 易门县| 沭阳县| 福海县| 兰西县| 富源县| 朔州市| 饶平县| 定西市| 卢氏县| 十堰市| 凌云县| 贺州市| 珠海市| 汪清县| 清徐县| 曲阳县| 鹤庆县| 黄梅县| 高清|