Skip to content

Commit

Permalink
Remove irrelevant participants from the diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Feb 14, 2025
1 parent 95a024b commit a1730c3
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
package io.ballerina.sequencemodelgenerator.core;

import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.compiler.api.symbols.ClassSymbol;
import io.ballerina.compiler.api.symbols.Qualifier;
import io.ballerina.compiler.api.symbols.Symbol;
import io.ballerina.compiler.api.symbols.SymbolKind;
import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol;
import io.ballerina.compiler.api.symbols.VariableSymbol;
import io.ballerina.compiler.syntax.tree.NonTerminalNode;
import io.ballerina.compiler.syntax.tree.SyntaxTree;
import io.ballerina.projects.Project;
Expand All @@ -35,10 +29,7 @@
import io.ballerina.tools.text.TextRange;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Represents the model generator for the sequence diagram.
Expand Down Expand Up @@ -74,51 +65,6 @@ public static Diagram getSequenceDiagramModel(Project project, LineRange lineRan
participantManager.generateParticipant(semanticModel, rootNode, moduleName);
List<Participant> participants = participantManager.getParticipants();

// Calculate the other participants
List<String> includedParticipants = participants.stream()
.map(Participant::name)
.collect(Collectors.toCollection(ArrayList::new));
List<Participant> allParticipants = semanticModel.moduleSymbols().stream()
.flatMap(symbol -> getParticipant(symbol, includedParticipants).stream())
.collect(Collectors.toCollection(ArrayList::new));

return new Diagram(participants, allParticipants, lineRange);
}

private static Optional<Participant> getParticipant(Symbol symbol, List<String> includedParticipants) {
// Check if the symbol has a name
if (symbol.getName().isEmpty()) {
return Optional.empty();
}
String name = symbol.getName().get();

if (symbol.kind() == SymbolKind.FUNCTION) {
if (includedParticipants.remove(name)) {
return Optional.empty();
}
return Optional.of(
new Participant("0", symbol.getName().orElse(""), Participant.ParticipantKind.FUNCTION,
symbol.getModule().flatMap(Symbol::getName).orElse(""), null,
null));
}

try {
VariableSymbol variableSymbol = (VariableSymbol) symbol;
TypeReferenceTypeSymbol typeReferenceTypeSymbol = (TypeReferenceTypeSymbol) variableSymbol.typeDescriptor();
ClassSymbol classSymbol = (ClassSymbol) typeReferenceTypeSymbol.definition();
if (classSymbol.qualifiers().contains(Qualifier.CLIENT)) {
if (includedParticipants.remove(name)) {
return Optional.empty();
}
return Optional.of(
new Participant("0", variableSymbol.getName().orElse(""), Participant.ParticipantKind.ENDPOINT,
variableSymbol.getModule().flatMap(Symbol::getName).orElse(""), null,
null));
}
} catch (ClassCastException e) {
return Optional.empty();
}

return Optional.empty();
return new Diagram(participants, lineRange);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
* Represents the sequence diagram for a root participant.
*
* @param participants participants in the diagram
* @param others other participants in the diagram who does not have any interactions
* @param location location of the root participant
* @since 2.0.0
*/
public record Diagram(List<Participant> participants, List<Participant> others, LineRange location) {
public record Diagram(List<Participant> participants, LineRange location) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,6 @@
}
}
}
],
"others": [
{
"id": "0",
"name": "foo",
"kind": "FUNCTION",
"moduleName": "."
},
{
"id": "0",
"name": "drinkClient",
"kind": "ENDPOINT",
"moduleName": "."
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@
}
}
}
],
"others": []
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
}
}
}
],
"others": []
]
}
}

0 comments on commit a1730c3

Please sign in to comment.