summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/FormatToken.h3
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTestJava.cpp16
3 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index c2cc3856024..0ef563b73a7 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -299,6 +299,7 @@ struct FormatToken {
bool isNot(T Kind) const {
return Tok.isNot(Kind);
}
+ bool isNot(IdentifierInfo *II) const { return II != Tok.getIdentifierInfo(); }
bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }
@@ -544,6 +545,7 @@ struct AdditionalKeywords {
kw_extends = &IdentTable.get("extends");
kw_implements = &IdentTable.get("implements");
+ kw_interface = &IdentTable.get("interface");
kw_synchronized = &IdentTable.get("synchronized");
kw_throws = &IdentTable.get("throws");
@@ -566,6 +568,7 @@ struct AdditionalKeywords {
// Java keywords.
IdentifierInfo *kw_extends;
IdentifierInfo *kw_implements;
+ IdentifierInfo *kw_interface;
IdentifierInfo *kw_synchronized;
IdentifierInfo *kw_throws;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d00e648706b..62ec93f3234 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -842,7 +842,8 @@ private:
// function declaration have been found.
Current.Type = TT_TrailingAnnotation;
} else if (Style.Language == FormatStyle::LK_Java && Current.Previous &&
- Current.Previous->is(tok::at)) {
+ Current.Previous->is(tok::at) &&
+ Current.isNot(Keywords.kw_interface)) {
const FormatToken& AtToken = *Current.Previous;
if (!AtToken.Previous ||
AtToken.Previous->Type == TT_LeadingJavaAnnotation)
diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp
index c51566715dd..44a7910e989 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -87,6 +87,22 @@ TEST_F(FormatTestJava, ClassDeclarations) {
" implements cccccccccccc {\n"
"}",
getStyleWithColumns(76));
+ verifyFormat("interface SomeInterface<A> extends Foo, Bar {\n"
+ " void doStuff(int theStuff);\n"
+ " void doMoreStuff(int moreStuff);\n"
+ "}");
+ verifyFormat("public interface SomeInterface {\n"
+ " void doStuff(int theStuff);\n"
+ " void doMoreStuff(int moreStuff);\n"
+ "}");
+ verifyFormat("@interface SomeInterface {\n"
+ " void doStuff(int theStuff);\n"
+ " void doMoreStuff(int moreStuff);\n"
+ "}");
+ verifyFormat("public @interface SomeInterface {\n"
+ " void doStuff(int theStuff);\n"
+ " void doMoreStuff(int moreStuff);\n"
+ "}");
}
TEST_F(FormatTestJava, EnumDeclarations) {
OpenPOWER on IntegriCloud