r222827 - clang-format: [Java] Improve cast detection.
Daniel Jasper
djasper at google.com
Wed Nov 26 04:23:11 PST 2014
Author: djasper
Date: Wed Nov 26 06:23:10 2014
New Revision: 222827
URL: http://llvm.org/viewvc/llvm-project?rev=222827&view=rev
Log:
clang-format: [Java] Improve cast detection.
Before:
a[b >> 1] = (byte)(c() << 4);
After:
a[b >> 1] = (byte) (c() << 4);
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222827&r1=222826&r2=222827&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 26 06:23:10 2014
@@ -921,15 +921,19 @@ private:
LeftOfParens->MatchingParen &&
LeftOfParens->MatchingParen->is(TT_LambdaLSquare))
return false;
+ if (Tok.Next) {
+ if (Style.Language == FormatStyle::LK_JavaScript &&
+ Tok.Next->is(Keywords.kw_in))
+ return false;
+ if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))
+ return true;
+ }
bool IsCast = false;
bool ParensAreEmpty = Tok.Previous == Tok.MatchingParen;
bool ParensAreType =
!Tok.Previous ||
Tok.Previous->isOneOf(TT_PointerOrReference, TT_TemplateCloser) ||
Tok.Previous->isSimpleTypeSpecifier();
- if (Style.Language == FormatStyle::LK_JavaScript && Tok.Next &&
- Tok.Next->is(Keywords.kw_in))
- return false;
bool ParensCouldEndDecl =
Tok.Next && Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace);
bool IsSizeOfOrAlignOf =
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222827&r1=222826&r2=222827&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Wed Nov 26 06:23:10 2014
@@ -54,6 +54,10 @@ TEST_F(FormatTestJava, NoAlternativeOper
verifyFormat("someObject.and();");
}
+TEST_F(FormatTestJava, UnderstandsCasts) {
+ verifyFormat("a[b >> 1] = (byte) (c() << 4);");
+}
+
TEST_F(FormatTestJava, FormatsInstanceOfLikeOperators) {
FormatStyle Style = getStyleWithColumns(50);
verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
More information about the cfe-commits
mailing list