将 OOP 代码转换为 AOP 的工具

发布于 2024-12-22 09:08:27 字数 60 浏览 3 评论 0原文

是否有任何开源工具可以将 OOP 代码(无论编程语言,即 .NET、Java 或 PHP)转换为 AOP?

Is there any open source tool which can transform the OOP code (irrespective of the programming language i.e. .NET, Java or PHP) into AOP?

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

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

发布评论

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

评论(1

能怎样 2024-12-29 09:08:27

你想要一个“AOPizer”。您似乎想要解决的问题有两个部分:

  • 在现有应用程序中查找潜在的横切代码
  • 将代码提取到该语言的方面

1) 第一个任务本质上需要一个克隆检测器。仅许多克隆检测器
找到相同的文本;这些不会很有帮助,因为你的方面可能
有必须从代码中获取的参数。 (如果您要登录
函数参数,方面必须通过这些参数以某种方式参数化)。
所以你需要一个可以找到参数化克隆的检测器。你也想要
这些克隆可以从代码中提取,因此无论发现什么都需要
对应于编程语言中一些明确定义的概念(表达式,
语句、块……)许多基于标记的克隆检测器可以找到按标识符参数化的克隆,但不理解语言结构,因此它们不会
有效地完成这项任务。

我们的 CloneDR 使用目标语言的抽象语法查找克隆
引导它;这需要精确的语言解析器;它有 PHP、Java、VB.net 和 C# 的解析器。它发现的克隆总是对应于上面定义的语言结构。它将找到作为单个标识符的参数,或任何较大的语言构造(表达式、语句等),这些参数在克隆之间一致变化。它生成人类可读的克隆集报告、所有实例的精确位置以及确切的参数值。它还生成相同信息的机器可读报告,使其他工具能够利用检测过程。 CloneDR 过去曾被用来寻找此类横切技术:从目标到方面:从需求目标模型中发现方面(我是 CloneDR 的作者)。

2) 有了克隆数据,您现在需要一个可以将克隆提取到方面的工具。首先,您需要定义方面语言,然后您需要一个可以解析语言、精确定位克隆、将它们抽象/翻译为此类方面的工具。据我所知,没有现成的工具可以直接执行此操作,因此您需要一个具有所有必要机制的自定义工具。我们的 DMS 软件再工程工具包在设计时就考虑到了构建此类自定义工具。
(这满足了我的评论中的“可以”部分;还需要做额外的工作才能得到你想要的东西)。事实上,DMS 已被用来为目前尚不具备方面工具的语言构建方面工具;请参阅使用程序转换引擎构建方面编织器的技术。 [CloneDR 实际上构建在 DMS 之上,这对您来说可能并不奇怪,更好的工程路径是运行 CloneDR 机器并将结果直接传递给自定义 AOP 提取代码,而不是通过中间导出/导入克隆数据位置)。

您还想要开源(每当我看到这个时,我都会将其视为“免费”的代号)。可惜的是,这些工具不是免费的。它们需要数十年的博士级工程来构建和完善(其中一些是我个人的十年;我是 DMS 的架构师),但我对免费这样做的想法有些困难。它们确实拥有商业许可证,并且可以以我们认为的所提供价值的适中价格获得(坦白说,价值的很大一部分是允许以通用方式构建这些工具的观点),并且有研究许可证。线下联系我们了解更多详情;看我的简历。

You want an "AOPizer". The problem you appear to want to solve has two parts:

  • Finding potentially cross-cutting code in an existing application
  • Extracting the code into aspects for that language

1) The first task requires essentially a clone detector. Many clone detectors only
find identical text; these won't be very helpful because your aspects likely
have parameters that have to be take from the code. (If you are going to log
function arguments, the aspect has to be parameterized somehow by those arguments).
So you want a detector that can find parameterized clones. You also want
those clones to be extractable from the code, so whatever it finds needs to
correspond to some well-defined concept in the programming language (expression,
statements, block, ...) Many token-based clone detectors can find parameterized-by-identifier clones, but don't understand the language structure, and so they won't
be effective for this task.

Our CloneDR finds clones using the abstract syntax of the targeted language
to guide it; this requires precise language parsers; it has such parsers for PHP, Java, VB.net and C#. The clones its finds always correspond to language structures as defined by the above. It will find parameters that are single identifiers, or any larger langauge construct (expression, statement, etc.) which consistently varies across the clones. It produces a human-readable report of clone sets and the precise location of all of their instances, as well as the exact parameter values. It also generates a machine-readable report of the same information, enabling another tool to take advantage of the detection process. CloneDR has been used to hunt for such cross-cutting techniques in the past: From goals to aspects: discovering aspects from requirements goal models (I'm the author of CloneDR).

2) Armed with clone data, you now need a tool that can extract the clones into aspects. First, you need to define the aspect language, then you need a tool that can parse the langauge, pin point the clones, abstract/translate them into such aspects. I know of no tools off-the-shelf that do this directly, so you'll need a custom tool that has all the necessary machinery. Our DMS Software Reengineering Toolkit is designed with building exactly such custom tools in mind.
(This satisfies the "could" part of my remark; there's additional work to do to get what you want). And in fact DMS has been used to build aspect tools for languages that don't presently have them; see A technique for constructing aspect weavers using a program transformation engine. [It might not be a surprise to you that CloneDR is actually built on top of DMS, and an even nicer engineering path would be run the CloneDR machinery and pass the results directly to custom AOP extraction code rather than going through an intermediate export/import of clone data locations).

You also wanted open source (whenever I see this, I read this as code words for "free"). Alas, these tools are not free. They have required decades of PhD level engineering to build and polish (some of those decades being my personal decades; I'm the architect of DMS) and I have some trouble with idea of doing that for free. They do have commercial licenses, and can be obtained at what we think are moderate prices for the value supplied (frankly IMHO a significant part of the value is the perspective that allowed these tools to built in a general way), and there are research licenses. Contact us offline for more details; see my bio.

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