eric6/Utilities/ClassBrowsers/rbclbr.py

changeset 7259
7c017076c12e
parent 7229
53054eb5b15a
child 7360
9190402e4505
equal deleted inserted replaced
7258:aff39db4dacc 7259:7c017076c12e
301 301
302 if m.start("Method") >= 0: 302 if m.start("Method") >= 0:
303 # found a method definition or function 303 # found a method definition or function
304 thisindent = indent 304 thisindent = indent
305 indent += 1 305 indent += 1
306 meth_name = m.group("MethodName") or \ 306 meth_name = (
307 m.group("MethodName2") or \ 307 m.group("MethodName") or
308 m.group("MethodName2") or
308 m.group("MethodName3") 309 m.group("MethodName3")
310 )
309 meth_sig = m.group("MethodSignature") 311 meth_sig = m.group("MethodSignature")
310 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' 312 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or ''
311 meth_sig = _commentsub('', meth_sig) 313 meth_sig = _commentsub('', meth_sig)
312 lineno = lineno + src.count('\n', last_lineno_pos, start) 314 lineno = lineno + src.count('\n', last_lineno_pos, start)
313 last_lineno_pos = start 315 last_lineno_pos = start
314 if meth_name.startswith('self.'): 316 if meth_name.startswith('self.'):
315 meth_name = meth_name[5:] 317 meth_name = meth_name[5:]
316 elif meth_name.startswith('self::'): 318 elif meth_name.startswith('self::'):
317 meth_name = meth_name[6:] 319 meth_name = meth_name[6:]
318 # close all classes/modules indented at least as much 320 # close all classes/modules indented at least as much
319 while classstack and \ 321 while classstack and classstack[-1][1] >= thisindent:
320 classstack[-1][1] >= thisindent:
321 if classstack[-1][0] is not None: 322 if classstack[-1][0] is not None:
322 # record the end line 323 # record the end line
323 classstack[-1][0].setEndLine(lineno - 1) 324 classstack[-1][0].setEndLine(lineno - 1)
324 del classstack[-1] 325 del classstack[-1]
325 while acstack and \ 326 while acstack and acstack[-1][1] >= thisindent:
326 acstack[-1][1] >= thisindent:
327 del acstack[-1] 327 del acstack[-1]
328 if classstack: 328 if classstack:
329 # it's a class/module method 329 # it's a class/module method
330 cur_class = classstack[-1][0] 330 cur_class = classstack[-1][0]
331 if isinstance(cur_class, Class) or \ 331 if (
332 isinstance(cur_class, Module): 332 isinstance(cur_class, Class) or
333 isinstance(cur_class, Module)
334 ):
333 # it's a method 335 # it's a method
334 f = Function(None, meth_name, 336 f = Function(None, meth_name,
335 file, lineno, meth_sig) 337 file, lineno, meth_sig)
336 cur_class._addmethod(meth_name, f) 338 cur_class._addmethod(meth_name, f)
337 else: 339 else:
380 thisindent = indent 382 thisindent = indent
381 indent += 1 383 indent += 1
382 lineno = lineno + src.count('\n', last_lineno_pos, start) 384 lineno = lineno + src.count('\n', last_lineno_pos, start)
383 last_lineno_pos = start 385 last_lineno_pos = start
384 # close all classes/modules indented at least as much 386 # close all classes/modules indented at least as much
385 while classstack and \ 387 while classstack and classstack[-1][1] >= thisindent:
386 classstack[-1][1] >= thisindent:
387 if classstack[-1][0] is not None: 388 if classstack[-1][0] is not None:
388 # record the end line 389 # record the end line
389 classstack[-1][0].setEndLine(lineno - 1) 390 classstack[-1][0].setEndLine(lineno - 1)
390 del classstack[-1] 391 del classstack[-1]
391 class_name = m.group("ClassName") or m.group("ClassName2") 392 class_name = m.group("ClassName") or m.group("ClassName2")
414 if lastGlobalEntry: 415 if lastGlobalEntry:
415 lastGlobalEntry.setEndLine(lineno - 1) 416 lastGlobalEntry.setEndLine(lineno - 1)
416 lastGlobalEntry = cur_class 417 lastGlobalEntry = cur_class
417 cur_obj = cur_class 418 cur_obj = cur_class
418 classstack.append((cur_class, thisindent)) 419 classstack.append((cur_class, thisindent))
419 while acstack and \ 420 while acstack and acstack[-1][1] >= thisindent:
420 acstack[-1][1] >= thisindent:
421 del acstack[-1] 421 del acstack[-1]
422 acstack.append(["public", thisindent]) 422 acstack.append(["public", thisindent])
423 # default access control is 'public' 423 # default access control is 'public'
424 424
425 elif m.start("Module") >= 0: 425 elif m.start("Module") >= 0:
427 thisindent = indent 427 thisindent = indent
428 indent += 1 428 indent += 1
429 lineno = lineno + src.count('\n', last_lineno_pos, start) 429 lineno = lineno + src.count('\n', last_lineno_pos, start)
430 last_lineno_pos = start 430 last_lineno_pos = start
431 # close all classes/modules indented at least as much 431 # close all classes/modules indented at least as much
432 while classstack and \ 432 while classstack and classstack[-1][1] >= thisindent:
433 classstack[-1][1] >= thisindent:
434 if classstack[-1][0] is not None: 433 if classstack[-1][0] is not None:
435 # record the end line 434 # record the end line
436 classstack[-1][0].setEndLine(lineno - 1) 435 classstack[-1][0].setEndLine(lineno - 1)
437 del classstack[-1] 436 del classstack[-1]
438 module_name = m.group("ModuleName") 437 module_name = m.group("ModuleName")
455 if lastGlobalEntry: 454 if lastGlobalEntry:
456 lastGlobalEntry.setEndLine(lineno - 1) 455 lastGlobalEntry.setEndLine(lineno - 1)
457 lastGlobalEntry = cur_class 456 lastGlobalEntry = cur_class
458 cur_obj = cur_class 457 cur_obj = cur_class
459 classstack.append((cur_class, thisindent)) 458 classstack.append((cur_class, thisindent))
460 while acstack and \ 459 while acstack and acstack[-1][1] >= thisindent:
461 acstack[-1][1] >= thisindent:
462 del acstack[-1] 460 del acstack[-1]
463 acstack.append(["public", thisindent]) 461 acstack.append(["public", thisindent])
464 # default access control is 'public' 462 # default access control is 'public'
465 463
466 elif m.start("AccessControl") >= 0: 464 elif m.start("AccessControl") >= 0:
467 aclist = m.group("AccessControlList") 465 aclist = m.group("AccessControlList")
468 if aclist is None: 466 if aclist is None:
469 index = -1 467 index = -1
470 while index >= -len(acstack): 468 while index >= -len(acstack):
471 if acstack[index][1] < indent: 469 if acstack[index][1] < indent:
472 actype = m.group("AccessControlType") or \ 470 actype = (
471 m.group("AccessControlType") or
473 m.group("AccessControlType2").split('_')[0] 472 m.group("AccessControlType2").split('_')[0]
473 )
474 acstack[index][0] = actype.lower() 474 acstack[index][0] = actype.lower()
475 break 475 break
476 else: 476 else:
477 index -= 1 477 index -= 1
478 else: 478 else:
479 index = -1 479 index = -1
480 while index >= -len(classstack): 480 while index >= -len(classstack):
481 if classstack[index][0] is not None and \ 481 if (
482 not isinstance(classstack[index][0], Function) and \ 482 classstack[index][0] is not None and
483 not classstack[index][1] >= indent: 483 not isinstance(classstack[index][0], Function) and
484 not classstack[index][1] >= indent
485 ):
484 parent = classstack[index][0] 486 parent = classstack[index][0]
485 actype = m.group("AccessControlType") or \ 487 actype = (
488 m.group("AccessControlType") or
486 m.group("AccessControlType2").split('_')[0] 489 m.group("AccessControlType2").split('_')[0]
490 )
487 actype = actype.lower() 491 actype = actype.lower()
488 for name in aclist.split(","): 492 for name in aclist.split(","):
489 name = name.strip()[1:] # get rid of leading ':' 493 name = name.strip()[1:] # get rid of leading ':'
490 acmeth = parent._getmethod(name) 494 acmeth = parent._getmethod(name)
491 if acmeth is None: 495 if acmeth is None:
503 elif m.start("Attribute") >= 0: 507 elif m.start("Attribute") >= 0:
504 lineno = lineno + src.count('\n', last_lineno_pos, start) 508 lineno = lineno + src.count('\n', last_lineno_pos, start)
505 last_lineno_pos = start 509 last_lineno_pos = start
506 index = -1 510 index = -1
507 while index >= -len(classstack): 511 while index >= -len(classstack):
508 if classstack[index][0] is not None and \ 512 if (
509 not isinstance(classstack[index][0], Function) and \ 513 classstack[index][0] is not None and
510 not classstack[index][1] >= indent: 514 not isinstance(classstack[index][0], Function) and
515 not classstack[index][1] >= indent
516 ):
511 attr = Attribute( 517 attr = Attribute(
512 module, m.group("AttributeName"), file, lineno) 518 module, m.group("AttributeName"), file, lineno)
513 classstack[index][0]._addattribute(attr) 519 classstack[index][0]._addattribute(attr)
514 break 520 break
515 else: 521 else:
521 elif m.start("Attr") >= 0: 527 elif m.start("Attr") >= 0:
522 lineno = lineno + src.count('\n', last_lineno_pos, start) 528 lineno = lineno + src.count('\n', last_lineno_pos, start)
523 last_lineno_pos = start 529 last_lineno_pos = start
524 index = -1 530 index = -1
525 while index >= -len(classstack): 531 while index >= -len(classstack):
526 if classstack[index][0] is not None and \ 532 if (
527 not isinstance(classstack[index][0], Function) and \ 533 classstack[index][0] is not None and
528 not classstack[index][1] >= indent: 534 not isinstance(classstack[index][0], Function) and
535 not classstack[index][1] >= indent
536 ):
529 parent = classstack[index][0] 537 parent = classstack[index][0]
530 if m.group("AttrType") is None: 538 if m.group("AttrType") is None:
531 nv = m.group("AttrList").split(",") 539 nv = m.group("AttrList").split(",")
532 if not nv: 540 if not nv:
533 break 541 break
534 name = nv[0].strip()[1:] # get rid of leading ':' 542 name = nv[0].strip()[1:] # get rid of leading ':'
535 attr = parent._getattribute("@" + name) or \ 543 attr = (
536 parent._getattribute("@@" + name) or \ 544 parent._getattribute("@" + name) or
545 parent._getattribute("@@" + name) or
537 Attribute(module, "@" + name, file, lineno) 546 Attribute(module, "@" + name, file, lineno)
547 )
538 if len(nv) == 1 or nv[1].strip() == "false": 548 if len(nv) == 1 or nv[1].strip() == "false":
539 attr.setProtected() 549 attr.setProtected()
540 elif nv[1].strip() == "true": 550 elif nv[1].strip() == "true":
541 attr.setPublic() 551 attr.setPublic()
542 parent._addattribute(attr) 552 parent._addattribute(attr)
543 else: 553 else:
544 access = m.group("AttrType") 554 access = m.group("AttrType")
545 for name in m.group("AttrList").split(","): 555 for name in m.group("AttrList").split(","):
546 name = name.strip()[1:] # get rid of leading ':' 556 name = name.strip()[1:] # get rid of leading ':'
547 attr = parent._getattribute("@" + name) or \ 557 attr = (
548 parent._getattribute("@@" + name) or \ 558 parent._getattribute("@" + name) or
559 parent._getattribute("@@" + name) or
549 Attribute(module, "@" + name, file, lineno) 560 Attribute(module, "@" + name, file, lineno)
561 )
550 if access == "_accessor": 562 if access == "_accessor":
551 attr.setPublic() 563 attr.setPublic()
552 elif access == "_reader" or access == "_writer": 564 elif access == "_reader" or access == "_writer":
553 if attr.isPrivate(): 565 if attr.isPrivate():
554 attr.setProtected() 566 attr.setProtected()

eric ide

mercurial