r221109 - clang-format: [Java] Support generics with "?".
Daniel Jasper
djasper at google.com
Sun Nov 2 13:52:57 PST 2014
Author: djasper
Date: Sun Nov 2 15:52:57 2014
New Revision: 221109
URL: http://llvm.org/viewvc/llvm-project?rev=221109&view=rev
Log:
clang-format: [Java] Support generics with "?".
Before:
@Override
public Map < String,
? > getAll() {
// ...
}
After:
@Override
public Map<String, ?> getAll() {
// ...
}
This fixes llvm.org/PR21454.
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=221109&r1=221108&r2=221109&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Nov 2 15:52:57 2014
@@ -64,7 +64,10 @@ private:
return true;
}
if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace,
- tok::colon, tok::question))
+ tok::colon))
+ return false;
+ if (CurrentToken->is(tok::question) &&
+ Style.Language != FormatStyle::LK_Java)
return false;
// If a && or || is found and interpreted as a binary operator, this set
// of angles is likely part of something like "a < b && c > d". If the
@@ -364,6 +367,10 @@ private:
}
bool parseConditional() {
+ if (Style.Language == FormatStyle::LK_Java &&
+ CurrentToken->isOneOf(tok::comma, tok::greater))
+ return true; // This is a generic "?".
+
while (CurrentToken) {
if (CurrentToken->is(tok::colon)) {
CurrentToken->Type = TT_ConditionalExpr;
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=221109&r1=221108&r2=221109&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Nov 2 15:52:57 2014
@@ -120,6 +120,10 @@ TEST_F(FormatTestJava, Generics) {
verifyFormat("Iterable<? extends SomeObject> a;");
verifyFormat("A.<B>doSomething();");
+
+ verifyFormat("@Override\n"
+ "public Map<String, ?> getAll() {\n"
+ "}");
}
TEST_F(FormatTestJava, StringConcatenation) {
More information about the cfe-commits
mailing list