Skip to content

Commit 320f947

Browse files
committed
basic support for java files
1 parent b93e917 commit 320f947

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/FileTypeFactory.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "FileType_Unknown.h"
66
#include "FileType_VB.h"
77
#include "FileType_Ada.h"
8+
#include "FileType_Java.h"
89
#include "StringUtil.h"
910

1011
#include <algorithm>
@@ -26,6 +27,8 @@ IFileTypePtr FileTypeFactory::CreateFileType(
2627
fileType.reset(new FileType_VB(ignorePrepStuff, minChars));
2728
else if (ext == "ads" || ext == "adb")
2829
fileType.reset(new FileType_Ada(ignorePrepStuff, minChars));
30+
else if (ext == "java")
31+
fileType.reset(new FileType_Java(ignorePrepStuff, minChars));
2932
else
3033
fileType.reset(new FileType_Unknown(minChars));
3134
return fileType;

src/FileType_Java.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "FileType_Java.h"
2+
#include "CstyleCommentsFilter.h"
3+
#include "CstyleUtils.h"
4+
#include "SourceLine.h"
5+
6+
#include <cstring>
7+
8+
FileType_Java::FileType_Java(bool ignorePrepStuff, unsigned minChars)
9+
: FileTypeBase(ignorePrepStuff, minChars) {
10+
}
11+
12+
ILineFilterPtr FileType_Java::CreateLineFilter() const {
13+
return std::make_shared<CstyleCommentsLineFilter>();
14+
}
15+
16+
std::string FileType_Java::GetCleanLine(const std::string& line) const {
17+
return CstyleUtils::RemoveSingleLineComments(line);
18+
}
19+
20+
bool FileType_Java::IsPreprocessorDirective(const std::string& line) const {
21+
// look for other markers to avoid
22+
const char* markers[] = { "package", "import", "private", "protected", "public" };
23+
24+
for (auto v : markers) {
25+
if (line.find(v, 0, std::strlen(v)) != std::string::npos)
26+
return true;
27+
}
28+
29+
return false;
30+
}

src/FileType_Java.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef _FILETYPE_JAVA_H_
2+
#define _FILETYPE_JAVA_H_
3+
4+
#include "FileTypeBase.h"
5+
6+
struct FileType_Java : public FileTypeBase {
7+
FileType_Java(bool ignorePrepStuff, unsigned minChars);
8+
9+
ILineFilterPtr CreateLineFilter() const override;
10+
11+
std::string GetCleanLine(const std::string& line) const override;
12+
13+
bool IsPreprocessorDirective(const std::string& line) const override;
14+
};
15+
16+
#endif

0 commit comments

Comments
 (0)