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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With