| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package com.puppycrawl.tools.checkstyle.checks.indentation; |
| 20 | |
|
| 21 | |
import com.puppycrawl.tools.checkstyle.api.DetailAST; |
| 22 | |
import com.puppycrawl.tools.checkstyle.api.TokenTypes; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public class MethodDefHandler extends BlockParentHandler |
| 31 | |
{ |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public MethodDefHandler(IndentationCheck aIndentCheck, |
| 41 | |
DetailAST aAst, ExpressionHandler aParent) |
| 42 | |
{ |
| 43 | 136 | super(aIndentCheck, (aAst.getType() == TokenTypes.CTOR_DEF) |
| 44 | |
? "ctor def" : "method def", aAst, aParent); |
| 45 | 136 | } |
| 46 | |
|
| 47 | |
@Override |
| 48 | |
protected DetailAST getToplevelAST() |
| 49 | |
{ |
| 50 | |
|
| 51 | 131 | return null; |
| 52 | |
} |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
private void checkIdent() |
| 58 | |
{ |
| 59 | 136 | final DetailAST ident = getMainAst().findFirstToken(TokenTypes.IDENT); |
| 60 | 136 | final int columnNo = expandedTabsColumnNo(ident); |
| 61 | 136 | if (startsLine(ident) && !getLevel().accept(columnNo)) { |
| 62 | 1 | logError(ident, "", columnNo); |
| 63 | |
} |
| 64 | 136 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
private void checkThrows() |
| 70 | |
{ |
| 71 | 136 | final DetailAST throwsAst = |
| 72 | |
getMainAst().findFirstToken(TokenTypes.LITERAL_THROWS); |
| 73 | 136 | if (throwsAst == null) { |
| 74 | 131 | return; |
| 75 | |
} |
| 76 | |
|
| 77 | 5 | final int columnNo = expandedTabsColumnNo(throwsAst); |
| 78 | 5 | final IndentLevel expectedColumnNo = |
| 79 | |
new IndentLevel(getLevel(), getIndentCheck().getThrowsIndent()); |
| 80 | |
|
| 81 | 5 | if (startsLine(throwsAst) |
| 82 | |
&& !expectedColumnNo.accept(columnNo)) |
| 83 | |
{ |
| 84 | 2 | logError(throwsAst, "throws", columnNo, expectedColumnNo); |
| 85 | |
} |
| 86 | 5 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
private void checkType() |
| 92 | |
{ |
| 93 | 100 | final DetailAST type = getMainAst().findFirstToken(TokenTypes.TYPE); |
| 94 | 100 | final DetailAST ident = ExpressionHandler.getFirstToken(type); |
| 95 | 100 | final int columnNo = expandedTabsColumnNo(ident); |
| 96 | 100 | if (startsLine(ident) && !getLevel().accept(columnNo)) { |
| 97 | 3 | logError(ident, "return type", columnNo); |
| 98 | |
} |
| 99 | 100 | } |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
private void checkParameters() |
| 105 | |
{ |
| 106 | 136 | final DetailAST params = |
| 107 | |
getMainAst().findFirstToken(TokenTypes.PARAMETERS); |
| 108 | 136 | checkExpressionSubtree(params, getLevel(), false, false); |
| 109 | 136 | } |
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public void checkIndentation() |
| 113 | |
{ |
| 114 | 136 | checkModifiers(); |
| 115 | 136 | checkIdent(); |
| 116 | 136 | checkThrows(); |
| 117 | 136 | if (getMainAst().getType() != TokenTypes.CTOR_DEF) { |
| 118 | 100 | checkType(); |
| 119 | |
} |
| 120 | 136 | checkParameters(); |
| 121 | |
|
| 122 | 136 | if (getLCurly() == null) { |
| 123 | |
|
| 124 | 5 | return; |
| 125 | |
} |
| 126 | 131 | super.checkIndentation(); |
| 127 | 131 | } |
| 128 | |
} |