Example #1
0
    def getDescription(self, text):
        try:
            obj = None
            if '.' not in text:
                try:
                    obj = self.get_namespace()[text]
                except KeyError:
                    return ''

            else:
                try:
                    splitted = text.split('.')
                    obj = self.get_namespace()[splitted[0]]
                    for t in splitted[1:]:
                        obj = getattr(obj, t)
                except:
                    return ''

            if obj is not None:
                try:
                    if sys.platform.startswith("java"):
                        #Jython
                        doc = obj.__doc__
                        if doc is not None:
                            return doc

                        from _pydev_bundle import _pydev_jy_imports_tipper

                        is_method, infos = _pydev_jy_imports_tipper.ismethod(
                            obj)
                        ret = ''
                        if is_method:
                            for info in infos:
                                ret += info.get_as_doc()
                            return ret

                    else:
                        #Python and Iron Python
                        import inspect  #@UnresolvedImport

                        doc = inspect.getdoc(obj)
                        if doc is not None:
                            return doc
                except:
                    pass

            try:
                #if no attempt succeeded, try to return repr()...
                return repr(obj)
            except:
                try:
                    #otherwise the class
                    return str(obj.__class__)
                except:
                    #if all fails, go to an empty string
                    return ''
        except:
            traceback.print_exc()
            return ''
Example #2
0
    def getDescription(self, text):
        try:
            obj = None
            if '.' not in text:
                try:
                    obj = self.get_namespace()[text]
                except KeyError:
                    return ''

            else:
                try:
                    splitted = text.split('.')
                    obj = self.get_namespace()[splitted[0]]
                    for t in splitted[1:]:
                        obj = getattr(obj, t)
                except:
                    return ''

            if obj is not None:
                try:
                    if sys.platform.startswith("java"):
                        #Jython
                        doc = obj.__doc__
                        if doc is not None:
                            return doc

                        from _pydev_bundle import _pydev_jy_imports_tipper

                        is_method, infos = _pydev_jy_imports_tipper.ismethod(obj)
                        ret = ''
                        if is_method:
                            for info in infos:
                                ret += info.get_as_doc()
                            return ret

                    else:
                        #Python and Iron Python
                        import inspect #@UnresolvedImport

                        doc = inspect.getdoc(obj)
                        if doc is not None:
                            return doc
                except:
                    pass

            try:
                #if no attempt succeeded, try to return repr()...
                return repr(obj)
            except:
                try:
                    #otherwise the class
                    return str(obj.__class__)
                except:
                    #if all fails, go to an empty string
                    return ''
        except:
            traceback.print_exc()
            return ''
def get_docstring(obj):
    if obj is not None:
        try:
            if IS_JYTHON:
                # Jython
                doc = obj.__doc__
                if doc is not None:
                    return doc

                from _pydev_bundle import _pydev_jy_imports_tipper

                is_method, infos = _pydev_jy_imports_tipper.ismethod(obj)
                ret = ''
                if is_method:
                    for info in infos:
                        ret += info.get_as_doc()
                    return ret

            else:

                doc = inspect.getdoc(obj)
                if doc is not None:
                    return doc
        except:
            pass
    else:
        return ''
    try:
        # if no attempt succeeded, try to return repr()...
        return repr(obj)
    except:
        try:
            # otherwise the class
            return str(obj.__class__)
        except:
            # if all fails, go to an empty string
            return ''
Example #4
0
def get_docstring(obj):
    if obj is not None:
        try:
            if IS_JYTHON:
                # Jython
                doc = obj.__doc__
                if doc is not None:
                    return doc

                from _pydev_bundle import _pydev_jy_imports_tipper

                is_method, infos = _pydev_jy_imports_tipper.ismethod(obj)
                ret = ''
                if is_method:
                    for info in infos:
                        ret += info.get_as_doc()
                    return ret

            else:

                doc = inspect.getdoc(obj)
                if doc is not None:
                    return doc
        except:
            pass
    else:
        return ''
    try:
        # if no attempt succeeded, try to return repr()...
        return repr(obj)
    except:
        try:
            # otherwise the class
            return str(obj.__class__)
        except:
            # if all fails, go to an empty string
            return ''
    def test_getting_info_on_jython(self):

        dbg('\n\n--------------------------- java')
        assert not ismethod(java)[0]
        assert not isclass(java)
        assert _pydev_jy_imports_tipper.ismodule(java)

        dbg('\n\n--------------------------- java.lang')
        assert not ismethod(java.lang)[0]
        assert not isclass(java.lang)
        assert _pydev_jy_imports_tipper.ismodule(java.lang)

        dbg('\n\n--------------------------- Method')
        assert not ismethod(Method)[0]
        assert isclass(Method)

        dbg('\n\n--------------------------- System')
        assert not ismethod(System)[0]
        assert isclass(System)

        dbg('\n\n--------------------------- String')
        assert not ismethod(System)[0]
        assert isclass(String)
        assert len(dir_obj(String)) > 10

        dbg('\n\n--------------------------- arraycopy')
        isMet = ismethod(arraycopy)
        assert isMet[0]
        assert isMet[1][0].basic_as_str() == "function:arraycopy args=['java.lang.Object', 'int', 'java.lang.Object', 'int', 'int'], varargs=None, kwargs=None, docs:None"
        assert not isclass(arraycopy)

        dbg('\n\n--------------------------- out')
        isMet = ismethod(out)
        assert not isMet[0]
        assert not isclass(out)

        dbg('\n\n--------------------------- out.println')
        isMet = ismethod(out.println) #@UndefinedVariable
        assert isMet[0]
        assert len(isMet[1]) == 10
        self.assertEqual(isMet[1][0].basic_as_str(), "function:println args=[], varargs=None, kwargs=None, docs:None")
        assert isMet[1][1].basic_as_str() == "function:println args=['long'], varargs=None, kwargs=None, docs:None"
        assert not isclass(out.println) #@UndefinedVariable

        dbg('\n\n--------------------------- str')
        isMet = ismethod(str)
        #the code below should work, but is failing on jython 22a1
        #assert isMet[0]
        #assert isMet[1][0].basic_as_str() == "function:str args=['org.python.core.PyObject'], varargs=None, kwargs=None, docs:None"
        assert not isclass(str)


        def met1():
            a = 3
            return a

        dbg('\n\n--------------------------- met1')
        isMet = ismethod(met1)
        assert isMet[0]
        assert isMet[1][0].basic_as_str() == "function:met1 args=[], varargs=None, kwargs=None, docs:None"
        assert not isclass(met1)

        def met2(arg1, arg2, *vararg, **kwarg):
            '''docmet2'''

            a = 1
            return a

        dbg('\n\n--------------------------- met2')
        isMet = ismethod(met2)
        assert isMet[0]
        assert isMet[1][0].basic_as_str() == "function:met2 args=['arg1', 'arg2'], varargs=vararg, kwargs=kwarg, docs:docmet2"
        assert not isclass(met2)
Example #6
0
    def test_getting_info_on_jython(self):

        dbg('\n\n--------------------------- java')
        assert not ismethod(java)[0]
        assert not isclass(java)
        assert _pydev_jy_imports_tipper.ismodule(java)

        dbg('\n\n--------------------------- java.lang')
        assert not ismethod(java.lang)[0]
        assert not isclass(java.lang)
        assert _pydev_jy_imports_tipper.ismodule(java.lang)

        dbg('\n\n--------------------------- Method')
        assert not ismethod(Method)[0]
        assert isclass(Method)

        dbg('\n\n--------------------------- System')
        assert not ismethod(System)[0]
        assert isclass(System)

        dbg('\n\n--------------------------- String')
        assert not ismethod(System)[0]
        assert isclass(String)
        assert len(dir_obj(String)) > 10

        dbg('\n\n--------------------------- arraycopy')
        isMet = ismethod(arraycopy)
        assert isMet[0]
        assert isMet[1][0].basic_as_str(
        ) == "function:arraycopy args=['java.lang.Object', 'int', 'java.lang.Object', 'int', 'int'], varargs=None, kwargs=None, docs:None"
        assert not isclass(arraycopy)

        dbg('\n\n--------------------------- out')
        isMet = ismethod(out)
        assert not isMet[0]
        assert not isclass(out)

        dbg('\n\n--------------------------- out.println')
        isMet = ismethod(out.println)  #@UndefinedVariable
        assert isMet[0]
        assert len(isMet[1]) == 10
        self.assertEqual(
            isMet[1][0].basic_as_str(),
            "function:println args=[], varargs=None, kwargs=None, docs:None")
        assert isMet[1][1].basic_as_str(
        ) == "function:println args=['long'], varargs=None, kwargs=None, docs:None"
        assert not isclass(out.println)  #@UndefinedVariable

        dbg('\n\n--------------------------- str')
        isMet = ismethod(str)
        #the code below should work, but is failing on jython 22a1
        #assert isMet[0]
        #assert isMet[1][0].basic_as_str() == "function:str args=['org.python.core.PyObject'], varargs=None, kwargs=None, docs:None"
        assert not isclass(str)

        def met1():
            a = 3
            return a

        dbg('\n\n--------------------------- met1')
        isMet = ismethod(met1)
        assert isMet[0]
        assert isMet[1][0].basic_as_str(
        ) == "function:met1 args=[], varargs=None, kwargs=None, docs:None"
        assert not isclass(met1)

        def met2(arg1, arg2, *vararg, **kwarg):
            '''docmet2'''

            a = 1
            return a

        dbg('\n\n--------------------------- met2')
        isMet = ismethod(met2)
        assert isMet[0]
        assert isMet[1][0].basic_as_str(
        ) == "function:met2 args=['arg1', 'arg2'], varargs=vararg, kwargs=kwarg, docs:docmet2"
        assert not isclass(met2)