Commit 06d50728 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Refactoring: Renaming and splitting classes into packages

parent 6de1c1b9
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.master;
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.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
......@@ -11,17 +12,17 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class CMakeMasterGenerator extends MasterGenerator {
public class CMakeGenerator extends StarBridgeGenerator {
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
long notInSubfolders = getGeneratorImpls().stream()
.map(this::getImplSubfolder)
long notInSubdirs = getGeneratorImpls().stream()
.map(this::getImplSubdir)
.filter(Objects::isNull)
.count();
if (notInSubfolders > 0) {
Log.error("All generators must have subfolders!");
if (notInSubdirs > 0) {
Log.error("All generators must have subdirs!");
return new ArrayList<>();
}
......@@ -40,8 +41,8 @@ public class CMakeMasterGenerator extends MasterGenerator {
content.append("set (CMAKE_CXX_STANDARD 11)\n");
getGeneratorImpls().stream()
.map(this::getImplSubfolder)
.forEach(subfolder -> content.append("add_subdirectory(" + subfolder + ")\n"));
.map(this::getImplSubdir)
.forEach(subdir -> content.append("add_subdirectory(" + subdir + ")\n"));
fileContent.setFileContent(content.toString());
......
......@@ -5,6 +5,8 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Expanded
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.roscpp.helper.TagHelper;
import de.monticore.lang.monticar.generator.rosmsg.RosMsg;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......@@ -14,7 +16,7 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
public class DistributedTargetGenerator extends CMakeMasterGenerator {
public class DistributedTargetGenerator extends CMakeGenerator {
private RosMsgImpl rosMsgImpl;
public DistributedTargetGenerator(String generationTargetPath) {
......@@ -48,7 +50,7 @@ public class DistributedTargetGenerator extends CMakeMasterGenerator {
List<File> files = new ArrayList<>();
CMakeMasterGenerator cmakeListsGenerator = new CMakeMasterGenerator();
CMakeGenerator cmakeListsGenerator = new CMakeGenerator();
cmakeListsGenerator.setGenerationTargetPath(generationTargetPath);
for (ExpandedComponentInstanceSymbol comp : generatorMap.keySet()) {
files.addAll(generatorMap.get(comp).generate(comp, taggingResolver));
......@@ -62,10 +64,10 @@ public class DistributedTargetGenerator extends CMakeMasterGenerator {
}
private GeneratorImpl createFullGenerator(String subdir) {
MiddlewareMasterGenerator res = new MiddlewareMasterGenerator();
MiddlewareGenerator res = new MiddlewareGenerator();
res.setGenerationTargetPath(generationTargetPath + (subdir.endsWith("/") ? subdir : subdir + "/"));
this.getGeneratorImpls().forEach(gen -> res.add(gen, this.getImplSubfolder(gen)));
this.getGeneratorImpls().forEach(gen -> res.add(gen, this.getImplSubdir(gen)));
return res;
}
......
......@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.master;
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.roscpp.helper.NameHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......@@ -10,7 +13,7 @@ import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
public class MiddlewareMasterGenerator extends CMakeMasterGenerator {
public class MiddlewareGenerator extends CMakeGenerator {
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
......
package de.monticore.lang.monticar.generator.master;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.master.impls.GeneratorImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
......@@ -8,19 +9,19 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
public class MasterGenerator implements GeneratorImpl {
public class StarBridgeGenerator implements GeneratorImpl {
private Map<GeneratorImpl, String> generatorImpls = new HashMap<>();
String generationTargetPath;
public void add(GeneratorImpl generator, String subfolder) {
generatorImpls.put(generator, subfolder);
public void add(GeneratorImpl generator, String subdir) {
generatorImpls.put(generator, subdir);
}
public Set<GeneratorImpl> getGeneratorImpls() {
return generatorImpls.keySet();
}
public String getImplSubfolder(GeneratorImpl generator) {
public String getImplSubdir(GeneratorImpl generator) {
return generatorImpls.get(generator);
}
......@@ -35,19 +36,18 @@ public class MasterGenerator implements GeneratorImpl {
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> result = new ArrayList<>();
generatorImpls.entrySet()
.forEach(entrySet -> {
generatorImpls.forEach((key, value) -> {
String fullTargetPath = generationTargetPath;
if (entrySet.getValue() != null)
fullTargetPath = fullTargetPath + entrySet.getValue();
if (value != null)
fullTargetPath = fullTargetPath + value;
if (!fullTargetPath.endsWith("/"))
fullTargetPath = fullTargetPath + "/";
entrySet.getKey().setGenerationTargetPath(fullTargetPath);
key.setGenerationTargetPath(fullTargetPath);
try {
result.addAll(entrySet.getKey().generate(componentInstanceSymbol, taggingResolver));
result.addAll(key.generate(componentInstanceSymbol, taggingResolver));
} catch (IOException e) {
Log.error("IOException occurred!", e);
}
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.helpers;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EMAPortBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceBuilder;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.helpers;
import de.monticore.lang.monticar.generator.FileContent;
import de.se_rwth.commons.logging.Log;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.helpers;
public class TemplateHelper {
static String coordinatorTemplate =
public static String coordinatorTemplate =
"#include <iostream>\n" +
"#include <thread>\n" +
"#include <chrono>\n" +
......@@ -59,7 +60,8 @@ public class TemplateHelper {
"\n" +
" return 0;\n" +
"}";
static String iAdapterTemplate = "#pragma once\n" +
public static String iAdapterTemplate = "#pragma once\n" +
"#include \"${compName}.h\"\n" +
"\n" +
"class IAdapter{\n" +
......@@ -68,7 +70,8 @@ public class TemplateHelper {
"\t\tvirtual void init(${compName}* comp) = 0;\n" +
"\t\tvirtual void tick() = 0;\n" +
"};";
static String cmakeListsTemplate =
public static String cmakeListsTemplate =
"cmake_minimum_required(VERSION 3.5)\n" +
"project (Coordinator_${compName} CXX)\n" +
"\n" +
......@@ -80,4 +83,51 @@ public class TemplateHelper {
"target_include_directories(Coordinator_${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" +
"\n" +
"export(TARGETS Coordinator_${compName} FILE Coordinator_${compName}.cmake)";
public static String cmakeCppTemplate =
"cmake_minimum_required(VERSION 3.5)\n" +
"project(${compName} LANGUAGES CXX)\n" +
"add_library(${compName} ${compName}.h)\n" +
"target_include_directories(${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" +
"set_target_properties(${compName} PROPERTIES LINKER_LANGUAGE CXX)\n" +
"export(TARGETS ${compName} FILE ${compName}.cmake)";
public static String dummyAdapterTemplate = "#pragma once\n" +
"#include \"${compName}.h\"\n" +
"#include <thread>\n" +
"#include <chrono>\n" +
"#include \"IAdapter.h\"\n" +
"\n" +
"class DummyAdapter_${compName}: public IAdapter{\n" +
"\t${compName}* component;\n" +
"\n" +
"public:\n" +
"\tDummyAdapter_${compName}(){\n" +
"\n" +
"\t}\n" +
"\n" +
"\tvoid tick(){\n" +
"\t\tcout << \"Dummy publish data: component.out1 = \"<< component->out1 << endl;\n" +
"\t}\n" +
"\t\n" +
"\tvoid init(${compName}* comp){\n" +
"\t\tthis->component = comp;\n" +
"\t\twhile(1){\n" +
" \t\t std::this_thread::sleep_for(std::chrono::seconds(1));\n" +
"\t\t component->in2 += 1000;\n" +
"\t\t}\n" +
"\t}\n" +
"\n" +
"\t\n" +
"};";
public static String dummyCmakeTemplate =
"cmake_minimum_required(VERSION 3.5)\n" +
"project (DummyAdapter_${compName})\n" +
"\n" +
"add_library(DummyAdapter_${compName} DummyAdapter_${compName}.h)\n" +
"set_target_properties(DummyAdapter_${compName} PROPERTIES LINKER_LANGUAGE CXX)\n" +
"target_link_libraries(DummyAdapter_${compName} ${compName})\n" +
"target_include_directories(DummyAdapter_${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" +
"export(TARGETS DummyAdapter_${compName} FILE DummyAdapter_${compName}.cmake)";
}
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.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.roscpp.helper.NameHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......@@ -11,17 +12,11 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CPPImpl implements GeneratorImpl {
//TODO: make GeneratorCpp implement GeneratorImpl directly!
public class CPPGenImpl implements GeneratorImpl {
private String generationTargetPath;
private String cmakeTemplate =
"cmake_minimum_required(VERSION 3.5)\n" +
"project(${compName} LANGUAGES CXX)\n" +
"add_library(${compName} ${compName}.h)\n" +
"target_include_directories(${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" +
"set_target_properties(${compName} PROPERTIES LINKER_LANGUAGE CXX)\n" +
"export(TARGETS ${compName} FILE ${compName}.cmake)";
//TODO: make GeneratorCpp implement GeneratorImpl directly!
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> files = new ArrayList<>();
......@@ -44,7 +39,7 @@ public class CPPImpl implements GeneratorImpl {
FileContent cmake = new FileContent();
cmake.setFileName("CMakeLists.txt");
String name = NameHelper.getComponentNameTargetLanguage(componentInstanceSymbol.getFullName());
cmake.setFileContent(cmakeTemplate.replace("${compName}", name));
cmake.setFileContent(TemplateHelper.cmakeCppTemplate.replace("${compName}", name));
return cmake;
}
}
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.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.roscpp.helper.NameHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......@@ -10,7 +12,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class DummyMiddlewareGenerator implements GeneratorImpl {
public class DummyMiddlewareGenImpl implements GeneratorImpl {
private String generationTargetPath;
......@@ -24,38 +26,9 @@ public class DummyMiddlewareGenerator implements GeneratorImpl {
}
private String dummyAdapterTemplate = "#pragma once\n" +
"#include \"${compName}.h\"\n" +
"#include <thread>\n" +
"#include <chrono>\n" +
"#include \"IAdapter.h\"\n" +
"\n" +
"class DummyAdapter_${compName}: public IAdapter{\n" +
"\t${compName}* component;\n" +
"\n" +
"public:\n" +
"\tDummyAdapter_${compName}(){\n" +
"\n" +
"\t}\n" +
"\n" +
"\tvoid tick(){\n" +
"\t\tcout << \"Dummy publish data: component.out1 = \"<< component->out1 << endl;\n" +
"\t}\n" +
"\t\n" +
"\tvoid init(${compName}* comp){\n" +
"\t\tthis->component = comp;\n" +
"\t\twhile(1){\n" +
" \t\t std::this_thread::sleep_for(std::chrono::seconds(1));\n" +
"\t\t component->in2 += 1000;\n" +
"\t\t}\n" +
"\t}\n" +
"\n" +
"\t\n" +
"};";
private FileContent generateAdapter(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
String name = NameHelper.getComponentNameTargetLanguage(componentInstanceSymbol.getFullName());
String content = dummyAdapterTemplate
String content = TemplateHelper.dummyAdapterTemplate
.replace("${compName}", name);
FileContent res = new FileContent();
......@@ -70,20 +43,10 @@ public class DummyMiddlewareGenerator implements GeneratorImpl {
}
private String cmakeTemplate =
"cmake_minimum_required(VERSION 3.5)\n" +
"project (DummyAdapter_${compName})\n" +
"\n" +
"add_library(DummyAdapter_${compName} DummyAdapter_${compName}.h)\n" +
"set_target_properties(DummyAdapter_${compName} PROPERTIES LINKER_LANGUAGE CXX)\n" +
"target_link_libraries(DummyAdapter_${compName} ${compName})\n" +
"target_include_directories(DummyAdapter_${compName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\n" +
"export(TARGETS DummyAdapter_${compName} FILE DummyAdapter_${compName}.cmake)";
private FileContent generateCMake(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
FileContent res = new FileContent();
String name = NameHelper.getComponentNameTargetLanguage(componentInstanceSymbol.getFullName());
String content = cmakeTemplate
String content = TemplateHelper.dummyCmakeTemplate
.replace("${compName}", name);
res.setFileName("CMakeLists.txt");
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.roscpp.GeneratorRosCpp;
......@@ -8,7 +8,8 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
public class RosCppImpl implements GeneratorImpl {
//TODO: make GeneratorRosCpp implement GeneratorImpl
public class RosCppGenImpl implements GeneratorImpl {
private String generationTargetPath;
@Override
......
package de.monticore.lang.monticar.generator.master;
package de.monticore.lang.monticar.generator.master.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.rosmsg.GeneratorRosMsg;
......@@ -12,6 +12,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
//TODO: make GeneratorRosMsg implement GeneratorImpl
public class RosMsgImpl implements GeneratorImpl {
private GeneratorRosMsg generatorRosMsg;
private List<MCTypeReference<? extends MCTypeSymbol>> rosTypesToGenerate = new ArrayList<>();
......
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.master;
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.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Finding;
......
......@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.master;
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.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Test;
......@@ -21,12 +24,12 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentInstanceSymbol);
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
MasterGenerator masterGenerator = new MasterGenerator();
masterGenerator.setGenerationTargetPath("./target/generated-sources-emam/basicGeneration/src/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
StarBridgeGenerator starBridgeGenerator = new StarBridgeGenerator();
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-emam/basicGeneration/src/");
starBridgeGenerator.add(new CPPGenImpl(), "cpp");
starBridgeGenerator.add(new RosCppGenImpl(), "roscpp");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
starBridgeGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
......@@ -38,12 +41,12 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentInstanceSymbol);
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
MasterGenerator masterGenerator = new CMakeMasterGenerator();
masterGenerator.setGenerationTargetPath("./target/generated-sources-cmake/CMakeGeneration/src/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
StarBridgeGenerator starBridgeGenerator = new CMakeGenerator();
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-cmake/CMakeGeneration/src/");
starBridgeGenerator.add(new CPPGenImpl(), "cpp");
starBridgeGenerator.add(new RosCppGenImpl(), "roscpp");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
starBridgeGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
......@@ -55,13 +58,13 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentInstanceSymbol);
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
MasterGenerator masterGenerator = new MiddlewareMasterGenerator();
masterGenerator.setGenerationTargetPath("./target/generated-sources-cmake/middlewareMasterGenerator/src/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
masterGenerator.add(new DummyMiddlewareGenerator(), "dummy");
StarBridgeGenerator starBridgeGenerator = new MiddlewareGenerator();
starBridgeGenerator.setGenerationTargetPath("./target/generated-sources-cmake/middlewareMasterGenerator/src/");
starBridgeGenerator.add(new CPPGenImpl(), "cpp");
starBridgeGenerator.add(new RosCppGenImpl(), "roscpp");
starBridgeGenerator.add(new DummyMiddlewareGenImpl(), "dummy");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
starBridgeGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
......@@ -74,11 +77,11 @@ public class GenerationTest extends AbstractSymtabTest {
TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
MasterGenerator masterGenerator = new DistributedTargetGenerator("./target/generated-sources-cmake/distributed/src/");
StarBridgeGenerator starBridgeGenerator = new DistributedTargetGenerator("./target/generated-sources-cmake/distributed/src/");
masterGenerator.add(new CPPImpl(), "cpp");
masterGenerator.add(new RosCppImpl(), "roscpp");
starBridgeGenerator.add(new CPPGenImpl(), "cpp");
starBridgeGenerator.add(new RosCppGenImpl(), "roscpp");
masterGenerator.generate(componentInstanceSymbol, taggingResolver);
starBridgeGenerator.generate(componentInstanceSymbol, taggingResolver);
}
}
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