Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:MontiCore/object-diagram into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpe committed Jan 3, 2025
2 parents 33ab92c + 8d2eb5c commit c814c19
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 37 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# (c) https://github.com/MontiCore/monticore
name: Gradle


concurrency: # run this test workflow only once per "branch"
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push: # run this test pipeline on every push
pull_request: # and pull request
repository_dispatch: # and on request of upstream projects
types: [ trigger_after_upstream_deploy ]


env:
GRADLE_VERSION: 7.4 # Gradle version used
GRADLE_CLI_OPTS: "-Pci -PgenTR=false --max-workers=4 -PgenTagging=true --build-cache " # CLI options passed to Gradle

permissions:
contents: read # This action may run somewhat unsafe code


jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout project sources
uses: actions/checkout@v3
- name: Gradle build
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{env.GRADLE_VERSION}}
arguments: build ${{env.GRADLE_CLI_OPTS}}

deploy:
permissions:
packages: write
runs-on: ubuntu-20.04
needs: build
if: github.ref == 'refs/heads/dev'
steps:
- name: Checkout project sources
uses: actions/checkout@v3
- name: Gradle publish
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{env.GRADLE_VERSION}}
arguments: publish ${{env.GRADLE_CLI_OPTS}} -PmavenPassword=${{ secrets.SE_NEXUS_PASSWORD }} -PmavenUser=${{ secrets.SE_NEXUS_USER }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion gentest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sourceSets {
task genExample(type: JavaExec) {
classpath += parent.tasks.shadowJar.outputs.files
mainClass = 'de.monticore.od4development.OD4DevelopmentTool'
args '-i','src/main/resources/Example.od', '-s' , 'src/main/resources/symboltable/', '-o', 'target/generated-sources/'
args '-i','src/main/resources/Example.od', '-path' , 'src/main/resources/symboltable/', '-o', 'target/generated-sources/'
dependsOn parent.tasks.shadowJar
}

Expand Down
7 changes: 5 additions & 2 deletions gentest/src/test/java/GeneratedClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import example.B;
import examples.ExamplesInstantiator;
import java.util.List;

import examples.ExamplesODInstances;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -21,7 +23,8 @@ public void setup() {

@Test
public void test() {
List<Object> list = new ExamplesInstantiator().instantiate();
assertEquals(5, list.size());
ExamplesODInstances objs = new ExamplesInstantiator().instantiate();
assertEquals(5, objs.getFoo().getX());
assertEquals("hello", objs.getFoo().getS());
}
}
8 changes: 4 additions & 4 deletions src/main/java/de/monticore/od2cd/CompositionPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public String create(ASTMCType type) {

IOD4DevelopmentGlobalScope gs = OD4DevelopmentMill.globalScope();

if (gs.getSubScopes().size() == 1) {
if (gs.getSubScopes().size() >= 1) {
IOD4DevelopmentArtifactScope as = (IOD4DevelopmentArtifactScope) gs.getSubScopes().get(0);

if (as.getTypeSymbols().containsKey(type.printType()) ||
Expand All @@ -39,7 +39,7 @@ public String read() {
public String write(String type) {
IOD4DevelopmentGlobalScope gs = OD4DevelopmentMill.globalScope();

if (gs.getSubScopes().size() == 1) {
if (gs.getSubScopes().size() >= 1) {
return ".build().get()";
}
return ".build()";
Expand All @@ -48,7 +48,7 @@ public String write(String type) {
public String update(String attribute, String value) {
IOD4DevelopmentGlobalScope gs = OD4DevelopmentMill.globalScope();

if (gs.getSubScopes().size() == 1) {
if (gs.getSubScopes().size() >= 1) {
String asName = gs.getSubScopes().get(0).getName();

String res = "";
Expand All @@ -69,7 +69,7 @@ public String update(String attribute, String value) {
public String genType(ASTMCType type) {
IOD4DevelopmentGlobalScope gs = OD4DevelopmentMill.globalScope();
String genType = OD4DevelopmentMill.prettyPrint(type, false);
if (gs.getSubScopes().size() == 1) {
if (gs.getSubScopes().size() >= 1) {
return genType + "Builder";
} else {
return genType;
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/de/monticore/od2cd/OD2CDObjectVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class OD2CDObjectVisitor implements ODBasisVisitor2 {
protected ASTCDPackage cdPackage;

protected ASTCDClass instantiatorClass;
protected ASTCDClass instancesClass;

protected ASTCDClass checkerClass;

Expand Down Expand Up @@ -83,17 +84,25 @@ public void visit(ASTODArtifact odArtifact) {
.setModifier(CDBasisMill.modifierBuilder().PUBLIC().build())
.build();

this.instancesClass = CDBasisMill.cDClassBuilder()
.setName(odArtifact.getObjectDiagram().getName() + "ODInstances")
.setModifier(CDBasisMill.modifierBuilder().PUBLIC().build())
.build();

this.checkerClass = CDBasisMill.cDClassBuilder()
.setName(odArtifact.getObjectDiagram().getName() + "Checker")
.setModifier(CDBasisMill.modifierBuilder().PUBLIC().build())
.build();

cd4C.addImport(instantiatorClass, imp.getQName() + ".*");
cd4C.addImport(instantiatorClass, "java.time.*");
cd4C.addImport(instancesClass, imp.getQName() + ".*");
cd4C.addImport(instancesClass, "java.time.*");
cd4C.addImport(checkerClass, imp.getQName() + ".*");


this.cdPackage.addCDElement(instantiatorClass);
this.cdPackage.addCDElement(instancesClass);
// this.cdPackage.addCDElement(checkerClass);
}

Expand All @@ -113,7 +122,8 @@ public void endVisit(ASTODArtifact odArtifact) {
.map(e -> ((ASTODNamedObject) e).getName())
.collect(Collectors.toList()),
this.linkAttributeList,
this.objectNameList);
this.objectNameList,
odArtifact.getObjectDiagram().getName());
}

public void createInstantiator(ASTODNamedObject odElement) {
Expand All @@ -132,6 +142,10 @@ public void createInstantiator(ASTODNamedObject odElement) {

this.objectNameList.add(odElement.getName());
}

public void createInstanceAccess(ASTODNamedObject odElement) {
this.cd4C.addAttribute(this.instancesClass, true, true, cp.genType(odElement.getMCObjectType()) + " " + odElement.getName());
}

public void createChecker(ASTODNamedObject odElement) {
this.cd4C.addMethod(checkerClass, "od2cd.Check",
Expand Down Expand Up @@ -224,6 +238,7 @@ else if (cdRoleOfLeft.isPresent() && !cdRoleOfRight.isPresent()) {
public void visit(ASTODElement odElement) {
if(odElement instanceof ASTODNamedObject) {
createInstantiator((ASTODNamedObject) odElement);
createInstanceAccess((ASTODNamedObject) odElement);
createChecker((ASTODNamedObject) odElement);
}
if(odElement instanceof ASTODLink) {
Expand Down Expand Up @@ -286,7 +301,7 @@ protected String constructLink(String src, String tgt, String roleName, Optional
cardModifier = cardModifier(cdRole.get());
}

if (OD4DevelopmentMill.globalScope().getSubScopes().size() == 1) {
if (OD4DevelopmentMill.globalScope().getSubScopes().size() >= 1) {
return src + "." + ((roleName.isEmpty())
? findObjectAccessorName4Role(tgt) + cardModifier
: roleName + cardModifier) + "(" + tgt + ")";
Expand All @@ -300,7 +315,7 @@ protected String constructLink(String src, String tgt, String roleName, Optional

protected String cardModifier(CDRoleAdapter cdRole) {
String cardModifier = "";
if (OD4DevelopmentMill.globalScope().getSubScopes().size() == 1) {
if (OD4DevelopmentMill.globalScope().getSubScopes().size() >= 1) {
switch (cdRole.getCardinality()) {
case ONE:
cardModifier = "";
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/de/monticore/od4development/OD4DevelopmentTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
import de.monticore.od4development._cocos.OD4DevelopmentCoCoChecker;
import de.monticore.od4development._cocos.OD4DevelopmentCoCos;
import de.monticore.od4development._symboltable.CDRoleSymbolDeSer;
import de.monticore.od4development._symboltable.IOD4DevelopmentArtifactScope;
import de.monticore.odbasis._ast.ASTODArtifact;
import de.monticore.odbasis._prettyprint.ODBasisFullPrettyPrinter;
import de.monticore.prettyprint.IndentPrinter;
import de.monticore.symbols.basicsymbols.BasicSymbolsMill;
import de.monticore.types.mcbasictypes._ast.ASTMCImportStatement;
import de.se_rwth.commons.Names;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -65,9 +69,9 @@ public void run(String[] args) {
// parse input file, which is now available
// (only returns if successful)
ASTODArtifact ast = parse(cmd.getOptionValue("i"));

if(cmd.hasOption("s")) {
MCPath mcPath = new MCPath(cmd.getOptionValue("s"));
if(cmd.hasOption("path")) {
MCPath mcPath = new MCPath(cmd.getOptionValue("path"));
OD4DevelopmentMill.globalScope().setSymbolPath(mcPath);
OD4DevelopmentMill.globalScope().putTypeSymbolDeSer("de.monticore.cdbasis._symboltable.CDTypeSymbol");
OD4DevelopmentMill.globalScope().putSymbolDeSer("de.monticore.cdassociation._symboltable.CDRoleSymbol", new CDRoleSymbolDeSer());
Expand All @@ -76,8 +80,12 @@ public void run(String[] args) {
for (ASTMCImportStatement i : ast.getMCImportStatementList()) {
OD4DevelopmentMill.globalScope().loadDiagram(i.getQName());
}
} else {
createSymbolTable(ast);
}

IOD4DevelopmentArtifactScope as = createSymbolTable(ast);

if (cmd.hasOption("s")) {
storeSymTab(as, cmd.getOptionValue("s"));
}

if (cmd.hasOption("c")) {
Expand Down Expand Up @@ -145,4 +153,21 @@ public Options addAdditionalOptions(Options options) {
options.addOption(new Option("o","output",true,"Sets the output path"));
return options;
}

/**
* prints the symboltable of the given scope out to a file
*
* @param as symboltable to store
* @param path location of the file or directory containing the printed table
*/
public void storeSymTab(IOD4DevelopmentArtifactScope as, String path) {
if (Path.of(path).toFile().isFile()) {
this.storeSymbols(as, path);
}
else {
this.storeSymbols(
as,
Paths.get(path, Names.getPathFromPackage(as.getFullName()) + ".odsym").toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package de.monticore.od4development._symboltable;

import de.monticore.odbasis._ast.ASTODArtifact;
import de.monticore.symboltable.ImportStatement;
import de.se_rwth.commons.logging.Log;

import java.util.ArrayList;
Expand All @@ -11,14 +12,21 @@ public class OD4DevelopmentScopesGenitor extends OD4DevelopmentScopesGenitorTOP
public IOD4DevelopmentArtifactScope createFromAST (ASTODArtifact rootNode) {
Log.errorIfNull(rootNode, "0xA7004x78995 Error by creating of the OD4DevelopmentScopesGenitor symbol table: top ast node is null");
IOD4DevelopmentArtifactScope artifactScope = de.monticore.od4development.OD4DevelopmentMill.artifactScope();

// set package
if (rootNode.isPresentMCPackageDeclaration()) {
artifactScope.setPackageName(
rootNode.getMCPackageDeclaration().getMCQualifiedName().getQName());
}
else {
} else {
artifactScope.setPackageName("");
}

// add imports
artifactScope.setImportsList(new ArrayList<>());
rootNode
.getMCImportStatementList()
.forEach(i -> artifactScope.addImports(new ImportStatement(i.getQName(), i.isStar())));

artifactScope.setName(rootNode.getObjectDiagram().getName());
artifactScope.setAstNode(rootNode);
putOnStack(artifactScope);
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/od2cd/InstList.ftl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<#-- (c) https://github.com/MontiCore/monticore -->
${tc.signature("types", "names", "links", "objects")}
${cd4c.method("public List<Object> instantiate()")}
${tc.signature("types", "names", "links", "objects", "odname")}
${cd4c.method("public " + odname + "ODInstances instantiate()")}

${odname}ODInstances _inst = new ${odname}ODInstances();
<#list objects as object>
${types[object?index]} ${names[object?index]} = instantiate${object?capFirst}();
</#list>
Expand All @@ -10,6 +11,7 @@ ${cd4c.method("public List<Object> instantiate()")}
</#list>
List<Object> objects = new ArrayList<>();
<#list objects as object>
objects.add(${object}${cp.write(types[object?index])});
//# objects.add(...)
_inst.set${object?capFirst}((${types[object?index]})${object}${cp.write(types[object?index])});
</#list>
return objects;
return _inst;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;

import java.io.File;

import static org.junit.Assert.assertTrue;

public class OD4DevelopmentToolTest {
Expand All @@ -21,8 +23,15 @@ public void before() {
@Test
public void testAddSymtabFile() {
assertTrue(OD4DevelopmentMill.globalScope().getSymbolPath().isEmpty());
OD4DevelopmentToolTOP.main(new String[] {"-i","src/test/resources/examples/od2cd/Example.od", "-s", "resources/symboltable/tooltest/"});
assertTrue(OD4DevelopmentMill.globalScope().getSymbolPath().toString().endsWith("resources/symboltable/tooltest]"));
OD4DevelopmentToolTOP.main(new String[] {"-i","src/test/resources/examples/od2cd/Example.od", "-path", "src/test/resources/symboltable/tooltest/"});
assertTrue(OD4DevelopmentMill.globalScope().getSymbolPath().toString().endsWith("resources/symboltable/tooltest/]"));
}

@Test
public void testStoreSymtabFile() {
OD4DevelopmentToolTOP.main(new String[] {"-i","src/test/resources/examples/od2cd/Example.od", "-path", "src/test/resources/symboltable/tooltest/", "-s", "target/generated-test-sources/tooltest/symboltable/"});
File symTab = new File("target/generated-test-sources/tooltest/symboltable/examples/od2cd/Examples.odsym");
assertTrue(symTab.exists() && symTab.isFile());
}

}
14 changes: 0 additions & 14 deletions src/test/resources/symboltable/tooltest/A.cdsym

This file was deleted.

15 changes: 15 additions & 0 deletions src/test/resources/symboltable/tooltest/examples/A.cdsym
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"generated-using": "www.MontiCore.de technology",
"package": "examples",
"name": "A",
"symbols": [
{
"kind": "de.monticore.symbols.basicsymbols._symboltable.TypeSymbol",
"name": "A"
},
{
"kind": "de.monticore.symbols.basicsymbols._symboltable.TypeSymbol",
"name": "B"
}
]
}

0 comments on commit c814c19

Please sign in to comment.