Analysis.jrag 3.72 KB
Newer Older
1
aspect Analysis {
2
  // --- lookupTokenEndpointDefinition ---
René Schöne's avatar
René Schöne committed
3
  inh java.util.List<TokenEndpointDefinition> TokenEndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token);
4
5
  eq RagConnect.getEndpointDefinition().lookupTokenEndpointDefinitions(TokenComponent token) = lookupTokenEndpointDefinitions(token);
  syn java.util.List<TokenEndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) {
René Schöne's avatar
René Schöne committed
6
    java.util.List<TokenEndpointDefinition> result = new java.util.ArrayList<>();
7
8
    for (EndpointDefinition def : getEndpointDefinitionList()) {
      if (def.isTokenEndpointDefinition() && def.asTokenEndpointDefinition().getToken().equals(token)) {
René Schöne's avatar
René Schöne committed
9
        result.add(def.asTokenEndpointDefinition());
René Schöne's avatar
René Schöne committed
10
      }
René Schöne's avatar
René Schöne committed
11
    }
René Schöne's avatar
René Schöne committed
12
    return result;
René Schöne's avatar
René Schöne committed
13
14
  }

René Schöne's avatar
René Schöne committed
15
16
  // --- lookupDependencyDefinition ---
  inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id);
17
  eq RagConnect.getDependencyDefinition().lookupDependencyDefinition(TypeDecl source, String id) {
René Schöne's avatar
René Schöne committed
18
19
20
21
22
23
24
    for (DependencyDefinition def : getDependencyDefinitionList()) {
      if (def.getID().equals(id) && def.getSource().containingTypeDecl().equals(source)) {
        return def;
      }
    }
    return null;
  }
25

René Schöne's avatar
René Schöne committed
26
  // --- isAlreadyDefined ---
27
  syn boolean TokenEndpointDefinition.isAlreadyDefined() = lookupTokenEndpointDefinitions(getToken()).size() > 1;
René Schöne's avatar
René Schöne committed
28
  syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
René Schöne's avatar
René Schöne committed
29

30
31
32
33
34
35
//  // --- protocol ---
//  syn String TokenEndpointDefinition.protocol();
//  eq ReceiveFromMqttDefinition.protocol() = "mqtt";
//  eq SendToMqttDefinition.protocol() = "mqtt";
//  eq ReceiveFromRestDefinition.protocol() = "rest";
//  eq SendToRestDefinition.protocol() = "rest";
René Schöne's avatar
René Schöne committed
36

37
38
39
//  // --- usesPROTOCOL ---
//  syn boolean RagConnect.usesMqtt() = !mqttEndpointDefinitions().isEmpty();
//  syn boolean RagConnect.usesRest() = !restEndpointDefinitions().isEmpty();
René Schöne's avatar
René Schöne committed
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//  // --- mqttEndpointDefinitions ---
//  coll java.util.List<TokenEndpointDefinition> RagConnect.mqttEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
//  ReceiveFromMqttDefinition contributes this
//    to RagConnect.mqttEndpointDefinitions()
//    for ragconnect();
//  SendToMqttDefinition contributes this
//    to RagConnect.mqttEndpointDefinitions()
//    for ragconnect();
//
//  // --- restEndpointDefinitions ---
//  coll java.util.List<TokenEndpointDefinition> RagConnect.restEndpointDefinitions() [new java.util.ArrayList<>()] root RagConnect;
//  ReceiveFromRestDefinition contributes this
//    to RagConnect.restEndpointDefinitions()
//    for ragconnect();
//  SendToRestDefinition contributes this
//    to RagConnect.restEndpointDefinitions()
//    for ragconnect();
René Schöne's avatar
René Schöne committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

  syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
  eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target);
  eq JavaArrayMappingDefinitionType.assignableTo(JavaTypeUse target) {
    if (!target.getName().endsWith("[]")) { return false; }
    return getType().assignableTo(new SimpleJavaTypeUse(target.getName().replace("[]", "")));
  }
  syn boolean JavaTypeUse.assignableTo(JavaTypeUse target) {
    // target var = this;
    return target.primitivePrettyPrint().equals(this.primitivePrettyPrint());
  }
  syn String JavaTypeUse.primitivePrettyPrint() {
    switch(getName()) {
      case "int":
      case "Integer": return "int";
      case "short":
      case "Short": return "short";
      case "long":
      case "Long": return "long";
      case "float":
      case "Float": return "float";
      case "double":
      case "Double": return "double";
      case "char":
      case "Character": return "char";
      default: return getName();
    }
  }
86
}