IDE: checking lfm files now check used units first

git-svn-id: trunk@10450 -
This commit is contained in:
mattias 2007-01-15 14:54:08 +00:00
parent 53737e0127
commit 82ebb63757
7 changed files with 115 additions and 13 deletions

View File

@ -446,7 +446,7 @@ type
function FindUsedUnitNames(Code: TCodeBuffer; var MainUsesSection, function FindUsedUnitNames(Code: TCodeBuffer; var MainUsesSection,
ImplementationUsesSection: TStrings): boolean; ImplementationUsesSection: TStrings): boolean;
function FindMissingUnits(Code: TCodeBuffer; var MissingUnits: TStrings; function FindMissingUnits(Code: TCodeBuffer; var MissingUnits: TStrings;
FixCase: boolean = false): boolean; FixCase: boolean = false; SearchImplementation: boolean = true): boolean;
function FindDelphiProjectUnits(Code: TCodeBuffer; function FindDelphiProjectUnits(Code: TCodeBuffer;
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean; var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
function FindDelphiPackageUnits(Code: TCodeBuffer; function FindDelphiPackageUnits(Code: TCodeBuffer;
@ -3033,7 +3033,8 @@ begin
end; end;
function TCodeToolManager.FindMissingUnits(Code: TCodeBuffer; function TCodeToolManager.FindMissingUnits(Code: TCodeBuffer;
var MissingUnits: TStrings; FixCase: boolean): boolean; var MissingUnits: TStrings; FixCase: boolean;
SearchImplementation: boolean): boolean;
begin begin
Result:=false; Result:=false;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
@ -3042,7 +3043,7 @@ begin
if not InitCurCodeTool(Code) then exit; if not InitCurCodeTool(Code) then exit;
try try
Result:=FCurCodeTool.FindMissingUnits(MissingUnits,FixCase, Result:=FCurCodeTool.FindMissingUnits(MissingUnits,FixCase,
SourceChangeCache); SearchImplementation,SourceChangeCache);
except except
on e: Exception do Result:=HandleException(e); on e: Exception do Result:=HandleException(e);
end; end;

View File

@ -114,6 +114,7 @@ type
function UsesSectionToFilenames(UsesNode: TCodeTreeNode): TStrings; function UsesSectionToFilenames(UsesNode: TCodeTreeNode): TStrings;
function UsesSectionToUnitnames(UsesNode: TCodeTreeNode): TStrings; function UsesSectionToUnitnames(UsesNode: TCodeTreeNode): TStrings;
function FindMissingUnits(var MissingUnits: TStrings; FixCase: boolean; function FindMissingUnits(var MissingUnits: TStrings; FixCase: boolean;
SearchImplementation: boolean;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
function CommentUnitsInUsesSections(MissingUnits: TStrings; function CommentUnitsInUsesSections(MissingUnits: TStrings;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
@ -1120,7 +1121,8 @@ begin
end; end;
function TStandardCodeTool.FindMissingUnits(var MissingUnits: TStrings; function TStandardCodeTool.FindMissingUnits(var MissingUnits: TStrings;
FixCase: boolean; SourceChangeCache: TSourceChangeCache): boolean; FixCase: boolean; SearchImplementation: boolean;
SourceChangeCache: TSourceChangeCache): boolean;
function CheckUsesSection(UsesNode: TCodeTreeNode): boolean; function CheckUsesSection(UsesNode: TCodeTreeNode): boolean;
var var
@ -1187,15 +1189,20 @@ function TStandardCodeTool.FindMissingUnits(var MissingUnits: TStrings;
begin begin
Result:=false; Result:=false;
BuildTree(false); BuildTree(false);
if FixCase then
SourceChangeCache.MainScanner:=Scanner; SourceChangeCache.MainScanner:=Scanner;
try try
if not CheckUsesSection(FindMainUsesSection) then exit; if not CheckUsesSection(FindMainUsesSection) then exit;
if not CheckUsesSection(FindImplementationUsesSection) then exit; if SearchImplementation
and not CheckUsesSection(FindImplementationUsesSection) then exit;
except except
FreeAndNil(MissingUnits); FreeAndNil(MissingUnits);
raise; raise;
end; end;
Result:=SourceChangeCache.Apply; if FixCase then
Result:=SourceChangeCache.Apply
else
Result:=true;
end; end;
function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings; function TStandardCodeTool.CommentUnitsInUsesSections(MissingUnits: TStrings;

View File

@ -107,6 +107,32 @@ function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
var var
LFMTree: TLFMTree; LFMTree: TLFMTree;
procedure WriteUnitError(Code: TCodeBuffer; x, Y: integer;
const ErrorMessage: string);
var
Dir: String;
Filename: String;
Msg: String;
begin
if not Assigned(OnOutput) then exit;
if Code=nil then
Code:=PascalBuffer;
Dir:=ExtractFilePath(Code.Filename);
Filename:=ExtractFilename(Code.Filename);
Msg:=Filename
+'('+IntToStr(Y)+','+IntToStr(X)+')'
+' Error: '
+ErrorMessage;
debugln('WriteLFMErrors ',Msg);
OnOutput(Msg,Dir,-1);
end;
procedure WriteCodeToolsError;
begin
WriteUnitError(CodeToolBoss.ErrorCode,CodeToolBoss.ErrorColumn,
CodeToolBoss.ErrorLine,CodeToolBoss.ErrorMessage);
end;
procedure WriteLFMErrors; procedure WriteLFMErrors;
var var
CurError: TLFMError; CurError: TLFMError;
@ -138,6 +164,7 @@ var
RegComp: TRegisteredComponent; RegComp: TRegisteredComponent;
i: Integer; i: Integer;
begin begin
DebugLn(['FixMissingComponentClasses ',LFMBuffer.Filename]);
Result:=mrCancel; Result:=mrCancel;
MissingObjectTypes:=TStringList.Create; MissingObjectTypes:=TStringList.Create;
try try
@ -151,6 +178,7 @@ var
end; end;
CurError:=CurError.NextError; CurError:=CurError.NextError;
end; end;
DebugLn(['FixMissingComponentClasses Missing object types in unit: ',MissingObjectTypes.Text]);
// keep all object types with a registered component class // keep all object types with a registered component class
for i:=MissingObjectTypes.Count-1 downto 0 do begin for i:=MissingObjectTypes.Count-1 downto 0 do begin
@ -159,36 +187,93 @@ var
MissingObjectTypes.Delete(i); MissingObjectTypes.Delete(i);
end; end;
if MissingObjectTypes.Count=0 then exit; if MissingObjectTypes.Count=0 then exit;
DebugLn(['FixMissingComponentClasses Missing object types, but luckily found in IDE: ',MissingObjectTypes.Text]);
// there are missing object types with registered component classes // there are missing object types with registered component classes
Result:=PackageEditingInterface.AddUnitDependenciesForComponentClasses( Result:=PackageEditingInterface.AddUnitDependenciesForComponentClasses(
PascalBuffer.Filename,MissingObjectTypes); PascalBuffer.Filename,MissingObjectTypes);
if Result<>mrOk then exit; if Result<>mrOk then begin
DebugLn(['FixMissingComponentClasses Failed to add dependencies for ',MissingObjectTypes.Text]);
exit;
end;
// check LFM again // check LFM again
LFMTree.Free; LFMTree.Free;
LFMTree:=nil; LFMTree:=nil;
if CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree, if CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf,ObjectsMustExists) RootMustBeClassInIntf,ObjectsMustExists)
then then begin
DebugLn(['FixMissingComponentClasses Success: All found errors fixed']);
Result:=mrOk; Result:=mrOk;
end else begin
Result:=mrCancel;
end;
finally finally
MissingObjectTypes.Free; MissingObjectTypes.Free;
end; end;
end; end;
function CheckUnit: boolean;
var
NewCode: TCodeBuffer;
NewX, NewY, NewTopLine: integer;
ErrorMsg: string;
MissingUnits: TStrings;
s: String;
begin
Result:=false;
// check syntax
DebugLn(['CheckUnit Checking syntax ...']);
if not CodeToolBoss.CheckSyntax(PascalBuffer,NewCode,NewX,NewY,NewTopLine,
ErrorMsg)
then begin
WriteUnitError(NewCode,NewX,NewY,ErrorMsg);
exit;
end;
// check used units
MissingUnits:=nil;
try
DebugLn(['CheckUnit Checking used units ...']);
if not CodeToolBoss.FindMissingUnits(PascalBuffer,MissingUnits,false,
false)
then begin
WriteCodeToolsError;
exit;
end;
if (MissingUnits<>nil) and (MissingUnits.Count>0) then begin
s:=StringListToText(MissingUnits,',');
WriteUnitError(PascalBuffer,1,1,'Units not found: '+s);
exit;
end;
finally
MissingUnits.Free;
end;
if NewTopLine=0 then ;
Result:=true;
end;
begin begin
Result:=mrCancel; Result:=mrCancel;
if not CheckUnit then begin
DebugLn(['CheckLFMBuffer failed parsing unit: ',PascalBuffer.Filename]);
exit;
end;
LFMTree:=nil; LFMTree:=nil;
try try
if CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree, if CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf,ObjectsMustExists) RootMustBeClassInIntf,ObjectsMustExists)
then begin then begin
DebugLn(['CheckLFMBuffer no errors found']);
Result:=mrOk; Result:=mrOk;
exit; exit;
end; end;
Result:=FixMissingComponentClasses; Result:=FixMissingComponentClasses;
if Result in [mrAbort,mrOk] then exit; if Result in [mrAbort,mrOk] then begin
DebugLn(['CheckLFMBuffer all errors fixed']);
exit;
end;
WriteLFMErrors; WriteLFMErrors;
Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree); Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree);
finally finally
@ -220,11 +305,13 @@ var
CheckLFMDialog: TCheckLFMDialog; CheckLFMDialog: TCheckLFMDialog;
begin begin
Result:=mrCancel; Result:=mrCancel;
DebugLn(['ShowRepairLFMWizard START']);
CheckLFMDialog:=TCheckLFMDialog.Create(nil); CheckLFMDialog:=TCheckLFMDialog.Create(nil);
CheckLFMDialog.LFMTree:=LFMTree; CheckLFMDialog.LFMTree:=LFMTree;
CheckLFMDialog.LFMSource:=LFMBuffer; CheckLFMDialog.LFMSource:=LFMBuffer;
CheckLFMDialog.LoadLFM; CheckLFMDialog.LoadLFM;
Result:=CheckLFMDialog.ShowModal; Result:=CheckLFMDialog.ShowModal;
DebugLn(['ShowRepairLFMWizard END']);
CheckLFMDialog.Free; CheckLFMDialog.Free;
end; end;

View File

@ -366,7 +366,8 @@ begin
e:=LineEnding; e:=LineEnding;
NewContent:=TMemoryStream.Create; NewContent:=TMemoryStream.Create;
// write header // write header - needed by editors like poedit so they know what encoding
// to create
WriteLine('msgid ""'); WriteLine('msgid ""');
WriteLine('msgstr ""'); WriteLine('msgstr ""');
WriteLine('"MIME-Version: 1.0\n"'); WriteLine('"MIME-Version: 1.0\n"');

View File

@ -8792,6 +8792,7 @@ begin
end; end;
if ToolStatus<>itNone then begin if ToolStatus<>itNone then begin
DebugLn(['TMainIDE.DoCheckLFMInEditor ToolStatus<>itNone']);
Result:=mrCancel; Result:=mrCancel;
exit; exit;
end; end;

View File

@ -4489,7 +4489,7 @@ end;
procedure TCustomGrid.DoEditorShow; procedure TCustomGrid.DoEditorShow;
begin begin
DebugLn(['TCustomGrid.DoEditorShow ']); //DebugLn(['TCustomGrid.DoEditorShow ']);
{$ifdef dbgGrid}DebugLn('grid.DoEditorShow INIT');{$endif} {$ifdef dbgGrid}DebugLn('grid.DoEditorShow INIT');{$endif}
ScrollToCell(FCol,FRow); ScrollToCell(FCol,FRow);
Editor.Parent := nil; Editor.Parent := nil;

View File

@ -2497,6 +2497,11 @@ var
end; end;
parser.NextToken; parser.NextToken;
parser.CheckToken(toSymbol); parser.CheckToken(toSymbol);
if parser.TokenSymbolIs('END') then begin
// 'object end': no name, no content
// this is normally invalid, but Delphi can create this, so ignore it
exit;
end;
ObjectName := ''; ObjectName := '';
ObjectType := parser.TokenString; ObjectType := parser.TokenString;
parser.NextToken; parser.NextToken;