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 RegexpCheck method isIgnore.
/**
* 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);
}
final int startColumn = start.getColumn();
final int endLine = end.getLine();
final int endColumn = end.getColumn();
boolean ignore = false;
if (ignoreComments) {
final FileContents theFileContents = getFileContents();
ignore = theFileContents.hasIntersectionWithComment(startLine, startColumn, endLine, endColumn);
}
return ignore;
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilter method tagSuppressions.
/**
* 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();
cComments.forEach(this::tagSuppressions);
}
Collections.sort(tags);
}
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 checkstyle by checkstyle.
the class SuppressionCommentFilter method tagSuppressions.
/**
* 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();
cComments.forEach(this::tagSuppressions);
}
Collections.sort(tags);
}
Aggregations