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

inheritence from Object & Test.py format

parent 99cbffd7
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,7 @@ def a2Multiple():
else:
correct += 1
print("\nSCORE: {} / {} -> {}%".format(correct, total, (correct/total)*100))
print("\nSCORE: {} / {} -> {:.3g}%".format(correct, total, (correct/total)*100))
......
......@@ -178,8 +178,6 @@ class ClassNode(ClassInterNode):
for con in superContains:
conOverwritten = False
for method in contains:
print(method)
print(con)
if (method == con):
# cannot have same signiture but different return types
if (method.methodType != con.methodType):
......@@ -267,4 +265,29 @@ class InterNode(ClassInterNode):
# hierarchy: string[]
def getContains(self, hierarchy):
# centralized logic
return super().getContains(hierarchy)
contains = super().getContains(hierarchy)
canonName = self.packageName + '.' + self.name
# an interface without any super interfaces implicitly declares an abstract version of every public method in java.lang.Object
if not self.superInter:
addToContains = []
objectInterface = self.env.getNode('java.lang.Object', 'type')
superContains = objectInterface.getContains(hierarchy + [canonName])
for con in superContains:
conOverwritten = False
if 'public' in con.mods:
for method in self.methods:
if (method == con):
# cannot have same signiture but different return types
if (method.methodType != con.methodType):
raise Exception("ERROR: Class '{}' contains 2 methods '{}' with the same signature but different return types".format(self.name, method.name))
# protected must not replace public
if 'protected' in method.mods and 'public' in con.mods:
raise Exception("ERROR: Protected method '{}' in class '{}' replaces public method '{}' in class {}".format(method.name, self.name, con.name, inter.name))
conOverwritten = True
break
if not conOverwritten:
addToContains.append(con)
# contains += addToContains # this is causing very VERY WEIRD ERRORS I AM VERY FRUSTRATED, DO NOT UNCOMMENT THIS IF YOU WISH TO HAVE A GOOD TIME, UNCOMMENT AT YOUR PERIL
return contains
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