MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / ErrorMessages

Class ErrorMessages

src/main/java/wyc/util/ErrorMessages.java:53–598  ·  view source on GitHub ↗

Contains global constants mapping syntax errors to their error messages. The purpose of this class is bring all syntax error messages into one place, such that: It's easy to change error messages, and be sure the changes are applied universally. It's easy to reflect on the

Source from the content-addressed store, hash-verified

51 *
52 */
53public class ErrorMessages {
54
55 public interface Message {
56 public String getMessage(Tuple<Syntactic.Item> context);
57
58 /**
59 * Determine whether an actual error message was generated from this template
60 * (or not).
61 *
62 * @param message
63 * @return
64 */
65 public boolean match(String message);
66 }
67
68 /**
69 * A static message is a single message which, once created, never changes.
70 *
71 * @author David J. Pearce
72 *
73 */
74 private static final class StaticMessage implements Message {
75 private final String message;
76
77 public StaticMessage(String message) {
78 this.message = message;
79 }
80
81 @Override
82 public String getMessage(Tuple<Syntactic.Item> context) {
83 return message;
84 }
85
86 @Override
87 public boolean match(String message) {
88 return this.message.equals(message);
89 }
90 }
91
92 /**
93 * A multi-part message is a dynamic message which is created based upon the
94 * context in which it exists.
95 *
96 * @author David J. Pearce
97 *
98 */
99 private static final class MultiPartMessage implements Message {
100 private final String[] parts;
101
102 public MultiPartMessage(String... parts) {
103 this.parts = parts;
104 }
105
106 @Override
107 public boolean match(String message) {
108 return message.startsWith(parts[0]) || parts[0].startsWith(message);
109 }
110

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected