Search in sources :

Example 1 with ConfigurationLocationSource

use of org.infernus.idea.checkstyle.config.ConfigurationLocationSource 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);
    }
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) TreeSet(java.util.TreeSet) Collections.singletonList(java.util.Collections.singletonList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SeverityLevel(org.infernus.idea.checkstyle.csapi.SeverityLevel) ModuleUtil(com.intellij.openapi.module.ModuleUtil) InspectionManager(com.intellij.codeInspection.InspectionManager) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) Problem(org.infernus.idea.checkstyle.checker.Problem) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) CheckStyleBundle.message(org.infernus.idea.checkstyle.CheckStyleBundle.message) ConfigurationLocationSource(org.infernus.idea.checkstyle.config.ConfigurationLocationSource) Notifications.showException(org.infernus.idea.checkstyle.util.Notifications.showException) CheckerFactory(org.infernus.idea.checkstyle.checker.CheckerFactory) Optional.ofNullable(java.util.Optional.ofNullable) IOException(java.io.IOException) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) FileNotFoundException(java.io.FileNotFoundException) CheckStylePluginParseException(org.infernus.idea.checkstyle.exception.CheckStylePluginParseException) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ServiceManager(com.intellij.openapi.components.ServiceManager) Notifications.showWarning(org.infernus.idea.checkstyle.util.Notifications.showWarning) CheckStyleInspectionPanel(org.infernus.idea.checkstyle.ui.CheckStyleInspectionPanel) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) PluginConfigurationManager(org.infernus.idea.checkstyle.config.PluginConfigurationManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Async.asyncResultOf(org.infernus.idea.checkstyle.util.Async.asyncResultOf) javax.swing(javax.swing) CheckStylePluginParseException(org.infernus.idea.checkstyle.exception.CheckStylePluginParseException) ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

InspectionManager (com.intellij.codeInspection.InspectionManager)1 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 ModuleUtil (com.intellij.openapi.module.ModuleUtil)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Optional.ofNullable (java.util.Optional.ofNullable)1 TreeSet (java.util.TreeSet)1 Collectors.toList (java.util.stream.Collectors.toList)1 javax.swing (javax.swing)1