本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.FileContents类的典型用法代码示例。如果您正苦于以下问题:Java FileContents类的具体用法?Java FileContents怎么用?Java FileContents使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileContents类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了FileContents类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:MethodLengthCheck.java
示例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;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:EmptyLineSeparatorCheck.java
示例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;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:EmptyLineSeparatorCheck.java
示例4: processAST
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Override
protected final void processAST(DetailAST ast) {
final Scope theScope = calculateScope(ast);
if (shouldCheck(ast, theScope)) {
final FileContents contents = getFileContents();
final TextBlock textBlock = contents.getJavadocBefore(ast.getLineNo());
if (textBlock == null) {
if (!isMissingJavadocAllowed(ast)) {
log(ast, MSG_JAVADOC_MISSING);
}
}
else {
checkComment(ast, textBlock);
}
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:JavadocMethodCheck.java
示例5: isIgnore
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
/**
* Detect ignore situation.
* @param startLine position of line
* @param text file text
* @param start line column
* @return true is that need to be ignored
*/
private boolean isIgnore(int startLine, FileText text, LineColumn start) {
final LineColumn end;
if (matcher.end() == 0) {
end = text.lineColumn(0);
}
else {
end = text.lineColumn(matcher.end() - 1);
}
boolean ignore = false;
if (ignoreComments) {
final FileContents theFileContents = getFileContents();
final int startColumn = start.getColumn();
final int endLine = end.getLine();
final int endColumn = end.getColumn();
ignore = theFileContents.hasIntersectionWithComment(startLine,
startColumn, endLine, endColumn);
}
return ignore;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:RegexpCheck.java
示例6: accept
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Override
public boolean accept(TreeWalkerAuditEvent event) {
boolean accepted = true;
if (event.getLocalizedMessage() != null) {
// Lazy update. If the first event for the current file, update file
// contents and tag suppressions
final FileContents currentContents = event.getFileContents();
if (getFileContents() != currentContents) {
setFileContents(currentContents);
tagSuppressions();
}
if (matchesTag(event)) {
accepted = false;
}
}
return accepted;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:SuppressWithNearbyCommentFilter.java
示例7: accept
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Override
public boolean accept(TreeWalkerAuditEvent event) {
boolean accepted = true;
if (event.getLocalizedMessage() != null) {
// Lazy update. If the first event for the current file, update file
// contents and tag suppressions
final FileContents currentContents = event.getFileContents();
if (getFileContents() != currentContents) {
setFileContents(currentContents);
tagSuppressions();
}
final Tag matchTag = findNearestMatch(event);
accepted = matchTag == null || matchTag.getTagType() == TagType.ON;
}
return accepted;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:SuppressionCommentFilter.java
示例8: tagSuppressions
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
/**
* Collects all the suppression tags for all comments into a list and
* sorts the list.
*/
private void tagSuppressions() {
tags.clear();
final FileContents contents = getFileContents();
if (checkCPP) {
tagSuppressions(contents.getSingleLineComments().values());
}
if (checkC) {
final Collection<List<TextBlock>> cComments = contents
.getBlockComments().values();
for (List<TextBlock> element : cComments) {
tagSuppressions(element);
}
}
Collections.sort(tags);
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:SuppressionCommentFilter.java
示例9: getFilteredMessages
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
/**
* Returns filtered set of {@link LocalizedMessage}.
* @param fileName path to the file
* @param fileContents the contents of the file
* @param rootAST root AST element {@link DetailAST} of the file
* @return filtered set of messages
*/
private SortedSet<LocalizedMessage> getFilteredMessages(
String fileName, FileContents fileContents, DetailAST rootAST) {
final SortedSet<LocalizedMessage> result = new TreeSet<LocalizedMessage>(messages);
for (LocalizedMessage element : messages) {
final TreeWalkerAuditEvent event =
new TreeWalkerAuditEvent(fileContents, fileName, element, rootAST);
for (TreeWalkerFilter filter : filters) {
if (!filter.accept(event)) {
result.remove(element);
break;
}
}
}
return result;
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:TreeWalker.java
示例10: notifyBegin
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
/**
* Notify checks that we are about to begin walking a tree.
* @param rootAST the root of the tree.
* @param contents the contents of the file the AST was generated from.
* @param astState state of AST.
*/
private void notifyBegin(DetailAST rootAST, FileContents contents,
AstState astState) {
final Set<AbstractCheck> checks;
if (astState == AstState.WITH_COMMENTS) {
checks = commentChecks;
}
else {
checks = ordinaryChecks;
}
for (AbstractCheck check : checks) {
check.setFileContents(contents);
check.clearMessages();
check.beginTree(rootAST);
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:TreeWalker.java
示例11: parse
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
/**
* Static helper method to parses a Java source file.
*
* @param contents
* contains the contents of the file
* @return the root of the AST
* @throws TokenStreamException
* if lexing failed
* @throws RecognitionException
* if parsing failed
*/
public static DetailAST parse(FileContents contents)
throws RecognitionException, TokenStreamException {
final String fullText = contents.getText().getFullText().toString();
final Reader reader = new StringReader(fullText);
final GeneratedJavaLexer lexer = new GeneratedJavaLexer(reader);
lexer.setCommentListener(contents);
lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
final TokenStreamHiddenTokenFilter filter =
new TokenStreamHiddenTokenFilter(lexer);
filter.hide(TokenTypes.SINGLE_LINE_COMMENT);
filter.hide(TokenTypes.BLOCK_COMMENT_BEGIN);
final GeneratedJavaRecognizer parser =
new GeneratedJavaRecognizer(filter);
parser.setFilename(contents.getFileName());
parser.setASTNodeClass(DetailAST.class.getName());
parser.compilationUnit();
return (DetailAST) parser.getAST();
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:TreeWalker.java
示例12: testTagsAreClearedEachRun
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Test
public void testTagsAreClearedEachRun() {
final SuppressionCommentFilter suppressionCommentFilter = new SuppressionCommentFilter();
final FileContents contents =
new FileContents("filename", "//CHECKSTYLE:OFF", "line2");
contents.reportSingleLineComment(1, 0);
final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, "filename",
new LocalizedMessage(1, null, null, null, null, Object.class, null), null);
suppressionCommentFilter.accept(dummyEvent);
final FileContents contents2 =
new FileContents("filename2", "some line", "//CHECKSTYLE:OFF");
contents2.reportSingleLineComment(2, 0);
final TreeWalkerAuditEvent dummyEvent2 = new TreeWalkerAuditEvent(contents2, "filename",
new LocalizedMessage(1, null, null, null, null, Object.class, null), null);
suppressionCommentFilter.accept(dummyEvent2);
final List<SuppressionCommentFilter.Tag> tags =
Whitebox.getInternalState(suppressionCommentFilter, "tags");
assertEquals("Invalid tags size", 1, tags.size());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:SuppressionCommentFilterTest.java
示例13: testTagsAreClearedEachRun
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Test
public void testTagsAreClearedEachRun() {
final SuppressWithNearbyCommentFilter suppressionCommentFilter =
new SuppressWithNearbyCommentFilter();
final FileContents contents =
new FileContents("filename", "//SUPPRESS CHECKSTYLE ignore", "line2");
contents.reportSingleLineComment(1, 0);
final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, "filename",
new LocalizedMessage(1, null, null, null, null, Object.class, null), null);
suppressionCommentFilter.accept(dummyEvent);
final FileContents contents2 =
new FileContents("filename2", "some line", "//SUPPRESS CHECKSTYLE ignore");
contents2.reportSingleLineComment(2, 0);
final TreeWalkerAuditEvent dummyEvent2 = new TreeWalkerAuditEvent(contents2, "filename",
new LocalizedMessage(1, null, null, null, null, Object.class, null), null);
suppressionCommentFilter.accept(dummyEvent2);
final List<SuppressionCommentFilter.Tag> tags =
Whitebox.getInternalState(suppressionCommentFilter, "tags");
assertEquals("Invalid tags size", 1, tags.size());
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:SuppressWithNearbyCommentFilterTest.java
示例14: accept
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
public boolean accept(AuditEvent aEvent) {
if (aEvent.getLocalizedMessage() == null) {
return true; // special event
}
FileContents currentContents = FileContentsHolder.getContents();
if (currentContents == null) {
return true;
}
if (getFileContents() != currentContents) {
setFileContents(currentContents);
tagComments();
}
if (ignoredLines.contains(aEvent.getLine())) {
return false;
}
SectionTag matchTag = findPreceedingTag(aEvent);
if (matchTag != null && !matchTag.isBegin()) {
return false;
}
return true;
}
开发者ID:willfleury,项目名称:netbeans-checkstyle,代码行数:26,代码来源:GeneratedUIFilter.java
示例15: 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;
}
开发者ID:teamed,项目名称:qulice,代码行数:26,代码来源:NonStaticMethodCheck.java
示例16: 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;
}
开发者ID:checkstyle,项目名称:checkstyle,代码行数:24,代码来源:EmptyLineSeparatorCheck.java
示例17: processFiltered
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Override
protected void processFiltered(File file, FileText fileText) throws CheckstyleException {
// check if already checked and passed the file
if (CommonUtils.matchesFileExtension(file, getFileExtensions())
&& (!ordinaryChecks.isEmpty() || !commentChecks.isEmpty())) {
final FileContents contents = new FileContents(fileText);
final DetailAST rootAST = JavaParser.parse(contents);
if (!ordinaryChecks.isEmpty()) {
walk(rootAST, contents, AstState.ORDINARY);
}
if (!commentChecks.isEmpty()) {
final DetailAST astWithComments = JavaParser.appendHiddenCommentNodes(rootAST);
walk(astWithComments, contents, AstState.WITH_COMMENTS);
}
if (filters.isEmpty()) {
addMessages(messages);
}
else {
final SortedSet<LocalizedMessage> filteredMessages =
getFilteredMessages(file.getPath(), contents, rootAST);
addMessages(filteredMessages);
}
messages.clear();
}
}
开发者ID:checkstyle,项目名称:checkstyle,代码行数:26,代码来源:TreeWalker.java
示例18: getFilteredMessages
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
/**
* Returns filtered set of {@link LocalizedMessage}.
* @param fileName path to the file
* @param fileContents the contents of the file
* @param rootAST root AST element {@link DetailAST} of the file
* @return filtered set of messages
*/
private SortedSet<LocalizedMessage> getFilteredMessages(
String fileName, FileContents fileContents, DetailAST rootAST) {
final SortedSet<LocalizedMessage> result = new TreeSet<>(messages);
for (LocalizedMessage element : messages) {
final TreeWalkerAuditEvent event =
new TreeWalkerAuditEvent(fileContents, fileName, element, rootAST);
for (TreeWalkerFilter filter : filters) {
if (!filter.accept(event)) {
result.remove(element);
break;
}
}
}
return result;
}
开发者ID:checkstyle,项目名称:checkstyle,代码行数:23,代码来源:TreeWalker.java
示例19: visitToken
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
if (shouldCheck(ast)) {
final FileContents contents = getFileContents();
// Need to start searching for the comment before the annotations
// that may exist. Even if annotations are not defined on the
// package, the ANNOTATIONS AST is defined.
final TextBlock textBlock =
contents.getJavadocBefore(ast.getFirstChild().getLineNo());
checkComment(ast, textBlock);
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:JavadocStyleCheck.java
示例20: visitToken
import com.puppycrawl.tools.checkstyle.api.FileContents; //导入依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
if (shouldCheck(ast)) {
final FileContents contents = getFileContents();
final int lineNo = ast.getLineNo();
final TextBlock textBlock = contents.getJavadocBefore(lineNo);
if (textBlock == null) {
log(lineNo, MSG_JAVADOC_MISSING);
}
else {
final List<JavadocTag> tags = getJavadocTags(textBlock);
if (ScopeUtils.isOuterMostType(ast)) {
// don't check author/version for inner classes
checkTag(lineNo, tags, JavadocTagInfo.AUTHOR.getName(),
authorFormat);
checkTag(lineNo, tags, JavadocTagInfo.VERSION.getName(),
versionFormat);
}
final List<String> typeParamNames =
CheckUtils.getTypeParameterNames(ast);
if (!allowMissingParamTags) {
//Check type parameters that should exist, do
for (final String typeParamName : typeParamNames) {
checkTypeParamTag(
lineNo, tags, typeParamName);
}
}
checkUnusedTypeParamTags(tags, typeParamNames);
}
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:35,代码来源:JavadocTypeCheck.java
注:本文中的com.puppycrawl.tools.checkstyle.api.FileContents类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论