mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 22:40:56 +02:00
codetools: fixed checking if a proc header has already a classname, when there are tabs
git-svn-id: trunk@42750 -
This commit is contained in:
parent
5e9e93f7d7
commit
7538f3a4e4
@ -60,8 +60,6 @@
|
|||||||
FItems.Free;
|
FItems.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
-VarExists: search vars in ancestors too
|
|
||||||
}
|
}
|
||||||
unit CodeCompletionTool;
|
unit CodeCompletionTool;
|
||||||
|
|
||||||
@ -8217,7 +8215,9 @@ var
|
|||||||
ANode:=TheNodeExt.Node;
|
ANode:=TheNodeExt.Node;
|
||||||
if (ANode<>nil) and (ANode.Desc=ctnProcedure) then begin
|
if (ANode<>nil) and (ANode.Desc=ctnProcedure) then begin
|
||||||
ProcCode:=ExtractProcHead(ANode,ProcAttrDefToBody);
|
ProcCode:=ExtractProcHead(ANode,ProcAttrDefToBody);
|
||||||
|
//debugln(['CreateCodeForMissingProcBody Definition="',ProcCode,'"']);
|
||||||
TheNodeExt.ExtTxt3:=Beauty.BeautifyProc(ProcCode,Indent,true);
|
TheNodeExt.ExtTxt3:=Beauty.BeautifyProc(ProcCode,Indent,true);
|
||||||
|
//debugln(['CreateCodeForMissingProcBody Beautified="',TheNodeExt.ExtTxt3,'"']);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -1808,30 +1808,32 @@ end;
|
|||||||
|
|
||||||
function TBeautifyCodeOptions.AddClassAndNameToProc(const AProcCode, AClassName,
|
function TBeautifyCodeOptions.AddClassAndNameToProc(const AProcCode, AClassName,
|
||||||
AMethodName: string): string;
|
AMethodName: string): string;
|
||||||
var StartPos, NamePos, ProcLen: integer;
|
var
|
||||||
|
p, StartPos, NamePos, ProcLen: integer;
|
||||||
s: string;
|
s: string;
|
||||||
KeyWordPos: LongInt;
|
KeyWordPos: LongInt;
|
||||||
|
Level: Integer;
|
||||||
begin
|
begin
|
||||||
if CompareSubStrings('CLASS ',AProcCode,1,1,6,false)<>0 then
|
p:=1;
|
||||||
StartPos:=1
|
|
||||||
else
|
|
||||||
StartPos:=6;
|
|
||||||
ProcLen:=length(AProcCode);
|
ProcLen:=length(AProcCode);
|
||||||
// read proc keyword 'procedure', 'function', ...
|
// read proc keyword 'procedure', 'function', ...
|
||||||
while (StartPos<=ProcLen) and (IsSpaceChar[AProcCode[StartPos]]) do
|
ReadRawNextPascalAtom(AProcCode,p,KeyWordPos);
|
||||||
inc(StartPos);
|
//debugln(['TBeautifyCodeOptions.AddClassAndNameToProc keyword="',copy(AProcCode,KeyWordPos,p-KeyWordPos),'"']);
|
||||||
KeyWordPos:=StartPos;
|
if KeyWordPos>ProcLen then
|
||||||
while (StartPos<=ProcLen) and (IsIdentChar[AProcCode[StartPos]]) do
|
|
||||||
inc(StartPos);
|
|
||||||
if KeyWordPos=StartPos then
|
|
||||||
raise Exception.Create('TBeautifyCodeOptions.AddClassAndNameToProc missing keyword');
|
raise Exception.Create('TBeautifyCodeOptions.AddClassAndNameToProc missing keyword');
|
||||||
while (StartPos<=ProcLen) and (IsSpaceChar[AProcCode[StartPos]]) do
|
if CompareIdentifiers('CLASS',@AProcCode[KeyWordPos])=0 then begin
|
||||||
inc(StartPos);
|
ReadRawNextPascalAtom(AProcCode,p,KeyWordPos);
|
||||||
NamePos:=StartPos;
|
//debugln(['TBeautifyCodeOptions.AddClassAndNameToProc after class keyword="',copy(AProcCode,KeyWordPos,p-KeyWordPos),'"']);
|
||||||
while (StartPos<=ProcLen) and (IsIdentChar[AProcCode[StartPos]]) do
|
if KeyWordPos>ProcLen then
|
||||||
inc(StartPos);
|
raise Exception.Create('TBeautifyCodeOptions.AddClassAndNameToProc missing keyword');
|
||||||
if (NamePos=StartPos)
|
end;
|
||||||
or (CompareSubStrings('OF',AProcCode,1,NamePos,2,false)=0) then
|
if KeyWordPos>ProcLen then
|
||||||
|
raise Exception.Create('TBeautifyCodeOptions.AddClassAndNameToProc missing keyword');
|
||||||
|
// read name
|
||||||
|
ReadRawNextPascalAtom(AProcCode,p,NamePos);
|
||||||
|
//debugln(['TBeautifyCodeOptions.AddClassAndNameToProc name="',copy(AProcCode,NamePos,p-NamePos),'"']);
|
||||||
|
if (NamePos>ProcLen)
|
||||||
|
or (CompareIdentifiers('OF',@AProcCode[NamePos])=0) then
|
||||||
begin
|
begin
|
||||||
// there is no name yet
|
// there is no name yet
|
||||||
s:=AMethodName;
|
s:=AMethodName;
|
||||||
@ -1845,24 +1847,42 @@ begin
|
|||||||
+copy(AProcCode,NamePos,length(AProcCode)-NamePos+1);
|
+copy(AProcCode,NamePos,length(AProcCode)-NamePos+1);
|
||||||
end else begin
|
end else begin
|
||||||
// there is already a name
|
// there is already a name
|
||||||
if AClassName<>'' then begin
|
if AClassName='' then begin
|
||||||
while (StartPos<=ProcLen) do
|
// keep name
|
||||||
if IsSpaceChar[AProcCode[StartPos]] then
|
|
||||||
inc(StartPos)
|
|
||||||
else
|
|
||||||
if AProcCode[StartPos] = '<' then { the case of delphi style generics }
|
|
||||||
begin
|
|
||||||
while (StartPos<=ProcLen) and (AProcCode[StartPos]<>'>') do
|
|
||||||
inc(StartPos);
|
|
||||||
inc(StartPos)
|
|
||||||
end else Break;
|
|
||||||
if (StartPos<=ProcLen) and (AProcCode[StartPos]<>'.') then
|
|
||||||
Result:=copy(AProcCode,1,NamePos-1)+AClassName+'.'
|
|
||||||
+copy(AProcCode,NamePos,length(AProcCode)-NamePos+1)
|
|
||||||
else
|
|
||||||
Result:=AProcCode;
|
|
||||||
end else
|
|
||||||
Result:=AProcCode;
|
Result:=AProcCode;
|
||||||
|
end else begin
|
||||||
|
// read atom behind name
|
||||||
|
ReadRawNextPascalAtom(AProcCode,p,StartPos);
|
||||||
|
//debugln(['TBeautifyCodeOptions.AddClassAndNameToProc behind name="',copy(AProcCode,StartPos,p-StartPos),'"']);
|
||||||
|
if (p>StartPos) and (AProcCode[StartPos]='<') then begin
|
||||||
|
// skip generic "name<>"
|
||||||
|
Level:=1;
|
||||||
|
repeat
|
||||||
|
ReadRawNextPascalAtom(AProcCode,p,StartPos);
|
||||||
|
if StartPos>ProcLen then break;
|
||||||
|
case AProcCode[StartPos] of
|
||||||
|
'<': inc(Level);
|
||||||
|
'>':
|
||||||
|
begin
|
||||||
|
dec(Level);
|
||||||
|
if Level=0 then begin
|
||||||
|
ReadRawNextPascalAtom(AProcCode,p,StartPos);
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
//debugln(['TBeautifyCodeOptions.AddClassAndNameToProc behind <>="',copy(AProcCode,StartPos,p-StartPos),'"']);
|
||||||
|
end;
|
||||||
|
if (StartPos>ProcLen) or (AProcCode[StartPos]<>'.') then begin
|
||||||
|
// has no class name yet => insert
|
||||||
|
Result:=copy(AProcCode,1,NamePos-1)+AClassName+'.'
|
||||||
|
+copy(AProcCode,NamePos,length(AProcCode)-NamePos+1);
|
||||||
|
end else begin
|
||||||
|
// keep classname and name
|
||||||
|
Result:=AProcCode;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user