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

Indentation: Annotation with RParen on new line when followed by other annotations causes invalid expectation #3733

Closed
bamapookie opened this Issue Jan 17, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@bamapookie
Contributor

bamapookie commented Jan 17, 2017

temp $ javac CheckstyleRightParenBug.java

temp $ cat CheckstyleRightParenBug.java

@interface RightParenBug {
    String value();
}
@interface RightParenNoBug {
    String value();
}
@RightParenBug(
    "Check out that warning on the next line"
) // Error on this line: ')' have incorrect indentation level 0, expected level should be 4. (3:0)
@RightParenNoBug(
    "Check out that not-warning on the next line"
) // But no bug here.  This is what is expected.
public class CheckstyleRightParenBug {}

temp $ cat config.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="Indentation" />
    </module>
</module>

temp $ java -jar checkstyle-7.4-all.jar -c config.xml CheckstyleRightParenBug.java
Starting audit...
[ERROR] /temp/CheckstyleRightParenBug.java:9: ')' have incorrect indentation level 0, expected level should be 4. [Indentation]
Audit done.
Checkstyle ends with 1 errors.


I expect the closing parenthesis to be at the same level as the start of the annotation, but this is only enforced on the last annotation before the class declaration. This error also occurs on annotations of other elements as well (class variables, methods, etc.). They are all erroneously expected to be one basic offset deeper than they should be.


I suspect that this might be related to issues #3134, #3130, and #553 as well.

@bamapookie

This comment has been minimized.

Show comment
Hide comment
@bamapookie

bamapookie Jan 17, 2017

Contributor

Stepping through the test code, I see that the two annotations are bunched together when calling checkAnnotationIndentation in LineWrappingHandler.java. The parameter atNode includes the lines from all the annotations and the public access modifier preceding the (class|method) declaration. lastAnnotationNode gets set to the last line of the last annotation, and not the last line of the current annotation.

I understand that resources are limited in addressing this (and the other indentation) bugs. I will take a stab at fixing it when I get some free time.

Contributor

bamapookie commented Jan 17, 2017

Stepping through the test code, I see that the two annotations are bunched together when calling checkAnnotationIndentation in LineWrappingHandler.java. The parameter atNode includes the lines from all the annotations and the public access modifier preceding the (class|method) declaration. lastAnnotationNode gets set to the last line of the last annotation, and not the last line of the current annotation.

I understand that resources are limited in addressing this (and the other indentation) bugs. I will take a stab at fixing it when I get some free time.

@rnveach rnveach added the indentaion label Jan 17, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Jan 18, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Jan 18, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 6, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 6, 2017

Issue #3733: Fix stacked annotation handling and end of scope checking
Modify annotation indentation check to check one annotation at a time
Add end of scope check to allow nested braces and brackets in
annotations

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 6, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 6, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 10, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 10, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 10, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 10, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 11, 2017

bamapookie added a commit to bamapookie/checkstyle that referenced this issue Feb 11, 2017

rnveach added a commit that referenced this issue Feb 15, 2017

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Feb 15, 2017

Member

Fix is merged

Member

rnveach commented Feb 15, 2017

Fix is merged

@rnveach rnveach closed this Feb 15, 2017

@romani romani added this to the 7.6 milestone Feb 15, 2017

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