private void popTillSourceProject() { while (!(peekSourceCode() instanceof SourceProject)) { popSourceCode(); } }
/** {@inheritDoc} */ @Override public void createFileViolation(CodeCheck check, String message, Object... messageParameters) { createLineViolation(check, message, -1, messageParameters); }
public void setFile(File file) { popTillSourceProject(); this.file = file; }
@Override public void log(CheckMessage message) { if (peekSourceCode() instanceof SourceFile) { peekSourceCode().log(message); } else if (peekSourceCode().getParent(SourceFile.class) != null) { peekSourceCode().getParent(SourceFile.class).log(message); } else { throw new IllegalStateException("Unable to log a check message on source code '" + (peekSourceCode() == null ? "[NULL]" : peekSourceCode().getKey()) + "'"); } }
VisitorContext context = new VisitorContext(project); context.setCommentAnalyser(commentAnalyser); count++; context.setFile(file);
/** {@inheritDoc} */ @Override public void createLineViolation(CodeCheck check, String message, int line, Object... messageParameters) { CheckMessage checkMessage = new CheckMessage(check, message, messageParameters); if (line > 0) { checkMessage.setLine(line); } log(checkMessage); }
/** {@inheritDoc} */ @Override public void addSourceCode(SourceCode child) { peekSourceCode().addChild(child); sourceCodeStack.add(child); }
/** * Collects actual issues detected when running a {@link JavaCheck} against a test {@link File}. * * @param testFile test {@link File} against which the {@link JavaCheck} has to be run. * @param check {@link JavaCheck} to run against the test {@link File}. * @return a {@link TreeMultimap} object containing detected actual issues. */ static TreeMultimap<Integer, String> collect(final File testFile, final JavaFileScanner check) { final Collection<File> classpath = Lists.newArrayList(); final File testJarDirectory = new File("target/test-jars"); if (testJarDirectory.exists() && testJarDirectory.isDirectory()) { classpath.addAll(FileUtils.listFiles(testJarDirectory, new String[] { "jar", "zip" }, true)); } classpath.add(new File("target/test-classes")); final VisitorsBridge visitorsBridge = new VisitorsBridge(Lists.newArrayList(check), Lists.newArrayList(classpath), null); JavaAstScanner.scanSingleFile(testFile, visitorsBridge); final VisitorContext context = visitorsBridge.getContext(); final SourceCode sourceCode = context.peekSourceCode(); return collectIssues(sourceCode); }
/** {@inheritDoc} */ @Override public void createLineViolation(CodeCheck check, String message, AstNode node, Object... messageParameters) { createLineViolation(check, message, node.getToken(), messageParameters); }
/** {@inheritDoc} */ @Override public void createLineViolation(CodeCheck check, String message, Token token, Object... messageParameters) { createLineViolation(check, message, token.getLine(), messageParameters); }