In DelphiAST there is a base class: TmwSimplePasPar
that parses Delphi code.
In addition there is a class: TPasSyntaxTreeBuilder
that is supposed to override every method in its base class.
Is there a way to check that a descendent class has overridden every single virtual method in its base class?
It would be nice to be able to put in a assert.
TPasSyntaxTreeBuilder.Create;
begin
Assert(Self.OverridenMethods.Count = (BaseClass.VirtualMethodCount - TObject.VirtualMethodCount));
....
Note that I'm talking about all virtual methods, not just abstract ones (not implementing abstract methods issues a warning).
Look at the VMT slots of the class and compare them again the VMT slots of a base class.
In Spring4D there is this function (in Spring.VirtualClass.pas
):
function IsVirtualMethodOverride(baseClass, classType: TClass; method: Pointer): Boolean;
I am not posting the entire code here because it works on some internal VMT structure record - take a look at the code yourself.
FWIW: There is a small bug inside that routine that I just found which I will fix asap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With