Aspect.jadd 2.51 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
  public String Ros2Rag.generateAspect(String rootNodeName) {
22
    StringBuilder sb = new StringBuilder();
23
24
    generateMqttAspect(sb);
    generateGrammarExtension(sb);
25
26
27
    return sb.toString();
  }

28
29
30
31
  public void Ros2Rag.generateMqttAspect(StringBuilder sb) {

  }

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

36
37
  public void Ros2Rag.generateGrammarExtension(StringBuilder sb) {
    sb.append("aspect ros2rag.GrammarExtension {\n");
38

39
    for (UpdateDefinition def : getUpdateDefinitionList()) {
40
41
42
43
44
45
      def.generateAspect(sb);
    }

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

46
  abstract void UpdateDefinition.generateAspect(StringBuilder sb);
47
48
49
50
//  @Override
//  void UpdateDefinition.generateAspect(StringBuilder sb) {
//    // TODO
//  }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

  // 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) {
66
    sb.append("public void ").append("type").append(".connectTo(String topic) {\n")
67
      .append(aspectIndent).append("mqttUpdater().addConnection")
68
69
70
      .append(getToken().containingTypeDecl().getName())
      .append("_")
      .append(getToken().getName())
71
72
73
74
75
76
      .append("(this, topic);\n")
      .append("}\n");
  }

  @Override
  void WriteToMqttDefinition.generateAspect(StringBuilder sb) {
77
78
79
80
81
82
83
    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");
84
  }
85

Johannes Mey's avatar
Johannes Mey committed
86
}