Ejemplo n.º 1
0
 def testInheritForeignTypeInForeignTypeInSamePackage(self):
     package = Package(name=Name(["foo"]))
     barClass = package.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[],
                                 supertypes=[getRootClassType()],
                                 constructors=[], fields=[],
                                 methods=[], flags=frozenset([PUBLIC]))
     bazClass = package.addClass(Name(["Baz"]), sourceName="Baz", typeParameters=[],
                                 supertypes=[ClassType(barClass), getRootClassType()],
                                 constructors=[], fields=[],
                                 methods=[], flags=frozenset([PUBLIC]))
     loader = FakePackageLoader([package])
     info = self.analyzeFromSource("class Quux <: foo.Baz", packageLoader=loader)
     quuxClass = info.package.findClass(name="Quux")
     self.assertEquals([ClassType(bazClass), ClassType(barClass), getRootClassType()],
                       quuxClass.supertypes)
Ejemplo n.º 2
0
 def testInheritForeignTypeInForeignTypeInDifferentPackage(self):
     fooPackage = Package(name=Name(["foo"]))
     barClass = fooPackage.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[],
                                    supertypes=[getRootClassType()],
                                    constructors=[], fields=[],
                                    methods=[], flags=frozenset([PUBLIC]))
     bazPackage = Package(name=Name(["baz"]))
     loader = FakePackageLoader([fooPackage, bazPackage])
     bazPackage.dependencies.append(PackageDependency.fromPackage(fooPackage))
     quuxClass = bazPackage.addClass(Name(["Quux"]), sourceName="Quux", typeParameters=[],
                                     supertypes=[ClassType(barClass), getRootClassType()],
                                     constructors=[], fields=[],
                                     methods=[], flags=frozenset([PUBLIC]))
     info = self.analyzeFromSource("class Zzyzx <: baz.Quux", packageLoader=loader)
     zzyzxClass = info.package.findClass(name="Zzyzx")
     self.assertEquals([ClassType(quuxClass), ClassType(barClass), getRootClassType()],
                       zzyzxClass.supertypes)
Ejemplo n.º 3
0
 def testTypeParameterCycleForeign(self):
     package = Package(name=Name(["foo"]))
     barClass = package.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[],
                                 supertypes=[getRootClassType()],
                                 constructors=[], fields=[],
                                 methods=[], flags=frozenset([PUBLIC]))
     loader = FakePackageLoader([package])
     source = "class Baz <: foo.Bar\n" + \
              "def f[static T <: Baz >: foo.Bar] = ()"
     self.assertRaises(InheritanceException, self.analyzeFromSource, source, packageLoader=loader)
Ejemplo n.º 4
0
    def testInheritFromImportedClass(self):
        foo = Package(name=Name(["foo"]))
        Bar = foo.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[],
                           supertypes=[getRootClassType()],
                           constructors=[], fields=[],
                           methods=[], flags=frozenset([PUBLIC]))
        x = foo.newField(Name(["Bar", "x"]), sourceName="x", flags=frozenset([PUBLIC, LET]))
        Bar.fields.append(x)

        source = "import foo.Bar\n" + \
                 "class Baz <: Bar"
        info = self.analyzeFromSource(source, packageLoader=FakePackageLoader([foo]))
        bazScope = info.getScope(info.ast.modules[0].definitions[1])
        self.assertTrue(bazScope.isBound("x"))
Ejemplo n.º 5
0
 def testInheritFromForeignType(self):
     package = Package(name=Name(["foo"]))
     foreignClass = package.addClass(Name(["Bar"]), sourceName="Bar", typeParameters=[],
                                     supertypes=[getRootClassType()],
                                     constructors=[], fields=[],
                                     methods=[], flags=frozenset([PUBLIC]))
     field = package.newField(Name(["Bar", "x"]), sourceName="x", flags=frozenset([PUBLIC]))
     foreignClass.fields = [field]
     loader = FakePackageLoader([package])
     source = "class Baz <: foo.Bar"
     info = self.analyzeFromSource(source, packageLoader=loader)
     bazClass = info.package.findClass(name="Baz")
     self.assertEquals([ClassType(foreignClass), getRootClassType()], bazClass.supertypes)
     bazScope = info.getScope(bazClass)
     self.assertTrue(bazScope.isBound("x"))