Skip to content

Commit

Permalink
basic support for java files
Browse files Browse the repository at this point in the history
  • Loading branch information
dlidstrom committed Jul 4, 2024
1 parent b93e917 commit 320f947
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/FileTypeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "FileType_Unknown.h"
#include "FileType_VB.h"
#include "FileType_Ada.h"
#include "FileType_Java.h"
#include "StringUtil.h"

#include <algorithm>
Expand All @@ -26,6 +27,8 @@ IFileTypePtr FileTypeFactory::CreateFileType(
fileType.reset(new FileType_VB(ignorePrepStuff, minChars));
else if (ext == "ads" || ext == "adb")
fileType.reset(new FileType_Ada(ignorePrepStuff, minChars));
else if (ext == "java")
fileType.reset(new FileType_Java(ignorePrepStuff, minChars));
else
fileType.reset(new FileType_Unknown(minChars));
return fileType;
Expand Down
30 changes: 30 additions & 0 deletions src/FileType_Java.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "FileType_Java.h"
#include "CstyleCommentsFilter.h"
#include "CstyleUtils.h"
#include "SourceLine.h"

#include <cstring>

FileType_Java::FileType_Java(bool ignorePrepStuff, unsigned minChars)
: FileTypeBase(ignorePrepStuff, minChars) {
}

ILineFilterPtr FileType_Java::CreateLineFilter() const {
return std::make_shared<CstyleCommentsLineFilter>();
}

std::string FileType_Java::GetCleanLine(const std::string& line) const {
return CstyleUtils::RemoveSingleLineComments(line);
}

bool FileType_Java::IsPreprocessorDirective(const std::string& line) const {
// look for other markers to avoid
const char* markers[] = { "package", "import", "private", "protected", "public" };

for (auto v : markers) {
if (line.find(v, 0, std::strlen(v)) != std::string::npos)
return true;
}

return false;
}
16 changes: 16 additions & 0 deletions src/FileType_Java.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _FILETYPE_JAVA_H_
#define _FILETYPE_JAVA_H_

#include "FileTypeBase.h"

struct FileType_Java : public FileTypeBase {
FileType_Java(bool ignorePrepStuff, unsigned minChars);

ILineFilterPtr CreateLineFilter() const override;

std::string GetCleanLine(const std::string& line) const override;

bool IsPreprocessorDirective(const std::string& line) const override;
};

#endif

0 comments on commit 320f947

Please sign in to comment.