It is common in many tools, especially IDEs, to query the contents of .class files to determine a class's methods, fields, and constructors. In this assignment, you will develop a Java application that uses Java reflection to output the names of classes and their public non-static and public static members for all classes in a package.
You may work alone or in groups of two (but NOT 3 or more).
To begin, install JDK and Netbeans.
begin, make sure that you can set your classpath properly. Follow
these iustructions, and don't proceed until you have them working.
You will write an application with the following command-line invocation:
> java -jar reflect.jar <name-of-qualified-package> <directory>
<name-of-qualified-package> = qualified package name with no blanks (e.g. java.util)
<directory> = directory in which the class files of <name-of-qualified-package> package resides.
> java -jar reflect.jar jarreader C:\Users\me\Documents\NetBeansProjects\JarReader\build\classes\jarreader
Your program will retrieve the names of all .class files in the given directory and use "class reflection" to examine the contents of each class file. The key Java statement to inspect a .class file is:
Class<?> c = Class.forName("qualified.package.name");
where c is a Java object from which you can extract the desired structural information and "qualified.package.name" is exactly that -- the qualified name of a Java class that is on your classpath (e.g., "java.util.Stack"). You must read JDK documents on the Class class (click here for more details) and the way Java encodes type names (click here for more details). Finding the names of public fields and methods using reflection is simple, once you have the Class<?> object for a given class.
the classes that you want to introspect MUST be on your class path AND
they must not be in JAR files. I will give you a zip file
for you to test your program. For your program to work, you will
have to unzip it in a directory that is on your classpath.
Here are key limitations for this assignment to make your life easier:
The goal of this assignment is not to make this a complete tool, but rather to give you an idea of what reflective programs like this can do and how they work. Further, part of this assignment is to follow instructions -- if you don't pay attention, you lose points. Of course, you can always ask for clarifications.
To test your program on a specific packages, unzip this 7zip file and place its contents on your classpath, and execute the following command line, where "c:\blah\blah\yparser" is the path to the directory that contains the yparser package.
In a nutshell, you are generating a Prolog file:
This header is followed by tuples that you generate. The tuples produced for class yparser.connection) are shown below. This is the form of output that you should generate -- it is an executable Prolog file. The full and correct output file is here.
A zip file with all source code. The zip file must unzip into <yourName>/<YourFilesAndDirectories>.
The Grader should be able to invoke your program
just like "java -jar reflect.jar <name-of-qualified-package> <directory>"
exactly like the above
from a command line in the unzipped directory. The Grader will reject any submission where this is not the case.
Your program outputs for the 4 packages in
this zip file; a readme.txt file would be useful to show me where your results are.
You should expect that other packages, known only to the grader, will be used to evaluate your program.
A critical part of any design is clarity and understandability. Hence, you will be graded on the clarity of your project and its ability to work correctly. Sloppy code, documentation, or anything that makes grading or understanding your program difficult will cost you points! Beware, some of these "beauty" points are subjective.
assignments/submissions will be accepted.