I think it'd be good to verify that D is an EnumDecl.

FYI, the static_cast cannot fail; there is no need to have an if(). But once you do a `dyn_cast<clang::EnumDecl>` you'll of course have to check for 0.