Skip to content

Commit 8603804

Browse files
author
Max Stachon
committed
fix resolving issue across packages in CDMerge and add missing import statements to test models (might require more comprehensive refactoring later on)
1 parent ab5f916 commit 8603804

File tree

14 files changed

+126
-24
lines changed

14 files changed

+126
-24
lines changed

cdmerge/src/main/java/de/monticore/cdmerge/MergeTool.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.google.common.base.Preconditions;
55
import com.google.common.collect.ImmutableList;
6+
import de.monticore.cd4code.CD4CodeMill;
67
import de.monticore.cd4code._cocos.CD4CodeCoCoChecker;
78
import de.monticore.cd4code._parser.CD4CodeParser;
89
import de.monticore.cdbasis._ast.ASTCDCompilationUnit;
@@ -367,6 +368,8 @@ public MergeStepResult mergeCDs(ASTCDCompilationUnit cd1, ASTCDCompilationUnit c
367368

368369
// Perfom the Merge of the CD Definitions
369370
cdMerger.mergeCDs(cd1.getCDDefinition(), cd2.getCDDefinition(), matchResult);
371+
CD4CodeMill.globalScope().removeSubScope(cd1.getEnclosingScope());
372+
CD4CodeMill.globalScope().removeSubScope(cd2.getEnclosingScope());
370373

371374
mergeBlackBoard.addLog(ErrorLevel.INFO, "Merging completed.", MergePhase.CD_MERGING, cd1, cd2);
372375

@@ -493,6 +496,7 @@ private void checkCoCos(ASTCDCompilationUnit cd) {
493496

494497
// check for errors and register them in our log
495498
try {
499+
CDMergeUtils.refreshSymbolTable(cd);
496500
checker.checkAll(cd);
497501
}
498502
catch (Throwable e) {

cdmerge/src/main/java/de/monticore/cdmerge/util/ASTCDHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import de.monticore.cdinterfaceandenum._ast.ASTCDInterface;
88
import de.monticore.cdmerge.exceptions.ConfigurationException;
99
import de.monticore.types.mcbasictypes._ast.ASTMCObjectType;
10+
import org.apache.commons.lang3.StringUtils;
11+
1012
import java.util.*;
1113
import java.util.stream.Collectors;
1214

@@ -241,6 +243,12 @@ public Optional<ASTCDClass> getClass(final String className) {
241243
if (this.classes.containsKey(className)) {
242244
return Optional.of(this.classes.get(className));
243245
}
246+
else {
247+
String simpleName = StringUtils.substringAfterLast(className, ".");
248+
if (this.classes.containsKey(simpleName)) {
249+
return Optional.of(this.classes.get(simpleName));
250+
}
251+
}
244252
return Optional.empty();
245253
}
246254

cdmerge/src/test/java/de/monticore/cdmerge/BaseTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.nio.file.Path;
1818
import java.util.Optional;
1919

20+
import de.se_rwth.commons.logging.Log;
21+
import de.se_rwth.commons.logging.LogStub;
2022
import org.junit.jupiter.api.AfterEach;
2123
import org.junit.jupiter.api.BeforeAll;
2224
import org.junit.jupiter.api.BeforeEach;
@@ -48,6 +50,7 @@ public static void init() {
4850

4951
@BeforeEach
5052
public void initBefore() {
53+
LogStub.init();
5154
CD4CodeMill.reset();
5255
CD4CodeMill.init();
5356
parser = CD4CodeMill.parser();
@@ -97,7 +100,7 @@ protected void processResult(MergeStepResult result) {
97100
}
98101
}
99102
if (PRINTOUT_TRACE | getSystemProperty("test.printout.trace").equals("1")) {
100-
result.getMergeLog().getAllLogs(false).forEach(log -> System.out.println(log
103+
result.getMergeLog().getAllLogs(false).forEach(log -> Log.println(log
101104
.toStringWithTimeStamp()));
102105
}
103106
}
@@ -111,9 +114,9 @@ protected void processResult(MergeResult result) {
111114
int i = 1;
112115
if (result.getIntermediateResults().size() > 1) {
113116
for (MergeStepResult step : result.getIntermediateResults()) {
114-
System.out.println(">>>> STEP " + i + " >>>>");
117+
Log.println(">>>> STEP " + i + " >>>>");
115118
processResult(step);
116-
System.out.println();
119+
Log.println("");
117120
}
118121
}
119122
else if (result.getIntermediateResults().size() == 1) {

cdmerge/src/test/java/de/monticore/cdmerge/CDMergeTest.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.List;
1313
import java.util.Set;
1414
import java.util.stream.Collectors;
15+
16+
import de.se_rwth.commons.logging.Log;
1517
import org.junit.jupiter.api.Test;
1618

1719
public class CDMergeTest extends BaseTest {
@@ -33,7 +35,7 @@ public void testMerge() {
3335
ASTCDCompilationUnit mergedCD = CDMerge.merge(inputSet, "ABC", new LinkedHashSet<>());
3436

3537
assertNotNull(mergedCD);
36-
System.out.println(CD4CodeMill.prettyPrint(mergedCD, true));
38+
Log.print(CD4CodeMill.prettyPrint(mergedCD, true));
3739
}
3840

3941
@Test
@@ -56,7 +58,30 @@ public void testMotivatingExample() {
5658
ASTCDCompilationUnit mergedCD = CDMerge.merge(inputSet, "UniversitySystem", params);
5759

5860
assertNotNull(mergedCD);
59-
System.out.println(CD4CodeMill.prettyPrint(mergedCD, true));
61+
Log.print(CD4CodeMill.prettyPrint(mergedCD, true));
62+
}
63+
64+
@Test
65+
public void testMotivatingExampleWithPackages() {
66+
final String srcDir = "src/test/resources/class_diagrams/CDMergeTest/";
67+
List<ASTCDCompilationUnit> inputSet = new ArrayList<>();
68+
try {
69+
inputSet.add(loadModel(srcDir + "PackagedTeaching.cd"));
70+
inputSet.add(loadModel(srcDir + "PackagedManagement.cd"));
71+
}
72+
catch (IOException e) {
73+
fail("IO exception while accessing input models: " + e.getMessage());
74+
}
75+
76+
LinkedHashSet<MergeParameter> params = new LinkedHashSet<>();
77+
78+
params.add(MergeParameter.LOG_VERBOSE);
79+
params.add(MergeParameter.LOG_TO_CONSOLE);
80+
81+
ASTCDCompilationUnit mergedCD = CDMerge.merge(inputSet, "UniversitySystem", params);
82+
83+
assertNotNull(mergedCD);
84+
Log.print(CD4CodeMill.prettyPrint(mergedCD, true));
6085
}
6186

6287
@Test
@@ -81,7 +106,7 @@ public void testUMLPExample() {
81106
ASTCDCompilationUnit mergedCD = CDMerge.merge(inputSet, "MergeDriveAndEmployment", params);
82107

83108
assertNotNull(mergedCD);
84-
System.out.println(CD4CodeMill.prettyPrint(mergedCD, true));
109+
Log.print(CD4CodeMill.prettyPrint(mergedCD, true));
85110
assertTrue(mergedCD.deepEquals(expected, false));
86111
}
87112

@@ -104,8 +129,8 @@ public void testCarRental_correct() {
104129
for (List<ASTCDCompilationUnit> permutation : computeAllPermutations(inputSet)) {
105130
LinkedHashSet<MergeParameter> params = new LinkedHashSet<>();
106131

107-
System.out.println("Merging " + permutation.stream().map(cd -> cd.getCDDefinition().getName())
108-
.collect(Collectors.toList()));
132+
Log.print("Merging " + permutation.stream().map(cd -> cd.getCDDefinition().getName()).collect(
133+
Collectors.toList()));
109134

110135
params.add(MergeParameter.LOG_VERBOSE);
111136
params.add(MergeParameter.LOG_TO_CONSOLE);

cdmerge/src/test/resources/class_diagrams/Attribute/conflictDifferentTypes/B.cd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/* (c) https://github.com/MontiCore/monticore */
2+
23
package conflictDifferentTypes;
4+
5+
import java.util.Date;
6+
37
classdiagram B {
48
class Person {
59
Date birthday;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* (c) https://github.com/MontiCore/monticore */
2+
3+
classdiagram PackagedManagement {
4+
package work {
5+
abstract class Employee {
6+
String name;
7+
}
8+
}
9+
10+
package uni {
11+
class Professor extends work.Employee{
12+
int salary;
13+
}
14+
class Lecture{
15+
int courseID;
16+
}
17+
association Professor (lecturer) -> (holds) Lecture [1..*];
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* (c) https://github.com/MontiCore/monticore */
2+
3+
classdiagram PackagedTeaching {
4+
package uni {
5+
class Professor{
6+
String name;
7+
String mail;
8+
}
9+
class Lecture {
10+
int credits;
11+
}
12+
class Student {
13+
long matrNr;
14+
}
15+
association [1] Professor (lecturer) <-> (holds) Lecture;
16+
}
17+
association attendance [*] uni.Lecture <- uni.Student;
18+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/* (c) https://github.com/MontiCore/monticore */
22
package inheritanceAttributePullup1;
3+
4+
import java.util.Date;
5+
36
classdiagram A {
47

58
class Person {
69
String nickname;
710
int age;
811
}
9-
12+
1013
class Customer extends Person {
1114
int id;
1215
Date birthday;
13-
}
16+
}
1417
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
/* (c) https://github.com/MontiCore/monticore */
22
package inheritanceAttributePullup1;
3+
4+
import java.util.Date;
5+
36
classdiagram mergedCD {
47

58

69
class Person {
710
String nickname;
811
int age;
9-
int id;
12+
int id;
1013
}
11-
14+
1215
class Customer extends Person {
1316
Date birthday;
14-
}
15-
17+
}
18+
1619
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/* (c) https://github.com/MontiCore/monticore */
22
package inheritanceAttributePullup2;
3+
4+
import java.util.Date;
5+
36
classdiagram A {
47

58
class Person {
69
Date birthday;
710
}
8-
11+
912
class Customer extends Person {
1013
String name;
1114
int persNumber;
12-
}
15+
}
1316
}

0 commit comments

Comments
 (0)