Commit 002d0785 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Extend SymbolPrinter to print instances as components

parent 9a6e62b8
Pipeline #180617 passed with stage
in 2 minutes and 50 seconds
......@@ -10,7 +10,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<version>0.1.14-SNAPSHOT</version>
<version>0.1.15-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......
......@@ -270,4 +270,47 @@ public class SymbolPrinter {
printEMAComponentInstance(inst, ip, false);
return ip.getContent();
}
public static String printEMAComponentInstanceAsEMAComponent(EMAComponentInstanceSymbol instance) {
IndentPrinter ip = new IndentPrinter();
printEMAComponentInstanceAsEMAComponent(instance, ip);
return ip.getContent();
}
public static void printEMAComponentInstanceAsEMAComponent(EMAComponentInstanceSymbol instance, IndentPrinter ip) {
ip.print("component " + capitalize(normalize(instance.getName())));
ip.println("{");
ip.indent();
printPorts(instance.getPortInstanceList(), ip);
ip.println();
instance.getSubComponents()
.forEach(inst -> printEMAComponentInstanceAsEMAComponent(inst, ip));
ip.println();
instance.getSubComponents()
.stream()
.map(inst -> "instance " + capitalize(normalize(inst.getName())) + " " + normalize(inst.getName()) + ";")
.forEach(ip::println);
ip.println();
instance.getConnectorInstances().forEach(con -> printConnector(con, ip));
ip.unindent();
ip.println("}");
}
private static String normalize(String s){
return s.replace("[", "_").replace("]","");
}
private static String capitalize(String s){
return s.substring(0,1).toUpperCase() + s.substring(1);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment