mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-27 08:21:36 +01:00
codetools: class completion Delphi generic, from Pascal Riekenberg
git-svn-id: trunk@56571 -
This commit is contained in:
parent
082c327248
commit
e70bcaab5a
@ -7202,7 +7202,7 @@ var
|
|||||||
RaiseExceptionFmt(20170421201752,ctsIndexParameterExpectedButAtomFound,[GetAtom]);
|
RaiseExceptionFmt(20170421201752,ctsIndexParameterExpectedButAtomFound,[GetAtom]);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
RaiseExceptionFmt(20170421201755,ctsStrExpectedButAtomFound,[';',GetAtom]);
|
RaiseExceptionFmt(20170421201755,ctsStrExpectedButAtomFound,[';',GetAtom]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -7515,7 +7515,7 @@ var
|
|||||||
begin
|
begin
|
||||||
ProcBody:=
|
ProcBody:=
|
||||||
'procedure '
|
'procedure '
|
||||||
+ExtractClassName(PropNode.Parent.Parent,false)+'.'+AccessParam
|
+ExtractClassName(PropNode.Parent.Parent,false,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE])+'.'+AccessParam
|
||||||
+'('+AccessVariableNameParam+':'+PropType+');'
|
+'('+AccessVariableNameParam+':'+PropType+');'
|
||||||
+BeautifyCodeOpts.LineEnd
|
+BeautifyCodeOpts.LineEnd
|
||||||
+'begin'+BeautifyCodeOpts.LineEnd
|
+'begin'+BeautifyCodeOpts.LineEnd
|
||||||
@ -7902,7 +7902,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
CurCode:=ANodeExt.ExtTxt1;
|
CurCode:=ANodeExt.ExtTxt1;
|
||||||
CurCode:=Beauty.BeautifyStatement(CurCode,Indent);
|
CurCode:=Beauty.BeautifyStatement(CurCode,Indent,[bcfChangeSymbolToBracketForGenericTypeBrackets]);
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TCodeCompletionCodeTool.InsertNewClassParts:');
|
DebugLn('TCodeCompletionCodeTool.InsertNewClassParts:');
|
||||||
DebugLn(CurCode);
|
DebugLn(CurCode);
|
||||||
@ -8722,7 +8722,7 @@ begin
|
|||||||
TypeSectionNode:=ClassNode.GetTopMostNodeOfType(ctnTypeSection);
|
TypeSectionNode:=ClassNode.GetTopMostNodeOfType(ctnTypeSection);
|
||||||
Result:=GatherProcNodes(TypeSectionNode,
|
Result:=GatherProcNodes(TypeSectionNode,
|
||||||
[phpInUpperCase,phpIgnoreForwards,phpOnlyWithClassname],
|
[phpInUpperCase,phpIgnoreForwards,phpOnlyWithClassname],
|
||||||
ExtractClassName(ClassNode,true));
|
ExtractClassName(ClassNode,true,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeCompletionCodeTool.CreateMissingClassProcBodies(
|
function TCodeCompletionCodeTool.CreateMissingClassProcBodies(
|
||||||
@ -9008,7 +9008,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
exit(true);
|
exit(true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result:=false;
|
Result:=false;
|
||||||
Beauty:=FSourceChangeCache.BeautifyCodeOptions;
|
Beauty:=FSourceChangeCache.BeautifyCodeOptions;
|
||||||
MethodInsertPolicy:=Beauty.MethodInsertPolicy;
|
MethodInsertPolicy:=Beauty.MethodInsertPolicy;
|
||||||
@ -9044,7 +9044,7 @@ begin
|
|||||||
{$IF defined(CTDEBUG) or defined(VerboseCreateMissingClassProcBodies)}
|
{$IF defined(CTDEBUG) or defined(VerboseCreateMissingClassProcBodies)}
|
||||||
DebugLn('TCodeCompletionCodeTool.CreateMissingClassProcBodies Gather existing method declarations ... ');
|
DebugLn('TCodeCompletionCodeTool.CreateMissingClassProcBodies Gather existing method declarations ... ');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
TheClassName:=ExtractClassName(CodeCompleteClassNode,false);
|
TheClassName:=ExtractClassName(CodeCompleteClassNode,false,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]);
|
||||||
|
|
||||||
// check for double defined methods in ClassProcs
|
// check for double defined methods in ClassProcs
|
||||||
CheckForDoubleDefinedMethods;
|
CheckForDoubleDefinedMethods;
|
||||||
@ -9167,7 +9167,8 @@ begin
|
|||||||
if (ExistingNode=nil) and (not ProcNodeHasSpecifier(ANodeExt.Node,psEXTERNAL))
|
if (ExistingNode=nil) and (not ProcNodeHasSpecifier(ANodeExt.Node,psEXTERNAL))
|
||||||
then begin
|
then begin
|
||||||
{$IFDEF VerboseCreateMissingClassProcBodies}
|
{$IFDEF VerboseCreateMissingClassProcBodies}
|
||||||
DebugLn(['TCodeCompletionCodeTool.CreateMissingClassProcBodies ANodeExt.Txt=',ANodeExt.Txt,' ExistingNode=',TCodeTreeNodeExtension(ExistingNode.Data).Txt]);
|
//generates AV:
|
||||||
|
//DebugLn(['TCodeCompletionCodeTool.CreateMissingClassProcBodies ANodeExt.Txt=',ANodeExt.Txt,' ExistingNode=',TCodeTreeNodeExtension(ExistingNode.Data).Txt]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// MissingNode does not have a body -> insert proc body
|
// MissingNode does not have a body -> insert proc body
|
||||||
case MethodInsertPolicy of
|
case MethodInsertPolicy of
|
||||||
@ -9588,7 +9589,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
// we have a codetool error, let's try to find the assignment in any case
|
// we have a codetool error, let's try to find the assignment in any case
|
||||||
LastCodeToolsErrorCleanPos := CurPos.StartPos;
|
LastCodeToolsErrorCleanPos := CurPos.StartPos;
|
||||||
LastCodeToolsError := ECodeToolError.Create(E.Sender,20170421201904,E.Message);
|
LastCodeToolsError := ECodeToolError.Create(E.Sender,E.Id,E.Message);
|
||||||
end else
|
end else
|
||||||
raise;
|
raise;
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -1327,7 +1327,7 @@ begin
|
|||||||
CurNode.Desc:=ctnProcedureHead;
|
CurNode.Desc:=ctnProcedureHead;
|
||||||
CheckOperatorProc(ParseAttr);
|
CheckOperatorProc(ParseAttr);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if Scanner.CompilerMode=cmDELPHI then
|
if Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE] then
|
||||||
ReadGenericParamList(false,true);
|
ReadGenericParamList(false,true);
|
||||||
if (CurPos.Flag<>cafPoint) then begin
|
if (CurPos.Flag<>cafPoint) then begin
|
||||||
// read rest
|
// read rest
|
||||||
@ -1659,7 +1659,7 @@ begin
|
|||||||
if (phpCreateNodes in Attr) then begin
|
if (phpCreateNodes in Attr) then begin
|
||||||
EndChildNode;
|
EndChildNode;
|
||||||
end;
|
end;
|
||||||
if (Scanner.CompilerMode=cmDELPHI) and AtomIsChar('<') then
|
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and AtomIsChar('<') then
|
||||||
ReadSpecialize(phpCreateNodes in Attr,Extract,Copying,Attr);
|
ReadSpecialize(phpCreateNodes in Attr,Extract,Copying,Attr);
|
||||||
end;
|
end;
|
||||||
if (phpCreateNodes in Attr) then begin
|
if (phpCreateNodes in Attr) then begin
|
||||||
@ -1772,7 +1772,7 @@ begin
|
|||||||
ReadTypeReference(pphCreateNodes in ParseAttr);
|
ReadTypeReference(pphCreateNodes in ParseAttr);
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if (Scanner.CompilerMode<>cmDelphi) then
|
if not (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) then
|
||||||
SaveRaiseCharExpectedButAtomFound(20170421195449,':')
|
SaveRaiseCharExpectedButAtomFound(20170421195449,':')
|
||||||
else begin
|
else begin
|
||||||
// Delphi Mode
|
// Delphi Mode
|
||||||
@ -4285,14 +4285,14 @@ begin
|
|||||||
inc(Cnt,2);
|
inc(Cnt,2);
|
||||||
end;
|
end;
|
||||||
if AtomIsChar('<') then begin
|
if AtomIsChar('<') then begin
|
||||||
if ((Cnt=1) and LastUpAtomIs(-1,'STRING'))
|
if ((Cnt=1) and LastUpAtomIs(1,'STRING'))
|
||||||
or ((Cnt=3) and LastUpAtomIs(-3,'SYSTEM') and LastUpAtomIs(-1,'STRING'))
|
or ((Cnt=3) and LastUpAtomIs(3,'SYSTEM') and LastUpAtomIs(1,'STRING'))
|
||||||
then begin
|
then begin
|
||||||
// e.g. string<codepage>
|
// e.g. string<codepage>
|
||||||
ReadAnsiStringParams;
|
ReadAnsiStringParams;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
end
|
end
|
||||||
else if (Scanner.CompilerMode=cmDELPHI) then begin
|
else if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) then begin
|
||||||
// e.g. atype<params>
|
// e.g. atype<params>
|
||||||
if CreateNodes then begin
|
if CreateNodes then begin
|
||||||
CurNode.Desc:=ctnSpecialize;
|
CurNode.Desc:=ctnSpecialize;
|
||||||
|
|||||||
@ -639,7 +639,7 @@ begin
|
|||||||
|
|
||||||
// build full class name
|
// build full class name
|
||||||
if ([phpAddClassname,phpWithoutClassName]*Attr=[phpAddClassName]) then
|
if ([phpAddClassname,phpWithoutClassName]*Attr=[phpAddClassName]) then
|
||||||
PrependName(ExtractClassName(ProcNode,phpInUpperCase in Attr,true),TheClassName);
|
PrependName(ExtractClassName(ProcNode,phpInUpperCase in Attr,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]),TheClassName);
|
||||||
|
|
||||||
// reparse the clean source
|
// reparse the clean source
|
||||||
InitExtraction;
|
InitExtraction;
|
||||||
@ -678,7 +678,7 @@ begin
|
|||||||
// read classname and name
|
// read classname and name
|
||||||
repeat
|
repeat
|
||||||
ExtractNextAtom(true,Attr);
|
ExtractNextAtom(true,Attr);
|
||||||
if Scanner.CompilerMode = cmDELPHI then
|
if Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE] then
|
||||||
begin
|
begin
|
||||||
// delphi generics
|
// delphi generics
|
||||||
if AtomIsChar('<') then
|
if AtomIsChar('<') then
|
||||||
@ -698,7 +698,7 @@ begin
|
|||||||
// read only part of name
|
// read only part of name
|
||||||
repeat
|
repeat
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if (Scanner.CompilerMode = cmDELPHI) and AtomIsChar('<') then
|
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and AtomIsChar('<') then
|
||||||
begin
|
begin
|
||||||
while not AtomIsChar('>') and (CurPos.EndPos < SrcLen) do
|
while not AtomIsChar('>') and (CurPos.EndPos < SrcLen) do
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
@ -887,7 +887,7 @@ begin
|
|||||||
Result:=GetIdentifier(@Src[Node.StartPos])+Result
|
Result:=GetIdentifier(@Src[Node.StartPos])+Result
|
||||||
else if Node.FirstChild<>nil then
|
else if Node.FirstChild<>nil then
|
||||||
begin
|
begin
|
||||||
if (Scanner.CompilerMode = cmDELPHI) and (Node.Desc = ctnGenericType) then
|
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and (Node.Desc = ctnGenericType) then
|
||||||
Result := Result + ExtractNode(Node.FirstChild.NextBrother, []);
|
Result := Result + ExtractNode(Node.FirstChild.NextBrother, []);
|
||||||
Result:=GetIdentifier(@Src[Node.FirstChild.StartPos])+Result;
|
Result:=GetIdentifier(@Src[Node.FirstChild.StartPos])+Result;
|
||||||
end;
|
end;
|
||||||
@ -953,7 +953,7 @@ begin
|
|||||||
if not AtomIsIdentifier then break;
|
if not AtomIsIdentifier then break;
|
||||||
Part:=GetAtom;
|
Part:=GetAtom;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if (Scanner.CompilerMode = cmDELPHI) and AtomIsChar('<') then
|
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and AtomIsChar('<') then
|
||||||
begin { delphi generics }
|
begin { delphi generics }
|
||||||
Part := Part + GetAtom;
|
Part := Part + GetAtom;
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
@ -97,7 +97,8 @@ type
|
|||||||
TBeautifyCodeFlag = (
|
TBeautifyCodeFlag = (
|
||||||
bcfNoIndentOnBreakLine,
|
bcfNoIndentOnBreakLine,
|
||||||
bcfDoNotIndentFirstLine,
|
bcfDoNotIndentFirstLine,
|
||||||
bcfIndentExistingLineBreaks
|
bcfIndentExistingLineBreaks,
|
||||||
|
bcfChangeSymbolToBracketForGenericTypeBrackets
|
||||||
);
|
);
|
||||||
TBeautifyCodeFlags = set of TBeautifyCodeFlag;
|
TBeautifyCodeFlags = set of TBeautifyCodeFlag;
|
||||||
|
|
||||||
@ -1738,7 +1739,7 @@ var
|
|||||||
p, CurAtomStart: PChar;
|
p, CurAtomStart: PChar;
|
||||||
Start: String;
|
Start: String;
|
||||||
begin
|
begin
|
||||||
Result:=BeautifyStatement(AProcCode,IndentSize);
|
Result:=BeautifyStatement(AProcCode,IndentSize,[bcfChangeSymbolToBracketForGenericTypeBrackets]);
|
||||||
if AddBeginEnd then begin
|
if AddBeginEnd then begin
|
||||||
Start:='begin';
|
Start:='begin';
|
||||||
p:=PChar(AProcCode);
|
p:=PChar(AProcCode);
|
||||||
@ -1833,15 +1834,18 @@ begin
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
until false;
|
until false;
|
||||||
|
// in implementation of generic methods
|
||||||
|
// "<" and ">" have a sense of brackets
|
||||||
|
if (
|
||||||
|
AfterProcedure
|
||||||
|
or (bcfChangeSymbolToBracketForGenericTypeBrackets in BeautifyFlags)
|
||||||
|
) and (CurAtomType = atSymbol)
|
||||||
|
and (CurAtom[1] in ['<', '>']) then
|
||||||
|
CurAtomType := atBracket;
|
||||||
if AfterProcedure then
|
if AfterProcedure then
|
||||||
begin
|
begin
|
||||||
if CurAtomType = atSemicolon then
|
if CurAtomType = atSemicolon then
|
||||||
AfterProcedure := False
|
AfterProcedure := False;
|
||||||
else
|
|
||||||
// in implementation of generic methods in DELPHI mode
|
|
||||||
// "<" and ">" have a sense of brackets
|
|
||||||
if (CurAtomType = atSymbol) and (CurAtom[1] in ['<', '>']) then
|
|
||||||
CurAtomType := atBracket;
|
|
||||||
end else
|
end else
|
||||||
if (CurAtomType = atKeyword)
|
if (CurAtomType = atKeyword)
|
||||||
and (SameText(CurAtom, 'procedure') or SameText(CurAtom, 'function'))
|
and (SameText(CurAtom, 'procedure') or SameText(CurAtom, 'function'))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user