def add_method_from_parent_class(self, method): name = method.get("name") args = argument_list_for_declaration(method.env, method) if (name, args) in self.methods: # If this method is already defined error_if("final" in modifiers(method), "Cannot override final methods.") error_if("static" in modifiers(self.methods[name, args]), "Cannot override a method with a static methods.") error_if("static" in modifiers(method), "Cannot override a static method.") error_if("protected" in modifiers(self.methods[name, args]) and "public" in modifiers(method), "A protected method must not override a public method.") error_if((return_type(self.methods[name, args]) != return_type(method)), "An overriding method cannot have a different return " + "type from what it is overriding") else: error_if(is_abstract(method) and "abstract" not in modifiers(self.tree), "Must override abstract method.") self.methods[name, args] = method
def add_method_from_parent_interface(self, method): name = method.get("name") args = argument_list_for_declaration(method.env, method) error_if((name, args) not in self.methods and "abstract" not in modifiers(self.tree) and "class" == self.tree.tag, "Must override interface methods") if ((name, args) in self.methods and "protected" in modifiers(self.methods[name, args]) and "public" in modifiers(method)): concrete_method = self.methods[name, args] if (concrete_method.find(".//block") is None and concrete_method not in self.tree.findall(".//method")): self.methods[name, args] = method else: error_if(True, "A protected method canot override a public method.") if (name, args) in self.methods: error_if((return_type(self.methods[name, args]) != return_type(method)), "An overriding method cannot have a different return " + "type from what it is overriding") else: self.methods[name, args] = method