From 3abebdf034f7a6f5fa49b32f90fbd330fc3615b8 Mon Sep 17 00:00:00 2001 From: Nicholas Robinson <nwrobins@edu.uwaterloo.ca> Date: Fri, 28 Feb 2020 22:53:36 -0500 Subject: [PATCH] inheritence from Object & Test.py format --- Test.py | 2 +- TypeNodes.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Test.py b/Test.py index 7a52152..13df40f 100644 --- a/Test.py +++ b/Test.py @@ -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)) diff --git a/TypeNodes.py b/TypeNodes.py index 69a1a34..39d0f5d 100644 --- a/TypeNodes.py +++ b/TypeNodes.py @@ -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 -- GitLab