Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I identify the lowest required visibility of methods?

As part of a large refactoring project, I need to identify methods that are no longer used, or where the visibility can be reduced.

Consider the following code:

program Project1;

type
  TMyClass = class(TObject)
  private
    function Method1 : integer;
  public
    function Method2 : integer;
    function Method3 : integer;
    function Method4 : integer;
  end;

var
  vMyObject : TMyClass;

function TMyClass.Method1: integer;
begin
  Result := Method2;
end;

function TMyClass.Method2: integer;
begin
  Result := 2;
end;

function TMyClass.Method3: integer;
begin
  Result := 3;
end;

function TMyClass.Method4: integer;
begin
  Result := 4;
end;

begin
  vMyObject := TMyClass.Create;
  try
    writeln(vMyObject.Method3);
  finally
    vMyObject.Free;
  end;
end.

The Delphi compiler gives the warning "[DCC Hint] Project1.dpr(6): H2219 Private symbol 'Method1' declared but never used", which is very helpful. But there are other issues with this code that I would like to be warned about:

  1. Method4 is never used, but I don't get a warning since it's public.
  2. Method2 is declared public, but only used privately.

Are there any tools I can use to identify issues like these?

like image 358
Svein Bringsli Avatar asked Aug 18 '11 13:08

Svein Bringsli


1 Answers

Pascal Analyzer can do it and much more cases.

like image 106
TheHorse Avatar answered Sep 17 '22 20:09

TheHorse