@@ -48,36 +48,39 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
48
48
*/
49
49
protected def msg : String
50
50
51
- /** The kind of the error message is something like "Syntax" or "Type
52
- * Mismatch"
51
+ /** The kind of the error message, e.g. "Syntax" or "Type Mismatch".
52
+ * This will be printed as "$kind Error", "$kind Warning", etc, on the first
53
+ * line of the message.
53
54
*/
54
55
def kind : String
55
56
56
57
/** The explanation should provide a detailed description of why the error
57
58
* occurred and use examples from the user's own code to illustrate how to
58
- * avoid these errors.
59
+ * avoid these errors. It might contain embedded <nonsensical> tags.
59
60
*/
60
- def explanation : String
61
+ protected def explain : String
61
62
62
63
private var myMsg : String | Null = null
63
64
private var myIsNonSensical : Boolean = false
64
65
66
+ private def dropNonSensical (msg : String ): String =
67
+ if msg.contains(nonSensicalStartTag) then
68
+ myIsNonSensical = true
69
+ // myMsg might be composed of several d"..." invocations -> nested
70
+ // nonsensical tags possible
71
+ msg
72
+ .replaceAllLiterally(nonSensicalStartTag, " " )
73
+ .replaceAllLiterally(nonSensicalEndTag, " " )
74
+ else msg
75
+
65
76
/** The message with potential embedded <nonsensical> tags */
66
77
def rawMessage = message
67
78
68
79
/** The message to report. <nonsensical> tags are filtered out */
69
- def message : String =
70
- if myMsg == null then
71
- myMsg =
72
- if msg.contains(nonSensicalStartTag) then
73
- myIsNonSensical = true
74
- // myMsg might be composed of several d"..." invocations -> nested
75
- // nonsensical tags possible
76
- msg
77
- .replaceAllLiterally(nonSensicalStartTag, " " )
78
- .replaceAllLiterally(nonSensicalEndTag, " " )
79
- else msg
80
- myMsg
80
+ lazy val message : String = dropNonSensical(msg)
81
+
82
+ /** The explanation to report. <nonsensical> tags are filtered out */
83
+ lazy val explanation : String = dropNonSensical(explain)
81
84
82
85
/** A message is non-sensical if it contains references to <nonsensical>
83
86
* tags. Such tags are inserted by the error diagnostic framework if a
@@ -94,30 +97,30 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
94
97
* that was captured in the original message.
95
98
*/
96
99
def persist : Message = new Message (errorId) {
97
- val kind = self.kind
98
- val msg = self.msg
99
- val explanation = self.explanation
100
+ val kind = self.kind
101
+ val msg = self.msg
102
+ val explain = self.explain
100
103
}
101
104
102
105
def append (suffix : => String ): Message = mapMsg(_ ++ suffix)
103
106
104
107
def mapMsg (f : String => String ): Message = new Message (errorId):
105
- val kind = self.kind
106
- lazy val msg = f(self.msg)
107
- lazy val explanation = self.explanation
108
+ val kind = self.kind
109
+ def msg = f(self.msg)
110
+ def explain = self.explain
108
111
109
112
def appendExplanation (suffix : => String ): Message = new Message (errorId):
110
- val kind = self.kind
111
- lazy val msg = self.msg
112
- lazy val explanation = self.explanation ++ suffix
113
+ val kind = self.kind
114
+ def msg = self.msg
115
+ def explain = self.explain ++ suffix
113
116
114
117
override def toString = msg
115
118
}
116
119
117
120
/** The fallback `Message` containing no explanation and having no `kind` */
118
121
class NoExplanation (msgFn : => String ) extends Message (ErrorMessageID .NoExplanationID ) {
119
- lazy val msg : String = msgFn
120
- val explanation : String = " "
122
+ def msg : String = msgFn
123
+ def explain : String = " "
121
124
val kind : String = " "
122
125
123
126
override def toString (): String = msg
0 commit comments