Skip to content

Commit 77d081f

Browse files
authored
Merge pull request #59 from firewave/extensions
added more supported extensions to match ones supported by Cppcheck internally
2 parents d90bebc + 5737c5e commit 77d081f

File tree

8 files changed

+63
-28
lines changed

8 files changed

+63
-28
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Deployment.
6262
- Only scan files which actually exist. (Contribution by @firewave)
6363
- Use unique file names for temporary files used for analysis. (Contribution by @firewave)
6464
- Properly handle `debug` messages generated by `--debug-warnings`. (Contribution by @firewave)
65+
- Added `.cl`, `.hxx`, `.tpp` and `.txx` to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave)
6566

6667
### 1.5.1 - 2020-11-12
6768

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- Only scan files which actually exist. (Contribution by @firewave)
6767
- Use unique file names for temporary files used for analysis. (Contribution by @firewave)
6868
- Properly handle "debug" messages generated by --debug-warnings. (Contribution by @firewave
69+
- Added .cl, .hxx, .tpp and .txx to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave
6970
]]>
7071
</change-notes>
7172

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import javax.swing.event.DocumentEvent;
1010
import javax.swing.event.DocumentListener;
1111

12-
public class Configuration implements Configurable {
12+
class Configuration implements Configurable {
1313
private boolean modified = false;
1414
private JFilePicker cppcheckFilePicker;
1515
private JTextField cppcheckOptionsField;
@@ -105,7 +105,7 @@ public boolean isModified() {
105105
}
106106

107107
private void setModified() {
108-
this.modified = true;
108+
modified = true;
109109
}
110110

111111
@Override
@@ -140,22 +140,22 @@ public void disposeUIResources() {
140140
private static class CppcheckConfigurationModifiedListener implements DocumentListener {
141141
private final Configuration option;
142142

143-
CppcheckConfigurationModifiedListener(Configuration option) {
143+
CppcheckConfigurationModifiedListener(final Configuration option) {
144144
this.option = option;
145145
}
146146

147147
@Override
148-
public void insertUpdate(DocumentEvent documentEvent) {
148+
public void insertUpdate(final DocumentEvent documentEvent) {
149149
option.setModified();
150150
}
151151

152152
@Override
153-
public void removeUpdate(DocumentEvent documentEvent) {
153+
public void removeUpdate(final DocumentEvent documentEvent) {
154154
option.setModified();
155155
}
156156

157157
@Override
158-
public void changedUpdate(DocumentEvent documentEvent) {
158+
public void changedUpdate(final DocumentEvent documentEvent) {
159159
option.setModified();
160160
}
161161
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import java.util.ArrayList;
3636
import java.util.List;
3737

38-
public class CppCheckInspectionImpl {
38+
class CppCheckInspectionImpl {
3939
private static ProblemHighlightType severityToHighlightType(@NotNull final String severity) {
4040
switch (severity) {
4141
case "error":
@@ -77,8 +77,8 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
7777

7878
final List<ProblemDescriptor> descriptors = new ArrayList<>();
7979

80-
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
81-
DocumentBuilder db = dbf.newDocumentBuilder();
80+
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
81+
final DocumentBuilder db = dbf.newDocumentBuilder();
8282
final org.w3c.dom.Document doc = db.parse(new InputSource(new StringReader(cppcheckOutput)));
8383

8484
final NodeList errors = doc.getElementsByTagName("error");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.jetbrains.annotations.NotNull;
44

5-
public class CppcheckError extends Error {
5+
class CppcheckError extends Error {
66
public CppcheckError(@NotNull final String message)
77
{
88
super(message);

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

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
import javax.xml.parsers.ParserConfigurationException;
2222
import java.io.File;
2323
import java.io.IOException;
24+
import java.util.ArrayList;
25+
import java.util.Arrays;
26+
import java.util.Collections;
2427
import java.util.List;
2528

26-
public class CppcheckInspection extends LocalInspectionTool {
29+
class CppcheckInspection extends LocalInspectionTool {
2730
@Nullable
2831
@Override
29-
public ProblemDescriptor[] checkFile(@NotNull PsiFile file,
30-
@NotNull InspectionManager manager,
31-
boolean isOnTheFly) {
32+
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file,
33+
@NotNull final InspectionManager manager,
34+
final boolean isOnTheFly) {
3235
final VirtualFile vFile = file.getVirtualFile();
3336
if (vFile == null || !vFile.isInLocalFileSystem() || !isCFamilyFile(vFile)) {
3437
return ProblemDescriptor.EMPTY_ARRAY;
@@ -65,7 +68,7 @@ public ProblemDescriptor[] checkFile(@NotNull PsiFile file,
6568
final List<ProblemDescriptor> descriptors = CppCheckInspectionImpl.parseOutput(file, manager, document, cppcheckOutput,
6669
tempFile.getName());
6770
return descriptors.toArray(new ProblemDescriptor[0]);
68-
} catch (ExecutionException | CppcheckError | IOException | SAXException | ParserConfigurationException ex) {
71+
} catch (final ExecutionException | CppcheckError | IOException | SAXException | ParserConfigurationException ex) {
6972
Notifications.Bus.notify(new Notification("Cppcheck",
7073
"Cppcheck execution failed.",
7174
ex.getClass().getSimpleName() + ": " + ex.getMessage(),
@@ -80,7 +83,7 @@ public ProblemDescriptor[] checkFile(@NotNull PsiFile file,
8083
}
8184

8285
@NotNull
83-
private static String prependIncludeDir(@NotNull String cppcheckOptions, @NotNull VirtualFile vFile) {
86+
private static String prependIncludeDir(@NotNull final String cppcheckOptions, @NotNull final VirtualFile vFile) {
8487
final VirtualFile dir = vFile.getParent();
8588
if (dir == null) {
8689
return cppcheckOptions;
@@ -92,21 +95,51 @@ private static String prependIncludeDir(@NotNull String cppcheckOptions, @NotNul
9295
return String.format("-I\"%s\" %s", path, cppcheckOptions);
9396
}
9497

98+
// TODO: get the list of supported extensions from Cppcheck if it provides that information
99+
// TODO: extend list by extensions configured within CLion
100+
private final static List<String> supportedCExtensions = new ArrayList<>(Arrays.asList(
101+
"c",
102+
"cl"));
103+
104+
private final static List<String> supportedCPPExtensions = new ArrayList<>(Arrays.asList(
105+
"cc",
106+
"cp",
107+
"cpp",
108+
"c++",
109+
"cxx",
110+
"hh",
111+
"hpp",
112+
"hxx",
113+
"tpp",
114+
"txx"));
115+
116+
private final static List<String> supportedHeaderExtensions = new ArrayList<>(Collections.singletonList(
117+
"h"));
118+
95119
private static boolean isCFamilyFile(@NotNull final VirtualFile file) {
120+
return isCFile(file) || isCPPFile(file) || isHeaderFile(file);
121+
}
122+
123+
static private boolean isFile(@NotNull final VirtualFile file, @NotNull final List<String> supportedExtensions)
124+
{
96125
final String fileExtension = file.getExtension();
97126
if (fileExtension == null) {
98127
return false;
99128
}
100129

101130
final String lowerFileExtension = fileExtension.toLowerCase();
102-
return lowerFileExtension.equals("c") ||
103-
lowerFileExtension.equals("cc") ||
104-
lowerFileExtension.equals("cp") ||
105-
lowerFileExtension.equals("cpp") ||
106-
lowerFileExtension.equals("c++") ||
107-
lowerFileExtension.equals("cxx") ||
108-
lowerFileExtension.equals("h") ||
109-
lowerFileExtension.equals("hh") ||
110-
lowerFileExtension.equals("hpp");
131+
return supportedExtensions.contains(lowerFileExtension);
132+
}
133+
134+
static private boolean isCFile(@NotNull final VirtualFile file) {
135+
return isFile(file, supportedCExtensions);
136+
}
137+
138+
static private boolean isCPPFile(@NotNull final VirtualFile file) {
139+
return isFile(file, supportedCPPExtensions);
140+
}
141+
142+
static private boolean isHeaderFile(@NotNull final VirtualFile file) {
143+
return isFile(file, supportedHeaderExtensions);
111144
}
112145
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class JFilePicker extends JPanel {
1111
private final JTextField textField;
1212
private final JFileChooser fileChooser;
1313

14-
JFilePicker(String textFieldLabel, String buttonLabel) {
14+
JFilePicker(final String textFieldLabel, final String buttonLabel) {
1515
fileChooser = new JFileChooser();
1616

1717
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
class Properties {
66
private static final PropertiesComponent INSTANCE = PropertiesComponent.getInstance();
77

8-
static void set(String key, String value) {
8+
static void set(final String key, final String value) {
99
INSTANCE.setValue(key, value);
1010
}
1111

12-
static String get(String key) {
12+
static String get(final String key) {
1313
return INSTANCE.getValue(key);
1414
}
1515
}

0 commit comments

Comments
 (0)