Skip to content
Snippets Groups Projects
Commit 86e39ea6 authored by Nicholas Robinson's avatar Nicholas Robinson
Browse files

set self.contains in super checkHierarchy

parent 84cccef3
Branches chris/feature/user-auth-api
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ class ClassInterNode(ASTNode): ...@@ -40,7 +40,7 @@ class ClassInterNode(ASTNode):
# 9. A class or interface must not contain (declare or inherit) two methods with the same signature but different return types # 9. A class or interface must not contain (declare or inherit) two methods with the same signature but different return types
# 11. A nonstatic method must not replace a static method # 11. A nonstatic method must not replace a static method
# 13. A protected method must not replace a public method # 13. A protected method must not replace a public method
return self.getContains([]) self.contains = self.getContains([])
def getContains(self, hierarchy): def getContains(self, hierarchy):
# check if not acyclic # check if not acyclic
...@@ -176,17 +176,15 @@ class ClassNode(ClassInterNode): ...@@ -176,17 +176,15 @@ class ClassNode(ClassInterNode):
raise Exception("ERROR: Class '{}' declares 2 constructors with the same parameter types".format(self.name)) raise Exception("ERROR: Class '{}' declares 2 constructors with the same parameter types".format(self.name))
unique.append(key) unique.append(key)
# centralized point for overlapping class & interface logic # centralized point for overlapping class & interface logic. Also sets self.contains
contains = super().checkHierarchy() super().checkHierarchy()
# 10. A class that contains (declares or inherits) any abstract methods must be abstract. # 10. A class that contains (declares or inherits) any abstract methods must be abstract.
for con in contains: for con in self.contains:
if 'abstract' in con.mods and (not('abstract' in self.mods)): if 'abstract' in con.mods and (not('abstract' in self.mods)):
raise Exception("ERROR: Non-abstract Class '{}' contains an abstract method".format(self.name)) raise Exception("ERROR: Non-abstract Class '{}' contains an abstract method".format(self.name))
if (not con.body) and (not ('native' in con.mods)) and (not ('abstract' in self.mods)) and (not (con in self.constructors)): if (not con.body) and (not ('native' in con.mods)) and (not ('abstract' in self.mods)) and (not (con in self.constructors)):
raise Exception("ERROR: Non-abstract Class '{}' contains an abstract method {}".format(self.name, con.name)) raise Exception("ERROR: Non-abstract Class '{}' contains an abstract method {}".format(self.name, con.name))
self.contains = contains
# hierarchy: string[] # hierarchy: string[]
def getContains(self, hierarchy): def getContains(self, hierarchy):
...@@ -290,8 +288,8 @@ class InterNode(ClassInterNode): ...@@ -290,8 +288,8 @@ class InterNode(ClassInterNode):
raise Exception("ERROR: Interface '{}' extends duplicate interfaces '{}'".format(self.name, inter.name)) raise Exception("ERROR: Interface '{}' extends duplicate interfaces '{}'".format(self.name, inter.name))
unique.append(inter.name) unique.append(inter.name)
# centralized point for overlapping class & interface logic # centralized point for overlapping class & interface logic. Also sets self.contains
self.contains = super().checkHierarchy() super().checkHierarchy()
# hierarchy: string[] # hierarchy: string[]
def getContains(self, hierarchy): def getContains(self, hierarchy):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment