Commit c801070a authored by Michael Günther Beyer's avatar Michael Günther Beyer

resolve merge

parents c12f3ea4 908db221
Pipeline #98796 failed with stages
in 60 minutes and 1 second
......@@ -10,9 +10,9 @@ for your new MiddlewareSymbol. Make sure to load all your tags before starting g
## Generator
The new middleware generator needs to the following methods
* `setGenerationTargetPath(String path)`: Sets the directory the generated files are written to.
* `boolean willAccept(ExpandedComponentInstanceSymbol componentInstanceSymbol)`: Signals the DistributedTargetGenerator if the middleware generator will generate useful files for the given component.
* `boolean willAccept(EMAComponentInstanceSymbol componentInstanceSymbol)`: Signals the DistributedTargetGenerator if the middleware generator will generate useful files for the given component.
* Example: If a Component without RosConnections is passed to the ROS generator, it will reject it.
* `List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver)`: Generates all files(Adapter + CMake) for the given Component.
* `List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver)`: Generates all files(Adapter + CMake) for the given Component.
These 3 methods are combined in the Interface [GeneratorImpl](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMAM2Middleware/blob/master/src/main/java/de/monticore/lang/monticar/generator/middleware/impls/GeneratorImpl.java).
To avoid a cyclic dependency between the new middleware generator and EMAM2Middleware, it is advised to write a small wrapper in EMAM2Middleware instead of implementing the Interface directly. See [RosCppGenImpl](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMAM2Middleware/blob/master/src/main/java/de/monticore/lang/monticar/generator/middleware/impls/RosCppGenImpl.java) for an example.
......
......@@ -9,7 +9,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-middleware-generator</artifactId>
<version>0.0.13-SNAPSHOT</version>
<version>0.0.14-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......@@ -18,14 +18,13 @@
<!-- .. SE-Libraries .................................................. -->
<se-commons.version>1.7.7</se-commons.version>
<Embedded-montiarc-math-generator.version>0.0.26-SNAPSHOT</Embedded-montiarc-math-generator.version>
<Embedded-montiarc-math-roscpp-generator.version>0.0.4-SNAPSHOT</Embedded-montiarc-math-roscpp-generator.version>
<Embedded-montiarc-math-rosmsg-generator.version>0.0.3-SNAPSHOT</Embedded-montiarc-math-rosmsg-generator.version>
<EMADL.version>0.2.3</EMADL.version>
<EMADL2CPP.version>0.2.4</EMADL2CPP.version>
<!--TODO: remove with update to new emam version-->
<Tagging.version>0.0.6</Tagging.version>
<embedded-montiarc.version>0.1.9-SNAPSHOT</embedded-montiarc.version>
<Embedded-montiarc-math-generator.version>0.1.3-SNAPSHOT</Embedded-montiarc-math-generator.version>
<Embedded-montiarc-math-roscpp-generator.version>0.1.1-SNAPSHOT</Embedded-montiarc-math-roscpp-generator.version>
<EMADL.version>0.2.4</EMADL.version>
<EMADL2CPP.version>0.2.6-SNAPSHOT</EMADL2CPP.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
<junit.version>4.12</junit.version>
......@@ -52,6 +51,12 @@
</properties>
<dependencies>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<version>${embedded-montiarc.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
......@@ -114,12 +119,6 @@
<version>${Embedded-montiarc-math-roscpp-generator.version}</version>
</dependency>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-rosmsg-generator</artifactId>
<version>${Embedded-montiarc-math-rosmsg-generator.version}</version>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-core</artifactId>
......@@ -147,13 +146,6 @@
</dependency>
<!-- MontiCore Dependencies -->
<dependency>
<groupId>de.monticore.lang</groupId>
<artifactId>Tagging</artifactId>
<version>${Tagging.version}</version>
</dependency>
<dependency>
<groupId>de.se_rwth.commons</groupId>
<artifactId>se-commons-groovy</artifactId>
......
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......@@ -15,7 +15,7 @@ import java.util.Objects;
public class CMakeGenerator extends StarBridgeGenerator {
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
long notInSubdirs = getGeneratorImpls().stream()
.map(this::getImplSubdir)
.filter(Objects::isNull)
......@@ -31,7 +31,7 @@ public class CMakeGenerator extends StarBridgeGenerator {
return res;
}
protected File generateCMake(ExpandedComponentInstanceSymbol componentInstanceSymbol) throws IOException {
protected File generateCMake(EMAComponentInstanceSymbol componentInstanceSymbol) throws IOException {
FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt");
StringBuilder content = new StringBuilder();
......
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusterFromTagsHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.*;
......@@ -36,12 +36,12 @@ public class DistributedTargetGenerator extends CMakeGenerator {
}
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
Map<ExpandedComponentInstanceSymbol, GeneratorImpl> generatorMap = new HashMap<>();
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
Map<EMAComponentInstanceSymbol, GeneratorImpl> generatorMap = new HashMap<>();
fixComponentInstance(componentInstanceSymbol);
List<ExpandedComponentInstanceSymbol> clusterSubcomponents = ClusterFromTagsHelper.getClusterSubcomponents(componentInstanceSymbol);
List<EMAComponentInstanceSymbol> clusterSubcomponents = ClusterFromTagsHelper.getClusterSubcomponents(componentInstanceSymbol);
if (clusterSubcomponents.size() > 0) {
clusterSubcomponents.forEach(clusterECIS -> {
String nameTargetLanguage = NameHelper.getNameTargetLanguage(clusterECIS.getFullName());
......@@ -54,7 +54,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
List<File> files = new ArrayList<>();
for (ExpandedComponentInstanceSymbol comp : generatorMap.keySet()) {
for (EMAComponentInstanceSymbol comp : generatorMap.keySet()) {
files.addAll(generatorMap.get(comp).generate(comp, taggingResolver));
//add empty generator to subDirs so that CMakeLists.txt will be generated correctly
subDirs.add(NameHelper.getNameTargetLanguage(comp.getFullName()));
......@@ -91,12 +91,12 @@ public class DistributedTargetGenerator extends CMakeGenerator {
return res;
}
private void fixComponentInstance(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
private void fixComponentInstance(EMAComponentInstanceSymbol componentInstanceSymbol) {
RosHelper.fixRosConnectionSymbols(componentInstanceSymbol);
}
@Override
protected File generateCMake(ExpandedComponentInstanceSymbol componentInstanceSymbol) throws IOException {
protected File generateCMake(EMAComponentInstanceSymbol componentInstanceSymbol) throws IOException {
FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt");
StringBuilder content = new StringBuilder();
......
......@@ -2,7 +2,7 @@ package de.monticore.lang.monticar.generator.middleware;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.monticar.emadl.generator.EMADLAbstractSymtab;
import de.monticore.lang.monticar.emadl.generator.EMADLGeneratorCli;
......@@ -127,7 +127,7 @@ public final class DistributedTargetGeneratorCli {
}
});
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve(cliParameters.getRootModel(), ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve(cliParameters.getRootModel(), EMAComponentInstanceSymbol.KIND).orElse(null);
if (componentInstanceSymbol == null) {
Log.error("0x5FFAE: The given component cannot be resolved.");
......
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
......@@ -17,7 +17,7 @@ import java.util.stream.Collectors;
public class MiddlewareGenerator extends CMakeGenerator {
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
//Add dummy GeneratorImpl for the subdir
String subdir = "coordinator/";
this.add(new GeneratorImpl() {
......@@ -30,7 +30,7 @@ public class MiddlewareGenerator extends CMakeGenerator {
return files;
}
private FileContent generateIAdapter(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
private FileContent generateIAdapter(EMAComponentInstanceSymbol componentInstanceSymbol) {
FileContent res = new FileContent();
String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
res.setFileName("IAdapter_" + name + ".h");
......@@ -39,7 +39,7 @@ public class MiddlewareGenerator extends CMakeGenerator {
}
private FileContent generateCoordinator(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<File> files) {
private FileContent generateCoordinator(EMAComponentInstanceSymbol componentInstanceSymbol, List<File> files) {
String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
......@@ -80,7 +80,7 @@ public class MiddlewareGenerator extends CMakeGenerator {
}
private FileContent generateCoordinatorCMakeList(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<File> files) {
private FileContent generateCoordinatorCMakeList(EMAComponentInstanceSymbol componentInstanceSymbol, List<File> files) {
FileContent res = new FileContent();
String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
......
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
......@@ -34,7 +34,7 @@ public class StarBridgeGenerator implements GeneratorImpl {
this.generationTargetPath = path.endsWith("/") ? path : path + "/";
}
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> result = new ArrayList<>();
generatorImpls.forEach((key, value) -> {
if (key.willAccept(componentInstanceSymbol)) {
......
......@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.math._ast.ASTNumberExpression;
import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType;
......@@ -15,30 +18,26 @@ import de.monticore.symboltable.resolving.ResolvingFilter;
import de.se_rwth.commons.logging.Log;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class AutomaticClusteringHelper {
public static double[][] createAdjacencyMatrix(List<ExpandedComponentInstanceSymbol> subcomps, Collection<ConnectorSymbol> connectors, Map<String, Integer> subcompLabels) {
// public static double[][] createAdjacencyMatrix(List<ExpandedComponentInstanceSymbol> subcomps, Collection<ConnectorSymbol> connectors, Map<String, Integer> subcompLabels) {
public static double[][] createAdjacencyMatrix(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors, Map<String, Integer> subcompLabels) {
// Nodes = subcomponents
// Verts = connectors between subcomponents
double[][] res = new double[subcomps.size()][subcomps.size()];
connectors.forEach(con -> {
Optional<ExpandedComponentInstanceSymbol> sourceCompOpt = con.getSourcePort().getComponentInstance();
Optional<ExpandedComponentInstanceSymbol> targetCompOpt = con.getTargetPort().getComponentInstance();
EMAComponentInstanceSymbol sourceCompOpt = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetCompOpt = con.getTargetPort().getComponentInstance();
if (sourceCompOpt.isPresent() && targetCompOpt.isPresent()) {
int index1 = subcompLabels.get(sourceCompOpt.get().getFullName());
int index2 = subcompLabels.get(targetCompOpt.get().getFullName());
int index1 = subcompLabels.get(sourceCompOpt.getFullName());
int index2 = subcompLabels.get(targetCompOpt.getFullName());
res[index1][index2] = getTypeCostHeuristic(con.getSourcePort());
res[index2][index1] = getTypeCostHeuristic(con.getSourcePort());
} else {
Log.error("0xADE65: Component of source or target not found!");
}
});
......@@ -104,16 +103,16 @@ public class AutomaticClusteringHelper {
return normalizeMatrix(inverseProbabilitiesMatrix(adjacencyMatrix));
}
public static void annotateComponentWithRosTagsForClusters(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<Set<ExpandedComponentInstanceSymbol>> clusters) {
Collection<ConnectorSymbol> connectors = componentInstanceSymbol.getConnectors();
public static void annotateComponentWithRosTagsForClusters(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clusters) {
Collection<EMAConnectorInstanceSymbol> connectors = componentInstanceSymbol.getConnectorInstances();
connectors.forEach(con -> {
// -1 = super comp
int sourceClusterLabel = -1;
int targetClusterLabel = -1;
ExpandedComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance().get();
ExpandedComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance().get();
EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance();
for(int i = 0; i < clusters.size(); i++){
if(clusters.get(i).contains(sourceComp)){
......@@ -134,7 +133,7 @@ public class AutomaticClusteringHelper {
}
public static double getTypeCostHeuristic(PortSymbol port){
public static double getTypeCostHeuristic(EMAPortSymbol port){
return getTypeCostHeuristic(port.getTypeReference());
}
......@@ -174,159 +173,6 @@ public class AutomaticClusteringHelper {
return 50;
}
public static ExpandedComponentInstanceSymbol flattenArchitecture(ExpandedComponentInstanceSymbol symbol){
if (symbol.getSubComponents().isEmpty()){
if (symbol.getEnclosingComponent().isPresent()){
return copySymbolWithSystemName(symbol);
}
return symbol;
}
for (ExpandedComponentInstanceSymbol sym : symbol.getSubComponents()){
symbol = flattenArchitecture(sym);
}
if (symbol.getEnclosingComponent().isPresent()){
ExpandedComponentInstanceSymbol enclosingComponent = copySymbolWithSystemName(symbol);
symbol = enclosingComponent.getSubComponent(symbol.getFullName().replace(".", "_")).get();
ExpandedComponentInstanceSymbol thisSymbol = symbol;
List<ExpandedComponentInstanceSymbol> newSubcomponents = enclosingComponent.getSubComponents().stream()
.filter(e -> !e.getFullName().equals(thisSymbol.getFullName())).collect(Collectors.toList());
newSubcomponents.addAll(newSubcomponents.size(), new ArrayList<>(symbol.getSubComponents()));
HashSet<String> incomingPorts = new HashSet<>(symbol.getIncomingPorts().stream().map(p ->{
return p.getFullName();
}).collect(Collectors.toList()));
HashSet<String> outgoingPorts = new HashSet<>(symbol.getOutgoingPorts().stream().map(p ->{
return p.getFullName();
}).collect(Collectors.toList()));
//only connectors from incoming ports
Set<ConnectorSymbol> incomingConnectors = symbol.getConnectors().stream()
.filter(c -> incomingPorts.contains(thisSymbol.getFullName() + "." + thisSymbol.getName() + "_"+ c.getSource()))
.collect(Collectors.toSet());
//only connectors going into symbol
Set<ConnectorSymbol> incomingParentConnectors = enclosingComponent.getConnectors().stream()
.filter(c -> c.getTargetPort().getComponentInstance().get().getFullName().equals(thisSymbol.getFullName()))
.collect(Collectors.toSet());
//only connectors from outgoing ports
Set<ConnectorSymbol> outgoingConnectors = symbol.getConnectors().stream()
.filter(c -> outgoingPorts.contains(thisSymbol.getFullName() + "." + thisSymbol.getName() + "_"+ c.getTarget()))
.collect(Collectors.toSet());
//only connectors going out of symbol
Set<ConnectorSymbol> outgoingParentConnectors = enclosingComponent.getConnectors().stream()
.filter(c -> c.getSourcePort().getComponentInstance().get().getFullName().equals(thisSymbol.getFullName()))
.collect(Collectors.toSet());
//untouched connectors of enclosing symbol
Set<ConnectorSymbol> newConnectors = enclosingComponent.getConnectors().stream()
.filter(c -> !(incomingParentConnectors.contains(c) || outgoingParentConnectors.contains(c)))
.collect(Collectors.toSet());
//untouched connectors of symbol with renamed ports
newConnectors.addAll(symbol.getConnectors().stream()
//.map(c -> {return mapToNewName(c);})
.filter(c -> !(incomingConnectors.contains(c) || outgoingConnectors.contains(c)))
.collect(Collectors.toSet()));
for (ConnectorSymbol con : incomingConnectors){
for (ConnectorSymbol connectorSymbol : incomingParentConnectors){
if (con.getSource().equals(connectorSymbol.getTarget().replaceFirst(".*_", ""))){
ConnectorSymbol tmpConnector = ConnectorSymbol.builder()
.setSource(connectorSymbol.getSource())
.setTarget(con.getTarget())
.build();
newConnectors.add(tmpConnector);
}
}
}
for (ConnectorSymbol con : outgoingConnectors){
for (ConnectorSymbol connectorSymbol : outgoingParentConnectors){
if (con.getTarget().equals(connectorSymbol.getSource().replaceFirst(".*_", ""))){
ConnectorSymbol tmpConnector = ConnectorSymbol.builder()
.setSource(con.getSource())
.setTarget(connectorSymbol.getTarget())
.build();
newConnectors.add(tmpConnector);
}
}
}
ExpandedComponentInstanceSymbol res = constructECIS(enclosingComponent, newSubcomponents, newConnectors,
enclosingComponent.getName(), new ArrayList<>(enclosingComponent.getPortsList()));
return res;
} else {
return symbol;
}
}
private static ExpandedComponentInstanceSymbol copySymbolWithSystemName(ExpandedComponentInstanceSymbol symbol) {
ExpandedComponentInstanceSymbol enclosingComponent = symbol.getEnclosingComponent().get();
ExpandedComponentInstanceSymbol thisSymbol = symbol;
List<ExpandedComponentInstanceSymbol> subcomponents = enclosingComponent.getSubComponents().stream()
.filter(e -> !e.getFullName().equals(thisSymbol.getFullName())).collect(Collectors.toList());
List<PortSymbol> ports = new ArrayList<>();
String newName = symbol.getFullName().replace(".", "_");
String newEnclosingName = enclosingComponent.getFullName().replace(".", "_");
for (PortSymbol port : symbol.getPortsList()) {
ports.add((PortSymbol)(port.isConstant() ?
(new EMAPortBuilder()).setName(newName + "_" + port.getName()).setDirection(port.isIncoming())
.setTypeReference(port.getTypeReference()).setConstantValue(((ConstantPortSymbol)port).getConstantValue())
.setASTNode(port.getAstNode()).buildConstantPort()
: (new EMAPortBuilder()).setName(newName + "_" + port.getName()).setDirection(port.isIncoming())
.setTypeReference(port.getTypeReference()).setASTNode(port.getAstNode()).setConfig(port.isConfig())
.setMiddlewareSymbol(port.getMiddlewareSymbol()).build()));
}
ExpandedComponentInstanceSymbol e = constructECIS(symbol, new ArrayList<>(symbol.getSubComponents()),
new HashSet<>(symbol.getConnectors()), newName, ports);
subcomponents.add(e);
HashSet<String> incomingPorts = new HashSet<>(symbol.getIncomingPorts().stream().map(p ->{
return p.getFullName();
}).collect(Collectors.toList()));
HashSet<String> outgoingPorts = new HashSet<>(symbol.getOutgoingPorts().stream().map(p ->{
return p.getFullName();
}).collect(Collectors.toList()));
Set<ConnectorSymbol> newConnectors = enclosingComponent.getConnectors().stream()
.map(c ->{
if (incomingPorts.contains(c.getComponentInstance().get().getFullName() + "." + c.getTarget().substring(0,1).toLowerCase()
+ c.getTarget().substring(1))){
c.setSource(c.getSource());
c.setTarget(c.getTarget().replaceFirst("[^.]*.",e.getName() + "." + newName + "_"));
} else if (outgoingPorts.contains(c.getComponentInstance().get().getFullName() + "." + c.getSource().substring(0,1).toLowerCase()
+ c.getSource().substring(1))){
c.setSource(c.getSource().replaceFirst("[^.]*.",e.getName() + "." + newName + "_"));
c.setTarget(c.getTarget());
}
return c;
})
.collect(Collectors.toSet());
return constructECIS(enclosingComponent, subcomponents, newConnectors, enclosingComponent.getName(),
new ArrayList<>(enclosingComponent.getPortsList()));
}
private static ExpandedComponentInstanceSymbol constructECIS(ExpandedComponentInstanceSymbol enclosingComponent,
List<ExpandedComponentInstanceSymbol> newSubcomponents,
Set<ConnectorSymbol> newConnectors, String name, List<PortSymbol> ports) {
Set<ResolvingFilter<? extends Symbol>> resolvingFilters = enclosingComponent.getSpannedScope().getResolvingFilters();
newSubcomponents.forEach(sc -> ((CommonScope) sc.getSpannedScope()).setResolvingFilters(resolvingFilters));
ExpandedComponentInstanceSymbol res = new ExpandedComponentInstanceBuilder()
.setName(name)
.setSymbolReference(enclosingComponent.getComponentType())
.addPorts(ports)
.addConnectors(newConnectors)
.addSubComponents(newSubcomponents)
.addResolutionDeclarationSymbols(enclosingComponent.getResolutionDeclarationSymbols())
.build();
((CommonScope) res.getSpannedScope()).setResolvingFilters(resolvingFilters);
res.setEnclosingScope((MutableScope) enclosingComponent.getEnclosingScope());
return res;
}
}
package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAConnectorBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.symboltable.CommonScope;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.Symbol;
......@@ -19,17 +26,17 @@ public class ClusterFromTagsHelper {
private ClusterFromTagsHelper() {
}
public static List<Set<ExpandedComponentInstanceSymbol>> getClusters(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
Graph<ExpandedComponentInstanceSymbol, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
public static List<Set<EMAComponentInstanceSymbol>> getClusters(EMAComponentInstanceSymbol componentInstanceSymbol) {
Graph<EMAComponentInstanceSymbol, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
componentInstanceSymbol.getSubComponents().forEach(graph::addVertex);
graph.addVertex(componentInstanceSymbol);
componentInstanceSymbol.getConnectors().stream()
componentInstanceSymbol.getConnectorInstances().stream()
.filter(c -> !(c.getSourcePort().getMiddlewareSymbol().isPresent() && c.getTargetPort().getMiddlewareSymbol().isPresent()))
.forEach(c -> {
ExpandedComponentInstanceSymbol compSource = c.getSourcePort().getComponentInstance().orElse(null);
ExpandedComponentInstanceSymbol compTarget = c.getTargetPort().getComponentInstance().orElse(null);
EMAComponentInstanceSymbol compSource = c.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol compTarget = c.getTargetPort().getComponentInstance();
if (compSource == null || compTarget == null) {
Log.error("ComponentInstance of source or target not found!");
}
......@@ -38,7 +45,7 @@ public class ClusterFromTagsHelper {
}
});
ConnectivityInspector<ExpandedComponentInstanceSymbol, DefaultEdge> connectivityInspector = new ConnectivityInspector<>(graph);
ConnectivityInspector<EMAComponentInstanceSymbol, DefaultEdge> connectivityInspector = new ConnectivityInspector<>(graph);