Refactoring: Renaming and splitting classes into packages

parent 06d50728
# MasterGenerator
# EMAM2Middleware
TODO
......@@ -8,7 +8,7 @@
<groupId>de.moticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-master-generator</artifactId>
<artifactId>embedded-montiarc-math-middleware-generator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.master.helpers.FileHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.MiddlewareSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.RosConnectionSymbol;
import de.monticore.lang.monticar.generator.master.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.master.impls.RosMsgImpl;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RosMsgImpl;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.monticar.generator.rosmsg.RosMsg;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.master.helpers.FileHelper;
import de.monticore.lang.monticar.generator.master.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.master.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.roscpp.helper.NameHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.master.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
......
package de.monticore.lang.monticar.generator.master.helpers;
package de.monticore.lang.monticar.generator.middleware.helpers;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EMAPortBuilder;
import com.google.common.collect.Sets;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
......@@ -10,9 +11,8 @@ import org.jgrapht.alg.ConnectivityInspector;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.SimpleGraph;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
public class ClusterHelper {
......@@ -48,36 +48,64 @@ public class ClusterHelper {
public static List<ExpandedComponentInstanceSymbol> getClusterSubcomponents(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
List<Set<ExpandedComponentInstanceSymbol>> clusters = getClusters(componentInstanceSymbol);
List<ExpandedComponentInstanceSymbol> res = new ArrayList<>();
int[] i = {0};
clusters.forEach(c -> {
if (c.size() == 1) {
res.add(ExpandedComponentInstanceBuilder.clone(c.iterator().next()));
} else {
res.add(createECISFromCluster(c));
//TODO: can lead to naming conflicts: subcomp that is named <componentName>Cluster<i[0]>
String clusterName = componentInstanceSymbol.getName() + "Cluster" + i[0];
i[0]++;
res.add(createECISFromCluster(componentInstanceSymbol, c, clusterName));
}
});
return res;
}
private static ExpandedComponentInstanceSymbol createECISFromCluster(Set<ExpandedComponentInstanceSymbol> cluster) {
//TODO: implement
ExpandedComponentInstanceBuilder res = new ExpandedComponentInstanceBuilder();
cluster.forEach(ecis -> {
List<PortSymbol> unconnectedPorts = getUnconnectedPortsFromCluster(cluster);
unconnectedPorts.forEach(p -> {
PortSymbol superPort = EMAPortBuilder.clone(p);
res.addPort(superPort);
});
});
return res.build();
}
private static List<PortSymbol> getUnconnectedPortsFromCluster(Set<ExpandedComponentInstanceSymbol> cluster) {
// Cases: Connector Super,Sub -> Super,Sub
// Super normal -> *: 0x8EFC3
// Super Ros -> * normal: 0x8EFC3
// Super Ros -> Super Ros: remove and warn
// Super Ros -> Sub Ros: handled(let ros connect)
// Sub normal -> * Ros: disallowed, RosTargetRosSender CoCo
// Sub Ros -> Super normal: 0x8EFC3
// Sub Ros -> Super Ros: handled(let ros connect)
// Sub Ros -> Sub Ros: do nothing, wrapper and therefore the mw does not affect this level
// Sub Ros -> Sub normal: handled(let comp connect)
private static ExpandedComponentInstanceSymbol createECISFromCluster(ExpandedComponentInstanceSymbol inst, Set<ExpandedComponentInstanceSymbol> cluster, String clusterName) {
//TODO: implement
return new ArrayList<>();
Set<PortSymbol> curClusterPorts = cluster.stream().flatMap(ecis -> ecis.getPorts().stream()).collect(Collectors.toSet());
Set<PortSymbol> combinedPorts = new HashSet<>();
combinedPorts.addAll(curClusterPorts);
combinedPorts.addAll(inst.getPorts());
Set<ConnectorSymbol> validConnectors = inst.getConnectors().stream()
//remove all connections that use subcomponents not in cluster
.filter(c -> combinedPorts.contains(c.getSourcePort()) && combinedPorts.contains(c.getTargetPort()))
//remove all connections from super -> super and warn
.filter(c -> {
if (inst.containsPort(c.getSourcePort()) && inst.containsPort(c.getTargetPort())) {
Log.warn("Direct connections from super comp to super comp are not supported!");
return false;
}
return true;
})
.collect(Collectors.toSet());
Collection<PortSymbol> validPorts = validConnectors.stream()
.flatMap(c -> Sets.newHashSet(c.getTargetPort(), c.getSourcePort()).stream())
.filter(p -> !inst.containsPort(p))
.collect(Collectors.toSet());
return new ExpandedComponentInstanceBuilder()
.setName(clusterName)
.setSymbolReference(inst.getComponentType())
.addPorts(validPorts)
.addConnectors(validConnectors)
.addSubComponents(cluster.stream().map(ExpandedComponentInstanceBuilder::clone).collect(Collectors.toList()))
.addResolutionDeclarationSymbols(inst.getResolutionDeclarationSymbols())
.build();
}
......
package de.monticore.lang.monticar.generator.master.helpers;
package de.monticore.lang.monticar.generator.middleware.helpers;
import de.monticore.lang.monticar.generator.FileContent;
import de.se_rwth.commons.logging.Log;
......
package de.monticore.lang.monticar.generator.master.helpers;
package de.monticore.lang.monticar.generator.middleware.helpers;
public class TemplateHelper {
......
package de.monticore.lang.monticar.generator.master.impls;
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.monticar.generator.master.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.roscpp.helper.NameHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......
package de.monticore.lang.monticar.generator.master.impls;
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.master.helpers.FileHelper;
import de.monticore.lang.monticar.generator.master.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.TemplateHelper;
import de.monticore.lang.monticar.generator.roscpp.helper.NameHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......
package de.monticore.lang.monticar.generator.master.impls;
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......
package de.monticore.lang.monticar.generator.master.impls;
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.roscpp.GeneratorRosCpp;
......
package de.monticore.lang.monticar.generator.master.impls;
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.rosmsg.GeneratorRosMsg;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
/*
* Copyright (c) 2015 RWTH Aachen. All rights reserved.
*
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.RosToEmamTagSchema;
import de.monticore.lang.monticar.generator.master.helpers.ClusterHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.ClusterHelper;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Finding;
......@@ -60,6 +60,17 @@ public class ClusterTest extends AbstractSymtabTest {
assertTrue(clusters.contains(cluster1));
assertTrue(clusters.contains(cluster2));
// List<ExpandedComponentInstanceSymbol> clusterComps = ClusterHelper.getClusterSubcomponents(componentInstanceSymbol);
// assertTrue(clusterComps.size() == 2);
//
// ExpandedComponentInstanceSymbol clusterComp1 = clusterComps.get(0);
// ExpandedComponentInstanceSymbol clusterComp2 = clusterComps.get(1);
//
// assertTrue(clusterComp1.getPort("rosOut").isPresent());
//TODO: copy ansatz funktioniert nicht gut: ports müssen hinzugefügt werden(nicht jeder port einer inneren comp ist umbedingt mit der äußeren verbunden)
}
@Test
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.RosToEmamTagSchema;
import de.monticore.lang.monticar.generator.master.impls.CPPGenImpl;
import de.monticore.lang.monticar.generator.master.impls.DummyMiddlewareGenImpl;
import de.monticore.lang.monticar.generator.master.impls.RosCppGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.CPPGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.DummyMiddlewareGenImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RosCppGenImpl;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Test;
......@@ -50,7 +50,7 @@ public class GenerationTest extends AbstractSymtabTest {
}
@Test
public void testMiddlewareMasterGenerator() throws IOException {
public void testMiddlewareGenerator() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
RosToEmamTagSchema.registerTagTypes(taggingResolver);
......@@ -59,7 +59,7 @@ public class GenerationTest extends AbstractSymtabTest {
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
StarBridgeGenerator starBridgeGenerator = new MiddlewareGenerator();
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-cmake/middlewareMasterGenerator/src/");
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-cmake/middlewareGenerator/src/");
starBridgeGenerator.add(new CPPGenImpl(), "cpp");
starBridgeGenerator.add(new RosCppGenImpl(), "roscpp");
starBridgeGenerator.add(new DummyMiddlewareGenImpl(), "dummy");
......
Markdown is supported
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