New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javadoc: Column number of DetailNode is always 0 for first line #3507

Closed
baratali opened this Issue Oct 20, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@baratali
Contributor

baratali commented Oct 20, 2016

While transforming ANTRL4 ParseTree to our Checkstyle DetailNode tree, column number is copied as is. However, if DetailNode object matches an object in first line of Javadoc comment, there is no any offset appended.
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/JavadocDetailNodeParser.java#L290

For example:
test.java

class A {
    /** This is
        a method */
    void method(){}
}
$ java -jar checkstyle-7.2-SNAPSHOT-all.jar -J test.java
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|--LITERAL_CLASS -> class [1:0]
|--IDENT -> A [1:6]
`--OBJBLOCK -> OBJBLOCK [1:8]
    |--LCURLY -> { [1:8]
    |--METHOD_DEF -> METHOD_DEF [4:4]
    |   |--MODIFIERS -> MODIFIERS [4:4]
    |   |--TYPE -> TYPE [4:4]
    |   |   |--JAVADOC ->  This is\n        a method <EOF> [2:0]
    |   |   |   |--TEXT ->  This is [2:0]
    |   |   |   |   |--WS ->   [2:0]
    |   |   |   |   |--CHAR -> T [2:1]
    |   |   |   |   |--CHAR -> h [2:2]
    |   |   |   |   |--CHAR -> i [2:3]
    |   |   |   |   |--CHAR -> s [2:4]
    |   |   |   |   |--WS ->   [2:5]
    |   |   |   |   |--CHAR -> i [2:6]
    |   |   |   |   `--CHAR -> s [2:7]
    |   |   |   |--NEWLINE -> \n [2:8]
    |   |   |   |--TEXT ->         a method  [3:0]
    |   |   |   |   |--WS ->          [3:0]
    |   |   |   |   |--CHAR -> a [3:8]
    |   |   |   |   |--WS ->   [3:9]
    |   |   |   |   |--CHAR -> m [3:10]
    |   |   |   |   |--CHAR -> e [3:11]
    |   |   |   |   |--CHAR -> t [3:12]
    |   |   |   |   |--CHAR -> h [3:13]
    |   |   |   |   |--CHAR -> o [3:14]
    |   |   |   |   |--CHAR -> d [3:15]
    |   |   |   |   `--WS ->   [3:16]
    |   |   |   `--EOF -> <EOF> [3:17]
    |   |   `--LITERAL_VOID -> void [4:4]
    |   |--IDENT -> method [4:9]
    |   |--LPAREN -> ( [4:15]
    |   |--PARAMETERS -> PARAMETERS [4:16]
    |   |--RPAREN -> ) [4:16]
    |   `--SLIST -> { [4:17]
    |       `--RCURLY -> } [4:18]
    `--RCURLY -> } [5:0]

Attention to JAVADOC -> This is\n a method <EOF> [2:0]. Line number is 2, however column number is 0 despite it is actually on 7th column. So expected column number is 7.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Nov 16, 2016

Member

@kazachka , do you want to fix this issue ? (as you already familiar with the problem)

Member

romani commented Nov 16, 2016

@kazachka , do you want to fix this issue ? (as you already familiar with the problem)

@kazachka

This comment has been minimized.

Show comment
Hide comment
@kazachka

kazachka Nov 16, 2016

Collaborator

I'm not so close with it, but I might do it.

Collaborator

kazachka commented Nov 16, 2016

I'm not so close with it, but I might do it.

@romani romani added the approved label Nov 25, 2016

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jan 4, 2017

Member

@kazachka Are you doing this and made any progress?

The issue looks like it is similar to the Javadoc's line number, which has a fix using the field blockCommentLineNumber.

node.setLineNumber(getLine(parseTree) + blockCommentLineNumber);

We are giving the javadoc parser only what is in the actual Javadoc, so its lines and column numbers are based off the parser thinking that's the entire document. blockCommentLineNumber is used to increase the line number to the correct full document line number. We need to do something similar with the column number.
The reason the column numbers are wrong for just the first line is because everything after it is an exact copy of what is in the full document, so the column numbers after line 1 are always correct.
The fix needs to only be applied to the first line.

Member

rnveach commented Jan 4, 2017

@kazachka Are you doing this and made any progress?

The issue looks like it is similar to the Javadoc's line number, which has a fix using the field blockCommentLineNumber.

node.setLineNumber(getLine(parseTree) + blockCommentLineNumber);

We are giving the javadoc parser only what is in the actual Javadoc, so its lines and column numbers are based off the parser thinking that's the entire document. blockCommentLineNumber is used to increase the line number to the correct full document line number. We need to do something similar with the column number.
The reason the column numbers are wrong for just the first line is because everything after it is an exact copy of what is in the full document, so the column numbers after line 1 are always correct.
The fix needs to only be applied to the first line.

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 5, 2017

@kazachka

This comment has been minimized.

Show comment
Hide comment
@kazachka

kazachka Jan 5, 2017

Collaborator

@rnveach Thanks, it was useful.

Collaborator

kazachka commented Jan 5, 2017

@rnveach Thanks, it was useful.

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 9, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 9, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 12, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 12, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 14, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 16, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 16, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 16, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 16, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 16, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 17, 2017

rnveach added a commit that referenced this issue Jan 17, 2017

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jan 17, 2017

Member

Fix is merged

Member

rnveach commented Jan 17, 2017

Fix is merged

@rnveach rnveach closed this Jan 17, 2017

@rnveach rnveach added this to the 7.5 milestone Jan 17, 2017

@rnveach rnveach added the bug label Jan 17, 2017

kazachka added a commit to kazachka/checkstyle that referenced this issue Jan 20, 2017

romani added a commit that referenced this issue Jan 20, 2017

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