Best way to visit all classes

I was wondering about what is the most effective way to visit all the classes in a module.

Any ideas ?

1 comment
Comment actions Permalink

For future reference, here's what i did:

PsiManager.getInstance(_module.getProject()).findPackage("");
basePackage.accept(new LocalClassVisitor(_module) {
public void visitClass(PsiClass aClass) {
// whatever
}
});

public abstract class LocalClassVisitor extends PsiRecursiveElementVisitor {
private Module _module;

protected LocalClassVisitor(Module module) {
_module = module;
}

public void visitPackage(PsiPackage aPackage) {
PsiPackage[] subPackages = aPackage.getSubPackages(GlobalSearchScope.moduleRuntimeScope(_module, false));

for (PsiPackage subPackage : subPackages)
subPackage.accept(this);

PsiClass[] classes = aPackage.getClasses(GlobalSearchScope.moduleRuntimeScope(_module, false));

for (PsiClass clazz : classes)
clazz.accept(this);
}

public abstract void visitClass(PsiClass aClass);
}

0

Please sign in to leave a comment.