1

I need to find if a class is inheriting other class using Javaparser's getExtendedType method. Can someone point the correct syntax for this and also the logic to find it recursively.

Suppose class A is extending class B which in turn is extending class C, I want to start with A and reach class C.

Thanks.

1 Answers1

2

you can use this code using VoidVisitorAdabter by calling this visitor form your compilation unit like this :

   cu.accept(new VoidVisitorAdapter<Void>() {
            @Override
            public void visit(ClassOrInterfaceDeclaration n, Void arg) {

                 Iterator extendedClassesItr = n.getExtendedTypes().iterator();

                    while (extendedClassesItr.hasNext()) {

                        ClassOrInterfaceType extendedClass = (ClassOrInterfaceType) extendedClassesItr.next();

                      if(extendedClass.getNameAsString().equals("your class name")) {
                           //you now have your class that you look for
                      }             
            }
        }, null);
Eslam Ashour
  • 113
  • 12