NameResolution.jrag 1.46 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
2
3
4
5
6
7
8
9
10
11
12
13
aspect NameResolution {

  refine RefResolverStubs eq ASTNode.globallyResolveTypeDeclByToken(String id) = program().resolveTypeDecl(id);

  syn TypeDecl Program.resolveTypeDecl(String name) {
    for (TypeDecl decl : typeDecls()) {
      if (decl.getName().equals(name)) {
        return decl;
      }
    }
    throw new RuntimeException("TypeDecl " + name + " could not be resolved.");
  }

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  refine RefResolverStubs eq ASTNode.globallyResolveTokenComponentByToken(String id) {
    // return a TokenComponent. id is of the form 'type_name + "." + token_name'
    int dotIndex = id.indexOf(".");
    String typeName = id.substring(0, dotIndex);
    String tokenName = id.substring(dotIndex + 1);
    TypeDecl type = program().resolveTypeDecl(typeName);
    // iterate over components and find the matching tokenComponent
    for (Component comp : type.getComponentList()) {
      if (comp.isTokenComponent() && comp.getName().equals(tokenName)) {
        return comp.asTokenComponent();
      }
    }
    System.err.println("Could not resolve TokenComponent '" + id + "'.");
    return null;
  }

  refine RefResolverStubs eq UpdateDefinition.resolveMappingByToken(String id) {
    // return a MappingDefinition
    for (MappingDefinition mappingDefinition : ros2rag().getMappingDefinitionList()) {
      if (mappingDefinition.getID().equals(id)) {
        return mappingDefinition;
      }
    }
    System.err.println("Could not resolve MappingDefinition '" + id + "'.");
    return null;
  }
Johannes Mey's avatar
Johannes Mey committed
40
41

}