生活随笔
收集整理的這篇文章主要介紹了
android studio插件 统计代码行数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一直好奇 這個插件如何統計代碼行數 注釋行數 和空行數的,
下載其jar包,查看源碼發現,是這樣的
學習下
boolean isInComment
= false;Integer total
= 0;Integer blank
= 0;Integer comment
= 0;Integer code
= 0;try {BufferedInputStream inputStream
= new BufferedInputStream(stream
);LineNumberReader streamReader
= new LineNumberReader(new InputStreamReader(inputStream
));while(true) {while(true) {String line
;do {if (!streamReader
.ready()) {return new LOCBean(total
, blank
, comment
, code
);}line
= streamReader
.readLine();} while(line
== null);total
= total
+ 1;line
= line
.trim();if (line
.length() == 0) {blank
= blank
+ 1;} else if (!line
.startsWith("//") && !line
.startsWith("#")) {if (isInComment
) {comment
= comment
+ 1;if (line
.contains("*/") || line
.contains("\"\"\"") || line
.contains("'''") || line
.contains("-->")) {isInComment
= false;}} else if (!line
.equals("\"\"\"") && !line
.equals("'''")) {if ((!line
.startsWith("/*") || !line
.endsWith("*/")) && (!line
.startsWith("\"\"\"") || !line
.endsWith("\"\"\"")) && (!line
.startsWith("<!--") || !line
.endsWith("-->"))) {if (!line
.startsWith("/*") && !line
.startsWith("\"\"\"") && !line
.startsWith("<!--")) {code
= code
+ 1;} else {comment
= comment
+ 1;if (!line
.contains("*/") || !line
.contains("\"\"\"") || !line
.contains("-->")) {isInComment
= true;}}} else {comment
= comment
+ 1;}} else {comment
= comment
+ 1;isInComment
= true;}} else {comment
= comment
+ 1;}}}} catch (IOException var11
) {var11
.printStackTrace();return new LOCBean(total
, blank
, comment
, code
);}
總結
以上是生活随笔為你收集整理的android studio插件 统计代码行数的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。