modelbuilder: add option `--ignore-visibility`
authorJean Privat <jean@pryen.org>
Tue, 25 Mar 2014 19:03:54 +0000 (15:03 -0400)
committerJean Privat <jean@pryen.org>
Tue, 25 Mar 2014 19:03:54 +0000 (15:03 -0400)
This option will allow `nitunit` to execute tests that use
protected methods.

Signed-off-by: Jean Privat <jean@pryen.org>

src/modelbuilder.nit
src/typing.nit

index b916077..72e4425 100644 (file)
@@ -43,10 +43,13 @@ redef class ToolContext
        # Option --only-parse
        var opt_only_parse: OptionBool = new OptionBool("Only proceed to parse step of loaders", "--only-parse")
 
+       # Option --ignore-visibility
+       var opt_ignore_visibility: OptionBool = new OptionBool("Do not check, and produce errors, on visibility issues.", "--ignore-visibility")
+
        redef init
        do
                super
-               option_context.add_option(opt_path, opt_only_parse, opt_only_metamodel)
+               option_context.add_option(opt_path, opt_only_parse, opt_only_metamodel, opt_ignore_visibility)
        end
 
        fun modelbuilder: ModelBuilder do return modelbuilder_real.as(not null)
index ccba0af..791903a 100644 (file)
@@ -242,7 +242,7 @@ private class TypeVisitor
                end
 
                assert mproperty isa MMethod
-               if mproperty.visibility == protected_visibility and not recv_is_self and self.mmodule.visibility_for(mproperty.intro_mclassdef.mmodule) < intrude_visibility then
+               if mproperty.visibility == protected_visibility and not recv_is_self and self.mmodule.visibility_for(mproperty.intro_mclassdef.mmodule) < intrude_visibility and not modelbuilder.toolcontext.opt_ignore_visibility.value then
                        self.modelbuilder.error(node, "Error: Method '{name}' is protected and can only acceded by self.")
                        return null
                end