diff options
author | Daniel Jasper <djasper@google.com> | 2015-02-18 17:17:15 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-02-18 17:17:15 +0000 |
commit | 3c42dba2dcd5c945fe34dbcc3aad94e750ef0b5b (patch) | |
tree | 1a47e0857f9086cdc1390d1f7c0adfa848c9eeac | |
parent | 1fd6548297791bf548d30518a707541f31c8376b (diff) | |
download | bcm5719-llvm-3c42dba2dcd5c945fe34dbcc3aad94e750ef0b5b.tar.gz bcm5719-llvm-3c42dba2dcd5c945fe34dbcc3aad94e750ef0b5b.zip |
clang-format: [JS] support AtScript style annotations for JS.
Based on Java annotation support and style.
Patch by Martin Probst.
llvm-svn: 229703
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 13 |
2 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8db48ff1ed5..40573429685 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -881,7 +881,9 @@ private: // Line.MightBeFunctionDecl can only be true after the parentheses of a // function declaration have been found. Current.Type = TT_TrailingAnnotation; - } else if (Style.Language == FormatStyle::LK_Java && Current.Previous) { + } else if ((Style.Language == FormatStyle::LK_Java || + Style.Language == FormatStyle::LK_JavaScript) && + Current.Previous) { if (Current.Previous->is(tok::at) && Current.isNot(Keywords.kw_interface)) { const FormatToken &AtToken = *Current.Previous; @@ -1920,6 +1922,10 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace) && Left.NestingLevel == 0) return true; + if (Left.is(TT_LeadingJavaAnnotation) && + Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) && + Line.Last->is(tok::l_brace)) + return true; } else if (Style.Language == FormatStyle::LK_Java) { if (Left.is(TT_LeadingJavaAnnotation) && Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) && diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index f062cbfaf23..8c74b0425ad 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -510,5 +510,18 @@ TEST_F(FormatTestJS, ClassDeclarations) { verifyFormat("class C extends P implements I {}"); } +TEST_F(FormatTestJS, MetadataAnnotations) { + verifyFormat("@A\nclass C {\n}"); + verifyFormat("@A({arg: 'value'})\nclass C {\n}"); + verifyFormat("@A\n@B\nclass C {\n}"); + verifyFormat("class C {\n @A x: string;\n}"); + verifyFormat("class C {\n" + " @A\n" + " private x(): string {\n" + " return 'y';\n" + " }\n" + "}"); +} + } // end namespace tooling } // end namespace clang |