Assignment 2: The Reflection Pattern. Using reflective
features of programming languages
This is one of the choices for Assignment 2.
MyReverseEngineeringTool
Objectives: Using reflective properties of programming languages - using Introspection
Assignment description
Using reflective capabilities of java (java.lang.reflection)
or .NET (System.Reflection)
implement a simple reverse engineering tool to extract design information from
compiled code.
Standard requirements
The tool accepts as command line arguments
the name of a compiled file (could be a *.jar file or a *.dll / *.exe file)
and extracts all informations that are needed to describe the class diagram
of the classes contained in this file.
The standard requirement is to display (in a textual representation of your choice)
all the informations that would go into the class diagram:
classes, interfaces, methods, fields, relationships between classes/interfaces.
For Java implementation: In order to work with jar files use the utility
class java.util.jar.JarFile to open a jar file. Use a
URLClassLoader to load classes and retrieve the Class metaobjects. Use intensivly introspection to gather information.
Bonus requirements
Your tool must produce outputs compatible with the formats required by UML drawing tools such as
yuml and
plantuml.
You can see on their respectives websites what are their required notations.
Implement a
good design for your tool, such that new output formats for
different UML drawing tools
can be added with minimal effort and no changes to the main parts of tool.
Your tool also must be able to receive additional configuration options:
- give a set of classes to be ignored when drawing the diagram
(for example, all java.lang.* classes), and whatever you want to ignore
- write class names as fully qualified names: yes/no
- show method names: yes/no
- show attributes: yes/no
You can distinguish 4 types of relationships between classes and/or
interfaces: extends, implements, association, dependency.
Please note that information
extracted by reflection is not enough to distinguish subtypes of
associations such as aggregation or composition. Thus aggregation and
composition relationships
will be reverse engineeered as associations by your tool.
Cardinality of association relationships is ignored.
When parametrized types are found, include also its actual type
arguments in the diagram.
Example: for the code given in TempSensor.jar:
If you select as target yuml,
your tool produces the output
TempSensor-yuml.txt.
If you put this description in
yuml it will draw the
reverse engineered classdiagram of
TempSensor
If you select as target plantuml,
your tool produces the output
TempSensor-plantuml.txt.
If you put this description in
plantuml it will draw the
reverse engineered classdiagram of
TempSensor
Example2: For the code given in EventNotifier.jar and target yuml
your tool produces the output EventNotifier1.txt if the tool is used with the option to put class members on the diagram, respectively
EventNotifier2.txt if it is used without this option.
The class diagrams drawn by yuml are
classdiagram case 1
respectively
classdiagram case 2.
Deadlines and Grading
The deadline for this assignment is in Week 7. See the Grading Policy on CV for
PASSC and
DACSS.
Frameworks to use
Reflective languages: Java or C#
Resources
- Slides - Lecture notes on Reflection (weeks 4 and 5) link
- Source code of examples - Reflection in Java:
- The Java tutorials - The reflection API link
- MSDN - Reflection overview link