use of org.infernus.idea.checkstyle.checker.ScannableFile in project checkstyle-idea by jshiell.
the class CheckStyleInspection method inspectFile.
@Nullable
public List<Problem> inspectFile(@NotNull final PsiFile psiFile, @Nullable final Module module, @NotNull final InspectionManager manager) {
LOG.debug("Inspection has been invoked.");
final CheckStylePlugin plugin = plugin(manager.getProject());
ConfigurationLocation configurationLocation = null;
final List<ScannableFile> scannableFiles = new ArrayList<>();
try {
configurationLocation = plugin.getConfigurationLocation(module, null);
if (configurationLocation == null || configurationLocation.isBlacklisted()) {
return NO_PROBLEMS_FOUND;
}
scannableFiles.addAll(ScannableFile.createAndValidate(singletonList(psiFile), plugin, module));
return checkerFactory(psiFile.getProject()).checker(module, configurationLocation).map(checker -> checker.scan(scannableFiles, plugin.configurationManager().getCurrent().isSuppressErrors())).map(results -> results.get(psiFile)).map(this::dropIgnoredProblems).orElse(NO_PROBLEMS_FOUND);
} catch (ProcessCanceledException | AssertionError e) {
LOG.debug("Process cancelled when scanning: " + psiFile.getName());
return NO_PROBLEMS_FOUND;
} catch (CheckStylePluginParseException e) {
LOG.debug("Parse exception caught when scanning: " + psiFile.getName(), e);
return NO_PROBLEMS_FOUND;
} catch (Throwable e) {
handlePluginException(e, psiFile, plugin, configurationLocation, manager.getProject());
return NO_PROBLEMS_FOUND;
} finally {
scannableFiles.forEach(ScannableFile::deleteIfRequired);
}
}
use of org.infernus.idea.checkstyle.checker.ScannableFile in project checkstyle-idea by jshiell.
the class CheckStyleInspection method inspectFile.
private List<Problem> inspectFile(@NotNull final PsiFile psiFile, @NotNull final List<ScannableFile> scannableFiles, @Nullable final Module module, @NotNull final InspectionManager manager) {
LOG.debug("Inspection has been invoked for " + psiFile.getName());
ConfigurationLocation configurationLocation = null;
try {
configurationLocation = configurationLocationSource(manager.getProject()).getConfigurationLocation(module, null);
if (configurationLocation == null || configurationLocation.isBlocked()) {
return NO_PROBLEMS_FOUND;
}
return checkerFactory(psiFile.getProject()).checker(module, configurationLocation).map(checker -> checker.scan(scannableFiles, configurationManager(psiFile.getProject()).getCurrent().isSuppressErrors())).map(results -> results.get(psiFile)).map(this::dropIgnoredProblems).orElse(NO_PROBLEMS_FOUND);
} catch (ProcessCanceledException | AssertionError e) {
LOG.debug("Process cancelled when scanning: " + psiFile.getName());
return NO_PROBLEMS_FOUND;
} catch (CheckStylePluginParseException e) {
LOG.debug("Parse exception caught when scanning: " + psiFile.getName(), e);
return NO_PROBLEMS_FOUND;
} catch (Throwable e) {
handlePluginException(e, psiFile, configurationLocation, manager.getProject());
return NO_PROBLEMS_FOUND;
} finally {
scannableFiles.forEach(ScannableFile::deleteIfRequired);
}
}
use of org.infernus.idea.checkstyle.checker.ScannableFile in project checkstyle-idea by jshiell.
the class VersionMixExceptionTest method runChecker.
private void runChecker(@NotNull final CheckStyleChecker checker) throws URISyntaxException {
final File sourceFile = new File(getClass().getResource("SourceFile.java").toURI());
final ScannableFile file1 = mock(ScannableFile.class);
when(file1.getFile()).thenReturn(sourceFile);
final List<ScannableFile> filesToScan = Collections.singletonList(file1);
final CheckstyleActions csInstance = csService.getCheckstyleInstance();
//
csInstance.scan(//
checker.getCheckerWithConfig4UnitTest(), //
filesToScan, //
false, //
2, Optional.of(sourceFile.getParent()));
}
use of org.infernus.idea.checkstyle.checker.ScannableFile in project checkstyle-idea by jshiell.
the class ServiceLayerBasicTest method runChecker.
private void runChecker(@NotNull final CheckStyleChecker checker) throws URISyntaxException {
final File sourceFile = new File(getClass().getResource("SourceFile.java").toURI());
final ScannableFile file1 = mock(ScannableFile.class);
when(file1.getFile()).thenReturn(sourceFile);
final List<ScannableFile> filesToScan = Collections.singletonList(file1);
final CheckstyleActions csInstance = checkstyleProjectService.getCheckstyleInstance();
//
csInstance.scan(//
checker.getCheckerWithConfig4UnitTest(), //
filesToScan, //
false, //
2, Optional.of(sourceFile.getParent()));
}
use of org.infernus.idea.checkstyle.checker.ScannableFile in project checkstyle-idea by jshiell.
the class CheckStyleInspection method checkFile.
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (InjectedLanguageManager.getInstance(manager.getProject()).isInjectedFragment(psiFile)) {
LOG.debug("Ignoring file as it is an injected fragment: " + psiFile);
return noProblemsFound(manager);
}
final Module module = moduleOf(psiFile);
List<ScannableFile> scannableFiles = ScannableFile.createAndValidate(singletonList(psiFile), manager.getProject(), module);
if (scannableFiles.isEmpty()) {
LOG.debug("Inspection has been cancelled as file is not scannable: " + psiFile.getName());
return noProblemsFound(manager);
}
try {
return asProblemDescriptors(asyncResultOf(() -> {
try {
return inspectFile(psiFile, scannableFiles, module, manager);
} finally {
scannableFiles.forEach(ScannableFile::deleteIfRequired);
}
}, NO_PROBLEMS_FOUND, FIVE_SECONDS), manager, isOnTheFly);
} catch (ProcessCanceledException | AssertionError e) {
LOG.debug("Inspection cancelled when scanning: " + psiFile.getName());
return noProblemsFound(manager);
} catch (Throwable e) {
LOG.warn("CheckStyle threw an exception when inspecting: " + psiFile.getName(), e);
showException(manager.getProject(), e);
return noProblemsFound(manager);
}
}
Aggregations