diff options
| author | Daniel Jasper <djasper@google.com> | 2014-09-15 11:21:46 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-09-15 11:21:46 +0000 |
| commit | c58c70e2f37f666faad94ef3bfab6d63eb5b0837 (patch) | |
| tree | b7befd19772568ade6088070d67acd7b130bb2c4 /clang/lib | |
| parent | 41a25dd7ef54366ce53da3d07fe0cdec84f18969 (diff) | |
| download | bcm5719-llvm-c58c70e2f37f666faad94ef3bfab6d63eb5b0837.tar.gz bcm5719-llvm-c58c70e2f37f666faad94ef3bfab6d63eb5b0837.zip | |
clang-format: Basic support for Java.
llvm-svn: 217759
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 8 |
2 files changed, 20 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5f9536dac8b..2948ec48cde 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -41,6 +41,7 @@ namespace yaml { template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> { static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) { IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp); + IO.enumCase(Value, "Java", FormatStyle::LK_Java); IO.enumCase(Value, "JavaScript", FormatStyle::LK_JavaScript); IO.enumCase(Value, "Proto", FormatStyle::LK_Proto); } @@ -405,7 +406,11 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200; GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1; - if (Language == FormatStyle::LK_JavaScript) { + if (Language == FormatStyle::LK_Java) { + GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; + GoogleStyle.ColumnLimit = 100; + GoogleStyle.SpaceAfterCStyleCast = true; + } else if (Language == FormatStyle::LK_JavaScript) { GoogleStyle.BreakBeforeTernaryOperators = false; GoogleStyle.MaxEmptyLinesToKeep = 3; GoogleStyle.SpacesInContainerLiterals = false; @@ -1031,6 +1036,8 @@ private: /// For example, 'public:' labels in classes are offset by 1 or 2 /// characters to the left from their level. int getIndentOffset(const FormatToken &RootToken) { + if (Style.Language == FormatStyle::LK_Java) + return 0; if (RootToken.isAccessSpecifier(false) || RootToken.isObjCAccessSpecifier()) return Style.AccessModifierOffset; return 0; @@ -1754,6 +1761,8 @@ static StringRef getLanguageName(FormatStyle::LanguageKind Language) { switch (Language) { case FormatStyle::LK_Cpp: return "C++"; + case FormatStyle::LK_Java: + return "Java"; case FormatStyle::LK_JavaScript: return "JavaScript"; case FormatStyle::LK_Proto: @@ -2120,7 +2129,9 @@ const char *StyleOptionHelpDescription = " -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\""; static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { - if (FileName.endswith_lower(".js")) { + if (FileName.endswith(".java")) { + return FormatStyle::LK_Java; + } else if (FileName.endswith_lower(".js")) { return FormatStyle::LK_JavaScript; } else if (FileName.endswith_lower(".proto") || FileName.endswith_lower(".protodevel")) { diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index edb68a3d79c..2b215fd09f9 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -685,7 +685,10 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::kw_public: case tok::kw_protected: case tok::kw_private: - parseAccessSpecifier(); + if (Style.Language == FormatStyle::LK_Java) + nextToken(); + else + parseAccessSpecifier(); return; case tok::kw_if: parseIfThenElse(); @@ -1405,6 +1408,9 @@ void UnwrappedLineParser::parseRecord() { // We fall through to parsing a structural element afterwards, so // class A {} n, m; // will end up in one unwrapped line. + // This does not apply for Java. + if (Style.Language == FormatStyle::LK_Java) + addUnwrappedLine(); } void UnwrappedLineParser::parseObjCProtocolList() { |

