Search in sources :

Example 1 with Problem

use of org.infernus.idea.checkstyle.checker.Problem 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 Problem

use of org.infernus.idea.checkstyle.checker.Problem 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 Problem

use of org.infernus.idea.checkstyle.checker.Problem in project checkstyle-idea by jshiell.

the class ResultTreeModel method setModel.

/**
 * Set the displayed model.
 *
 * @param results the model.
 * @param levels  the levels to display.
 */
public void setModel(final Map<PsiFile, List<Problem>> results, final SeverityLevel... levels) {
    visibleRootNode.removeAllChildren();
    int itemCount = 0;
    for (final PsiFile file : sortedFileNames(results)) {
        final TogglableTreeNode fileNode = new TogglableTreeNode();
        final List<Problem> problems = results.get(file);
        int problemCount = 0;
        if (problems != null) {
            for (final Problem problem : problems) {
                if (problem.severityLevel() != SeverityLevel.Ignore) {
                    final ResultTreeNode problemObj = new ResultTreeNode(file, problem);
                    final TogglableTreeNode problemNode = new TogglableTreeNode(problemObj);
                    fileNode.add(problemNode);
                    ++problemCount;
                }
            }
        }
        itemCount += problemCount;
        if (problemCount > 0) {
            final ResultTreeNode nodeObject = new ResultTreeNode(file.getName(), problemCount);
            fileNode.setUserObject(nodeObject);
            visibleRootNode.add(fileNode);
        }
    }
    if (itemCount == 0) {
        setRootMessage("plugin.results.scan-no-results");
    } else {
        setRootText(CheckStyleBundle.message("plugin.results.scan-results", itemCount, results.size()));
    }
    filter(false, levels);
    nodeStructureChanged(visibleRootNode);
}
Also used : PsiFile(com.intellij.psi.PsiFile) Problem(org.infernus.idea.checkstyle.checker.Problem)

Aggregations

PsiFile (com.intellij.psi.PsiFile)3 Problem (org.infernus.idea.checkstyle.checker.Problem)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 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