-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42370 from ballerina-platform/poorna_formatter
[Master] Maintain minimum number of new lines when formatting methods in a class/service
- Loading branch information
Showing
11 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.../ballerina-parser/src/test/resources/declarations/service-decl/service_decl_source_23.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
service / on new http:Listener(8080) { | ||
resource function get /hello(string name) { | ||
} | ||
|
||
resource function get hello/(string name) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ class Foo { | |
function getName() { | ||
|
||
} | ||
|
||
remote function get() { | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...c/test/resources/declarations/class-definition/assert/class_definition_declaration_18.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Student { | ||
string name; | ||
int age; | ||
|
||
public function init(string name, int age) { | ||
self.name = name; | ||
self.age = age; | ||
} | ||
|
||
public function getName() returns string { | ||
return self.name; | ||
} | ||
|
||
public function getAge() returns int { | ||
return self.age; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...c/test/resources/declarations/class-definition/source/class_definition_declaration_18.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Student { | ||
string name; | ||
int age; | ||
|
||
public function init(string name, int age) { | ||
self.name = name; | ||
self.age = age; | ||
} | ||
public function getName() returns string { | ||
return self.name; | ||
} | ||
|
||
|
||
|
||
public function getAge() returns int { | ||
return self.age; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...rc/test/resources/declarations/service-listener/assert/service_listener_declaration_3.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ballerina/http; | ||
|
||
public type Student readonly & record { | ||
string name; | ||
int age; | ||
}; | ||
|
||
http:Listener httpListener = check new (9090); | ||
|
||
public service class StudentService { | ||
*http:Service; | ||
|
||
Student[] students = []; | ||
|
||
resource function get students() returns Student[] { | ||
return self.students; | ||
} | ||
|
||
resource function post student(Student student) { | ||
self.students.push(student); | ||
} | ||
|
||
resource function post students(Student[] students) { | ||
self.students.push(...students); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rc/test/resources/declarations/service-listener/assert/service_listener_declaration_4.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import ballerina/grpc; | ||
|
||
configurable int port = 9090; | ||
|
||
type Book record { | ||
string id; | ||
string title; | ||
string author; | ||
float price; | ||
}; | ||
|
||
Book[] books = [ | ||
{id: "1", title: "Book One", author: "Author One", price: 29.99}, | ||
{id: "2", title: "Book Two", author: "Author Two", price: 19.99}, | ||
{id: "3", title: "Book Three", author: "Author Three", price: 39.99} | ||
]; | ||
|
||
service "Books" on new grpc:Listener(port) { | ||
remote function addBook(Book book) returns Book|error { | ||
books.push(book); | ||
return book; | ||
} | ||
|
||
remote function getBook(string id) returns Book|error { | ||
Book[] book = books.filter(b => b.id == id); | ||
if (book.length() == 0) { | ||
return error grpc:NotFoundError(string `Cannot find the album for ID ${id}`); | ||
} | ||
return book[0]; | ||
} | ||
|
||
remote function listBooks() returns stream<Book, error?>|error { | ||
return books.toStream(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...rc/test/resources/declarations/service-listener/source/service_listener_declaration_3.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ballerina/http; | ||
|
||
public type Student readonly & record { | ||
string name; | ||
int age; | ||
}; | ||
|
||
http:Listener httpListener = check new (9090); | ||
|
||
public service class StudentService { | ||
*http:Service; | ||
|
||
Student[] students = []; | ||
|
||
resource function get students() returns Student[] { | ||
return self.students; | ||
} | ||
resource function post student(Student student) { | ||
self.students.push(student); | ||
} | ||
|
||
|
||
|
||
resource function post students(Student[] students) { | ||
self.students.push(...students); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...rc/test/resources/declarations/service-listener/source/service_listener_declaration_4.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ballerina/grpc; | ||
|
||
|
||
configurable int port = 9090; | ||
|
||
type Book record { | ||
string id; | ||
string title; | ||
string author; | ||
float price; | ||
}; | ||
|
||
Book[] books = [ | ||
{id: "1", title: "Book One", author: "Author One", price: 29.99}, | ||
{id: "2", title: "Book Two", author: "Author Two", price: 19.99}, | ||
{id: "3", title: "Book Three", author: "Author Three", price: 39.99} | ||
]; | ||
|
||
service "Books" on new grpc:Listener(port) { | ||
remote function addBook(Book book) returns Book | error { | ||
books.push(book); | ||
return book; | ||
} | ||
remote function getBook(string id) returns Book | error { | ||
Book[] book = books.filter(b => b.id == id); | ||
if (book.length() == 0) { | ||
return error grpc:NotFoundError(string `Cannot find the album for ID ${id}`); | ||
} | ||
return book[0]; | ||
} | ||
|
||
|
||
|
||
remote function listBooks( ) returns stream<Book, error?> | error { | ||
return books.toStream(); | ||
} | ||
} |