Errors.jrag 3.78 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

10
    ReceiveFromMqttDefinition 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

14
    ReceiveFromMqttDefinition 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
19
    ReceiveFromMqttDefinition contributes error("No suitable default mapping found for type " +
René Schöne's avatar
René Schöne committed
20
21
22
23
      ((getMappingList().isEmpty())
        ? getToken().getJavaTypeUse().prettyPrint()
        : getMappingList().get(0).getFromType().prettyPrint()))
      when effectiveMappings().get(0) == null
24
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
25

26
    ReceiveFromMqttDefinition contributes error("to-type of last mapping must be type of the Token!")
René Schöne's avatar
René Schöne committed
27
28
      when getToken().getJavaTypeUse().prettyPrint().equals(
          effectiveMappings().get(effectiveMappings().size() - 1))
29
      to RagConnect.errors();
René Schöne's avatar
René Schöne committed
30

31
    SendToMqttDefinition 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

35
    SendToMqttDefinition 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

47
    DependencyDefinition contributes error("There must be a send update 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);
  }
}