codetools: fixed AddUnitWarnDirective insert position

git-svn-id: branches/fixes_1_8@56078 -
This commit is contained in:
mattias 2017-10-16 12:00:17 +00:00
parent 91e848b779
commit 24af7385ca
2 changed files with 12 additions and 18 deletions

View File

@ -717,7 +717,7 @@ begin
break;
until false;
if CurNode.Desc=ctnSrcName then begin
CurNode.EndPos:=CurPos.StartPos;
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
end;
if CurSection in [ctnProgram,ctnLibrary,ctnPackage] then

View File

@ -6555,7 +6555,7 @@ end;
function TStandardCodeTool.AddUnitWarnDirective(WarnID, Comment: string;
TurnOn: boolean; SourceChangeCache: TSourceChangeCache): boolean;
const
DirectiveFlagValue: array[boolean] of string = ('on','off');
DirectiveFlagValue: array[boolean] of string = ('off','on');
var
ACleanPos, DirEndPos, InsertStartPos, MaxPos: Integer;
Node: TCodeTreeNode;
@ -6577,24 +6577,18 @@ begin
if not (Comment[1] in [' ',#9,#10,#13]) then Comment:=' '+Comment;
end;
MaxPos:=0;
Node:=FindInterfaceNode;
if Node=nil then
Node:=FindMainUsesNode;
debugln(['TStandardCodeTool.AddUnitWarnDirective AAA1 ',Tree.Root.DescAsString]);
debugln(['TStandardCodeTool.AddUnitWarnDirective AAA2 ',Tree.Root.FirstChild.DescAsString]);
if Node=nil then begin
Node:=Tree.Root.FirstChild;
if (Node<>nil) and (Node.Desc=ctnSrcName) then begin
debugln(['TStandardCodeTool.AddUnitWarnDirective AA3 ',Node.DescAsString]);
Node:=Node.NextSkipChilds;
end;
// insert in front of first node after source name
Node:=Tree.Root;
MaxPos:=Node.StartPos;
if Node.Desc in AllSourceTypes then
Node:=Node.Next;
if (Node<>nil) and (Node.Desc=ctnSrcName) then begin
MaxPos:=Node.EndPos;
Node:=Node.NextSkipChilds;
end;
debugln(['TStandardCodeTool.AddUnitWarnDirective ',Node.DescAsString]);
if Node<>nil then
MaxPos:=Node.StartPos
else
MaxPos:=SrcLen;
MaxPos:=Node.StartPos;
MaxPos:=FindLineEndOrCodeAfterPosition(MaxPos,true,true);
// find existing directive for replacement
ACleanPos:=1;