Pharo 和 Squeak Smalltalk:列出包中未实现的方法?

发布于 2024-12-24 23:03:55 字数 166 浏览 3 评论 0原文

如何列出包中所有未实现的方法?鉴于该方法应该在该包中实现,而不是在其他包中实现(例如在包外的超类中或在 Object 中)。

编辑:是的,我想知道“发送的未实现的消息”,但将分析限制为一个特定的给定包,例如:

FooPackage unimplementedMessageSends。

How do I list all unimplemented methods in a package? Given that the method should be implemented in that package and not in other (for example in a superclass outside the package or in Object).

Edit: Yes, I'd like to know "messages sent that are not implemented" but to limit the analysis to one specific given package, for ex:

FooPackage unimplementedMessageSends.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-12-31 23:03:55

我还没有对此进行全面测试,因此您可能需要对其进行一些调整以满足您的要求,但从我对您问题的理解来看,您可能会遇到这样的事情:

| allMethodsSent allMethodsImplemented |
allMethodsSent := IdentitySet new.
allMethodsImplemented := IdentitySet new.
(SystemOrganization listAtCategoryNamed: #'Collections-Arrayed')
    do: [:eachClassName |
        (Smalltalk at: eachClassName) methodDictionary valuesDo: [:eachMethod |
            allMethodsSent addAll: eachMethod messages.
            ].
        allMethodsImplemented addAll: (Smalltalk at: eachClassName) selectors
        ].
^allMethodsSent
    removeAllFoundIn: allMethodsImplemented;
    yourself

希望这至少可以帮助您开始,如果您需要调整它,看看类 Behavior (看看你可以使用什么,而不是改变它!),CompiledMethodSystemOrganization.

显然这个例子使用了类别(我假设这就是你所说的包的意思?)“Collections-Arrayed”,但是你当然可以调整它以使其成为方法参数,例如:

MyUtilClass unimplementedMessageSendsFor: aCategorySymbol

I haven't fully tested this so you might need to tweak it a bit to suit your requirements, but from how I understand your question, you might be after something like this:

| allMethodsSent allMethodsImplemented |
allMethodsSent := IdentitySet new.
allMethodsImplemented := IdentitySet new.
(SystemOrganization listAtCategoryNamed: #'Collections-Arrayed')
    do: [:eachClassName |
        (Smalltalk at: eachClassName) methodDictionary valuesDo: [:eachMethod |
            allMethodsSent addAll: eachMethod messages.
            ].
        allMethodsImplemented addAll: (Smalltalk at: eachClassName) selectors
        ].
^allMethodsSent
    removeAllFoundIn: allMethodsImplemented;
    yourself

Hopefully that'll help you get started at least, if you need to tweak it, have a look at the classes Behavior (to see what you can use, not to change it!), CompiledMethod, and SystemOrganization.

Obviously this example uses the category (I'm assuming that's what you mean by package?) "Collections-Arrayed", but you could of course adapt it to make that a method parameter, something like:

MyUtilClass unimplementedMessageSendsFor: aCategorySymbol
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文