Skip to content

Commit 89e1b14

Browse files
committed
wrap notification calls with CppcheckNotification
1 parent 8e46962 commit 89e1b14

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/com/github/johnthagen/cppcheck/CppCheckInspectionImpl.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import com.intellij.execution.configurations.GeneralCommandLine;
88
import com.intellij.execution.process.CapturingProcessHandler;
99
import com.intellij.execution.process.ProcessOutput;
10-
import com.intellij.notification.Notification;
1110
import com.intellij.notification.NotificationType;
12-
import com.intellij.notification.Notifications;
1311
import com.intellij.openapi.editor.Document;
1412
import com.intellij.openapi.progress.EmptyProgressIndicator;
1513
import com.intellij.openapi.progress.ProcessCanceledException;
@@ -69,10 +67,9 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
6967

7068
if (VERBOSE_LOG) {
7169
// TODO: provide XML output via a "Show Cppcheck output" action - event log messages are truncated
72-
Notifications.Bus.notify(new Notification("Cppcheck",
73-
"Cppcheck execution output for " + psiFile.getName(),
70+
CppcheckNotification.send("execution output for " + psiFile.getName(),
7471
cppcheckOutput,
75-
NotificationType.INFORMATION));
72+
NotificationType.INFORMATION);
7673
}
7774

7875
final List<ProblemDescriptor> descriptors = new ArrayList<>();
@@ -160,10 +157,9 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
160157

161158
// Cppcheck error
162159
if (lineNumber <= 0 || lineNumber > document.getLineCount()) {
163-
Notifications.Bus.notify(new Notification("Cppcheck",
164-
"Cppcheck line number out-of-bounds " + i,
160+
CppcheckNotification.send("line number out-of-bounds " + i,
165161
id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column,
166-
NotificationType.ERROR));
162+
NotificationType.ERROR);
167163
continue;
168164
}
169165

src/com/github/johnthagen/cppcheck/CppcheckInspection.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.intellij.codeInspection.LocalInspectionTool;
55
import com.intellij.codeInspection.ProblemDescriptor;
66
import com.intellij.execution.ExecutionException;
7-
import com.intellij.notification.Notification;
87
import com.intellij.notification.NotificationType;
9-
import com.intellij.notification.Notifications;
108
import com.intellij.openapi.editor.Document;
119
import com.intellij.openapi.fileEditor.FileDocumentManager;
1210
import com.intellij.openapi.util.io.FileUtil;
@@ -66,10 +64,9 @@ public ProblemDescriptor[] checkFile(@NotNull final PsiFile file,
6664
tempFile.getName());
6765
return descriptors.toArray(new ProblemDescriptor[0]);
6866
} catch (final ExecutionException | CppcheckError | IOException | SAXException | ParserConfigurationException ex) {
69-
Notifications.Bus.notify(new Notification("Cppcheck",
70-
"Cppcheck execution failed.",
67+
CppcheckNotification.send("execution failed",
7168
ex.getClass().getSimpleName() + ": " + ex.getMessage(),
72-
NotificationType.ERROR));
69+
NotificationType.ERROR);
7370
} finally {
7471
if (tempFile != null) {
7572
FileUtil.delete(tempFile);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.johnthagen.cppcheck;
2+
3+
import com.intellij.notification.Notification;
4+
import com.intellij.notification.NotificationType;
5+
import com.intellij.notification.Notifications;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
class CppcheckNotification {
9+
public static void send(@NotNull final String title, @NotNull final String content, final NotificationType type) {
10+
Notifications.Bus.notify(new Notification("Cppcheck",
11+
"Cppcheck " + title,
12+
content,
13+
type));
14+
}
15+
}

0 commit comments

Comments
 (0)