Thanks for the replies so far guys. I've been going through some pages on reflection an now Im kinda stuck.
Our professor wants us to invoke our program from the command line, like so: "java MethodDump c:\\projects\\demo", where demo is the name of package that is to be analyzed.
I've been trying to get this code to load the demo package but with no luck.
When I do "java MethodDump.java /Users/john/Documents/Demo.java", but that throws an error "java.lang.ClassNotFoundException"
Code:
import java.lang.reflect.*;
public class DumpMethods {
public static void main(String args[])
{
try {
Class c = Class.forName(args[0]);
Method m[] = c.getDeclaredMethods();
for (int i = 0; i < m.length; i++)
System.out.println(m[i].toString());
}
catch (Throwable e) {
System.err.println(e);
}
}
}
Does someone know how i can get the demo package into this program?
Also, here is the demo java file that Im trying to analyze:
Code:
package demo;
class A {
public void meth1() {
System.out.println("calling " + getClass() + ".meth1");
}
public void meth2() {
System.out.println("calling " + getClass() + ".meth2");
}
}
class B extends A {
public void meth1() {
System.out.println("calling " + getClass() + ".meth1");
}
public void meth2() {
System.out.println("calling " + getClass() + ".meth2");
}
}
class C extends B {
public void meth1() {
System.out.println("calling " + getClass() + ".meth1");
}
public void meth2() {
System.out.println("calling " + getClass() + ".meth2");
}
public void meth3() {
System.out.println("calling " + getClass() + ".meth3");
}
public void meth4() {
System.out.println("calling " + getClass() + ".meth4");
}
}
class D {
private B b = new B();
public void meth1() {
System.out.println("calling " + getClass() + ".meth1");
}
}
class E {
public void meth1(D d, A a) {
System.out.println("calling " + getClass() + ".meth1");
}
public void meth2() {
System.out.println("calling " + getClass() + ".meth2");
}
}
class F {
private D d = new D();
public void meth1(E e) {
System.out.println("calling " + getClass() + ".meth1");
}
public void meth2() {
System.out.println("calling " + getClass() + ".meth2");
}
}
public class Demo {
public static void main(String[] args) {
A a = new A();
a.meth1();
a.meth2();
B b = new B();
b.meth1();
b.meth2();
// etc.
}
}
To make it a bit more clear, here is the output, when passing the demo package to the analyzer:
Code:
C inDepth(C) instability(C) responsibility(C) workload(C)
A 1 0 .28 .14
B 2 .14 .28 .14
C 3 .14 0 .28
D 1 .14 .28 .07
E 1 .28 .14 .14
F 1 .28 0 .14
Demo 1 0 0 .07
Hopefully someone could help me a little further here.
Thanks in advance!