Search in sources :

Example 1 with CheckStylePluginParseException

use of org.infernus.idea.checkstyle.exception.CheckStylePluginParseException 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);
    }
}
Also used : ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) ArrayList(java.util.ArrayList) 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) 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) 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) ArrayList(java.util.ArrayList) ScannableFile(org.infernus.idea.checkstyle.checker.ScannableFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Optional.ofNullable(java.util.Optional.ofNullable) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CheckStylePluginParseException

use of org.infernus.idea.checkstyle.exception.CheckStylePluginParseException 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)

Example 3 with CheckStylePluginParseException

use of org.infernus.idea.checkstyle.exception.CheckStylePluginParseException in project checkstyle-idea by jshiell.

the class CheckStyleToolWindowPanel method displayErrorResult.

/**
 * Clear the results and display notice to say an error occurred.
 *
 * @param error the error that occurred.
 */
public void displayErrorResult(final Throwable error) {
    // match some friendly error messages.
    String errorText = null;
    if (error instanceof CheckstyleToolException && error.getCause() != null) {
        for (final Map.Entry<Pattern, String> errorPatternEntry : CHECKSTYLE_ERROR_PATTERNS.entrySet()) {
            final Matcher errorMatcher = errorPatternEntry.getKey().matcher(error.getCause().getMessage());
            if (errorMatcher.find()) {
                final Object[] args = new Object[errorMatcher.groupCount()];
                for (int i = 0; i < errorMatcher.groupCount(); ++i) {
                    args[i] = errorMatcher.group(i + 1);
                }
                errorText = message(errorPatternEntry.getValue(), args);
            }
        }
    }
    if (errorText == null) {
        if (error instanceof CheckStylePluginParseException) {
            errorText = message("plugin.results.unparseable");
        } else {
            errorText = message("plugin.results.error");
        }
    }
    treeModel.clear();
    treeModel.setRootText(errorText);
    clearProgress();
}
Also used : Pattern(java.util.regex.Pattern) CheckStylePluginParseException(org.infernus.idea.checkstyle.exception.CheckStylePluginParseException) Matcher(java.util.regex.Matcher) CheckstyleToolException(org.infernus.idea.checkstyle.exception.CheckstyleToolException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CheckStylePluginParseException (org.infernus.idea.checkstyle.exception.CheckStylePluginParseException)3 InspectionManager (com.intellij.codeInspection.InspectionManager)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 ServiceManager (com.intellij.openapi.components.ServiceManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Module (com.intellij.openapi.module.Module)2 ModuleUtil (com.intellij.openapi.module.ModuleUtil)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Collectors.toList (java.util.stream.Collectors.toList)2 javax.swing (javax.swing)2 CheckStyleBundle.message (org.infernus.idea.checkstyle.CheckStyleBundle.message)2