本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.FileContents.lineIsBlank方法的典型用法代码示例。如果您正苦于以下问题:Java FileContents.lineIsBlank方法的具体用法?Java FileContents.lineIsBlank怎么用?Java FileContents.lineIsBlank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.FileContents
的用法示例。
在下文中一共展示了FileContents.lineIsBlank方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLengthOfBlock
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入方法依赖的package包/类
/**
* Returns length of code only without comments and blank lines.
* @param openingBrace block opening brace
* @param closingBrace block closing brace
* @return number of lines with code for current block
*/
private int getLengthOfBlock(DetailAST openingBrace, DetailAST closingBrace) {
int length = closingBrace.getLineNo() - openingBrace.getLineNo() + 1;
if (!countEmpty) {
final FileContents contents = getFileContents();
final int lastLine = closingBrace.getLineNo();
// lastLine - 1 is actual last line index. Last line is line with curly brace,
// which is always not empty. So, we make it lastLine - 2 to cover last line that
// actually may be empty.
for (int i = openingBrace.getLineNo() - 1; i <= lastLine - 2; i++) {
if (contents.lineIsBlank(i) || contents.lineIsComment(i)) {
length--;
}
}
}
return length;
}
示例2: getEmptyLines
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入方法依赖的package包/类
/**
* Get list of empty lines.
* @param ast the ast to check.
* @return list of line numbers for empty lines.
*/
private List<Integer> getEmptyLines(DetailAST ast) {
final DetailAST lastToken = ast.getLastChild().getLastChild();
int lastTokenLineNo = 0;
if (lastToken != null) {
// -1 as count starts from 0
// -2 as last token line cannot be empty, because it is a RCURLY
lastTokenLineNo = lastToken.getLineNo() - 2;
}
final List<Integer> emptyLines = new ArrayList<Integer>();
final FileContents fileContents = getFileContents();
for (int lineNo = ast.getLineNo(); lineNo <= lastTokenLineNo; lineNo++) {
if (fileContents.lineIsBlank(lineNo)) {
emptyLines.add(lineNo);
}
}
return emptyLines;
}
示例3: hasEmptyLine
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入方法依赖的package包/类
/**
* Checks, whether there are empty lines within the specified line range. Line numbering is
* started from 1 for parameter values
* @param startLine number of the first line in the range
* @param endLine number of the second line in the range
* @return {@code true} if found any blank line within the range, {@code false}
* otherwise
*/
private boolean hasEmptyLine(int startLine, int endLine) {
// Initial value is false - blank line not found
boolean result = false;
if (startLine <= endLine) {
final FileContents fileContents = getFileContents();
for (int line = startLine; line <= endLine; line++) {
// Check, if the line is blank. Lines are numbered from 0, so subtract 1
if (fileContents.lineIsBlank(line - 1)) {
result = true;
break;
}
}
}
return result;
}
示例4: countSemiColons
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入方法依赖的package包/类
/**
* Determines the number semicolons in a method excluding those in
* comments.
* @param method Method to count
* @return The number of semicolons in the method as an int
*/
private int countSemiColons(final DetailAST method) {
final DetailAST openingbrace = method.findFirstToken(TokenTypes.SLIST);
int count = 0;
if (openingbrace != null) {
final DetailAST closingbrace =
openingbrace.findFirstToken(TokenTypes.RCURLY);
final int lastline = closingbrace.getLineNo();
final int firstline = openingbrace.getLineNo();
final FileContents contents = this.getFileContents();
for (int line = firstline - 1; line < lastline; line += 1) {
if (!contents.lineIsBlank(line)
&& !contents.lineIsComment(line)
&& contents.getLine(line).contains(";")) {
count += 1;
}
}
}
return count;
}
示例5: getEmptyLines
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入方法依赖的package包/类
/**
* Get list of empty lines.
* @param ast the ast to check.
* @return list of line numbers for empty lines.
*/
private List<Integer> getEmptyLines(DetailAST ast) {
final DetailAST lastToken = ast.getLastChild().getLastChild();
int lastTokenLineNo = 0;
if (lastToken != null) {
// -1 as count starts from 0
// -2 as last token line cannot be empty, because it is a RCURLY
lastTokenLineNo = lastToken.getLineNo() - 2;
}
final List<Integer> emptyLines = new ArrayList<>();
final FileContents fileContents = getFileContents();
for (int lineNo = ast.getLineNo(); lineNo <= lastTokenLineNo; lineNo++) {
if (fileContents.lineIsBlank(lineNo)) {
emptyLines.add(lineNo);
}
}
return emptyLines;
}