Hi..
I have a serious problem...
I am making a tool that will dynamicallly load the classes inside a dir strcuture to find the name of a class that has the declaration of a method.I am using the Reflection API...But it has become very slow....
Please suggest
private void findMethod(
String mthdname, File pckg) {
File files[] = pckg.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
findMethod(mthdname,files[i]);
} else {
if (files[i].getName().endsWith(".class")) {
try {
String classnme = files[i].getName();
int indexofclass = classnme.indexOf(".class");
Class classname = Class.forName(classnme.substring(0, indexofclass));
Method[] methods = classname.getDeclaredMethods();
for (int j = 0; j < methods.length; j++) {
String methodname = methods[j].getName();
if (methodname.equals(mthdname)) {
boolean nopackage = false;
try {
targetname = methods[j].getDeclaringClass().getName();
targetpackage = methods[j].getDeclaringClass().getPackage().getName();
} catch (NullPointerException nullpointer) {
nopackage = true;
} finally {
if (!nopackage)
System.out.println("Package name: " + targetpackage);
System.out.println("Class name: " + targetname);
return;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}