src: add tag to existing warnings
authorJean Privat <jean@pryen.org>
Fri, 19 Sep 2014 18:17:56 +0000 (14:17 -0400)
committerJean Privat <jean@pryen.org>
Fri, 19 Sep 2014 18:17:56 +0000 (14:17 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/frontend/check_annotation.nit
src/frontend/simple_misc_analysis.nit
src/modelbuilder.nit
src/modelize/modelize_class.nit
src/modelize/modelize_property.nit
src/semantize/typing.nit
src/testing/testing_doc.nit
src/testing/testing_suite.nit

index 6178a39..41abe43 100644 (file)
@@ -60,7 +60,7 @@ private class CheckAnnotationPhase
 
                        for m in super_mmodules do
                                if declared_annotations[m].has(name) then
-                                       modelbuilder.warning(annot, "Warning: an annotation `{name}` is already declared in module `{m}`")
+                                       modelbuilder.warning(annot, "multiple-annotation-declarations", "Warning: an annotation `{name}` is already declared in module `{m}`")
                                        break label
                                end
                        end
@@ -120,7 +120,7 @@ platform
 
                if annots.has(name) then return
 
-               toolcontext.modelbuilder.warning(nat, "Warning: unknown annotation `{name}`")
+               toolcontext.modelbuilder.warning(nat, "unknown-annotation", "Warning: unknown annotation `{name}`")
 
                annots.add(name) # to avoid multiple errors on the same name
        end
index 26d6710..a50b45b 100644 (file)
@@ -54,9 +54,9 @@ private class SimpleMiscVisitor
 
        var toolcontext: ToolContext
 
-       fun warning(node: ANode, msg: String)
+       fun warning(node: ANode, tag, msg: String)
        do
-               toolcontext.warning(node.hot_location, msg)
+               toolcontext.warning(node.hot_location, tag, msg)
        end
 
        init(toolcontext: ToolContext)
@@ -81,7 +81,7 @@ redef class ASignature
        redef fun after_simple_misc(v)
        do
                if self.n_opar != null and self.n_params.is_empty then
-                       v.warning(self, "Warning: superfluous parentheses.")
+                       v.warning(self, "parentheses", "Warning: superfluous parentheses.")
                end
        end
 end
@@ -94,7 +94,7 @@ end
 redef class AParExpr
        redef fun warn_parentheses(v)
        do
-               v.warning(self, "Warning: superfluous parentheses.")
+               v.warning(self, "parentheses", "Warning: superfluous parentheses.")
        end
 end
 
@@ -102,7 +102,7 @@ redef class AParExprs
        redef fun after_simple_misc(v)
        do
                if n_exprs.is_empty then
-                       v.warning(self, "Warning: superfluous parentheses.")
+                       v.warning(self, "parentheses", "Warning: superfluous parentheses.")
                end
        end
 end
@@ -141,7 +141,7 @@ redef class AWhileExpr
        redef fun after_simple_misc(v)
        do
                if n_expr isa ATrueExpr then
-                       v.warning(self, "Warning: use 'loop' instead of 'while true do'.")
+                       v.warning(self, "loop", "Warning: use `loop` instead of `while true do`.")
                else
                        n_expr.warn_parentheses(v)
                end
@@ -173,7 +173,7 @@ redef class AOnceExpr
        redef fun accept_simple_misc(v)
        do
                if v.once_count > 0 then
-                       v.warning(self, "Useless once in a once expression.")
+                       v.warning(self, "nested-once", "Warning: useless once in a once expression.")
                end
                v.once_count = v.once_count + 1
 
index eac98df..bdb76ae 100644 (file)
@@ -715,9 +715,9 @@ class ModelBuilder
 
        # Helper function to display a warning on a node.
        # Alias for: `self.toolcontext.warning(n.hot_location, text)`
-       fun warning(n: ANode, text: String)
+       fun warning(n: ANode, tag, text: String)
        do
-               self.toolcontext.warning(n.hot_location, text)
+               self.toolcontext.warning(n.hot_location, tag, text)
        end
 
        # Force to get the primitive method named `name` on the type `recv` or do a fatal error on `n`
index ff0295f..ed4df60 100644 (file)
@@ -133,7 +133,7 @@ redef class ModelBuilder
                                        return
                                end
                                for c in ptname.chars do if c >= 'a' and c<= 'z' then
-                                       warning(nfd, "Warning: lowercase in the formal parameter type {ptname}")
+                                       warning(nfd, "formal-type-name", "Warning: lowercase in the formal parameter type {ptname}")
                                        break
                                end
                                names.add(ptname)
@@ -155,7 +155,7 @@ redef class ModelBuilder
                                                nfd.bound = bound
                                        end
                                        if bound isa MClassType and bound.mclass.kind == enum_kind then
-                                               warning(nfdt, "Warning: Useless formal parameter type since `{bound}` cannnot have subclasses.")
+                                               warning(nfdt, "useless-bound", "Warning: Useless formal parameter type since `{bound}` cannnot have subclasses.")
                                        end
                                else if mclass.mclassdefs.is_empty then
                                        # No bound, then implicitely bound by nullable Object
@@ -385,12 +385,12 @@ redef class ModelBuilder
                                if not parents.has(sc) or sc == objectclass then
                                        # Skip the warning on generated code
                                        if ntype.location.file != null and not ntype.location.file.filename.is_empty then
-                                               warning(ntype, "Warning: superfluous super-class {mtype} in class {mclassdef.mclass}.")
+                                               warning(ntype, "useless-superclass", "Warning: superfluous super-class {mtype} in class {mclassdef.mclass}.")
                                        end
                                else if not seen_parents.has_key(sc) then
                                        seen_parents[sc] = ntype
                                else
-                                       warning(ntype, "Warning: duplicated super-class {mtype} in class {mclassdef.mclass}.")
+                                       warning(ntype, "useless-superclass", "Warning: duplicated super-class {mtype} in class {mclassdef.mclass}.")
                                end
                        end
                end
index f0c46a5..b6371f6 100644 (file)
@@ -405,7 +405,7 @@ redef class APropdef
                        else if mvisibility == private_visibility then
                                assert nvisibility != null
                                # Not yet
-                               # modelbuilder.warning(nvisibility, "Warning: private is unrequired since the only legal visibility for properties in a private class is private.")
+                               modelbuilder.warning(nvisibility, "useless-visibility", "Warning: private is superfluous since the only legal visibility for properties in a private class is private.")
                        end
                        mvisibility = private_visibility
                end
@@ -968,7 +968,7 @@ redef class AAttrPropdef
                        if nexpr isa ANewExpr then
                                var xmtype = modelbuilder.resolve_mtype(mmodule, mclassdef, nexpr.n_type)
                                if xmtype == mtype and modelbuilder.toolcontext.opt_warn.value >= 2 then
-                                       modelbuilder.warning(ntype, "Warning: useless type definition")
+                                       modelbuilder.warning(ntype, "useless-type", "Warning: useless type definition")
                                end
                        end
                end
@@ -1110,7 +1110,7 @@ redef class ATypePropdef
                        var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
                        mprop = new MVirtualTypeProp(mclassdef, name, mvisibility)
                        for c in name.chars do if c >= 'a' and c<= 'z' then
-                               modelbuilder.warning(n_id, "Warning: lowercase in the virtual type {name}")
+                               modelbuilder.warning(n_id, "bad-type-name", "Warning: lowercase in the virtual type {name}")
                                break
                        end
                        if not self.check_redef_keyword(modelbuilder, mclassdef, self.n_kwredef, false, mprop) then return
@@ -1189,7 +1189,7 @@ redef class ATypePropdef
                        end
                        if p.mclassdef.mclass == mclassdef.mclass then
                                # Still a warning to pass existing bad code
-                               modelbuilder.warning(n_type, "Redef Error: a virtual type cannot be refined.")
+                               modelbuilder.warning(n_type, "refine-type", "Redef Error: a virtual type cannot be refined.")
                                break
                        end
                        if not bound.is_subtype(mmodule, anchor, supbound) then
index e5f131d..0102c2b 100644 (file)
@@ -188,9 +188,9 @@ private class TypeVisitor
                if sup == null then return null # Forward error
 
                if sup == sub then
-                       self.modelbuilder.warning(node, "Warning: Expression is already a {sup}.")
+                       self.modelbuilder.warning(node, "useless-type-test", "Warning: Expression is already a {sup}.")
                else if self.is_subtype(sub, sup) then
-                       self.modelbuilder.warning(node, "Warning: Expression is already a {sup} since it is a {sub}.")
+                       self.modelbuilder.warning(node, "useless-type-test", "Warning: Expression is already a {sup} since it is a {sub}.")
                end
                return sup
        end
@@ -266,9 +266,9 @@ private class TypeVisitor
                if info != null and self.mpropdef.mproperty.deprecation == null then
                        var mdoc = info.mdoc
                        if mdoc != null then
-                               self.modelbuilder.warning(node, "Deprecation Warning: Method '{name}' is deprecated: {mdoc.content.first}")
+                               self.modelbuilder.warning(node, "deprecated-method", "Deprecation Warning: Method '{name}' is deprecated: {mdoc.content.first}")
                        else
-                               self.modelbuilder.warning(node, "Deprecation Warning: Method '{name}' is deprecated.")
+                               self.modelbuilder.warning(node, "deprecated-method", "Deprecation Warning: Method '{name}' is deprecated.")
                        end
                end
 
@@ -280,7 +280,7 @@ private class TypeVisitor
                else if propdefs.length == 1 then
                        mpropdef = propdefs.first
                else
-                       self.modelbuilder.warning(node, "Warning: confliting property definitions for property {name} in {unsafe_type}: {propdefs.join(" ")}")
+                       self.modelbuilder.warning(node, "property-conflict", "Warning: conflicting property definitions for property {name} in {unsafe_type}: {propdefs.join(" ")}")
                        mpropdef = mproperty.intro
                end
 
@@ -1212,13 +1212,13 @@ redef class AAsNotnullExpr
                self.mtype = mtype
 
                if mtype isa MClassType then
-                       v.modelbuilder.warning(self, "Warning: expression is already not null, since it is a `{mtype}`.")
+                       v.modelbuilder.warning(self, "useless-type-test", "Warning: expression is already not null, since it is a `{mtype}`.")
                        return
                end
                assert mtype.need_anchor
                var u = v.anchor_to(mtype)
                if not u isa MNullableType then
-                       v.modelbuilder.warning(self, "Warning: expression is already not null, since it is a `{mtype}: {u}`.")
+                       v.modelbuilder.warning(self, "useless-type-test", "Warning: expression is already not null, since it is a `{mtype}: {u}`.")
                        return
                end
        end
@@ -1738,7 +1738,7 @@ redef class ADebugTypeExpr
                var mtype = v.resolve_mtype(ntype)
                if mtype != null and mtype != expr then
                        var umtype = v.anchor_to(mtype)
-                       v.modelbuilder.warning(self, "Found type {expr} (-> {unsafe}), expected {mtype} (-> {umtype})")
+                       v.modelbuilder.warning(self, "debug", "Found type {expr} (-> {unsafe}), expected {mtype} (-> {umtype})")
                end
                self.is_typed = true
        end
index e370b8a..fe37ca9 100644 (file)
@@ -51,8 +51,8 @@ class NitUnitExecutor
                # We want executable code
                if not (ast isa AModule or ast isa ABlockExpr or ast isa AExpr) then
                        if ndoc != null and n.tag == "pre" and toolcontext.opt_warn.value > 1 then
-                               toolcontext.warning(ndoc.location, "Warning: There is a block of code that is not valid Nit, thus not considered a nitunit")
-                               if ast isa AError then toolcontext.warning(ast.location, ast.message)
+                               toolcontext.warning(ndoc.location, "invalid-block", "Warning: There is a block of code that is not valid Nit, thus not considered a nitunit")
+                               if ast isa AError then toolcontext.warning(ast.location, "syntax-error", ast.message)
                                ndoc = null # To avoid multiple warning in the same node
                        end
                        return
@@ -63,7 +63,7 @@ class NitUnitExecutor
                v.enter_visit(ast)
                if not v.foundit then
                        if ndoc != null and n.tag == "pre" and toolcontext.opt_warn.value > 1 then
-                               toolcontext.warning(ndoc.location, "Warning: There is a block of Nit code without `assert`, thus not considered a nitunit")
+                               toolcontext.warning(ndoc.location, "invalid-block", "Warning: There is a block of Nit code without `assert`, thus not considered a nitunit")
                                ndoc = null # To avoid multiple warning in the same node
                        end
                        return
@@ -156,13 +156,13 @@ class NitUnitExecutor
                        var ne = new HTMLTag("failure")
                        ne.attr("message", msg)
                        tc.add ne
-                       toolcontext.warning(ndoc.location, "FAILURE: {tc.attrs["classname"]}.{tc.attrs["name"]} (in {file}): {msg}")
+                       toolcontext.warning(ndoc.location, "failure", "FAILURE: {tc.attrs["classname"]}.{tc.attrs["name"]} (in {file}): {msg}")
                        toolcontext.modelbuilder.failed_entities += 1
                else if res2 != 0 then
                        var ne = new HTMLTag("error")
                        ne.attr("message", msg)
                        tc.add ne
-                       toolcontext.warning(ndoc.location, "ERROR: {tc.attrs["classname"]}.{tc.attrs["name"]} (in {file}): {msg}")
+                       toolcontext.warning(ndoc.location, "error", "ERROR: {tc.attrs["classname"]}.{tc.attrs["name"]} (in {file}): {msg}")
                        toolcontext.modelbuilder.failed_entities += 1
                end
                toolcontext.check_errors
index 30cbed5..28e6945 100644 (file)
@@ -231,7 +231,7 @@ class TestCase
                var loc = test_method.location
                if res != 0 then
                        failure = msg
-                       toolcontext.warning(loc, "FAILURE: {test_method.name} (in file {file}.nit): {msg}")
+                       toolcontext.warning(loc, "failure", "FAILURE: {test_method.name} (in file {file}.nit): {msg}")
                        toolcontext.modelbuilder.failed_tests += 1
                end
                toolcontext.check_errors
@@ -252,7 +252,7 @@ class TestCase
                var loc = test_method.location
                if res != 0 then
                        error = msg
-                       toolcontext.warning(loc, "ERROR: {test_method.name} (in file {file}.nit): {msg}")
+                       toolcontext.warning(loc, "failure", "ERROR: {test_method.name} (in file {file}.nit): {msg}")
                        toolcontext.modelbuilder.failed_tests += 1
                end
                toolcontext.check_errors