Frage

I have been using the ASTVisitor class in Eclipse in order to take data at Method Declaration and Method Invocation nodes. I now also want to take data at Class Declaration nodes, but I can't find anything in the API for the ASTVisitor that would allow me to do this. Am I missing something? What would be a good way to do this?

War es hilfreich?

Lösung

If you want to get ClassDeclaration you should look for TypeDeclaration objects because:

A type declaration is the union of a class declaration and an interface declaration.

Once you found it you just have to use isInterface() method and if it returns false then it is ClassDeclaration.

Andere Tipps

The node "Class Declaration" that you are interested in is actually the TypeDeclaration, the node from which to take in the information that you need. For example:

  • The list of modifiers ('public', etc.) allows you to figure out which and how many modifiers (node.modifiers ())
  • The type of the super class, if it exists (node.getSuperclassType ())
  • All the declarations of the methods
  • etc

However, these are details that you need to build from a TypeDeclaration

However, both methods are inherited TypeDeclaration that can help you get all the info that you need to traverse the tree in a top-down approach.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top