@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()) + "'"); } }
/** {@inheritDoc} */ @Override public void addSourceCode(SourceCode child) { peekSourceCode().addChild(child); sourceCodeStack.add(child); }
private void popTillSourceProject() { while (!(peekSourceCode() instanceof SourceProject)) { popSourceCode(); } }
/** * 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); }