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 @@ -347,25 +347,44 @@ public void visit(VariableDeclarationNode variableDeclarationNode) {
@Override
public void visit(ListenerDeclarationNode listenerDeclarationNode) {
List<Listener.KeyValue> arguments = new ArrayList<>();
Optional<Symbol> symbol = semanticModel.symbol(listenerDeclarationNode.typeDescriptor().get());
Optional<TypeSymbol> typeSymbol;
String typeName;
Node initializer = listenerDeclarationNode.initializer();

if (listenerDeclarationNode.typeDescriptor().isPresent()) {
// If explicit type descriptor is present, use it to get the type symbol and name
Optional<Symbol> symbol = semanticModel.symbol(listenerDeclarationNode.typeDescriptor().get());
typeSymbol = symbol.filter(s -> s instanceof TypeSymbol).map(s -> (TypeSymbol) s);
typeName = listenerDeclarationNode.typeDescriptor().get().toSourceCode().strip();
} else if (initializer instanceof ExplicitNewExpressionNode explicitNewExpressionNode) {
// If inferred type from explicit new expression
Optional<Symbol> symbol = semanticModel.symbol(explicitNewExpressionNode.typeDescriptor());
typeSymbol = symbol.filter(s -> s instanceof TypeSymbol).map(s -> (TypeSymbol) s);
typeName = explicitNewExpressionNode.typeDescriptor().toSourceCode().strip();
} else {
// Fallback to getting the type from the initializer expression
typeSymbol = semanticModel.typeOf(initializer);
typeName = typeSymbol.map(TypeSymbol::signature).orElse("");
}

if (initializer instanceof NewExpressionNode newExpressionNode) {
if (symbol.isPresent() && symbol.get() instanceof TypeSymbol typeSymbol) {
TypeSymbol rawType = CommonUtils.getRawType(typeSymbol);
if (typeSymbol.isPresent()) {
TypeSymbol rawType = CommonUtils.getRawType(typeSymbol.get());
if (rawType instanceof ClassSymbol classSymbol) {
arguments = getInitMethodParamNames(classSymbol, connectionFinder.getArgList(newExpressionNode));
}
}
}

String icon = symbol.flatMap(Symbol::getModule)
String icon = typeSymbol.flatMap(Symbol::getModule)
.map(module -> CommonUtils.generateIcon(module.id())).orElse("");
LineRange lineRange = listenerDeclarationNode.lineRange();
String sortText = lineRange.fileName() + lineRange.startLine().line();

this.intermediateModel.listeners.put(listenerDeclarationNode.variableName().text(),
new Listener(listenerDeclarationNode.variableName().text(), sortText,
getLocation(listenerDeclarationNode.lineRange()),
listenerDeclarationNode.typeDescriptor().get().toSourceCode().strip(),
typeName,
icon, Listener.Kind.NAMED, arguments, true));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"description": "Project with only listener",
"projectPath": "project_8",
"output": {
"designModel": {
"connections": [],
"listeners": [
{
"symbol": "list",
"location": {
"filePath": "/Users/pasindufernando/Desktop/BI/Ballerina-Language-Server/ballerina-language-server/architecture-model-generator/modules/architecture-model-generator-ls-extension/src/test/resources/get_design_model/source/project_8/main.bal",
"startLine": {
"line": 2,
"offset": 0
},
"endLine": {
"line": 2,
"offset": 40
}
},
"attachedServices": [],
"kind": "NAMED",
"type": "http:Listener",
"args": [
{
"key": "port",
"value": "8080"
}
],
"icon": "https://bcentral-packageicons.azureedge.net/images/ballerina_http_2.14.1.png",
"uuid": "PLACEHOLDER",
"enableFlowModel": true,
"sortText": "main.bal2"
}
],
"services": []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "wso2"
name = "service"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ballerina/http;

listener list = new http:Listener(8080);
Loading