use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class MethodCallHandler method checkIndentation.
@Override
public void checkIndentation() {
final DetailAST exprNode = getMainAst().getParent();
if (exprNode.getParent().getType() == TokenTypes.SLIST) {
final DetailAST methodName = getMainAst().getFirstChild();
checkExpressionSubtree(methodName, getIndent(), false, false);
final DetailAST lparen = getMainAst();
final DetailAST rparen = getMainAst().findFirstToken(TokenTypes.RPAREN);
checkLeftParen(lparen);
if (rparen.getLineNo() != lparen.getLineNo()) {
checkExpressionSubtree(getMainAst().findFirstToken(TokenTypes.ELIST), new IndentLevel(getIndent(), getBasicOffset()), false, true);
checkRightParen(lparen, rparen);
checkWrappingIndentation(getMainAst(), getMethodCallLastNode(getMainAst()));
}
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class MethodCallHandler method getSuggestedChildIndent.
@Override
public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child) {
// for whatever reason a method that crosses lines, like asList
// here:
// System.out.println("methods are: " + Arrays.asList(
// new String[] {"method"}).toString());
// will not have the right line num, so just get the child name
final DetailAST first = getMainAst().getFirstChild();
IndentLevel suggestedLevel = new IndentLevel(getLineStart(first));
if (!areOnSameLine(child.getMainAst().getFirstChild(), getMainAst().getFirstChild())) {
suggestedLevel = new IndentLevel(suggestedLevel, getBasicOffset(), getIndentCheck().getLineWrappingIndentation());
}
// If the right parenthesis is at the start of a line;
// include line wrapping in suggested indent level.
final DetailAST rparen = getMainAst().findFirstToken(TokenTypes.RPAREN);
if (getLineStart(rparen) == rparen.getColumnNo()) {
suggestedLevel.addAcceptedIndent(new IndentLevel(getParent().getSuggestedChildIndent(this), getIndentCheck().getLineWrappingIndentation()));
}
return suggestedLevel;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class MethodCallHandler method isChainedMethodCallWrapped.
/**
* If this is the first chained method call which was moved to the next line.
* @return true if chained class are wrapped
*/
private boolean isChainedMethodCallWrapped() {
boolean result = false;
final DetailAST main = getMainAst();
final DetailAST dot = main.getFirstChild();
final DetailAST target = dot.getFirstChild();
final DetailAST dot1 = target.getFirstChild();
final DetailAST target1 = dot1.getFirstChild();
if (dot1.getType() == TokenTypes.DOT && target1.getType() == TokenTypes.METHOD_CALL) {
result = true;
}
return result;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class MethodDefHandler method getMethodDefLineStart.
/**
* Gets the start line of the method, excluding any annotations. This is required because the
* current {@link TokenTypes#METHOD_DEF} may not always be the start as seen in
* https://github.com/checkstyle/checkstyle/issues/3145.
*
* @param mainAst
* The method definition ast.
* @return The start column position of the method.
*/
private int getMethodDefLineStart(DetailAST mainAst) {
// get first type position
int lineStart = mainAst.findFirstToken(TokenTypes.IDENT).getLineNo();
// check if there is a type before the indent
final DetailAST typeNode = mainAst.findFirstToken(TokenTypes.TYPE);
if (typeNode != null) {
lineStart = getFirstLine(lineStart, typeNode);
}
// check if there is a modifier before the type
for (DetailAST node = mainAst.findFirstToken(TokenTypes.MODIFIERS).getFirstChild(); node != null; node = node.getNextSibling()) {
// skip annotations as we check them else where as outside the method
if (node.getType() == TokenTypes.ANNOTATION) {
continue;
}
if (node.getLineNo() < lineStart) {
lineStart = node.getLineNo();
}
}
return lineStart;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class NewHandler method checkIndentation.
@Override
public void checkIndentation() {
final DetailAST type = getMainAst().getFirstChild();
if (type != null) {
checkExpressionSubtree(type, getIndent(), false, false);
}
final DetailAST lparen = getMainAst().findFirstToken(TokenTypes.LPAREN);
checkLeftParen(lparen);
}
Aggregations