Let's say, within a single file, I have the following java code:

  //#if defined(LOGGING)
4    static {
8        if (System.getProperty(ARGO_CONSOLE_SUPPRESS) != null) {
12            Category.getRoot().getLoggerRepository().setThreshold(Level.OFF);
8        }
4    }
  //#endif

Or, this:

//#if defined(LOGGING)
0 static {
0 if (System.getProperty(ARGO_CONSOLE_SUPPRESS) != null) {
0 Category.getRoot().getLoggerRepository().setThreshold(Level.OFF);
0 }
0 }
//#endif

The two comments are added in the file, in addition to the code, and the numbers show the number of spaces (they are added only here for ilustration). Now, my purpose is to identify the two patterns of indentations between the comments: Bubble (first piece of code) or Straight (second piece of code) one.

Ideally, I'm trying to say, for example:

LOGGING: Bubble 1, Straight 1

LOGGING2: Bubble 15, Straight 14

... (and so on, for each //#if defined(...) ... //#endif.

To find the indentations I'm using the following method:

    public static void lineIndents(File file) throws IOException {
        scan = new Scanner(file);   
        while(scan.hasNextLine()) {
        String strLine = scan.nextLine();

        if(strLine.isEmpty()) {
            System.out.println(strLine); 
        } else {
            if(strLine.charAt(0) == '\t') { 
                System.out.println("t" + strLine.lastIndexOf('\t') + strLine);
            } else {
                //writeIndents(file, strLine.indexOf(strLine.trim()));
                System.out.println(strLine.indexOf(strLine.trim()) + ": " + strLine);
                }
             }
        }   

    }

Thank you for any suggestion, help, or comment!

0 Answers