Skip to content

Commit

Permalink
Add support for type reference
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Mar 5, 2024
1 parent ada86d6 commit 1f5e6ee
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
{
"kind": "STRING_KEYWORD",
"leadingMinutiae": [
{
"kind": "END_OF_LINE_MINUTIAE",
"value": "\n"
},
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Foo {
*;

string name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ public ServiceDeclarationNode transform(ServiceDeclarationNode serviceDeclaratio
formatSeparatedNodeList(serviceDeclarationNode.expressions(), 0, 0, 1, 0);
Token openBrace = formatToken(serviceDeclarationNode.openBraceToken(), 0, 1);
indent(); // increase the indentation of the following statements.
NodeList<Node> members = formatMemberDeclarations(serviceDeclarationNode.members(), n -> isMemberOfScope(n));
NodeList<Node> members = formatMemberDeclarations(serviceDeclarationNode.members(), n -> isClassOrServiceMember(n));
unindent(); // reset the indentation.
Optional<Token> optSemicolon = serviceDeclarationNode.semicolonToken();
Token closeBrace = optSemicolon.isPresent() ?
Expand Down Expand Up @@ -3464,7 +3464,7 @@ public ClassDefinitionNode transform(ClassDefinitionNode classDefinitionNode) {
Token openBrace = formatToken(classDefinitionNode.openBrace(), 0, 1);

indent();
NodeList<Node> members = formatMemberDeclarations(classDefinitionNode.members(), n -> isMemberOfScope(n));
NodeList<Node> members = formatMemberDeclarations(classDefinitionNode.members(), n -> isClassOrServiceMember(n));
unindent();
Optional<Token> optSemicolon = classDefinitionNode.semicolonToken();
Token closeBrace = optSemicolon.isPresent() ?
Expand Down Expand Up @@ -3905,14 +3905,15 @@ private <T extends Node> boolean isMultilineModuleMember(T node) {
}
}

private <T extends Node> boolean isMemberOfScope(T node) {
private boolean isClassOrServiceMember(Node node) {
if (node == null) {
return false;
}

switch (node.kind()) {
case OBJECT_METHOD_DEFINITION:
case RESOURCE_ACCESSOR_DEFINITION:
case TYPE_REFERENCE:
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type Vehicle object {
function kind() returns string;
};

type Tesla object {
function model() returns string;
};

class CyberTruck {
*Vehicle;

string name;
int wheels;

public function init(string name, int wheels) {
self.name = name;
self.wheels = wheels;
}

function kind() returns string {
return "car";
}

*Tesla;

function model() returns string {
return "tesla";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Person {
*A;

public int age = 10;

function foo() returns int {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type Vehicle object {
function kind() returns string;
};

type Tesla object {
function model() returns string;
};

class CyberTruck {
*Vehicle;
string name;
int wheels;

public function init(string name, int wheels) {
self.name = name;
self.wheels = wheels;
}
function kind() returns string {
return "car";
}



*Tesla;



function model() returns string {
return "tesla";
}
}

0 comments on commit 1f5e6ee

Please sign in to comment.