def registerClassImplementation(classname, proto):
    """ (internal) Add an implementation for a class

    Use @JImplementationFor(cls) to access this.
    """
    if classname in _JP_IMPLEMENTATIONS:
        _JP_IMPLEMENTATIONS[classname].append(proto)
    else:
        _JP_IMPLEMENTATIONS[classname] = [proto]

    # If we have already created a class, apply it retroactively.
    if _jpype._hasClass(classname):
        _applyCustomizerPost(_jpype._getClass(classname), proto)
def registerClassBase(name, cls):
    """ (internal) Add an implementation for a class

    Use @JImplementationFor(cls, base=True) to access this.

    """
    if name in _JP_BASES:
        _JP_BASES[name].append(cls)
    else:
        _JP_BASES[name] = [cls]

    # Changing the base class in python can break things,
    # so we will tag this as an error for now.
    if _jpype._hasClass(name):
        raise TypeError(
            "Base classes must be added before class is created")
Ejemplo n.º 3
0
 def testModuleHasClass(self):
     self.assertTrue(_jpype._hasClass("java.lang.Object"))
Ejemplo n.º 4
0
 def testHasClass(self):
     with self.assertRaisesRegex(TypeError, "not found"):
         _jpype._hasClass("not.a.class")
     with self.assertRaisesRegex(TypeError, "str is required"):
         _jpype._hasClass(object())
Ejemplo n.º 5
0
 def testHasClass(self):
     self.assertTrue(_jpype._hasClass("java.lang.String"))
     with self.assertRaises(TypeError):
         _jpype._hasClass(object())