Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ protected Object[] getConfigsList() {
{Path.of("function_def7.json")},
{Path.of("variable53.json")},
{Path.of("variable55.json")},
{Path.of("variable56.json")},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,11 @@
"typeName": "Elephant",
"kind": "record",
"ref": "-2143678211"
},
{
"name": "animal",
"displayName": "animal",
"typeName": "()",
"kind": "()"
}
],
"name": "animal",
"displayName": "animal",
"typeName": "Dog|Elephant|()",
"typeName": "Dog|Elephant",
"kind": "union",
"optional": false,
"ref": "1484"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,11 @@
"typeName": "Elephant",
"kind": "record",
"ref": "-2143678211"
},
{
"name": "animal",
"displayName": "animal",
"typeName": "()",
"kind": "()"
}
],
"name": "animal",
"displayName": "animal",
"typeName": "Dog|Elephant|()",
"typeName": "Dog|Elephant",
"kind": "union",
"optional": false,
"ref": "1484"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,11 @@
"typeName": "Elephant",
"kind": "record",
"ref": "-2143678211"
},
{
"name": "animal",
"displayName": "animal",
"typeName": "()",
"kind": "()"
}
],
"name": "animal",
"displayName": "animal",
"typeName": "Dog|Elephant|()",
"typeName": "Dog|Elephant",
"kind": "union",
"optional": false,
"ref": "1484"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,11 @@
"typeName": "Elephant",
"kind": "record",
"ref": "-2143678211"
},
{
"name": "animal",
"displayName": "animal",
"typeName": "()",
"kind": "()"
}
],
"name": "animal",
"displayName": "animal",
"typeName": "Dog|Elephant|()",
"typeName": "Dog|Elephant",
"kind": "union",
"optional": false,
"ref": "1484"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"source": "variable34.bal",
"description": "Sample diagram node",
"codedata": {
"node": "VARIABLE",
"lineRange": {
"fileName": "variable34.bal",
"startLine": {
"line": 25,
"offset": 12
},
"endLine": {
"line": 25,
"offset": 35
}
},
"sourceCode": "Student student = {};"
},
"position": {
"line": 23,
"offset": 12
},
"propertyKey": "expression",
"targetField": "student",
"model": {
"inputs": [
{
"name": "CONST",
"displayName": "CONST",
"typeName": "string",
"kind": "string",
"category": "constant"
},
{
"fields": [],
"name": "myStudent",
"displayName": "myStudent",
"typeName": "Student",
"kind": "record",
"category": "module-variable",
"ref": "545732303"
}
],
"output": {
"fields": [],
"name": "student",
"displayName": "student",
"typeName": "UserInfo",
"kind": "record",
"ref": "1889977605"
},
"mappings": [],
"refs": {
"-262167728": {
"fields": [
{
"name": "username",
"displayName": "username",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "password",
"displayName": "password",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "'record",
"displayName": "'record",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "data",
"displayName": "data",
"typeName": "json",
"kind": "json",
"optional": false
},
{
"name": "info",
"displayName": "info",
"typeName": "any",
"kind": "any",
"optional": false
}
],
"typeName": "Student?",
"kind": "record"
},
"545732303": {
"fields": [
{
"name": "username",
"displayName": "username",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "password",
"displayName": "password",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "'record",
"displayName": "'record",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "data",
"displayName": "data",
"typeName": "json",
"kind": "json",
"optional": false
},
{
"name": "info",
"displayName": "info",
"typeName": "any",
"kind": "any",
"optional": false
}
],
"typeName": "Student",
"kind": "record"
},
"1889977605": {
"fields": [
{
"name": "username",
"displayName": "username",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"name": "password",
"displayName": "password",
"typeName": "string",
"kind": "string",
"optional": false
},
{
"fields": [],
"name": "student",
"displayName": "student",
"typeName": "Student?",
"kind": "record",
"optional": false,
"ref": "-262167728"
}
],
"typeName": "UserInfo",
"kind": "record"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ballerina/http;

type UserInfo record {|
string username;
string password;
Student? student;
|};

type Student record {|
string username;
string password;
string 'record;
json data;
any info;
|};

const string CONST = "CONST";
Student myStudent = {};

service OASServiceType on new http:Listener(9090) {

resource function get pet() returns int|http:NotFound {
do {
Student? student1 = {};
Student student2 = {};
UserInfo userInfo = {};
} on fail error e {
return http:NOT_FOUND;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,19 @@ public static RefType fromSemanticSymbol(TypeSymbol symbol, String name, ModuleI
return arrayType;
} else if (kind == TypeDescKind.UNION) {
UnionTypeSymbol unionTypeSymbol = (UnionTypeSymbol) symbol;
List<TypeSymbol> typeSymbols = filterNilOrError(unionTypeSymbol);
if (typeSymbols.size() == 1) {
TypeSymbol soleTypeSymbol = typeSymbols.getFirst();
ModuleID soleModuleId = getModuleID(soleTypeSymbol, moduleID);
return fromSemanticSymbol(soleTypeSymbol, unionTypeSymbol.signature(), soleModuleId, typeDefSymbols);
}
RefUnionType unionType = new RefUnionType(name);
unionType.hashCode = typeHash;
unionType.key = typeKey;
unionType.moduleInfo = moduleID != null ? createTypeInfo(moduleID) : null;
visitedTypeMap.put(typeKey, unionType);

for (TypeSymbol memberTypeSymbol : unionTypeSymbol.memberTypeDescriptors()) {
for (TypeSymbol memberTypeSymbol : typeSymbols) {
String memberTypeName = memberTypeSymbol.getName().orElse("");
ModuleID memberModuleId = getModuleID(memberTypeSymbol, moduleID);
RefType memberType = fromSemanticSymbol(memberTypeSymbol, memberTypeName,
Expand Down Expand Up @@ -328,6 +334,16 @@ public static RefType fromSemanticSymbol(TypeSymbol symbol, String name, ModuleI
"Unsupported type kind: " + kind + " for symbol: " + symbol.getName().orElse("unknown"));
}

private static List<TypeSymbol> filterNilOrError(UnionTypeSymbol unionTypeSymbol) {
List<TypeSymbol> filteredMembers = new ArrayList<>();
for (TypeSymbol member : unionTypeSymbol.memberTypeDescriptors()) {
if (member.typeKind() != TypeDescKind.NIL && member.typeKind() != TypeDescKind.ERROR) {
filteredMembers.add(member);
}
}
return filteredMembers;
}

private static RefType getPrimitiveType(TypeDescKind kind) {
String primitiveTypeName = getPrimitiveTypeName(kind);
if (primitiveTypeName == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void getRefTypeForSymbol(Path jsonPath) throws IOException {
String refTypeJson = gson.toJson(refType).concat(System.lineSeparator());
String expectedRefTypeJson = gson.toJson(jsonObject.get("refType")).concat(System.lineSeparator());
if (!refTypeJson.equals(expectedRefTypeJson)) {
// updateConfig(jsonPath, refTypeJson);
updateConfig(jsonPath, refTypeJson);
Assert.fail(
String.format("Reference type JSON does not match.\n Expected : %s\n Received %s",
expectedRefTypeJson, refTypeJson));
Expand Down
Loading