diff --git a/Test.py b/Test.py index 7a5215256244acade8d57c4b2a207138bd43cf05..13df40ff887fde42a899f95cf1cdb244fb1f1d58 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 69a1a345b2c7faf58f05392ec7ad7ee663d4bb85..39d0f5dd346cafd5970da7858de5fc0cb5555134 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