issue #129: make a handler for INDEX_OP so child method call gets a proper suggested indent level
This commit is contained in:
parent
f84b3c3495
commit
001d9cc213
|
|
@ -118,6 +118,7 @@ public class HandlerFactory
|
|||
register(TokenTypes.BOR_ASSIGN, AssignHandler.class);
|
||||
register(TokenTypes.VARIABLE_DEF, MemberDefHandler.class);
|
||||
register(TokenTypes.LITERAL_NEW, NewHandler.class);
|
||||
register(TokenTypes.INDEX_OP, IndexHandler.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2014 Oliver Burn
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks.indentation;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
|
||||
/**
|
||||
* Handler for array index operation.
|
||||
*
|
||||
* @author yudindi
|
||||
*/
|
||||
public class IndexHandler extends ExpressionHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct an instance of this handler with the given indentation check,
|
||||
* abstract syntax tree, and parent handler.
|
||||
*
|
||||
* @param aIndentCheck the indentation check
|
||||
* @param aAST the abstract syntax tree
|
||||
* @param aParent the parent handler
|
||||
*/
|
||||
public IndexHandler(IndentationCheck aIndentCheck,
|
||||
DetailAST aAST,
|
||||
ExpressionHandler aParent)
|
||||
{
|
||||
super(aIndentCheck, "index op", aAST, aParent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIndentation()
|
||||
{
|
||||
// do nothing. Used to provide a correct suggested child level for now.
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndentLevel suggestedChildLevel(ExpressionHandler aChild)
|
||||
{
|
||||
return getLevel();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -134,6 +134,7 @@ public class IndentationCheckTest extends BaseCheckTestSupport
|
|||
"164: method def child at indentation level 4 not at correct indentation, 8",
|
||||
"169: method def child at indentation level 4 not at correct indentation, 8",
|
||||
"173: method def return type at indentation level 0 not at correct indentation, 4",
|
||||
"184: method def child at indentation level 12 not at correct indentation, 8",
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,4 +175,12 @@ int[]
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private int[] getArray() {
|
||||
return new int[] {1};
|
||||
}
|
||||
|
||||
private void indexTest() {
|
||||
getArray()[0] = 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,5 +181,13 @@ public class InputValidMethodIndent extends java.awt.event.MouseAdapter implemen
|
|||
|
||||
|
||||
}
|
||||
|
||||
private int[] getArray() {
|
||||
return new int[] {1};
|
||||
}
|
||||
|
||||
private void indexTest() {
|
||||
getArray()[0] = 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue