You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hbase.apache.org by Stephen Jiang <sy...@gmail.com> on 2016/05/04 14:13:42 UTC

A checkstyle question: indentation in switch-case statements

I got two checkstyle warning for the style of switch-case statements:

./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
           cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
error: 'block' child have incorrect indentation level 12, expected
level should be one of the following: 14, 16.
./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
           cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
error: 'method call' child have incorrect indentation level 12,
expected level should be one of the following: 14, 16.

To me, the 2-space indentation looks correct.  What is wrong for this style
(switch and case are in the same level, is this wrong?  I set up HBASE
coding style in eclipse and it automatically did it this way)?

          switch (state) {

          case ADD_COLUMN_FAMILY_PRE_OPERATION:

            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);

            break;

          case ADD_COLUMN_FAMILY_POST_OPERATION:

            cpHost.postCompletedAddColumnFamilyAction(tableName,
cfDescriptor);

            break;

          default:

            throw new UnsupportedOperationException(this + " unhandled
state=" + state);

          }


Any insight would be helpful.

Thanks

Stephen

Re: A checkstyle question: indentation in switch-case statements

Posted by Ted Yu <yu...@gmail.com>.
Looks like there is no official indentation in this case.

I think you can go with what HBASE code style gives you.

On Wed, May 4, 2016 at 9:16 AM, Stephen Jiang <sy...@gmail.com>
wrote:

> thanks, Matteo.  I also suspected that this is the issue.  I am just
> surprised that the code exists for a while and no complain in the past.
>
> When I loaded the HBASE code style in Eclipse, this is the indentation
> style I got when I hit 'return' after typing 'case'.  And I checked other
> existing code (eg. TableState.java and MetaTableAccessor.java), there are
> using the same indentation style (AKA, no indentation for case-statement);
> however, some other code (eg. HBaseAdmin.java), 2-space indentations are
> used.  So which style is official?
>
> thanks
> Stephen
>
> On Wed, May 4, 2016 at 7:20 AM, Matteo Bertozzi <th...@gmail.com>
> wrote:
>
> > I think it is complaining because the "case" is aligned with the "switch"
> > and not indented
> >
> > Matteo
> >
> >
> > On Wed, May 4, 2016 at 7:13 AM, Stephen Jiang <sy...@gmail.com>
> > wrote:
> >
> > > I got two checkstyle warning for the style of switch-case statements:
> > >
> > >
> > >
> >
> ./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
> > >            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
> > > error: 'block' child have incorrect indentation level 12, expected
> > > level should be one of the following: 14, 16.
> > >
> > >
> >
> ./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
> > >            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
> > > error: 'method call' child have incorrect indentation level 12,
> > > expected level should be one of the following: 14, 16.
> > >
> > > To me, the 2-space indentation looks correct.  What is wrong for this
> > style
> > > (switch and case are in the same level, is this wrong?  I set up HBASE
> > > coding style in eclipse and it automatically did it this way)?
> > >
> > >           switch (state) {
> > >
> > >           case ADD_COLUMN_FAMILY_PRE_OPERATION:
> > >
> > >             cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);
> > >
> > >             break;
> > >
> > >           case ADD_COLUMN_FAMILY_POST_OPERATION:
> > >
> > >             cpHost.postCompletedAddColumnFamilyAction(tableName,
> > > cfDescriptor);
> > >
> > >             break;
> > >
> > >           default:
> > >
> > >             throw new UnsupportedOperationException(this + " unhandled
> > > state=" + state);
> > >
> > >           }
> > >
> > >
> > > Any insight would be helpful.
> > >
> > > Thanks
> > >
> > > Stephen
> > >
> >
>

Re: A checkstyle question: indentation in switch-case statements

Posted by Stephen Jiang <sy...@gmail.com>.
thanks, Matteo.  I also suspected that this is the issue.  I am just
surprised that the code exists for a while and no complain in the past.

When I loaded the HBASE code style in Eclipse, this is the indentation
style I got when I hit 'return' after typing 'case'.  And I checked other
existing code (eg. TableState.java and MetaTableAccessor.java), there are
using the same indentation style (AKA, no indentation for case-statement);
however, some other code (eg. HBaseAdmin.java), 2-space indentations are
used.  So which style is official?

thanks
Stephen

On Wed, May 4, 2016 at 7:20 AM, Matteo Bertozzi <th...@gmail.com>
wrote:

> I think it is complaining because the "case" is aligned with the "switch"
> and not indented
>
> Matteo
>
>
> On Wed, May 4, 2016 at 7:13 AM, Stephen Jiang <sy...@gmail.com>
> wrote:
>
> > I got two checkstyle warning for the style of switch-case statements:
> >
> >
> >
> ./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
> >            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
> > error: 'block' child have incorrect indentation level 12, expected
> > level should be one of the following: 14, 16.
> >
> >
> ./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
> >            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
> > error: 'method call' child have incorrect indentation level 12,
> > expected level should be one of the following: 14, 16.
> >
> > To me, the 2-space indentation looks correct.  What is wrong for this
> style
> > (switch and case are in the same level, is this wrong?  I set up HBASE
> > coding style in eclipse and it automatically did it this way)?
> >
> >           switch (state) {
> >
> >           case ADD_COLUMN_FAMILY_PRE_OPERATION:
> >
> >             cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);
> >
> >             break;
> >
> >           case ADD_COLUMN_FAMILY_POST_OPERATION:
> >
> >             cpHost.postCompletedAddColumnFamilyAction(tableName,
> > cfDescriptor);
> >
> >             break;
> >
> >           default:
> >
> >             throw new UnsupportedOperationException(this + " unhandled
> > state=" + state);
> >
> >           }
> >
> >
> > Any insight would be helpful.
> >
> > Thanks
> >
> > Stephen
> >
>

Re: A checkstyle question: indentation in switch-case statements

Posted by Matteo Bertozzi <th...@gmail.com>.
I think it is complaining because the "case" is aligned with the "switch"
and not indented

Matteo


On Wed, May 4, 2016 at 7:13 AM, Stephen Jiang <sy...@gmail.com>
wrote:

> I got two checkstyle warning for the style of switch-case statements:
>
>
> ./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
>            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
> error: 'block' child have incorrect indentation level 12, expected
> level should be one of the following: 14, 16.
>
> ./hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/AddColumnFamilyProcedure.java:386:
>            cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);:
> error: 'method call' child have incorrect indentation level 12,
> expected level should be one of the following: 14, 16.
>
> To me, the 2-space indentation looks correct.  What is wrong for this style
> (switch and case are in the same level, is this wrong?  I set up HBASE
> coding style in eclipse and it automatically did it this way)?
>
>           switch (state) {
>
>           case ADD_COLUMN_FAMILY_PRE_OPERATION:
>
>             cpHost.preAddColumnFamilyAction(tableName, cfDescriptor);
>
>             break;
>
>           case ADD_COLUMN_FAMILY_POST_OPERATION:
>
>             cpHost.postCompletedAddColumnFamilyAction(tableName,
> cfDescriptor);
>
>             break;
>
>           default:
>
>             throw new UnsupportedOperationException(this + " unhandled
> state=" + state);
>
>           }
>
>
> Any insight would be helpful.
>
> Thanks
>
> Stephen
>