Aspect.jadd 2.37 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
2
3
4
5
6
7
8
9
10
aspect Aspect {

  public static final String ASTNode.aspectIndent = "  ";

  public String Program.generateAspect() {
    StringBuilder sb = new StringBuilder();
    generateAspect(sb);
    return sb.toString();
  }

11
  @Deprecated
Johannes Mey's avatar
Johannes Mey committed
12
13
14
15
16
17
18
19
  public void Program.generateAspect(StringBuilder sb) {

    sb.append("aspect ROS2RAG {\n");

    // TODO generate getters and setters for ROS2RAG terminals (and attributes?)

    sb.append("}\n");
  }
20
21
22
23
24
25
26
27
28
29
30
31
32
33

  public String Ros2Rag.generateAspect() {
    StringBuilder sb = new StringBuilder();
    generateAspect(sb);
    return sb.toString();
  }

  // from "[always] read Joint.CurrentPosition using PoseToPosition;" generate method connectTo
//    Joint j;
//    j.getCurrentPosition().connectTo("/robot/joint2/pos");

  public void Ros2Rag.generateAspect(StringBuilder sb) {
    sb.append("aspect ROS2RAG {\n");

34
    for (UpdateDefinition def : getUpdateDefinitionList()) {
35
36
37
38
39
40
      def.generateAspect(sb);
    }

    sb.append("}\n");
  }

41
  abstract void UpdateDefinition.generateAspect(StringBuilder sb);
42
43
44
45
//  @Override
//  void UpdateDefinition.generateAspect(StringBuilder sb) {
//    // TODO
//  }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

  // will be "addConnectionJoint_CurrentPosition" in example
/* // see discussion in codimd (InstanceLocation), why this won't work here
  Position.connectTo(String topic) {
    mqttUpdater().addConnectionJoint_CurrentPosition(this, topic);
  }
  MqttUpdater.addConnectionJoint_CurrentPosition(Position target, String topic) {
    // either
    topicActionMap.put(topic, new Action(JOINT_CURRENTPOSITION, target));
    // or
    topicForJoint_CurrentPosition.put(topic, target);
  }
 */
  @Override
  void ReadFromMqttDefinition.generateAspect(StringBuilder sb) {
61
    sb.append("public void ").append("type").append(".connectTo(String topic) {\n")
62
      .append(aspectIndent).append("mqttUpdater().addConnection")
63
64
65
      .append(getToken().containingTypeDecl().getName())
      .append("_")
      .append(getToken().getName())
66
67
68
69
70
71
      .append("(this, topic);\n")
      .append("}\n");
  }

  @Override
  void WriteToMqttDefinition.generateAspect(StringBuilder sb) {
72
73
74
75
76
77
78
    sb.append("public void ").append("type").append(".connectTo(String topic) {\n")
      .append(aspectIndent).append("mqttUpdater().addConnection")
      .append(getToken().containingTypeDecl().getName())
      .append("_")
      .append(getToken().getName())
      .append("(this, topic);\n")
      .append("}\n");
79
  }
80

Johannes Mey's avatar
Johannes Mey committed
81
}