Errors.jrag 3.99 KB
Newer Older
René Schöne's avatar
René Schöne committed
1
2
3
4
5
import java.util.Set;
import java.util.TreeSet;
import java.util.LinkedList;

aspect Errors {
6
  coll Set<ErrorMessage> RagConnect.errors()
René Schöne's avatar
René Schöne committed
7
    [new TreeSet<ErrorMessage>()]
8
    root RagConnect;
René Schöne's avatar
René Schöne committed
9

René Schöne's avatar
René Schöne committed
10
    ReceiveTokenEndpointDefinition contributes error("Receive definition already defined for " + getToken().getName())
René Schöne's avatar
René Schöne committed
11
      when isAlreadyDefined()
12
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
13

René Schöne's avatar
René Schöne committed
14
    ReceiveTokenEndpointDefinition contributes error("Receiving target token must not be an NTA token!")
René Schöne's avatar
René Schöne committed
15
      when getToken().getNTA()
16
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
17
18

    // if first mapping is null, then suitableDefaultMapping() == null
René Schöne's avatar
René Schöne committed
19
    ReceiveTokenEndpointDefinition contributes error("No suitable default mapping found for type " +
René Schöne's avatar
René Schöne committed
20
      ((getMappingList().isEmpty())
René Schöne's avatar
René Schöne committed
21
        ? getToken().effectiveJavaTypeUse().prettyPrint()
René Schöne's avatar
René Schöne committed
22
23
        : getMappingList().get(0).getFromType().prettyPrint()))
      when effectiveMappings().get(0) == null
24
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
25

René Schöne's avatar
René Schöne committed
26
27
28
    ReceiveTokenEndpointDefinition contributes error("to-type of last mapping (" + effectiveMappings().get(effectiveMappings().size() - 1).getToType().prettyPrint() + ") not assignable to type of the Token (" + getToken().effectiveJavaTypeUse().prettyPrint() + ")!")
      when !effectiveMappings().get(effectiveMappings().size() - 1).getToType().assignableTo(
          getToken().effectiveJavaTypeUse())
29
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
30

René Schöne's avatar
René Schöne committed
31
    SendTokenEndpointDefinition contributes error("Sending target token must be an NTA token!")
René Schöne's avatar
René Schöne committed
32
      when !getToken().getNTA()
33
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
34

René Schöne's avatar
René Schöne committed
35
    SendTokenEndpointDefinition contributes error("Send definition already defined for " + getToken().getName())
René Schöne's avatar
René Schöne committed
36
      when isAlreadyDefined()
37
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
38
39
40

    DependencyDefinition contributes error("Dependency definition already defined for " + getSource().containingTypeDecl().getName() + " with name " + getID())
      when isAlreadyDefined()
41
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
42
43
44

    DependencyDefinition contributes error("The name of a dependency definition must not be equal to a list-node on the source")
      when isAlreadyDefinedAsList()
45
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
46

René Schöne's avatar
René Schöne committed
47
    DependencyDefinition contributes error("There must be a send endpoint definition targeting " + getSource().parentTypeypeAndName() + " for dependency definition " + getID())
48
      when targetEndpointDefinition() == null
49
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
50
51
}

René Schöne's avatar
René Schöne committed
52
53
54
55
56
57
58
59
60
61
62
aspect ErrorHelpers {
  syn boolean DependencyDefinition.isAlreadyDefinedAsList() {
    for (Component comp : getSource().containingTypeDecl().getComponentList()) {
      if (comp.isListComponent() && comp.getName().equals(this.getID())) {
        return true;
      }
    }
    return false;
  }
  syn String TokenComponent.parentTypeypeAndName() = containingTypeDecl().getName() + "." + getName();
}
René Schöne's avatar
René Schöne committed
63
64
65
66
67
68
69
70
71
72
73

aspect ErrorMessage {
  public class ErrorMessage implements Comparable<ErrorMessage> {
    private final ASTNode node;
    private final String filename;
    private final int line;
    private final int col;
    private final String message;

    public ErrorMessage(ASTNode node, String message) {
      this.node = node;
René Schöne's avatar
René Schöne committed
74
      this.filename = node.containedFileName();
René Schöne's avatar
René Schöne committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
      this.line = node.getStartLine();
      this.col = node.getStartColumn();
      this.message = message;
    }

    public ASTNode getNode() {
      return node;
    }
    public int getLine() {
      return line;
    }
    public int getCol() {
      return col;
    }
    public String getMessage() {
      return message;
    }

    public String toString() {
      return filename + " Line " + line + ", column " + col + ": " + message;
    }

    @Override
    public int compareTo(ErrorMessage err) {
      int n = filename.compareTo(err.filename);
      if (n != 0) {
        return n;
      }

      n = line - err.line;
      if (n != 0) {
        return n;
      }

      n = col-err.col;
      if (n != 0) {
        return n;
      }

      return message.compareTo(err.message);
    }
  }

  protected ErrorMessage ASTNode.error(String message) {
    return new ErrorMessage(this, message);
  }
}