INRIA / spoon

Spoon is a metaprogramming library to analyze and transform Java source code. :spoon: is made with :heart:, :beers: and :sparkles:. It parses source files to build a well-designed AST with powerful analysis and transformation API.
http://spoon.gforge.inria.fr/
Other
1.76k stars 352 forks source link

Question: difference between `getModifiers` and `getExtendedModifiers` in `CtModifiable` #5979

Closed algomaster99 closed 2 months ago

algomaster99 commented 2 months ago

I am wondering about the difference in the purpose of getModifiers() and getExtendedModifiers(). I understand that extended modifiers are spoon elements and they also hold source positions. However, it explicitly says that implicit modifiers are included. Does it mean that getModifiers are supposed to ignore them? If yes, the abstract modifier is returned for an interface by getModifiers even though it is implicit.

SirYwell commented 2 months ago

ModifierKind doesn't hold information about whether the modifier is implicit. CtExtendedModifier holds that information in addition to the kind. So, if you only interested in which modifiers an element has, getModifiers() might be enough, but if you want to know which explicit or implicit modifiers an element has (or whether it has a specific explicit modifier), you need getExtendedModifiers().

algomaster99 commented 2 months ago

ModifierKind doesn't hold information about whether the modifier is implicit.

so getModifiers could also return implicit modifiers?

SirYwell commented 2 months ago

so getModifiers could also return implicit modifiers?

Yes, they should both contain the same modifiers (i.e. getModifiers() is equal to getExtendedModifiers().stream(CtExtendedModifier::getKind()).collect(...))

algomaster99 commented 2 months ago

Thanks for answering!