Skip to content

Commit 48fbec4

Browse files
committed
Added .cl, .hxx, .tpp and .txx to list of supported file extensions - now matches the ones supported by Cppcheck internally / separated extension list by C/C++/header for future usage to match Cppcheck as well
1 parent d90bebc commit 48fbec4

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
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/CppcheckInspection.java

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
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

2629
public class CppcheckInspection extends LocalInspectionTool {
@@ -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
}

0 commit comments

Comments
 (0)