--- a/src/eric7/Utilities/ClassBrowsers/protoclbr.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Utilities/ClassBrowsers/protoclbr.py Wed Jul 13 14:55:47 2022 +0200 @@ -17,7 +17,7 @@ from . import ClbrBaseClasses SUPPORTED_TYPES = [ClassBrowsers.PROTO_SOURCE] - + _getnext = re.compile( r""" (?P<String> @@ -79,20 +79,22 @@ | (?P<End> [ \t]* } [ \t]* ;? )""", - re.VERBOSE | re.DOTALL | re.MULTILINE).search + re.VERBOSE | re.DOTALL | re.MULTILINE, +).search # function to replace comments _commentsub = re.compile(r"""//[^\n]*\n|//[^\n]*$""").sub # function to normalize whitespace _normalize = re.compile(r"""[ \t]{2,}""").sub -_modules = {} # cache of modules we've seen +_modules = {} # cache of modules we've seen class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): """ Mixin class implementing the notion of visibility. """ + def __init__(self): """ Constructor @@ -104,10 +106,11 @@ """ Class to represent a ProtoBuf Message. """ + def __init__(self, module, name, file, lineno): """ Constructor - + @param module name of the module containing this message @type str @param name name of this message @@ -125,10 +128,11 @@ """ Class to represent a ProtoBuf Enum. """ + def __init__(self, module, name, file, lineno): """ Constructor - + @param module name of the module containing this enum @type str @param name name of this enum @@ -146,10 +150,11 @@ """ Class to represent a ProtoBuf Service. """ + def __init__(self, module, name, file, lineno): """ Constructor - + @param module name of the module containing this service @type str @param name name of this service @@ -159,8 +164,7 @@ @param lineno linenumber of the service definition @type int """ - ClbrBaseClasses.Class.__init__(self, module, name, None, file, - lineno) + ClbrBaseClasses.Class.__init__(self, module, name, None, file, lineno) VisibilityMixin.__init__(self) @@ -168,10 +172,11 @@ """ Class to represent a ProtoBuf Service Method. """ + def __init__(self, name, file, lineno, signature, returns): """ Constructor - + @param name name of this service method @type str @param file filename containing this service method @@ -183,9 +188,15 @@ @param returns return type of the service method @type str """ - ClbrBaseClasses.Function.__init__(self, None, name, file, lineno, - signature, - annotation="-> {0}".format(returns)) + ClbrBaseClasses.Function.__init__( + self, + None, + name, + file, + lineno, + signature, + annotation="-> {0}".format(returns), + ) VisibilityMixin.__init__(self) @@ -202,7 +213,7 @@ @rtype dict """ global _modules - + if module in _modules: # we've seen this file before... return _modules[module] @@ -224,7 +235,7 @@ # can't do anything with this module _modules[module] = {} return {} - + _modules[module] = scan(src, file, module) return _modules[module] @@ -232,7 +243,7 @@ def scan(src, file, module): """ Public method to scan the given source text. - + @param src source text to be scanned @type str @param file file name associated with the source text @@ -242,10 +253,11 @@ @return dictionary containing the extracted data @rtype dict """ + def calculateEndline(lineno, lines): """ Function to calculate the end line. - + @param lineno line number to start at (one based) @type int @param lines list of source lines @@ -269,7 +281,7 @@ else: # nothing found return -1 - + # convert eol markers the Python style src = src.replace("\r\n", "\n").replace("\r", "\n") srcLines = src.splitlines() @@ -292,14 +304,14 @@ thisindent = indent meth_name = m.group("MethodName") meth_sig = m.group("MethodSignature") - meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' - meth_sig = _commentsub('', meth_sig) - meth_sig = _normalize(' ', meth_sig) + meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" + meth_sig = _commentsub("", meth_sig) + meth_sig = _normalize(" ", meth_sig) meth_return = m.group("MethodReturn") - meth_return = meth_return and meth_return.replace('\\\n', '') or '' - meth_return = _commentsub('', meth_return) - meth_return = _normalize(' ', meth_return) - lineno += src.count('\n', last_lineno_pos, start) + meth_return = meth_return and meth_return.replace("\\\n", "") or "" + meth_return = _commentsub("", meth_return) + meth_return = _normalize(" ", meth_return) + lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start # close all interfaces/modules indented at least as much while classstack and classstack[-1][1] >= thisindent: @@ -309,8 +321,7 @@ cur_class = classstack[-1][0] if isinstance(cur_class, Service): # it's a method - f = ServiceMethod(meth_name, file, lineno, meth_sig, - meth_return) + f = ServiceMethod(meth_name, file, lineno, meth_sig, meth_return) cur_class._addmethod(meth_name, f) # else it's a nested def else: @@ -330,7 +341,7 @@ # we found a message definition thisindent = indent indent += 1 - lineno += src.count('\n', last_lineno_pos, start) + lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start message_name = m.group("MessageName") # close all messages/services indented at least as much @@ -354,7 +365,7 @@ # close all messages/services indented at least as much while classstack and classstack[-1][1] >= thisindent: del classstack[-1] - lineno += src.count('\n', last_lineno_pos, start) + lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start enum_name = m.group("EnumName") # remember this Enum @@ -375,7 +386,7 @@ # close all messages/services indented at least as much while classstack and classstack[-1][1] >= thisindent: del classstack[-1] - lineno += src.count('\n', last_lineno_pos, start) + lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start service_name = m.group("ServiceName") # remember this Service