Skip to content

Commit

Permalink
Merge 9da4f04 into c922d93
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Dec 16, 2015
2 parents c922d93 + 9da4f04 commit 16b3d31
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 117 deletions.
Expand Up @@ -71,7 +71,7 @@ public abstract class AbstractExpressionHandler {
private final AbstractExpressionHandler parent;

/** Indentation amount for this handler. */
private IndentLevel level;
private IndentLevel indent;

/**
* Construct an instance of this handler with the given indentation check,
Expand All @@ -98,20 +98,20 @@ protected AbstractExpressionHandler(IndentationCheck indentCheck, String typeNam
*
* @return the expected indentation amount
*/
public final IndentLevel getLevel() {
if (level == null) {
level = getLevelImpl();
public final IndentLevel getIndent() {
if (indent == null) {
indent = getIndentImpl();
}
return level;
return indent;
}

/**
* Compute the indentation amount for this handler.
*
* @return the expected indentation amount
*/
protected IndentLevel getLevelImpl() {
return parent.getSuggestedChildLevel(this);
protected IndentLevel getIndentImpl() {
return parent.getSuggestedChildIndent(this);
}

/**
Expand All @@ -123,32 +123,32 @@ protected IndentLevel getLevelImpl() {
*
* @return suggested indentation for child
*/
public IndentLevel getSuggestedChildLevel(AbstractExpressionHandler child) {
return new IndentLevel(getLevel(), getBasicOffset());
public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child) {
return new IndentLevel(getIndent(), getBasicOffset());
}

/**
* Log an indentation error.
*
* @param ast the expression that caused the error
* @param subtypeName the type of the expression
* @param actualLevel the actual indent level of the expression
* @param actualIndent the actual indent level of the expression
*/
protected final void logError(DetailAST ast, String subtypeName,
int actualLevel) {
logError(ast, subtypeName, actualLevel, getLevel());
int actualIndent) {
logError(ast, subtypeName, actualIndent, getIndent());
}

/**
* Log an indentation error.
*
* @param ast the expression that caused the error
* @param subtypeName the type of the expression
* @param actualLevel the actual indent level of the expression
* @param expectedLevel the expected indent level of the expression
* @param ast the expression that caused the error
* @param subtypeName the type of the expression
* @param actualIndent the actual indent level of the expression
* @param expectedIndent the expected indent level of the expression
*/
protected final void logError(DetailAST ast, String subtypeName,
int actualLevel, IndentLevel expectedLevel) {
int actualIndent, IndentLevel expectedIndent) {
final String typeStr;

if (subtypeName.isEmpty()) {
Expand All @@ -158,29 +158,29 @@ protected final void logError(DetailAST ast, String subtypeName,
typeStr = " " + subtypeName;
}
String messageKey = MSG_ERROR;
if (expectedLevel.isMultiLevel()) {
if (expectedIndent.isMultiLevel()) {
messageKey = MSG_ERROR_MULTI;
}
indentCheck.indentationLog(ast.getLineNo(), messageKey,
typeName + typeStr, actualLevel, expectedLevel);
typeName + typeStr, actualIndent, expectedIndent);
}

/**
* Log child indentation error.
*
* @param line the expression that caused the error
* @param actualLevel the actual indent level of the expression
* @param expectedLevel the expected indent level of the expression
* @param actualIndent the actual indent level of the expression
* @param expectedIndent the expected indent level of the expression
*/
private void logChildError(int line,
int actualLevel,
IndentLevel expectedLevel) {
int actualIndent,
IndentLevel expectedIndent) {
String messageKey = MSG_CHILD_ERROR;
if (expectedLevel.isMultiLevel()) {
if (expectedIndent.isMultiLevel()) {
messageKey = MSG_CHILD_ERROR_MULTI;
}
indentCheck.indentationLog(line, messageKey,
typeName, actualLevel, expectedLevel);
typeName, actualIndent, expectedIndent);
}

/**
Expand Down Expand Up @@ -381,23 +381,23 @@ private void checkLineIndent(int lineNum, int colNum,
* Check the indent level of the children of the specified parent
* expression.
*
* @param parentNode the parent whose children we are checking
* @param parentNode the parent whose children we are checking
* @param tokenTypes the token types to check
* @param startLevel the starting indent level
* @param startIndent the starting indent level
* @param firstLineMatches whether or not the first line needs to match
* @param allowNesting whether or not nested children are allowed
*/
protected final void checkChildren(DetailAST parentNode,
int[] tokenTypes,
IndentLevel startLevel,
IndentLevel startIndent,
boolean firstLineMatches,
boolean allowNesting) {
Arrays.sort(tokenTypes);
for (DetailAST child = parentNode.getFirstChild();
child != null;
child = child.getNextSibling()) {
if (Arrays.binarySearch(tokenTypes, child.getType()) >= 0) {
checkExpressionSubtree(child, startLevel,
checkExpressionSubtree(child, startIndent,
firstLineMatches, allowNesting);
}
}
Expand All @@ -407,7 +407,7 @@ protected final void checkChildren(DetailAST parentNode,
* Check the indentation level for an expression subtree.
*
* @param tree the expression subtree to check
* @param indentLevel the indentation level
* @param indentLevel the indentation level
* @param firstLineMatches whether or not the first line has to match
* @param allowNesting whether or not subtree nesting is allowed
*/
Expand Down Expand Up @@ -508,7 +508,7 @@ protected void checkModifiers() {
modifier != null;
modifier = modifier.getNextSibling()) {
if (startsLine(modifier)
&& !getLevel().isAcceptable(expandedTabsColumnNo(modifier))) {
&& !getIndent().isAcceptable(expandedTabsColumnNo(modifier))) {
logError(modifier, "modifier",
expandedTabsColumnNo(modifier));
}
Expand Down Expand Up @@ -577,7 +577,7 @@ protected final void checkRParen(DetailAST lparen, DetailAST rparen) {
// or has <lparen level> + 1 indentation
final int lparenLevel = expandedTabsColumnNo(lparen);

if (!getLevel().isAcceptable(rparenLevel) && startsLine(rparen)
if (!getIndent().isAcceptable(rparenLevel) && startsLine(rparen)
&& rparenLevel != lparenLevel + 1) {
logError(rparen, "rparen", rparenLevel);
}
Expand All @@ -592,7 +592,7 @@ protected final void checkLParen(final DetailAST lparen) {
// the rcurly can either be at the correct indentation, or on the
// same line as the lcurly
if (lparen == null
|| getLevel().isAcceptable(expandedTabsColumnNo(lparen))
|| getIndent().isAcceptable(expandedTabsColumnNo(lparen))
|| !startsLine(lparen)) {
return;
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public ArrayInitHandler(IndentationCheck indentCheck,
}

@Override
protected IndentLevel getLevelImpl() {
protected IndentLevel getIndentImpl() {
final DetailAST parentAST = getMainAst().getParent();
final int type = parentAST.getType();
if (type == TokenTypes.LITERAL_NEW || type == TokenTypes.ASSIGN) {
Expand All @@ -51,7 +51,7 @@ protected IndentLevel getLevelImpl() {
}
else {
// at this point getParent() is instance of BlockParentHandler
return ((BlockParentHandler) getParent()).getChildrenExpectedLevel();
return ((BlockParentHandler) getParent()).getChildrenExpectedIndent();
}
}

Expand All @@ -66,8 +66,8 @@ protected DetailAST getLCurly() {
}

@Override
protected IndentLevel curlyLevel() {
final IndentLevel level = new IndentLevel(getLevel(), getBraceAdjustment());
protected IndentLevel curlyIndent() {
final IndentLevel level = new IndentLevel(getIndent(), getBraceAdjustment());
level.addAcceptedIndent(level.getLastIndentLevel() + getLineWrappingIndentation());
return level;
}
Expand All @@ -93,9 +93,9 @@ protected DetailAST getListChild() {
}

@Override
protected IndentLevel getChildrenExpectedLevel() {
protected IndentLevel getChildrenExpectedIndent() {
final IndentLevel expectedIndent =
new IndentLevel(getLevel(), getIndentCheck().getArrayInitIndent(),
new IndentLevel(getIndent(), getIndentCheck().getArrayInitIndent(),
getIndentCheck().getLineWrappingIndentation());

final int firstLine = getFirstLine(Integer.MAX_VALUE, getListChild());
Expand Down
Expand Up @@ -93,7 +93,7 @@ protected void checkTopLevelToken() {
final DetailAST topLevel = getTopLevelAst();

if (topLevel == null
|| getLevel().isAcceptable(expandedTabsColumnNo(topLevel)) || hasLabelBefore()) {
|| getIndent().isAcceptable(expandedTabsColumnNo(topLevel)) || hasLabelBefore()) {
return;
}
if (!shouldTopLevelStartLine() && !startsLine(topLevel)) {
Expand Down Expand Up @@ -158,7 +158,7 @@ protected void checkLCurly() {
final DetailAST lcurly = getLCurly();
final int lcurlyPos = expandedTabsColumnNo(lcurly);

if (curlyLevel().isAcceptable(lcurlyPos) || !startsLine(lcurly)) {
if (curlyIndent().isAcceptable(lcurlyPos) || !startsLine(lcurly)) {
return;
}

Expand All @@ -170,8 +170,8 @@ protected void checkLCurly() {
*
* @return the curly brace indentation level
*/
protected IndentLevel curlyLevel() {
return new IndentLevel(getLevel(), getBraceAdjustment());
protected IndentLevel curlyIndent() {
return new IndentLevel(getIndent(), getBraceAdjustment());
}

/**
Expand Down Expand Up @@ -202,12 +202,12 @@ protected void checkRCurly() {
final DetailAST rcurly = getRCurly();
final int rcurlyPos = expandedTabsColumnNo(rcurly);

if (curlyLevel().isAcceptable(rcurlyPos)
if (curlyIndent().isAcceptable(rcurlyPos)
|| !shouldStartWithRCurly() && !startsLine(rcurly)
|| areOnSameLine(rcurly, lcurly)) {
return;
}
logError(rcurly, "rcurly", rcurlyPos, curlyLevel());
logError(rcurly, "rcurly", rcurlyPos, curlyIndent());
}

/**
Expand All @@ -228,7 +228,7 @@ private void checkNonListChild() {
return;
}

final IndentLevel expected = new IndentLevel(getLevel(), getBasicOffset());
final IndentLevel expected = new IndentLevel(getIndent(), getBasicOffset());
checkExpressionSubtree(nonList, expected, false, false);
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public void checkIndentation() {
if (!hasCurlies() || !areOnSameLine(getLCurly(), getRCurly())) {
checkChildren(listChild,
getCheckedChildren(),
getChildrenExpectedLevel(),
getChildrenExpectedIndent(),
true,
canChildrenBeNested());
}
Expand All @@ -289,17 +289,17 @@ public void checkIndentation() {
* Gets indentation level expected for children.
* @return indentation level expected for children
*/
protected IndentLevel getChildrenExpectedLevel() {
IndentLevel indentLevel = new IndentLevel(getLevel(), getBasicOffset());
protected IndentLevel getChildrenExpectedIndent() {
IndentLevel indentLevel = new IndentLevel(getIndent(), getBasicOffset());
// if we have multileveled expected level then we should
// try to suggest single level to children using curlies'
// levels.
if (getLevel().isMultiLevel() && hasCurlies()) {
if (getIndent().isMultiLevel() && hasCurlies()) {
if (startsLine(getLCurly())) {
indentLevel = new IndentLevel(expandedTabsColumnNo(getLCurly()) + getBasicOffset());
}
else if (startsLine(getRCurly())) {
final IndentLevel level = new IndentLevel(curlyLevel(), getBasicOffset());
final IndentLevel level = new IndentLevel(curlyIndent(), getBasicOffset());
level.addAcceptedIndent(level.getFirstIndentLevel() + getLineWrappingIndent());
indentLevel = level;
}
Expand All @@ -308,8 +308,8 @@ else if (startsLine(getRCurly())) {
}

@Override
public IndentLevel getSuggestedChildLevel(AbstractExpressionHandler child) {
return getChildrenExpectedLevel();
public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child) {
return getChildrenExpectedIndent();
}

/**
Expand Down
Expand Up @@ -50,21 +50,21 @@ public CaseHandler(IndentationCheck indentCheck,
}

@Override
protected IndentLevel getLevelImpl() {
return new IndentLevel(getParent().getLevel(),
protected IndentLevel getIndentImpl() {
return new IndentLevel(getParent().getIndent(),
getIndentCheck().getCaseIndent());
}

/**
* Check the indentation of the case statement.
*/
private void checkCase() {
checkChildren(getMainAst(), CASE_CHILDREN, getLevel(), true, false);
checkChildren(getMainAst(), CASE_CHILDREN, getIndent(), true, false);
}

@Override
public IndentLevel getSuggestedChildLevel(AbstractExpressionHandler child) {
return getLevel();
public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child) {
return getIndent();
}

@Override
Expand Down
Expand Up @@ -52,7 +52,7 @@ protected boolean shouldTopLevelStartLine() {
private void checkCondExpr() {
final DetailAST condAst = getMainAst().findFirstToken(TokenTypes.LPAREN)
.getNextSibling();
checkExpressionSubtree(condAst, getLevel(), false, false);
checkExpressionSubtree(condAst, getIndent(), false, false);
}

@Override
Expand Down
Expand Up @@ -71,7 +71,7 @@ public void checkIndentation() {
if (modifiers.getChildCount() == 0) {
final DetailAST ident = getMainAst().findFirstToken(TokenTypes.IDENT);
final int lineStart = getLineStart(ident);
if (!getLevel().isAcceptable(lineStart)) {
if (!getIndent().isAcceptable(lineStart)) {
logError(ident, "ident", lineStart);
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ public DoWhileHandler(IndentationCheck indentCheck,
private void checkCondExpr() {
final DetailAST condAst = getMainAst()
.findFirstToken(TokenTypes.LPAREN).getNextSibling();
checkExpressionSubtree(condAst, getLevel(), false, false);
checkExpressionSubtree(condAst, getIndent(), false, false);
}

@Override
Expand Down
Expand Up @@ -46,7 +46,7 @@ public ForHandler(IndentationCheck indentCheck,
*/
private void checkForParams() {
final IndentLevel expected =
new IndentLevel(getLevel(), getBasicOffset());
new IndentLevel(getIndent(), getBasicOffset());
final DetailAST init = getMainAst().findFirstToken(TokenTypes.FOR_INIT);

if (init == null) {
Expand Down

0 comments on commit 16b3d31

Please sign in to comment.