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: custom annotation not checked #3134

Closed
rnveach opened this Issue Apr 26, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@rnveach
Member

rnveach commented Apr 26, 2016

$ cat TestClass.java
     public class TestClass {}
     public interface TestInterface {}
     public enum TestEnum {}
     @interface MyAnnotation {} // line 4
     @interface MyAnnotation2 {
String author(); // line 6
     }

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<property name="tabWidth" value="4"/>

    <module name="Indentation">
      <property name="arrayInitIndent" value="4"/>
      <property name="basicOffset" value="4"/>
      <property name="braceAdjustment" value="0"/>
      <property name="lineWrappingIndentation" value="4"/>
    </module>
    </module>
</module>

$ java -jar checkstyle-6.17-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:1: 'class def modifier' have incorrect indentation level 5, expected level should be 0. [Indentation]
[ERROR] TestClass.java:2: 'interface def modifier' have incorrect indentation level 5, expected level should be 0. [Indentation]
[ERROR] TestClass.java:3: 'enum def modifier' have incorrect indentation level 5, expected level should be 0. [Indentation]
Audit done.
Checkstyle ends with 3 errors.

I was expecting a similar violation on line 4 as we require class, interface, and enum to all be at indent 0.
I was also expecting a violation at line 6 requiring a proper indentation, like expecting to be at column 9 (5 from brace + 4 for normal indentation).

@kukreja-vikramaditya

This comment has been minimized.

Show comment
Hide comment
@kukreja-vikramaditya

kukreja-vikramaditya Apr 10, 2017

Contributor

I am on it

Contributor

kukreja-vikramaditya commented Apr 10, 2017

I am on it

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 12, 2017

@kukreja-vikramaditya

This comment has been minimized.

Show comment
Hide comment
@kukreja-vikramaditya

kukreja-vikramaditya Apr 12, 2017

Contributor

I resolved the issue by adding these two lines to the HandlerFactory

        register(TokenTypes.ANNOTATION_DEF, ClassDefHandler.class);
        register(TokenTypes.ANNOTATION_FIELD_DEF, AnnotationDefHandler.class);

where newly created AnnotationDefHandler is based on MethodDefHandler (instead of ClassDefHandler)

However mvn clean verify fails as HandlerFactory is not allowed to have more than 30 executable statements. Can this limit be changed? If not, should MethodDefHandler be edited somehow to include AnnotationDefHandler as both of them are similar? (We will still be left with 1 extra execute command)
I will update the value in the config file, generate the reports and send the PR

My fix here master...kukreja-vikramaditya:fix-issue-3134 (PR not yet created as local build fails will be sent after fixing coverage errors)

Contributor

kukreja-vikramaditya commented Apr 12, 2017

I resolved the issue by adding these two lines to the HandlerFactory

        register(TokenTypes.ANNOTATION_DEF, ClassDefHandler.class);
        register(TokenTypes.ANNOTATION_FIELD_DEF, AnnotationDefHandler.class);

where newly created AnnotationDefHandler is based on MethodDefHandler (instead of ClassDefHandler)

However mvn clean verify fails as HandlerFactory is not allowed to have more than 30 executable statements. Can this limit be changed? If not, should MethodDefHandler be edited somehow to include AnnotationDefHandler as both of them are similar? (We will still be left with 1 extra execute command)
I will update the value in the config file, generate the reports and send the PR

My fix here master...kukreja-vikramaditya:fix-issue-3134 (PR not yet created as local build fails will be sent after fixing coverage errors)

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 14, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 16, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 19, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 24, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 25, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 25, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Apr 27, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue May 24, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue May 25, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Jun 4, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Jun 14, 2017

kukreja-vikramaditya added a commit to kukreja-vikramaditya/checkstyle that referenced this issue Jun 19, 2017

romani added a commit that referenced this issue Jun 27, 2017

@romani romani added the bug label Jun 27, 2017

@romani romani added this to the 8.0 milestone Jun 27, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 27, 2017

Member

@kukreja-vikramaditya , thanks a lot for hard work on this issue!!!

Member

romani commented Jun 27, 2017

@kukreja-vikramaditya , thanks a lot for hard work on this issue!!!

@romani romani closed this Jun 27, 2017

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