@Test public void shouldDetectEmptyFiles() { SourceFile file = (SourceFile) squid.search("org/foo/CommentedOutFile.java"); assertThat(file.getCheckMessages().size(), is(1)); CheckMessage message = file.getCheckMessages().iterator().next(); assertThat(message.getLine(), nullValue()); assertThat(message.getDefaultMessage(), is("This Java file is empty")); }
@Override public void visitFile(SourceFile sourceFile) { for (Integer line : sourceFile.getNoSonarTagLines()) { CheckMessage message = new CheckMessage( this, "Is //NOSONAR used to exclude false-positive or to hide real quality flaw ?"); message.setBypassExclusion(true); message.setLine(line); sourceFile.log(message); } }
private void saveViolations(File sonarFile, SourceFile squidFile) { Collection<CheckMessage> messages = squidFile.getCheckMessages(); if (messages != null) { for (CheckMessage message : messages) { Violation violation = Violation.create(annotationCheckFactory.getActiveRule(message.getCheck()), sonarFile) .setLineId(message.getLine()) .setMessage(message.getText(Locale.ENGLISH)); context.saveViolation(violation); } } }