some additional refactoring (to remove code duplication)

This commit is contained in:
Oleg Sukhodolsky 2005-07-23 09:18:36 +00:00
parent 50559c6876
commit bcbd31a5ec
4 changed files with 73 additions and 149 deletions

View File

@ -278,52 +278,6 @@ public class BlockParentHandler extends ExpressionHandler
return getMainAst().findFirstToken(TokenTypes.LPAREN);
}
/**
* Check the indentation of the right parenthesis.
*/
protected void checkRParen()
{
final DetailAST rparen = getRParen();
// no paren - no check :)
if (rparen == null) {
return;
}
// the rcurly can either be at the correct indentation,
// or not first on the line ...
final int rparenLevel = expandedTabsColumnNo(rparen);
if (getLevel().accept(rparenLevel) || !startsLine(rparen)) {
return;
}
// or has <lparen level> + 1 indentation
final DetailAST lparen = getLParen();
final int lparenLevel = expandedTabsColumnNo(lparen);
if (rparenLevel == (lparenLevel + 1)) {
return;
}
logError(rparen, "rparen", expandedTabsColumnNo(rparen));
}
/**
* Check the indentation of the left parenthesis.
*/
protected void checkLParen()
{
// the rcurly can either be at the correct indentation, or on the
// same line as the lcurly
DetailAST lparen = getLParen();
if (lparen == null
|| getLevel().accept(expandedTabsColumnNo(lparen))
|| !startsLine(lparen))
{
return;
}
logError(lparen, "lparen", expandedTabsColumnNo(lparen));
}
/**
* Check the indentation of the expression we are handling.
*/
@ -331,8 +285,8 @@ public class BlockParentHandler extends ExpressionHandler
{
checkToplevelToken();
// seperate to allow for eventual configuration
checkLParen();
checkRParen();
checkLParen(getLParen());
checkRParen(getLParen(), getRParen());
if (hasCurlys()) {
checkLCurly();
checkRCurly();

View File

@ -606,4 +606,49 @@ public abstract class ExpressionHandler
{
return getIndentCheck().getBraceAdjustement();
}
/**
* Check the indentation of the right parenthesis.
* @param aRparen parenthesis to check
* @param aLparen left parenthesis associated with aRparen
*/
protected final void checkRParen(DetailAST aLparen, DetailAST aRparen)
{
// no paren - no check :)
if (aRparen == null) {
return;
}
// the rcurly can either be at the correct indentation,
// or not first on the line ...
final int rparenLevel = expandedTabsColumnNo(aRparen);
if (getLevel().accept(rparenLevel) || !startsLine(aRparen)) {
return;
}
// or has <lparen level> + 1 indentation
final int lparenLevel = expandedTabsColumnNo(aLparen);
if (rparenLevel == (lparenLevel + 1)) {
return;
}
logError(aRparen, "rparen", rparenLevel);
}
/**
* Check the indentation of the left parenthesis.
* @param aLparen parenthesis to check
*/
protected final void checkLParen(final DetailAST aLparen)
{
// the rcurly can either be at the correct indentation, or on the
// same line as the lcurly
if (aLparen == null
|| getLevel().accept(expandedTabsColumnNo(aLparen))
|| !startsLine(aLparen))
{
return;
}
logError(aLparen, "lparen", expandedTabsColumnNo(aLparen));
}
}

View File

@ -46,39 +46,6 @@ public class MethodCallHandler extends ExpressionHandler
aParent);
}
/**
* Check the indentation of the left parenthesis.
*/
private void checkLParen()
{
final DetailAST lparen = getMainAst();
final int columnNo = expandedTabsColumnNo(lparen);
if (getLevel().accept(columnNo) || !startsLine(lparen)) {
return;
}
logError(lparen, "lparen", columnNo);
}
/**
* Check the indentation of the right parenthesis.
*/
private void checkRParen()
{
// the rparen can either be at the correct indentation, or on
// the same line as the lparen
final DetailAST rparen =
getMainAst().findFirstToken(TokenTypes.RPAREN);
final int columnNo = expandedTabsColumnNo(rparen);
if (getLevel().accept(columnNo) || !startsLine(rparen)) {
return;
}
logError(rparen, "rparen", columnNo);
}
/**
* Compute the indentation amount for this handler.
*
@ -199,29 +166,30 @@ public class MethodCallHandler extends ExpressionHandler
DetailAST methodName = (DetailAST) getMainAst().getFirstChild();
checkExpressionSubtree(methodName, getLevel(), false, false);
checkLParen();
DetailAST rparen = getMainAst().findFirstToken(TokenTypes.RPAREN);
DetailAST lparen = getMainAst();
DetailAST rparen = getMainAst().findFirstToken(TokenTypes.RPAREN);
checkLParen(lparen);
if (rparen.getLineNo() != lparen.getLineNo()) {
// if this method name is on the same line as a containing
// method, don't indent, this allows expressions like:
// method("my str" + method2(
// "my str2"));
// as well as
// method("my str" +
// method2(
// "my str2"));
//
checkExpressionSubtree(
getMainAst().findFirstToken(TokenTypes.ELIST),
new IndentLevel(getLevel(), getBasicOffset()),
false, true);
checkRParen();
if (rparen.getLineNo() == lparen.getLineNo()) {
return;
}
// if this method name is on the same line as a containing
// method, don't indent, this allows expressions like:
// method("my str" + method2(
// "my str2"));
// as well as
// method("my str" +
// method2(
// "my str2"));
//
checkExpressionSubtree(
getMainAst().findFirstToken(TokenTypes.ELIST),
new IndentLevel(getLevel(), getBasicOffset()),
false, true);
checkRParen(lparen, rparen);
}
/**

View File

@ -49,9 +49,9 @@ public class NewHandler extends ExpressionHandler
DetailAST type = (DetailAST) getMainAst().getFirstChild();
checkExpressionSubtree(type, getLevel(), false, false);
checkLParen();
DetailAST rparen = getMainAst().findFirstToken(TokenTypes.RPAREN);
DetailAST lparen = getMainAst().findFirstToken(TokenTypes.LPAREN);
DetailAST rparen = getMainAst().findFirstToken(TokenTypes.RPAREN);
checkLParen(lparen);
if (rparen == null || lparen == null
|| rparen.getLineNo() == lparen.getLineNo())
@ -74,7 +74,7 @@ public class NewHandler extends ExpressionHandler
new IndentLevel(getLevel(), getBasicOffset()),
false, true);
checkRParen();
checkRParen(lparen, rparen);
}
/** {@inheritDoc} */
@ -82,55 +82,12 @@ public class NewHandler extends ExpressionHandler
{
// if our expression isn't first on the line, just use the start
// of the line
int lineStart = getLineStart(getMainAst());
if (lineStart != getMainAst().getColumnNo()) {
return new IndentLevel(lineStart);
if (getLineStart(getMainAst()) != getMainAst().getColumnNo()) {
return new IndentLevel(getLineStart(getMainAst()));
}
return super.getLevelImpl();
}
/**
* Check the indentation of the left parenthesis.
*/
private void checkLParen()
{
final DetailAST lparen =
getMainAst().findFirstToken(TokenTypes.LPAREN);
if (lparen == null) {
return;
}
final int columnNo = expandedTabsColumnNo(lparen);
if (getLevel().accept(columnNo) || !startsLine(lparen)) {
return;
}
logError(lparen, "lparen", columnNo);
}
/**
* Check the indentation of the right parenthesis.
*/
private void checkRParen()
{
// the rparen can either be at the correct indentation, or on
// the same line as the lparen
final DetailAST rparen =
getMainAst().findFirstToken(TokenTypes.RPAREN);
if (rparen == null) {
return;
}
final int columnNo = expandedTabsColumnNo(rparen);
if (getLevel().accept(columnNo) || !startsLine(rparen)) {
return;
}
logError(rparen, "rparen", columnNo);
}
/** {@inheritDoc} */
protected boolean shouldIncreaseIndent()
{