itchyny / rexdep

Roughly extract dependency relation from source code
MIT License
176 stars 8 forks source link

Possible test with swift #3

Closed steve21124 closed 8 years ago

steve21124 commented 8 years ago

let say for swift language and need to search for all classes that use UITableview. what will be the right regular expression?

https://github.com/hilen/TSWeChat

final class TSChatViewController: UIViewController {
    var messageModel: MessageModel?
    @IBOutlet var refreshView: UIView!
    @IBOutlet weak var indicatorView: UIActivityIndicatorView!

    lazy var listTableView: UITableView = {
        let listTableView = UITableView(frame: CGRect.zero, style: .Plain)
        listTableView.dataSource = self
        listTableView.delegate = self
        listTableView.backgroundColor = UIColor.clearColor()
        listTableView.separatorStyle = .None
        // This background image is stolen from Telegram App
        listTableView.backgroundView = UIImageView(image: TSAsset.Chat_background.image)
        return listTableView
    }()

    var chatActionBarView: TSChatActionBarView!  //action bar
itchyny commented 8 years ago
 $ rexdep --pattern '^(?:final\s+)?(?:class|extension)\s+([[:alnum:]]+)' --module 'UITableView' --reverse --recursive .
UITableView MessageContentType
UITableView TSChatBaseCell
UITableView TSChatSystemCell
UITableView TSChatTimeCell
UITableView TSChatViewController
UITableView TSContactTableViewCell
UITableView TSContactsViewController
UITableView TSDiscoverViewController
UITableView TSImageTextTableViewCell
UITableView TSMeAvatarTableViewCell
UITableView TSMeViewController
UITableView TSMessageTableViewCell
UITableView TSMessageViewController
UITableView UITableView
steve21124 commented 8 years ago

Thank you. This definitely a great starting point to start exploring it with swift

steve21124 commented 8 years ago

sorry one more favor to ask. UITableViewCell is hardcode. how to get all the subclass and use that to loop through the pattern.

  1. write loop statement for each NSObject,TSChatBaseCell,TSModelProtocol, and call rexdep or
  2. some how in the module. it be able to pickup "something" between ":" and "{" => in the class.

I did see from the readme => --module '^module +([[:alnum:].]+Pandoc[[:alnum:].]*)'

====> ====== class AudioPlayManager: NSObject { class TSChatSystemCell: UITableViewCell class TSChatVoiceCell: TSChatBaseCell { @objc class ContactModel: NSObject, TSModelProtocol { class TSContactsViewController: UIViewController { class TSMessageActionFloatView: UIView {

itchyny commented 8 years ago

I'm not sure what you mean but how about this?

 $ rexdep --module 'class\s+([[:alnum:]]+)\s*:\s*(?:[[:alnum:]]+)' --pattern 'class\s+(?:[[:alnum:]]+)\s*:\s*([[:alnum:]]+)(?:\s*,\s*([[:alnum:]]+))?' --recursive --format dot . | dot -Tpng -o tswechat.png; open tswechat.png
steve21124 commented 8 years ago

yes, you got it right. great to know be able to get the module name