use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class IllegalInstantiationCheckTest method testNullClassLoader.
@Test
public void testNullClassLoader() throws Exception {
final DetailAST exprAst = new DetailAST();
exprAst.setType(TokenTypes.EXPR);
final DetailAST newAst = new DetailAST();
newAst.setType(TokenTypes.LITERAL_NEW);
newAst.setLineNo(1);
newAst.setColumnNo(1);
final DetailAST identAst = new DetailAST();
identAst.setType(TokenTypes.IDENT);
identAst.setText("Boolean");
final DetailAST lparenAst = new DetailAST();
lparenAst.setType(TokenTypes.LPAREN);
final DetailAST elistAst = new DetailAST();
elistAst.setType(TokenTypes.ELIST);
final DetailAST rparenAst = new DetailAST();
rparenAst.setType(TokenTypes.RPAREN);
exprAst.addChild(newAst);
newAst.addChild(identAst);
identAst.setNextSibling(lparenAst);
lparenAst.setNextSibling(elistAst);
elistAst.setNextSibling(rparenAst);
final IllegalInstantiationCheck check = new IllegalInstantiationCheck();
final File inputFile = new File(getNonCompilablePath("InputIllegalInstantiationLang.java"));
check.setFileContents(new FileContents(new FileText(inputFile, "UTF-8")));
check.configure(createCheckConfig(IllegalInstantiationCheck.class));
check.setMessages(new LocalizedMessages());
check.setClasses("java.lang.Boolean");
check.visitToken(newAst);
check.finishTree(newAst);
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class SuppressionCommentFilter method accept.
@Override
public boolean accept(AuditEvent 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 = FileContentsHolder.getCurrentFileContents();
if (getFileContents() != currentContents) {
setFileContents(currentContents);
tagSuppressions();
}
final Tag matchTag = findNearestMatch(event);
accepted = matchTag == null || matchTag.isReportingOn();
}
return accepted;
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project debezium by debezium.
the class UnusedImports method processJavaDocLinkParameters.
protected void processJavaDocLinkParameters(DetailAST aAST) {
final FileContents contents = getFileContents();
final int lineNo = aAST.getLineNo();
final TextBlock cmt = contents.getJavadocBefore(lineNo);
if (cmt != null) {
final JavadocTags tags = JavaDocUtil.getJavadocTags(cmt, JavadocUtils.JavadocTagType.ALL);
for (final JavadocTag tag : tags.getValidTags()) {
processJavaDocTag(tag);
}
for (final InvalidJavadocTag tag : tags.getInvalidTags()) {
log(tag.getLine(), tag.getCol(), "import.invalidJavaDocTag", tag.getName());
}
}
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project commons by twitter.
the class JavadocMethodRegexCheck method isShortEnoughToSkip.
/**
* Return true iff the method is short enough that we don't require
* a javadoc.
*/
private boolean isShortEnoughToSkip(final DetailAST aAST) {
// Based on code from
// com/puppycrawl/tools/checkstyle/api/MethodLengthCheck.java
final DetailAST openingBrace = aAST.findFirstToken(TokenTypes.SLIST);
if (openingBrace != null) {
final DetailAST closingBrace = openingBrace.findFirstToken(TokenTypes.RCURLY);
int length = closingBrace.getLineNo() - openingBrace.getLineNo() + 1;
// skip blank lines
final FileContents contents = getFileContents();
final int lastLine = closingBrace.getLineNo();
for (int i = openingBrace.getLineNo() - 1; i < lastLine; i++) {
if (contents.lineIsBlank(i)) {
length--;
}
}
if (length <= minLineCount) {
return true;
}
}
return false;
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class JavaParser method parseFileText.
/**
* Parse a text and return the parse tree.
*
* @param text the text to parse
* @param options {@link Options} to control inclusion of comment nodes
* @return the root node of the parse tree
* @throws CheckstyleException if the text is not a valid Java source
*/
public static DetailAST parseFileText(FileText text, Options options) throws CheckstyleException {
final FileContents contents = new FileContents(text);
final DetailAST ast = parse(contents);
if (options == Options.WITH_COMMENTS) {
appendHiddenCommentNodes(ast);
}
return ast;
}
Aggregations