toolcontext: error methods return the messages, to add information
[nit.git] / src / toolcontext.nit
index 5a6072c..5a3e3cb 100644 (file)
@@ -194,16 +194,21 @@ class ToolContext
        end
 
        # Display an error
-       fun error(l: nullable Location, s: String)
+       #
+       # Return the message (to add information)
+       fun error(l: nullable Location, s: String): Message
        do
                var m = new Message(l,null,s)
                if l != null then l.add_message m
                messages.add m
                error_count = error_count + 1
                if opt_stop_on_first_error.value then check_errors
+               return m
        end
 
        # Add an error, show errors and quit
+       #
+       # Because the program will quit, nothing is returned.
        fun fatal_error(l: nullable Location, s: String)
        do
                error(l,s)
@@ -220,16 +225,19 @@ class ToolContext
        # * They always are real issues (no false positive)
        #
        # First-level warnings are displayed by default (except if option `-q` is given).
-       fun warning(l: nullable Location, tag: String, text: String)
+       #
+       # Return the message (to add information) or null if the warning is disabled
+       fun warning(l: nullable Location, tag: String, text: String): nullable Message
        do
-               if opt_warning.value.has("no-{tag}") then return
-               if not opt_warning.value.has(tag) and opt_warn.value == 0 then return
-               if is_warning_blacklisted(l, tag) then return
+               if opt_warning.value.has("no-{tag}") then return null
+               if not opt_warning.value.has(tag) and opt_warn.value == 0 then return null
+               if is_warning_blacklisted(l, tag) then return null
                var m = new Message(l, tag, text)
                if l != null then l.add_message m
                messages.add m
                warning_count = warning_count + 1
                if opt_stop_on_first_error.value then check_errors
+               return m
        end
 
        # Display a second-level warning.
@@ -245,16 +253,19 @@ class ToolContext
        #
        # In order to prevent warning inflation à la Java, second-level warnings are not displayed by
        # default and require an additional option `-W`.
-       fun advice(l: nullable Location, tag: String, text: String)
+       #
+       # Return the message (to add information) or null if the warning is disabled
+       fun advice(l: nullable Location, tag: String, text: String): nullable Message
        do
-               if opt_warning.value.has("no-{tag}") then return
-               if not opt_warning.value.has(tag) and opt_warn.value <= 1 then return
-               if is_warning_blacklisted(l, tag) then return
+               if opt_warning.value.has("no-{tag}") then return null
+               if not opt_warning.value.has(tag) and opt_warn.value <= 1 then return null
+               if is_warning_blacklisted(l, tag) then return null
                var m = new Message(l, tag, text)
                if l != null then l.add_message m
                messages.add m
                warning_count = warning_count + 1
                if opt_stop_on_first_error.value then check_errors
+               return m
        end
 
        # Display an info