Analysis.jrag 2.47 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

  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();
    }
  }
57
}