From bba64bdf3c485d1549fb8223f0b840401eda7648 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 24 May 2011 21:55:20 +0000 Subject: [PATCH] codetools: GuessTypeOfIdentifier: guess type of for-in git-svn-id: trunk@30893 - --- components/codetools/codecompletiontool.pas | 36 ++++++++++++++++++++- components/codetools/ide/declarevardlg.pas | 1 - 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 705bfb1afe..8fa6afeaff 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -5337,6 +5337,7 @@ var Section: TCodeTreeNode; ExistingNodeInProc: Boolean; Keep: Boolean; + InAtomEndPos: Integer; begin Result:=false; IsKeyword:=false; @@ -5450,7 +5451,40 @@ begin end; debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier Assignment type=',NewType]); Result:=true; - end else begin + end; + + if not Result then begin + MoveCursorToAtomPos(IdentifierAtom); + // find 'in' operator + ReadNextAtom; + if UpAtomIs('IN') then begin + InAtomEndPos:=CurPos.EndPos; + + // find 'for' keyword + MoveCursorToCleanPos(IdentifierAtom.StartPos); + ReadPriorAtom; + if not UpAtomIs('FOR') then exit; + + // find term + MoveCursorToCleanPos(InAtomEndPos); + ReadNextAtom; + TermAtom.StartPos:=CurPos.StartPos; + TermAtom.EndPos:=FindEndOfExpression(TermAtom.StartPos); + + debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier guessing type of for-in list "',dbgstr(Src,TermAtom.StartPos,TermAtom.EndPos-TermAtom.StartPos),'"']); + // find type of term + Params:=TFindDeclarationParams.Create; + try + NewType:=FindForInTypeAsString(TermAtom,CursorNode,Params,NewExprType); + finally + Params.Free; + end; + debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier For-In type=',NewType]); + Result:=true; + end; + end; + + if not Result then begin debugln(['TCodeCompletionCodeTool.GuessTypeOfIdentifier can not guess type']); exit; end; diff --git a/components/codetools/ide/declarevardlg.pas b/components/codetools/ide/declarevardlg.pas index 0b755d5f97..c701217e00 100644 --- a/components/codetools/ide/declarevardlg.pas +++ b/components/codetools/ide/declarevardlg.pas @@ -26,7 +26,6 @@ that the user needs only to choose where to create the var. ToDo: - - guess for in - guess parameter - guess j:= - Extend uses section when adding to a class