Online docs: AST example for LITERAL_DO is missing the DO_WHILE node #3209

Closed
eric-milles opened this Issue May 22, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@eric-milles

eric-milles commented May 22, 2016

Hopefully this is an easy one. The online docs for TokenTypes shows an invalid AST for LITERAL_DO. After the statement list, it is showing LPAREN as the next sibling. I think DO_WHILE comes next. This would be useful because I was trying to use DescendantToken to check something specifically in the while clause of a do/while, but could not tell of the parens fall under DO_WHILE or LITERAL_FOR. (Sorry, I havent busted out the AST viewer in quite some time.)

Also, if possible, could you add an example for a for-each loop under LITERAL_FOR? That would be helpful since it is quite different from the counting loop's AST.

Thanks for your time and efforts.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 27, 2016

Member

@eric-milles , thanks for report , but I do not understand what you are trying to point to.

please use links to Check sections and quotation of wrong part of doc to let me find it and fix.

Member

romani commented Jun 27, 2016

@eric-milles , thanks for report , but I do not understand what you are trying to point to.

please use links to Check sections and quotation of wrong part of doc to let me find it and fix.

@eric-milles

This comment has been minimized.

Show comment
Hide comment
@eric-milles

eric-milles Jun 27, 2016

Link was provided. Here it is in the clear: http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO

I'll do my best to quote; the description above points out the exact spot in the AST that I think is incorrect.

+--LITERAL_DO (do)
     |
     +--SLIST ({)
         |
         +--EXPR
             |
             +--ASSIGN (=)
                 |
                 +--IDENT (x)
                 +--METHOD_CALL (()
                     |
                     +--DOT (.)
                         |
                         +--IDENT (rand)
                         +--IDENT (nextInt)
                     +--ELIST
                         |
                         +--EXPR
                             |
                             +--NUM_INT (10)
                     +--RPAREN ())
         +--SEMI (;)
         +--RCURLY (})
**I believe the token DO_WHILE comes here**
     +--LPAREN (()
     +--EXPR
         |
         +--LT (<)
             |
             +--IDENT (x)
             +--NUM_INT (5)
     +--RPAREN ())
     +--SEMI (;)

Link was provided. Here it is in the clear: http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO

I'll do my best to quote; the description above points out the exact spot in the AST that I think is incorrect.

+--LITERAL_DO (do)
     |
     +--SLIST ({)
         |
         +--EXPR
             |
             +--ASSIGN (=)
                 |
                 +--IDENT (x)
                 +--METHOD_CALL (()
                     |
                     +--DOT (.)
                         |
                         +--IDENT (rand)
                         +--IDENT (nextInt)
                     +--ELIST
                         |
                         +--EXPR
                             |
                             +--NUM_INT (10)
                     +--RPAREN ())
         +--SEMI (;)
         +--RCURLY (})
**I believe the token DO_WHILE comes here**
     +--LPAREN (()
     +--EXPR
         |
         +--LT (<)
             |
             +--IDENT (x)
             +--NUM_INT (5)
     +--RPAREN ())
     +--SEMI (;)
@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 28, 2016

Member

you are right , good catch !

/var/tmp $ cat TestClass.java 
public class TestClass {
    public void somePublicMethod() {
         do
         {
           x = rand.nextInt(10);
         }
         while(x < 5);
    }
}

/var/tmp $ java -jar checkstyle-7.0-all.jar -t TestClass.java 
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|   `--LITERAL_PUBLIC -> public [1:0]
|--LITERAL_CLASS -> class [1:7]
|--IDENT -> TestClass [1:13]
`--OBJBLOCK -> OBJBLOCK [1:23]
    |--LCURLY -> { [1:23]
    |--METHOD_DEF -> METHOD_DEF [2:4]
    |   |--MODIFIERS -> MODIFIERS [2:4]
    |   |   `--LITERAL_PUBLIC -> public [2:4]
    |   |--TYPE -> TYPE [2:11]
    |   |   `--LITERAL_VOID -> void [2:11]
    |   |--IDENT -> somePublicMethod [2:16]
    |   |--LPAREN -> ( [2:32]
    |   |--PARAMETERS -> PARAMETERS [2:33]
    |   |--RPAREN -> ) [2:33]
    |   `--SLIST -> { [2:35]
    |       |--LITERAL_DO -> do [3:6]
    |       |   |--SLIST -> { [4:3]
    |       |   |   |--EXPR -> EXPR [5:7]
    |       |   |   |   `--ASSIGN -> = [5:7]
    |       |   |   |       |--IDENT -> x [5:5]
    |       |   |   |       `--METHOD_CALL -> ( [5:21]
    |       |   |   |           |--DOT -> . [5:13]
    |       |   |   |           |   |--IDENT -> rand [5:9]
    |       |   |   |           |   `--IDENT -> nextInt [5:14]
    |       |   |   |           |--ELIST -> ELIST [5:22]
    |       |   |   |           |   `--EXPR -> EXPR [5:22]
    |       |   |   |           |       `--NUM_INT -> 10 [5:22]
    |       |   |   |           `--RPAREN -> ) [5:24]
    |       |   |   |--SEMI -> ; [5:25]
    |       |   |   `--RCURLY -> } [6:3]
    |       |   |--DO_WHILE -> while [7:3]
    |       |   |--LPAREN -> ( [7:8]
    |       |   |--EXPR -> EXPR [7:11]
    |       |   |   `--LT -> < [7:11]
    |       |   |       |--IDENT -> x [7:9]
    |       |   |       `--NUM_INT -> 5 [7:13]
    |       |   |--RPAREN -> ) [7:14]
    |       |   `--SEMI -> ; [7:15]
    |       `--RCURLY -> } [8:4]
    `--RCURLY -> } [9:0]
Member

romani commented Jun 28, 2016

you are right , good catch !

/var/tmp $ cat TestClass.java 
public class TestClass {
    public void somePublicMethod() {
         do
         {
           x = rand.nextInt(10);
         }
         while(x < 5);
    }
}

/var/tmp $ java -jar checkstyle-7.0-all.jar -t TestClass.java 
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|   `--LITERAL_PUBLIC -> public [1:0]
|--LITERAL_CLASS -> class [1:7]
|--IDENT -> TestClass [1:13]
`--OBJBLOCK -> OBJBLOCK [1:23]
    |--LCURLY -> { [1:23]
    |--METHOD_DEF -> METHOD_DEF [2:4]
    |   |--MODIFIERS -> MODIFIERS [2:4]
    |   |   `--LITERAL_PUBLIC -> public [2:4]
    |   |--TYPE -> TYPE [2:11]
    |   |   `--LITERAL_VOID -> void [2:11]
    |   |--IDENT -> somePublicMethod [2:16]
    |   |--LPAREN -> ( [2:32]
    |   |--PARAMETERS -> PARAMETERS [2:33]
    |   |--RPAREN -> ) [2:33]
    |   `--SLIST -> { [2:35]
    |       |--LITERAL_DO -> do [3:6]
    |       |   |--SLIST -> { [4:3]
    |       |   |   |--EXPR -> EXPR [5:7]
    |       |   |   |   `--ASSIGN -> = [5:7]
    |       |   |   |       |--IDENT -> x [5:5]
    |       |   |   |       `--METHOD_CALL -> ( [5:21]
    |       |   |   |           |--DOT -> . [5:13]
    |       |   |   |           |   |--IDENT -> rand [5:9]
    |       |   |   |           |   `--IDENT -> nextInt [5:14]
    |       |   |   |           |--ELIST -> ELIST [5:22]
    |       |   |   |           |   `--EXPR -> EXPR [5:22]
    |       |   |   |           |       `--NUM_INT -> 10 [5:22]
    |       |   |   |           `--RPAREN -> ) [5:24]
    |       |   |   |--SEMI -> ; [5:25]
    |       |   |   `--RCURLY -> } [6:3]
    |       |   |--DO_WHILE -> while [7:3]
    |       |   |--LPAREN -> ( [7:8]
    |       |   |--EXPR -> EXPR [7:11]
    |       |   |   `--LT -> < [7:11]
    |       |   |       |--IDENT -> x [7:9]
    |       |   |       `--NUM_INT -> 5 [7:13]
    |       |   |--RPAREN -> ) [7:14]
    |       |   `--SEMI -> ; [7:15]
    |       `--RCURLY -> } [8:4]
    `--RCURLY -> } [9:0]

romani added a commit that referenced this issue Jun 28, 2016

@romani romani added this to the 7.1 milestone Jun 28, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 28, 2016

Member

fixed.

Member

romani commented Jun 28, 2016

fixed.

@romani romani closed this Jun 28, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 28, 2016

Member

Also, if possible, could you add an example for a for-each loop under LITERAL_FOR? That would be helpful since it is quite different from the counting loop's AST.

should be done too

Member

romani commented Jun 28, 2016

Also, if possible, could you add an example for a for-each loop under LITERAL_FOR? That would be helpful since it is quite different from the counting loop's AST.

should be done too

@romani romani reopened this Jun 28, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 28, 2016

Member
/var/tmp $ cat TestClass.java 
public class TestClass {
    public void somePublicMethod() {
         for (int value : values) {
            doSmth();
         }
    }
}

/var/tmp $java -jar checkstyle-7.0-all.jar -t TestClass.java 
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|   `--LITERAL_PUBLIC -> public [1:0]
|--LITERAL_CLASS -> class [1:7]
|--IDENT -> TestClass [1:13]
`--OBJBLOCK -> OBJBLOCK [1:23]
    |--LCURLY -> { [1:23]
    |--METHOD_DEF -> METHOD_DEF [2:4]
    |   |--MODIFIERS -> MODIFIERS [2:4]
    |   |   `--LITERAL_PUBLIC -> public [2:4]
    |   |--TYPE -> TYPE [2:11]
    |   |   `--LITERAL_VOID -> void [2:11]
    |   |--IDENT -> somePublicMethod [2:16]
    |   |--LPAREN -> ( [2:32]
    |   |--PARAMETERS -> PARAMETERS [2:33]
    |   |--RPAREN -> ) [2:33]
    |   `--SLIST -> { [2:35]
    |       |--LITERAL_FOR -> for [3:6]
    |       |   |--LPAREN -> ( [3:10]
    |       |   |--FOR_EACH_CLAUSE -> FOR_EACH_CLAUSE [3:11]
    |       |   |   |--VARIABLE_DEF -> VARIABLE_DEF [3:11]
    |       |   |   |   |--MODIFIERS -> MODIFIERS [3:11]
    |       |   |   |   |--TYPE -> TYPE [3:11]
    |       |   |   |   |   `--LITERAL_INT -> int [3:11]
    |       |   |   |   `--IDENT -> value [3:15]
    |       |   |   |--COLON -> : [3:21]
    |       |   |   `--EXPR -> EXPR [3:23]
    |       |   |       `--IDENT -> values [3:23]
    |       |   |--RPAREN -> ) [3:29]
    |       |   `--SLIST -> { [3:31]
    |       |       |--EXPR -> EXPR [4:13]
    |       |       |   `--METHOD_CALL -> ( [4:13]
    |       |       |       |--IDENT -> doSmth [4:7]
    |       |       |       |--ELIST -> ELIST [4:14]
    |       |       |       `--RPAREN -> ) [4:14]
    |       |       |--SEMI -> ; [4:15]
    |       |       `--RCURLY -> } [5:6]
    |       `--RCURLY -> } [6:4]
    `--RCURLY -> } [7:0]
Member

romani commented Jun 28, 2016

/var/tmp $ cat TestClass.java 
public class TestClass {
    public void somePublicMethod() {
         for (int value : values) {
            doSmth();
         }
    }
}

/var/tmp $java -jar checkstyle-7.0-all.jar -t TestClass.java 
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|   `--LITERAL_PUBLIC -> public [1:0]
|--LITERAL_CLASS -> class [1:7]
|--IDENT -> TestClass [1:13]
`--OBJBLOCK -> OBJBLOCK [1:23]
    |--LCURLY -> { [1:23]
    |--METHOD_DEF -> METHOD_DEF [2:4]
    |   |--MODIFIERS -> MODIFIERS [2:4]
    |   |   `--LITERAL_PUBLIC -> public [2:4]
    |   |--TYPE -> TYPE [2:11]
    |   |   `--LITERAL_VOID -> void [2:11]
    |   |--IDENT -> somePublicMethod [2:16]
    |   |--LPAREN -> ( [2:32]
    |   |--PARAMETERS -> PARAMETERS [2:33]
    |   |--RPAREN -> ) [2:33]
    |   `--SLIST -> { [2:35]
    |       |--LITERAL_FOR -> for [3:6]
    |       |   |--LPAREN -> ( [3:10]
    |       |   |--FOR_EACH_CLAUSE -> FOR_EACH_CLAUSE [3:11]
    |       |   |   |--VARIABLE_DEF -> VARIABLE_DEF [3:11]
    |       |   |   |   |--MODIFIERS -> MODIFIERS [3:11]
    |       |   |   |   |--TYPE -> TYPE [3:11]
    |       |   |   |   |   `--LITERAL_INT -> int [3:11]
    |       |   |   |   `--IDENT -> value [3:15]
    |       |   |   |--COLON -> : [3:21]
    |       |   |   `--EXPR -> EXPR [3:23]
    |       |   |       `--IDENT -> values [3:23]
    |       |   |--RPAREN -> ) [3:29]
    |       |   `--SLIST -> { [3:31]
    |       |       |--EXPR -> EXPR [4:13]
    |       |       |   `--METHOD_CALL -> ( [4:13]
    |       |       |       |--IDENT -> doSmth [4:7]
    |       |       |       |--ELIST -> ELIST [4:14]
    |       |       |       `--RPAREN -> ) [4:14]
    |       |       |--SEMI -> ; [4:15]
    |       |       `--RCURLY -> } [5:6]
    |       `--RCURLY -> } [6:4]
    `--RCURLY -> } [7:0]

romani added a commit that referenced this issue Jun 28, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 28, 2016

Member

fixed.

as you notice one more problem, or smth you would like to improve please be welcome with Pull Request.

Member

romani commented Jun 28, 2016

fixed.

as you notice one more problem, or smth you would like to improve please be welcome with Pull Request.

@romani romani closed this Jun 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment