本文整理汇总了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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
}
}
示例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 */
* /* some comment */ 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();
}
示例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);
}
示例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();
}
示例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);
}