当前位置: 首页>>代码示例>>Java>>正文


Java CommonUtils.hasWhitespaceBefore方法代码示例

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.utils.CommonUtils.hasWhitespaceBefore方法的典型用法代码示例。如果您正苦于以下问题:Java CommonUtils.hasWhitespaceBefore方法的具体用法?Java CommonUtils.hasWhitespaceBefore怎么用?Java CommonUtils.hasWhitespaceBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.puppycrawl.tools.checkstyle.utils.CommonUtils的用法示例。


在下文中一共展示了CommonUtils.hasWhitespaceBefore方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyBrace

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Verifies that a specified left curly brace is placed correctly
 * according to policy.
 * @param brace token for left curly brace
 * @param startToken token for start of expression
 */
private void verifyBrace(final DetailAST brace,
                         final DetailAST startToken) {
    final String braceLine = getLine(brace.getLineNo() - 1);

    // Check for being told to ignore, or have '{}' which is a special case
    if (braceLine.length() <= brace.getColumnNo() + 1
            || braceLine.charAt(brace.getColumnNo() + 1) != '}') {
        if (option == LeftCurlyOption.NL) {
            if (!CommonUtils.hasWhitespaceBefore(brace.getColumnNo(), braceLine)) {
                log(brace, MSG_KEY_LINE_NEW, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
            }
        }
        else if (option == LeftCurlyOption.EOL) {

            validateEol(brace, braceLine);
        }
        else if (startToken.getLineNo() != brace.getLineNo()) {

            validateNewLinePosition(brace, startToken, braceLine);

        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:30,代码来源:LeftCurlyCheck.java

示例2: visitToken

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    if (ast.getChildCount() == 0) {
        //empty for initializer. test pad before semi.
        final DetailAST semi = ast.getNextSibling();
        final int semiLineIdx = semi.getLineNo() - 1;
        final String line = getLines()[semiLineIdx];
        final int before = semi.getColumnNo() - 1;
        //don't check if semi at beginning of line
        if (!CommonUtils.hasWhitespaceBefore(before, line)) {
            if (option == PadOption.NOSPACE
                && Character.isWhitespace(line.charAt(before))) {
                log(semi.getLineNo(), before, MSG_PRECEDED, SEMICOLON);
            }
            else if (option == PadOption.SPACE
                     && !Character.isWhitespace(line.charAt(before))) {
                log(semi.getLineNo(), before, MSG_NOT_PRECEDED, SEMICOLON);
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:EmptyForInitializerPadCheck.java

示例3: processRight

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Process a token representing a right parentheses.
 * @param ast the token representing a right parentheses
 */
protected void processRight(DetailAST ast) {
    final int before = ast.getColumnNo() - 1;
    if (before >= 0) {
        final String line = getLines()[ast.getLineNo() - 1];
        if (option == PadOption.NOSPACE
            && Character.isWhitespace(line.charAt(before))
            && !CommonUtils.hasWhitespaceBefore(before, line)) {
            log(ast.getLineNo(), before, MSG_WS_PRECEDED, CLOSE_PARENTHESIS);
        }
        else if (option == PadOption.SPACE
            && !Character.isWhitespace(line.charAt(before))
            && line.charAt(before) != OPEN_PARENTHESIS) {
            log(ast.getLineNo(), ast.getColumnNo(),
                MSG_WS_NOT_PRECEDED, CLOSE_PARENTHESIS);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:AbstractParenPadCheck.java

示例4: visitToken

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    final DetailAST parent = ast.getParent();
    //we do not want to check colon for cases and defaults
    if (ast.getType() != TokenTypes.COLON
            || parent.getType() != TokenTypes.LITERAL_DEFAULT
                && parent.getType() != TokenTypes.LITERAL_CASE) {
        final String text = ast.getText();
        final int colNo = ast.getColumnNo();
        final int lineNo = ast.getLineNo();
        final String currentLine = getLine(lineNo - 1);

        // Check if rest of line is whitespace, and not just the operator
        // by itself. This last bit is to handle the operator on a line by
        // itself.
        if (option == WrapOption.NL
                && !text.equals(currentLine.trim())
                && CommonUtils.isBlank(currentLine.substring(colNo + text.length()))) {
            log(lineNo, colNo, MSG_LINE_NEW, text);
        }
        else if (option == WrapOption.EOL
                && CommonUtils.hasWhitespaceBefore(colNo - 1, currentLine)) {
            log(lineNo, colNo, MSG_LINE_PREVIOUS, text);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:OperatorWrapCheck.java

示例5: validateEol

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Validate EOL case.
 * @param brace brace AST
 * @param braceLine line content
 */
private void validateEol(DetailAST brace, String braceLine) {
    if (CommonUtils.hasWhitespaceBefore(brace.getColumnNo(), braceLine)) {
        log(brace, MSG_KEY_LINE_PREVIOUS, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
    }
    if (!hasLineBreakAfter(brace)) {
        log(brace, MSG_KEY_LINE_BREAK_AFTER, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:LeftCurlyCheck.java

示例6: validateNewLinePosition

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Validate token on new Line position.
 * @param brace brace AST
 * @param startToken start Token
 * @param braceLine content of line with Brace
 */
private void validateNewLinePosition(DetailAST brace, DetailAST startToken, String braceLine) {
    // not on the same line
    if (startToken.getLineNo() + 1 == brace.getLineNo()) {
        if (CommonUtils.hasWhitespaceBefore(brace.getColumnNo(), braceLine)) {
            log(brace, MSG_KEY_LINE_PREVIOUS, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
        }
        else {
            log(brace, MSG_KEY_LINE_NEW, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
        }
    }
    else if (!CommonUtils.hasWhitespaceBefore(brace.getColumnNo(), braceLine)) {
        log(brace, MSG_KEY_LINE_NEW, OPEN_CURLY_BRACE, brace.getColumnNo() + 1);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:LeftCurlyCheck.java

示例7: visitToken

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
    final DetailAST parenAST;
    if (ast.getType() == TokenTypes.METHOD_CALL) {
        parenAST = ast;
    }
    else {
        parenAST = ast.findFirstToken(TokenTypes.LPAREN);
        // array construction => parenAST == null
    }

    if (parenAST != null) {
        final String line = getLines()[parenAST.getLineNo() - 1];
        if (CommonUtils.hasWhitespaceBefore(parenAST.getColumnNo(), line)) {
            if (!allowLineBreaks) {
                log(parenAST, MSG_LINE_PREVIOUS, parenAST.getText());
            }
        }
        else {
            final int before = parenAST.getColumnNo() - 1;
            if (option == PadOption.NOSPACE
                && Character.isWhitespace(line.charAt(before))) {
                log(parenAST, MSG_WS_PRECEDED, parenAST.getText());
            }
            else if (option == PadOption.SPACE
                     && !Character.isWhitespace(line.charAt(before))) {
                log(parenAST, MSG_WS_NOT_PRECEDED, parenAST.getText());
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:32,代码来源:MethodParamPadCheck.java

示例8: isTrailingBlockComment

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Checks if current comment block is trailing comment, e.g.:
 * <p>
 * {@code
 * double d = 3.14; /* some comment *&#47;
 * /* some comment *&#47; double d = 18.5;
 * }
 * </p>
 * @param blockComment {@link TokenTypes#BLOCK_COMMENT_BEGIN block comment begin}.
 * @return true if current comment block is trailing comment.
 */
private boolean isTrailingBlockComment(DetailAST blockComment) {
    final String commentLine = getLine(blockComment.getLineNo() - 1);
    final int commentColumnNo = blockComment.getColumnNo();
    final DetailAST nextSibling = blockComment.getNextSibling();
    return !CommonUtils.hasWhitespaceBefore(commentColumnNo, commentLine)
        || nextSibling != null && nextSibling.getLineNo() == blockComment.getLineNo();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:CommentsIndentationCheck.java

示例9: isTrailingSingleLineComment

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Checks if current single line comment is trailing comment, e.g.:
 * <p>
 * {@code
 * double d = 3.14; // some comment
 * }
 * </p>
 * @param singleLineComment {@link TokenTypes#SINGLE_LINE_COMMENT single line comment}.
 * @return true if current single line comment is trailing comment.
 */
private boolean isTrailingSingleLineComment(DetailAST singleLineComment) {
    final String targetSourceLine = getLine(singleLineComment.getLineNo() - 1);
    final int commentColumnNo = singleLineComment.getColumnNo();
    return !CommonUtils.hasWhitespaceBefore(commentColumnNo, targetSourceLine);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:CommentsIndentationCheck.java

示例10: isOnStartOfLine

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Whether right curly brace starts target source line.
 * @param details Details of right curly brace for validation
 * @param targetSourceLine source line to check
 * @return true if right curly brace starts target source line.
 */
private static boolean isOnStartOfLine(Details details, String targetSourceLine) {
    return CommonUtils.hasWhitespaceBefore(details.rcurly.getColumnNo(), targetSourceLine)
            || details.lcurly.getLineNo() == details.rcurly.getLineNo();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:11,代码来源:RightCurlyCheck.java

示例11: containsWhitespaceBefore

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入方法依赖的package包/类
/**
 * Returns whether the specified string contains only whitespace up to specified index.
 *
 * @param before the index to start the search from. Inclusive
 * @param line   the index to finish the search. Exclusive
 * @return {@code true} if there are only whitespaces,
 *     false if there is nothing before or some other characters
 */
private static boolean containsWhitespaceBefore(int before, String line) {
    return before != 0 && CommonUtils.hasWhitespaceBefore(before, line);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:12,代码来源:GenericWhitespaceCheck.java


注:本文中的com.puppycrawl.tools.checkstyle.utils.CommonUtils.hasWhitespaceBefore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。