r301399 - clang-format: [JS/Java] ignore Objective-C constructs in JS & Java.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 26 05:36:49 PDT 2017
Author: mprobst
Date: Wed Apr 26 07:36:49 2017
New Revision: 301399
URL: http://llvm.org/viewvc/llvm-project?rev=301399&view=rev
Log:
clang-format: [JS/Java] ignore Objective-C constructs in JS & Java.
Summary:
Java and JavaScript support annotations and decorators, respectively, that use a leading "@" token. clang-format currently detects this as an Objective-C construct and applies special formatting, for example no whitespace around "=" operators. This change disables the distinction for Java and JavaScript, which leads to normal formatting of single line annotated and initialized properties.
Before:
class X {
@foo() bar=false;
}
After:
class X {
@foo() bar = false;
}
Reviewers: djasper, bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D32532
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=301399&r1=301398&r2=301399&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Apr 26 07:36:49 2017
@@ -1120,7 +1120,11 @@ private:
Current.Type = TT_FunctionAnnotationRParen;
}
}
- } else if (Current.is(tok::at) && Current.Next) {
+ } else if (Current.is(tok::at) && Current.Next &&
+ Style.Language != FormatStyle::LK_JavaScript &&
+ Style.Language != FormatStyle::LK_Java) {
+ // In Java & JavaScript, "@..." is a decorator or annotation. In ObjC, it
+ // marks declarations and properties that need special formatting.
switch (Current.Next->Tok.getObjCKeywordID()) {
case tok::objc_interface:
case tok::objc_implementation:
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=301399&r1=301398&r2=301399&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Apr 26 07:36:49 2017
@@ -1239,6 +1239,9 @@ TEST_F(FormatTestJS, MetadataAnnotations
"}");
verifyFormat("class X {}\n"
"class Y {}");
+ verifyFormat("class X {\n"
+ " @property() private isReply = false;\n"
+ "}\n");
}
TEST_F(FormatTestJS, TypeAliases) {
More information about the cfe-commits
mailing list