Analysis.jrag 3.93 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
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;
  }
Johannes Mey's avatar
Johannes Mey committed
25

René Schöne's avatar
René Schöne committed
26
  // --- isAlreadyDefined ---
René Schöne's avatar
René Schöne committed
27
28
29
30
31
32
33
34
  syn boolean TokenEndpointDefinition.isAlreadyDefined() {
    java.util.List<TokenEndpointDefinition> definitions = lookupTokenEndpointDefinitions(getToken());
    java.util.Set<String> protocols = definitions
      .stream()
      .map(TokenEndpointDefinition::protocol)
      .collect(java.util.stream.Collectors.toSet());
    return definitions.size() > protocols.size();
  }
René Schöne's avatar
René Schöne committed
35
  syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
René Schöne's avatar
René Schöne committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
86
87
88
89
90
91
92

  // --- protocol ---
  syn String TokenEndpointDefinition.protocol();
  eq ReceiveFromMqttDefinition.protocol() = "mqtt";
  eq SendToMqttDefinition.protocol() = "mqtt";
  eq ReceiveFromRestDefinition.protocol() = "rest";
  eq SendToRestDefinition.protocol() = "rest";

  // --- usesPROTOCOL ---
  syn boolean RagConnect.usesMqtt() = !mqttEndpointDefinitions().isEmpty();
  syn boolean RagConnect.usesRest() = !restEndpointDefinitions().isEmpty();

  // --- 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();

  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();
    }
  }
Johannes Mey's avatar
Johannes Mey committed
93
}