In progress: [Issue 13] Implement a formatter.
* Improve formatting of stream and rpc elements.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java
index 5af39c7..9d6c459 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter_Test.java
@@ -105,18 +105,62 @@
}
// message Person {}
- // service PersonService { rpc PersonRpc (Person) returns (Person); }
+ // service PersonService {}
// message Person {
// }
//
// service PersonService {
- // rpc PersonRpc ( Person ) returns ( Person );
// }
@Test public void should_format_service() {
assertThatFormattingWorksCorrectly();
}
+ // message Person {}
+ // service PersonService { rpc PersonRpc ( Person ) returns ( Person ); }
+
+ // message Person {
+ // }
+ //
+ // service PersonService {
+ // rpc PersonRpc (Person) returns (Person);
+ // }
+ @Test public void should_format_rpc() {
+ assertThatFormattingWorksCorrectly();
+ }
+
+ // message Person {}
+ //
+ // service PersonService { stream PersonStream ( Person,Person ); }
+
+ // message Person {
+ // }
+ //
+ // service PersonService {
+ // stream PersonStream (Person, Person);
+ // }
+ @Test public void should_format_stream() {
+ assertThatFormattingWorksCorrectly();
+ }
+
+ // syntax = 'proto2';package com.google.protobuf.test;import 'google/protobuf/descriptor.proto';import
+ // public 'address.proto';import weak 'salary.proto';option java_package = "com.foo.bar";option
+ // optimize_for = CODE_SIZE;
+
+ // syntax = 'proto2';
+ //
+ // package com.google.protobuf.test;
+ //
+ // import 'google/protobuf/descriptor.proto';
+ // import public 'address.proto';
+ // import weak 'salary.proto';
+ //
+ // option java_package = "com.foo.bar";
+ // option optimize_for = CODE_SIZE;
+ @Ignore public void should_format() {
+ assertThatFormattingWorksCorrectly();
+ }
+
private void assertThatFormattingWorksCorrectly() {
ICompositeNode rootNode = commentReader.rootNode();
IFormattedRegion region = formatter.format(rootNode, 0, rootNode.getText().length());
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java
index 1d737e4..3e1509b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/formatting/ProtobufFormatter.java
@@ -41,12 +41,17 @@
c.setLinewrap(1).after(g.getEnumElementRule());
c.setLinewrap(1).after(g.getRpcRule());
c.setLinewrap(2).after(g.getServiceRule());
+ c.setLinewrap(1).after(g.getStreamRule());
for (Keyword k : g.findKeywords(EQUAL.toString())) {
c.setSpace(space()).around(k);
}
for (Keyword k : g.findKeywords(SEMICOLON.toString())) {
c.setNoSpace().before(k);
}
+ for (Keyword k : g.findKeywords(",")) {
+ c.setNoSpace().before(k);
+ c.setSpace(space()).after(k);
+ }
for (Keyword k : g.findKeywords(OPENING_CURLY_BRACKET.toString())) {
c.setIndentationIncrement().after(k);
c.setLinewrap(1).after(k);
@@ -55,10 +60,10 @@
c.setIndentationDecrement().before(k);
c.setLinewrap(1).after(k);
}
- for (Keyword k : g.findKeywords(OPENING_BRACKET.toString())) {
+ for (Keyword k : g.findKeywords(OPENING_BRACKET.toString(), "(")) {
c.setNoSpace().after(k);
}
- for (Keyword k : g.findKeywords(CLOSING_BRACKET.toString())) {
+ for (Keyword k : g.findKeywords(CLOSING_BRACKET.toString(), ")")) {
c.setNoSpace().before(k);
}
}