src/org/nutz/lang/Code.java
public static CodeAnalysisResult countingCode(File file,
                                                  CodeAnalysisConf conf) {
        if (!Files.isFile(file)) {
            throw new RuntimeException("file is not a File, can't analysis it.");
        }
        if (null == conf) {
            conf = CODE_INFO_JAVA;
        }
        BufferedReader br;
        try {
            br = new BufferedReader(new FileReader(file));
        }
        catch (FileNotFoundException e) {
            throw Lang.wrapThrow(e);
        }
        boolean comment = false;
        long whiteLines = 0;
        long commentLines = 0;
        long normalLines = 0;
        long importLines = 0;
        String line = "";
        try {
            while ((line = br.readLine()) != null) {
                line = line.trim();
                if (line.startsWith(conf.multiLineCommentStart)
                    && !line.endsWith(conf.multiLineCommentEnd)) {
                    // 多行注释开始
                    commentLines++;
                    comment = true;
                } else if (true == comment) {
                    // 多行注释结束
                    commentLines++;
                    if (line.endsWith(conf.multiLineCommentEnd)) {
                        comment = false;
                    }
                } else if (Regex.match(conf.emptyLinePattern, line)) {
                    // 空白行(多行注解内的空白行不算在内)
                    whiteLines++;
                } else if (line.startsWith(conf.singleLineCommentStart)
                           || (line.startsWith(conf.multiLineCommentStart) && line.endsWith(conf.multiLineCommentEnd))) {
                    // 单行注释
                    commentLines++;
                } else if (line.startsWith(conf.pakStart)
                           || line.startsWith(conf.impStart)) {
                    // package与import
                    importLines++;
                } else {
                    // 代码行
                    normalLines++;
                }
            }
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }
        if (br != null) {
            try {
                br.close();
            }
            catch (IOException e) {
                throw Lang.wrapThrow(e);
            }
        }
        // 记录并返回统计结果
        return new CodeAnalysisResult(normalLines,
                                      commentLines,
                                      whiteLines,
                                      importLines);
    }
public static CodeAnalysisResult countingCode(File file,
                                                  CodeAnalysisConf conf) {
        if (!Files.isFile(file)) {
            throw new RuntimeException("file is not a File, can't analysis it.");
        }
        if (null == conf) {
            conf = CODE_INFO_JAVA;
        }
        BufferedReader br;
        try {
            br = new BufferedReader(new FileReader(file));
        }
        catch (FileNotFoundException e) {
            throw Lang.wrapThrow(e);
        }
        boolean comment = false;
        long whiteLines = 0;
        long commentLines = 0;
        long normalLines = 0;
        long importLines = 0;
        String line = "";
        try {
            while ((line = br.readLine()) != null) {
                line = line.trim();
                if (line.startsWith(conf.multiLineCommentStart)
                    && !line.endsWith(conf.multiLineCommentEnd)) {
                    // 多行注释开始
                    commentLines++;
                    comment = true;
                } else if (true == comment) {
                    // 多行注释结束
                    commentLines++;
                    if (line.endsWith(conf.multiLineCommentEnd)) {
                        comment = false;
                    }
                } else if (Regex.match(conf.emptyLinePattern, line)) {
                    // 空白行(多行注解内的空白行不算在内)
                    whiteLines++;
                } else if (line.startsWith(conf.singleLineCommentStart)
                           || (line.startsWith(conf.multiLineCommentStart) && line.endsWith(conf.multiLineCommentEnd))) {
                    // 单行注释
                    commentLines++;
                } else if (line.startsWith(conf.pakStart)
                           || line.startsWith(conf.impStart)) {
                    // package与import
                    importLines++;
                } else {
                    // 代码行
                    normalLines++;
                }
            }
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }
        if (br != null) {
            try {
                br.close();
            }
            catch (IOException e) {
                throw Lang.wrapThrow(e);
            }
        }
        // 记录并返回统计结果
        return new CodeAnalysisResult(normalLines,
                                      commentLines,
                                      whiteLines,
                                      importLines);
    }
统计某个文件的信息。

@param file
被分析的文件
@param conf
代码分析配置项(为空的话，则按照JAVA代码来进行分析统计)
@return 分析结果