用于测试 Java 类结构的库或框架

发布于 2024-11-17 21:56:51 字数 310 浏览 2 评论 0原文

我有这组类,我用它们来查看创建的类是否与给定的结构匹配。我正在做的是读取属性文件,然后将其与类进行比较。

IE。

className: demo.HelloWorld
classFile: demo/HelloWorld.class
methods:   public static main(java/lang.String[]) : void 
attributes: name : java.lang.String

等等。

在我继续从事类似的工作之前,我想知道是否有人知道可以做同样事情的库或框架。

I have this ... set of classes that I use to see if a created class matches a given structure. What I'm doing is to read a properties file and then compare it with a class.

ie.

className: demo.HelloWorld
classFile: demo/HelloWorld.class
methods:   public static main(java/lang.String[]) : void 
attributes: name : java.lang.String

And so on.

Before I continue working on something like this, I would like to know if anyone knows of a library or framework to do the same.

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

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

发布评论

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

评论(4

诗化ㄋ丶相逢 2024-11-24 21:56:51

为了做好这一点,您需要一个 Java 解析器,它能够解析“结构”(Java 片段),并且可能能够查找所涉及的类型。 (使用某些脚本语言,您可能会做得很糟糕,但它会非常脆弱,并且容易产生误报,这会占用您希望此工具可以节省您的时间)。

我们的 DMS 软件重组工具包及其 Java Front End 是一个具有这些功能的框架。 DMS 旨在使人们能够构建任意自定义工具来分析或转换源代码。
DMS 提供解析器(由所选前端定义)、AST 构建器、C、C++、Java 和 COBOL 等语言的符号表构造、用于按程序和使用表面语法模式检查树的工具,这些工具使您能够直接表达代码片段(由前端解析确定)以用于代码生成或模式匹配目的。

对于您想要执行的任务,您可以让 DMS 解析感兴趣的软件,并进行名称和类型解析(构建符号表)。然后,您需要使用 DMS 的模式解析器来读取“规范文件”作为一组方法签名等,并使用名称解析器来定位/查找标识符(例如“demo.Helloworld”),找到相应的类,然后然后将解析的模式与方法签名进行匹配,不匹配会报告不一致,这就是我认为您正在寻找的。

To do this well, you'd need to have a Java parser that was able to parse the "structures" (Java fragments) and likely able to look up the types involved. (You could likely do this badly with some scripting langauge, but it would be extremely fragile and prone to producing false negatives, which would eat the very time you hope this tool might save you).

Our DMS Software Reengineering Toolkit with its Java Front End is a framework that has these capabilities. DMS is designed to enable one to build arbitrary custom tools for analyzing or transforming source code.
DMS provides parsers (which one is defined by the chosen front end), AST builders, symbol table construction for languages such a C, C++, Java and COBOL, tools for inspecting trees both procedurally and using surface syntax patterns, which allow to you to directly express fragments of code (as determined by the front end parse) for code generation or pattern matching purposes.

For the task you want to do, you'd have DMS parse the software of interest, and do name and type resolution (build up the symbol tables). Then you would want to use DMS's pattern parser to read your "specification file" as a set of method signatures, etc, and using the name resolver to locate/lookup identifiers (e.g, "demo.Helloworld), find the corresponding classes, and then match the parsed pattern against the method signatures. And mismatches would report an inconsistency, which is what I think you are looking for.

爱给你人给你 2024-11-24 21:56:51

我有一个用很多反射工具构建的很好的库,但由于许可问题我无法发布它(预告片!) 请查看此处。一旦你构建了一些基本的反射工具,事情就开始很快地整合起来。

I have a nice library built with a lot reflection tools but i can't release it because of licensing issues (teaser!) check this out tho or this here. Once you build some basic reflection tools things start to come together pretty quickly.

眼藏柔 2024-11-24 21:56:51

请参阅 http://innig.net/macker/

虽然它不完全是您想要的并且更基于规则。

See http://innig.net/macker/

Although its not exactly what you want and is more rule based.

徒留西风 2024-11-24 21:56:51

我前段时间使用过一个名为 clapper 的不错的库: http://software.clapper.org/javautil/ #documentation

在你的情况下 - 找到“classutil”包 - 它提供了简单而有用的类发现和过滤器,也许这会很有用。

I hava used some time ago a nice library called clapper : http://software.clapper.org/javautil/#documentation

In your case - find "classutil" package - it provides simple and useful class discovery and filters, maybe this will be useful.

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