codetools: class completion Delphi generic, from Pascal Riekenberg

git-svn-id: trunk@56571 -
This commit is contained in:
mattias 2017-12-01 09:40:20 +00:00
parent 082c327248
commit e70bcaab5a
4 changed files with 32 additions and 27 deletions

View File

@ -7202,7 +7202,7 @@ var
RaiseExceptionFmt(20170421201752,ctsIndexParameterExpectedButAtomFound,[GetAtom]);
ReadNextAtom;
end;
end else
end else
RaiseExceptionFmt(20170421201755,ctsStrExpectedButAtomFound,[';',GetAtom]);
end;
end;
@ -7515,7 +7515,7 @@ var
begin
ProcBody:=
'procedure '
+ExtractClassName(PropNode.Parent.Parent,false)+'.'+AccessParam
+ExtractClassName(PropNode.Parent.Parent,false,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE])+'.'+AccessParam
+'('+AccessVariableNameParam+':'+PropType+');'
+BeautifyCodeOpts.LineEnd
+'begin'+BeautifyCodeOpts.LineEnd
@ -7902,7 +7902,7 @@ begin
end;
end;
CurCode:=ANodeExt.ExtTxt1;
CurCode:=Beauty.BeautifyStatement(CurCode,Indent);
CurCode:=Beauty.BeautifyStatement(CurCode,Indent,[bcfChangeSymbolToBracketForGenericTypeBrackets]);
{$IFDEF CTDEBUG}
DebugLn('TCodeCompletionCodeTool.InsertNewClassParts:');
DebugLn(CurCode);
@ -8722,7 +8722,7 @@ begin
TypeSectionNode:=ClassNode.GetTopMostNodeOfType(ctnTypeSection);
Result:=GatherProcNodes(TypeSectionNode,
[phpInUpperCase,phpIgnoreForwards,phpOnlyWithClassname],
ExtractClassName(ClassNode,true));
ExtractClassName(ClassNode,true,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]));
end;
function TCodeCompletionCodeTool.CreateMissingClassProcBodies(
@ -9008,7 +9008,7 @@ begin
{$ENDIF}
exit(true);
end;
Result:=false;
Beauty:=FSourceChangeCache.BeautifyCodeOptions;
MethodInsertPolicy:=Beauty.MethodInsertPolicy;
@ -9044,7 +9044,7 @@ begin
{$IF defined(CTDEBUG) or defined(VerboseCreateMissingClassProcBodies)}
DebugLn('TCodeCompletionCodeTool.CreateMissingClassProcBodies Gather existing method declarations ... ');
{$ENDIF}
TheClassName:=ExtractClassName(CodeCompleteClassNode,false);
TheClassName:=ExtractClassName(CodeCompleteClassNode,false,true,Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]);
// check for double defined methods in ClassProcs
CheckForDoubleDefinedMethods;
@ -9167,7 +9167,8 @@ begin
if (ExistingNode=nil) and (not ProcNodeHasSpecifier(ANodeExt.Node,psEXTERNAL))
then begin
{$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}
// MissingNode does not have a body -> insert proc body
case MethodInsertPolicy of
@ -9588,7 +9589,7 @@ begin
begin
// we have a codetool error, let's try to find the assignment in any case
LastCodeToolsErrorCleanPos := CurPos.StartPos;
LastCodeToolsError := ECodeToolError.Create(E.Sender,20170421201904,E.Message);
LastCodeToolsError := ECodeToolError.Create(E.Sender,E.Id,E.Message);
end else
raise;
end;

View File

@ -1327,7 +1327,7 @@ begin
CurNode.Desc:=ctnProcedureHead;
CheckOperatorProc(ParseAttr);
ReadNextAtom;
if Scanner.CompilerMode=cmDELPHI then
if Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE] then
ReadGenericParamList(false,true);
if (CurPos.Flag<>cafPoint) then begin
// read rest
@ -1659,7 +1659,7 @@ begin
if (phpCreateNodes in Attr) then begin
EndChildNode;
end;
if (Scanner.CompilerMode=cmDELPHI) and AtomIsChar('<') then
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and AtomIsChar('<') then
ReadSpecialize(phpCreateNodes in Attr,Extract,Copying,Attr);
end;
if (phpCreateNodes in Attr) then begin
@ -1772,7 +1772,7 @@ begin
ReadTypeReference(pphCreateNodes in ParseAttr);
end
else begin
if (Scanner.CompilerMode<>cmDelphi) then
if not (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) then
SaveRaiseCharExpectedButAtomFound(20170421195449,':')
else begin
// Delphi Mode
@ -4285,14 +4285,14 @@ begin
inc(Cnt,2);
end;
if AtomIsChar('<') then begin
if ((Cnt=1) and LastUpAtomIs(-1,'STRING'))
or ((Cnt=3) and LastUpAtomIs(-3,'SYSTEM') and LastUpAtomIs(-1,'STRING'))
if ((Cnt=1) and LastUpAtomIs(1,'STRING'))
or ((Cnt=3) and LastUpAtomIs(3,'SYSTEM') and LastUpAtomIs(1,'STRING'))
then begin
// e.g. string<codepage>
ReadAnsiStringParams;
ReadNextAtom;
end
else if (Scanner.CompilerMode=cmDELPHI) then begin
else if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) then begin
// e.g. atype<params>
if CreateNodes then begin
CurNode.Desc:=ctnSpecialize;

View File

@ -639,7 +639,7 @@ begin
// build full class name
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
InitExtraction;
@ -678,7 +678,7 @@ begin
// read classname and name
repeat
ExtractNextAtom(true,Attr);
if Scanner.CompilerMode = cmDELPHI then
if Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE] then
begin
// delphi generics
if AtomIsChar('<') then
@ -698,7 +698,7 @@ begin
// read only part of name
repeat
ReadNextAtom;
if (Scanner.CompilerMode = cmDELPHI) and AtomIsChar('<') then
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and AtomIsChar('<') then
begin
while not AtomIsChar('>') and (CurPos.EndPos < SrcLen) do
ReadNextAtom;
@ -887,7 +887,7 @@ begin
Result:=GetIdentifier(@Src[Node.StartPos])+Result
else if Node.FirstChild<>nil then
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:=GetIdentifier(@Src[Node.FirstChild.StartPos])+Result;
end;
@ -953,7 +953,7 @@ begin
if not AtomIsIdentifier then break;
Part:=GetAtom;
ReadNextAtom;
if (Scanner.CompilerMode = cmDELPHI) and AtomIsChar('<') then
if (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) and AtomIsChar('<') then
begin { delphi generics }
Part := Part + GetAtom;
repeat

View File

@ -97,7 +97,8 @@ type
TBeautifyCodeFlag = (
bcfNoIndentOnBreakLine,
bcfDoNotIndentFirstLine,
bcfIndentExistingLineBreaks
bcfIndentExistingLineBreaks,
bcfChangeSymbolToBracketForGenericTypeBrackets
);
TBeautifyCodeFlags = set of TBeautifyCodeFlag;
@ -1738,7 +1739,7 @@ var
p, CurAtomStart: PChar;
Start: String;
begin
Result:=BeautifyStatement(AProcCode,IndentSize);
Result:=BeautifyStatement(AProcCode,IndentSize,[bcfChangeSymbolToBracketForGenericTypeBrackets]);
if AddBeginEnd then begin
Start:='begin';
p:=PChar(AProcCode);
@ -1833,15 +1834,18 @@ begin
else
break;
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
begin
if CurAtomType = atSemicolon then
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;
AfterProcedure := False;
end else
if (CurAtomType = atKeyword)
and (SameText(CurAtom, 'procedure') or SameText(CurAtom, 'function'))