Hi djasper,

Before

```
public void union
(Object o);

public void struct
(Object o);

public void delete (Object o);
```

After

```
public void union(Object o);

public void struct(Object o);

public void delete(Object o);
```

http://reviews.llvm.org/D6315

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJava.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1649,7 +1649,9 @@
     if (Left.is(tok::r_paren) && Left.Type == TT_AttributeParen)
       return true;
     return Line.Type == LT_ObjCDecl ||
-           Left.isOneOf(tok::kw_new, tok::kw_delete, tok::semi) ||
+           (Style.Language != FormatStyle::LK_Java &&
+            Left.is(tok::kw_delete)) ||
+           (Left.isOneOf(tok::kw_new, tok::semi)) ||
            (Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
             (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
                           tok::kw_switch, tok::kw_case) ||
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -751,7 +751,11 @@
     case tok::kw_struct:
     case tok::kw_union:
     case tok::kw_class:
-      parseRecord();
+      if (Style.Language == FormatStyle::LK_Java &&
+          FormatTok->Tok.getKind() != tok::kw_class)
+        nextToken();
+      else
+        parseRecord();
       // A record declaration or definition is always the start of a structural
       // element.
       break;
Index: unittests/Format/FormatTestJava.cpp
===================================================================
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -275,5 +275,11 @@
                getStyleWithColumns(40));
 }
 
+TEST_F(FormatTestJava, CppKeywords) {
+  verifyFormat("public void union(Type a, Type b);");
+  verifyFormat("public void struct(Object o);");
+  verifyFormat("public void delete(Object o);");
+}
+
 } // end namespace tooling
 } // end namespace clang
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to