Converter: Improve adding missing units and package dependencies etc. Issue #30895.

git-svn-id: trunk@53841 -
This commit is contained in:
juha 2017-01-02 22:02:50 +00:00
parent 5e8fb9d46e
commit 7328ad5783
6 changed files with 42 additions and 31 deletions

View File

@ -228,6 +228,7 @@ begin
if not ReplaceFuncCalls(fIsConsoleApp) then exit; if not ReplaceFuncCalls(fIsConsoleApp) then exit;
finally finally
fCTLink.SrcCache.EndUpdate; fCTLink.SrcCache.EndUpdate;
fCTLink.SrcCache.Apply;
end; end;
Result:=mrOK; Result:=mrOK;
end; end;
@ -373,7 +374,6 @@ begin
end; end;
CleanPos:=FindCommentEnd(Code.Source, CleanPos, CodeTool.Scanner.NestedComments); CleanPos:=FindCommentEnd(Code.Source, CleanPos, CodeTool.Scanner.NestedComments);
until false; until false;
//SrcCache.Apply;
end; end;
Result:=true; Result:=true;
end; end;

View File

@ -1411,6 +1411,7 @@ end;
function TConvertDelphiProjPack.CheckPackageDep(AUnitName: string): Boolean; function TConvertDelphiProjPack.CheckPackageDep(AUnitName: string): Boolean;
// Check if the given unit can be found in existing packages. Add a dependency if found. // Check if the given unit can be found in existing packages. Add a dependency if found.
// This is called only if the unit is reported as missing. // This is called only if the unit is reported as missing.
// Returns True if a dependency was really added.
var var
Pack: TPkgFile; Pack: TPkgFile;
Dep: TPkgDependency; Dep: TPkgDependency;
@ -1451,7 +1452,7 @@ begin
if not Result then if not Result then
// Package was not found. Add a message about a package that must be installed. // Package was not found. Add a message about a package that must be installed.
fSettings.AddLogLine(mluWarning, fSettings.AddLogLine(mluWarning,
Format(lisConvDelphiPackageRequired, [ADefaultPkgName])); Format(lisConvDelphiPackageRequired, [ADefaultPkgName]));
end; end;
end; end;
end; end;

View File

@ -9,7 +9,7 @@ uses
type type
TAddUnitEvent = procedure (AUnitName: string) of object; TAddUnitEvent = function (AUnitName: string): Boolean of object;
TCheckUnitEvent = function (AUnitName: string): Boolean of object; TCheckUnitEvent = function (AUnitName: string): Boolean of object;
// What to do with {$R *.RES} directive, convert to lowercase or delete. // What to do with {$R *.RES} directive, convert to lowercase or delete.

View File

@ -33,18 +33,18 @@ interface
uses uses
// FCL+LCL // FCL+LCL
Classes, SysUtils, LCLProc, Forms, Controls, Grids, LResources, Classes, SysUtils, contnrs,
LConvEncoding, Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls, contnrs, LCLProc, Forms, Controls, Grids, LResources, Dialogs, Buttons, StdCtrls, ExtCtrls,
LazFileUtils, LazUTF8Classes, LCLType, LazUTF8, // LazUtils
LazFileUtils, LazUTF8Classes, LazUTF8,
// components // components
SynHighlighterLFM, SynEdit, SynEditMiscClasses, LFMTrees, SynHighlighterLFM, SynEdit, SynEditMiscClasses,
// codetools // codetools
CodeCache, CodeToolManager, CodeToolsStructs, CodeCompletionTool, CodeCache, CodeToolManager, CodeToolsStructs, CodeCompletionTool, LFMTrees,
// IdeIntf // IdeIntf
ComponentReg, PackageIntf, IDEWindowIntf, IDEExternToolIntf, IDEExternToolIntf, ComponentReg,
// IDE // IDE
CustomFormEditor, LazarusIDEStrConsts, IDEProcs, LazarusIDEStrConsts, EditorOptions, CheckLFMDlg, Project, SourceMarks,
EditorOptions, CheckLFMDlg, Project, SourceMarks,
// Converter // Converter
ConverterTypes, ConvertSettings, ReplaceNamesUnit, ConverterTypes, ConvertSettings, ReplaceNamesUnit,
ConvCodeTool, FormFileConv, UsedUnits; ConvCodeTool, FormFileConv, UsedUnits;
@ -612,7 +612,8 @@ var
begin begin
Result:=mrOK; Result:=mrOK;
if not Assigned(fUsedUnitsTool) then Exit; if not Assigned(fUsedUnitsTool) then Exit;
for i := 0 to aMissingTypes.Count-1 do begin for i := 0 to aMissingTypes.Count-1 do
begin
RegComp:=IDEComponentPalette.FindComponent(aMissingTypes[i]); RegComp:=IDEComponentPalette.FindComponent(aMissingTypes[i]);
NeededUnitName:=''; NeededUnitName:='';
if (RegComp<>nil) then begin if (RegComp<>nil) then begin
@ -621,14 +622,17 @@ begin
if NeededUnitName='' then if NeededUnitName='' then
NeededUnitName:=RegComp.GetUnitName; NeededUnitName:=RegComp.GetUnitName;
end; end;
end else begin end
else begin
ClassUnitInfo:=Project1.UnitWithComponentClassName(aMissingTypes[i]); ClassUnitInfo:=Project1.UnitWithComponentClassName(aMissingTypes[i]);
if ClassUnitInfo<>nil then if ClassUnitInfo<>nil then
NeededUnitName:=ClassUnitInfo.GetUsesUnitName; NeededUnitName:=ClassUnitInfo.GetUsesUnitName;
end; end;
if NeededUnitName<>'' then begin if (NeededUnitName<>'')
if fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then and fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then
Result:=mrRetry; // Caller must check LFM validity again begin
Result:=mrRetry; // Caller must check LFM validity again
fUsedUnitsTool.MaybeAddPackageDep(NeededUnitName);
end; end;
end; end;
end; end;

View File

@ -125,7 +125,6 @@ type
fOnCheckPackageDependency: TCheckUnitEvent; fOnCheckPackageDependency: TCheckUnitEvent;
fOnCheckUnitForConversion: TCheckUnitEvent; fOnCheckUnitForConversion: TCheckUnitEvent;
function HasUnit(aUnitName: string): Boolean; function HasUnit(aUnitName: string): Boolean;
procedure MaybeOpenPackage(aUnitName: string);
function GetMissingUnitCount: integer; function GetMissingUnitCount: integer;
public public
constructor Create(ACTLink: TCodeToolLink; AFilename: string); constructor Create(ACTLink: TCodeToolLink; AFilename: string);
@ -135,7 +134,8 @@ type
function Remove(aUnit: string): TModalResult; function Remove(aUnit: string): TModalResult;
procedure MoveMissingToComment(aAllCommentedUnits: TStrings); procedure MoveMissingToComment(aAllCommentedUnits: TStrings);
function AddUnitImmediately(aUnitName: string): Boolean; function AddUnitImmediately(aUnitName: string): Boolean;
procedure AddUnitIfNeeded(aUnitName: string); function AddUnitIfNeeded(aUnitName: string): Boolean;
function MaybeAddPackageDep(aUnitName: string): Boolean;
function AddThreadSupport: TModalResult; function AddThreadSupport: TModalResult;
public public
property Filename: string read fFilename; property Filename: string read fFilename;
@ -305,7 +305,7 @@ begin
if fOwnerTool.HasUnit(sl[i]) then if fOwnerTool.HasUnit(sl[i]) then
sl.Delete(i) sl.Delete(i)
else else
fOwnerTool.MaybeOpenPackage(sl[i]); fOwnerTool.MaybeAddPackageDep(sl[i]);
end; end;
WillRemove:=sl.Count=0; WillRemove:=sl.Count=0;
if not WillRemove then begin if not WillRemove then begin
@ -645,16 +645,17 @@ begin
or fImplUsedUnits.fUnitsToRenameVals.Find(aUnitName, x); or fImplUsedUnits.fUnitsToRenameVals.Find(aUnitName, x);
end; end;
procedure TUsedUnitsTool.MaybeOpenPackage(aUnitName: string); function TUsedUnitsTool.MaybeAddPackageDep(aUnitName: string): Boolean;
// Open a package containing a unit. Called when the unit is not found. // Add a dependency to a package containing the unit and open it.
// Called when the unit is not found.
var var
s: String; s: String;
begin begin
Result := False;
s:=''; s:='';
if fCTLink.CodeTool.DirectoryCache.FindUnitSourceInCompletePath(aUnitName,s,True) = '' then if fCTLink.CodeTool.DirectoryCache.FindUnitSourceInCompletePath(aUnitName,s,True) = '' then
if Assigned(fOnCheckPackageDependency) then if Assigned(fOnCheckPackageDependency) then
if not fOnCheckPackageDependency(aUnitName) then Result := not fOnCheckPackageDependency(aUnitName);
;
end; end;
function TUsedUnitsTool.ConvertUsed: TModalResult; function TUsedUnitsTool.ConvertUsed: TModalResult;
@ -777,15 +778,19 @@ begin
RemoveFromAdded(fImplUsedUnits.fUnitsToAdd); RemoveFromAdded(fImplUsedUnits.fUnitsToAdd);
RemoveFromAdded(fMainUsedUnits.fUnitsToAddForLCL); RemoveFromAdded(fMainUsedUnits.fUnitsToAddForLCL);
RemoveFromAdded(fImplUsedUnits.fUnitsToAddForLCL); RemoveFromAdded(fImplUsedUnits.fUnitsToAddForLCL);
fCTLink.Settings.AddLogLine(mluNote,
Format(lisConvAddedUnitToUsesSection, [aUnitName]), fFilename);
end; end;
procedure TUsedUnitsTool.AddUnitIfNeeded(aUnitName: string); function TUsedUnitsTool.AddUnitIfNeeded(aUnitName: string): Boolean;
begin begin
if not HasUnit(aUnitName) then begin Result := not HasUnit(aUnitName);
if Result then
begin
fMainUsedUnits.fUnitsToAdd.Add(aUnitName); fMainUsedUnits.fUnitsToAdd.Add(aUnitName);
fCTLink.Settings.AddLogLine(mluNote, fCTLink.Settings.AddLogLine(mluNote,
Format(lisConvAddedUnitToUsesSection,[aUnitName]), fFilename); Format(lisConvAddedUnitToUsesSection, [aUnitName]), fFilename);
MaybeOpenPackage(aUnitName); MaybeAddPackageDep(aUnitName);
end; end;
end; end;

View File

@ -34,15 +34,16 @@ uses
// FCL+LCL // FCL+LCL
Classes, SysUtils, Math, TypInfo, contnrs, Classes, SysUtils, Math, TypInfo, contnrs,
LCLProc, LResources, Forms, Controls, LCLProc, LResources, Forms, Controls,
Graphics, Dialogs, Buttons, StdCtrls, ExtCtrls, Dialogs, Buttons, StdCtrls, ExtCtrls,
// components // components
SynHighlighterLFM, SynEdit, BasicCodeTools, CodeCache, CodeToolManager, SynHighlighterLFM, SynEdit, BasicCodeTools, CodeCache, CodeToolManager,
SynEditMiscClasses, LFMTrees, SynEditMiscClasses, LFMTrees,
// IDEIntf
IDEExternToolIntf, PackageIntf, IDEWindowIntf, PropEdits, PropEditUtils,
IDEMsgIntf, IDEDialogs, ComponentReg,
// IDE // IDE
IDEExternToolIntf, PackageIntf, IDEWindowIntf, PropEdits, PropEditUtils, IDEMsgIntf,
IDEDialogs, ComponentReg,
CustomFormEditor, LazarusIDEStrConsts, CustomFormEditor, LazarusIDEStrConsts,
IDEProcs, IDEOptionDefs, EditorOptions, SourceMarks, JITForms; IDEProcs, EditorOptions, SourceMarks, JITForms;
type type