From 7c0556f38d0368cfd717701dfc56290084387c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ronny=20B=C3=B6ttger?= <s6013406@mail.zih.tu-dresden.de> Date: Fri, 15 Jul 2022 14:26:48 +0200 Subject: [PATCH] added Relationship --- .../src/main/jastadd/CreateRoleType.jadd | 4 +- .../src/main/jastadd/Printing.jrag | 19 ++++++++++ .../src/main/jastadd/Rel.jadd | 38 ++++++++++++++++--- .../de/tudresden/inf/st/bank/BankMain.java | 1 + .../src/main/resources/Bank.relast | 6 +-- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/statemachine.solution/src/main/jastadd/CreateRoleType.jadd b/statemachine.solution/src/main/jastadd/CreateRoleType.jadd index 113e399..286055f 100644 --- a/statemachine.solution/src/main/jastadd/CreateRoleType.jadd +++ b/statemachine.solution/src/main/jastadd/CreateRoleType.jadd @@ -6,7 +6,7 @@ aspect CreateRoleType { public Consultant RoleRag.CreateConsultant(String name) { Consultant r = new Consultant(); - r.setName("Consultant"); + r.setName(name); addRoleType(r); //c.setWhole(getCompartmentByName("Bank")); //resolveCompartmentType("Bank").addParts(r); @@ -33,7 +33,7 @@ aspect CreateRoleType { public Customer RoleRag.CreateCustomer(String name) { Customer r = new Customer(); - r.setName("Customer"); + r.setName(name); addRoleType(r); //c.setWhole(getCompartmentByName("Bank")); //resolveCompartmentType("Bank").addParts(r); diff --git a/statemachine.solution/src/main/jastadd/Printing.jrag b/statemachine.solution/src/main/jastadd/Printing.jrag index 0b7b970..845d7a1 100644 --- a/statemachine.solution/src/main/jastadd/Printing.jrag +++ b/statemachine.solution/src/main/jastadd/Printing.jrag @@ -7,6 +7,7 @@ aspect Printing { getRoleTypeList().forEach(r -> sb.append(r.prettyPrint())); getCompartmentTypeList().forEach(c -> sb.append(c.prettyPrint())); //getFulfillmentList().forEach(f -> sb.append(f.prettyPrint())); + //getRelationshipList().forEach(rs -> sb.append(rs.prettyPrint())); sb.append("-------------\n"); return sb.toString(); } @@ -43,11 +44,13 @@ aspect Printing { eq CompartmentType.prettyPrint() { StringBuilder sb = new StringBuilder(); sb.append("CT " + getName()); + //plays if (!fulfillments().isEmpty()) sb.append("\n\tPlays "); for (Fulfillment f : fulfillments()) { sb.append("\n\t\t" + f.getFilled().getName() + " "); } + //contains if (getPartsList().getNumChild() != 0) sb.append("\n\tContains "); for (RoleType r : getPartsList()) { @@ -56,6 +59,13 @@ aspect Printing { for (CompartmentType c : getContainsList()) { sb.append("\n\t\t" + c.getName()); } + //rels + if (!rels().isEmpty()) + sb.append("\n\tRels "); + for (Relationship rs : rels()) { + sb.append("\n\t\t" + rs.getFirst().getName() + " " + rs.getName() + " " + rs.getSecond().getName()); + } + //attributes if (getAttributeList().getNumChild() != 0) sb.append("\n\tAttributes "); for (Attribute a : getAttributeList()) { @@ -65,6 +75,15 @@ aspect Printing { return sb.toString(); } //syn String Fulfillment.prettyPrint() = getFiller().getName() + " fills " + getFilled().getName() + ";\n"; + /*eq Relationship.prettyPrint() { + StringBuilder sb = new StringBuilder(); + sb.append("RST " + getName()); + sb.append("\n\t" + getFirst().getName() + " advises " + getSecond().getName()); + sb.append("\n"); + return sb.toString(); + }*/ + + /** Return a textual representation of the state machine */ /* diff --git a/statemachine.solution/src/main/jastadd/Rel.jadd b/statemachine.solution/src/main/jastadd/Rel.jadd index 342032b..fbd6e91 100644 --- a/statemachine.solution/src/main/jastadd/Rel.jadd +++ b/statemachine.solution/src/main/jastadd/Rel.jadd @@ -1,11 +1,39 @@ aspect Rel { - /* - coll ArrayList<Relationship> CompartmentType.rels() - [new ArrayList<Relationship>()] with add; - //PersonConsultantFulfillment contributes this + coll Set<Relationship> CompartmentType.rels() + [new HashSet<Relationship>()] with add; + Relationship contributes this to CompartmentType.rels() - for getFirst(); + for containingCompartmentType(); + + + inh CompartmentType Relationship.containingCompartmentType(); + eq RoleRag.getRelationship(int i).containingCompartmentType() { + for (CompartmentType c : getCompartmentTypeList()) { + for (RoleType r : c.getPartsList()) { + if (getRelationship(i).getFirst().equals(r)) + return c; + } + } + return null; + } + + public void Consultant.advises(Customer r) { + new Relationship().setName("advises").setFirst(this).setSecond(r); + } + + //syn Set<Relationship> CompartmentType.rels() = relsOfParts(this); + //inh Set<Relationship> CompartmentType.relsOfParts(CompartmentType c); + + //eq RoleRag.getRelationship(int i).aaaaaaaaaaaaaaa + + /* + inh Set<Relationship> CompartmentType.rels(); + eq RoleRag.getCompartmentTypeList(int i).rels() { + for (Relationship r : getRelationshipList()) { + + } + } */ } \ No newline at end of file diff --git a/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java b/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java index a285806..6f0dd8d 100644 --- a/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java +++ b/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java @@ -123,6 +123,7 @@ public class BankMain { peter2.addAttribute(phoneNumber1); con2.addAttribute(phoneNumber2); + con2.advises(cus2); System.out.println(rag.prettyPrint()); diff --git a/statemachine.solution/src/main/resources/Bank.relast b/statemachine.solution/src/main/resources/Bank.relast index eeba253..31563b0 100644 --- a/statemachine.solution/src/main/resources/Bank.relast +++ b/statemachine.solution/src/main/resources/Bank.relast @@ -1,4 +1,4 @@ -RoleRag ::= NaturalType* RoleType* CompartmentType* Fulfillment*; +RoleRag ::= NaturalType* RoleType* CompartmentType* Fulfillment* Relationship*; NamedElement ::= <Name>; TypedElement : NamedElement; rel TypedElement.Type? -> RigidType; @@ -9,12 +9,12 @@ RoleType : Type; rel RoleType.Incoming* -> Relationship; rel RoleType.Outgoing* -> Relationship; NaturalType : RigidType; -CompartmentType : RigidType ::= Parts:RoleType* Contains:CompartmentType* Relationships:Relationship*; +CompartmentType : RigidType ::= Parts:RoleType* Contains:CompartmentType*; // Relationships:Relationship*; //rel CompartmentType.Parts* <-> RoleType.Whole; Fulfillment ::= Filler:RigidType Filled:RoleType; //rel Fulfillment.Filler <-> NaturalType.Fulfillment*; //rel Fulfillment.Filled -> RoleType; -Relationship ::= <Name> [First:RoleType] [Second:RoleType]; +Relationship : NamedElement ::= First:RoleType Second:RoleType; //rel Relationship.First -> RoleType; //rel Relationship.Second -> RoleType; Irreflexive; -- GitLab