IDE: fixed adding event, when property unit has no implementation section

git-svn-id: trunk@61195 -
This commit is contained in:
mattias 2019-05-10 13:11:43 +00:00
parent 2248ddea17
commit e408bd979a
2 changed files with 35 additions and 6 deletions

View File

@ -557,6 +557,8 @@ begin
ContextNode:=FindImplementationNode; ContextNode:=FindImplementationNode;
if ContextNode=nil then if ContextNode=nil then
ContextNode:=FindMainBeginEndNode; ContextNode:=FindMainBeginEndNode;
if ContextNode=nil then
ContextNode:=FindInterfaceNode;
if ContextNode=nil then begin if ContextNode=nil then begin
MoveCursorToNodeStart(Tree.Root); MoveCursorToNodeStart(Tree.Root);
RaiseExceptionFmt(20170421202000,ctsIdentifierNotFound,[GetIdentifier(@TypeName[1])]); RaiseExceptionFmt(20170421202000,ctsIdentifierNotFound,[GetIdentifier(@TypeName[1])]);
@ -565,7 +567,9 @@ begin
try try
Params.SetIdentifier(Self,@TypeName[1],nil); Params.SetIdentifier(Self,@TypeName[1],nil);
Params.Flags:=[fdfExceptionOnNotFound,fdfSearchInParentNodes]; Params.Flags:=[fdfExceptionOnNotFound,fdfSearchInParentNodes];
//DebugLn(['TEventsCodeTool.FindMethodTypeInfo TypeName=',TypeName,' MainFilename=',MainFilename]); {$IFDEF VerboseMethodPropEdit}
DebugLn(['TEventsCodeTool.FindMethodTypeInfo TypeName=',TypeName,' MainFilename=',MainFilename,' ContextNode=',ContextNode.DescAsString]);
{$ENDIF}
FindIdentifierInContext(Params); FindIdentifierInContext(Params);
// find proc node // find proc node
if Params.NewNode.Desc<>ctnTypeDefinition then begin if Params.NewNode.Desc<>ctnTypeDefinition then begin
@ -891,6 +895,9 @@ function TEventsCodeTool.CreateMethod(ClassNode: TCodeTreeNode;
Result:=false; Result:=false;
if APropertyPath<>'' then begin if APropertyPath<>'' then begin
// find unit of property // find unit of property
{$IFDEF VerboseMethodPropEdit}
debugln(['FindPropertyType APropertyPath="',APropertyPath,'"']);
{$ENDIF}
Tool:=nil; Tool:=nil;
FindContext:=CleanFindContext; FindContext:=CleanFindContext;
if APropertyUnitName='' then begin if APropertyUnitName='' then begin
@ -906,14 +913,23 @@ function TEventsCodeTool.CreateMethod(ClassNode: TCodeTreeNode;
DebugLn(['FindPropertyType FindDeclarationOfPropertyPath failed: ',Tool.MainFilename,' APropertyPath=',APropertyPath]); DebugLn(['FindPropertyType FindDeclarationOfPropertyPath failed: ',Tool.MainFilename,' APropertyPath=',APropertyPath]);
exit; exit;
end; end;
{$IFDEF VerboseMethodPropEdit}
debugln(['FindPropertyType SUCCESS Tool=',Tool.MainFilename,' Found APropertyPath="',APropertyPath,'" Found=',FindContextToString(FindContext)]);
{$ENDIF}
if FindContext.Node.Desc<>ctnProperty then if FindContext.Node.Desc<>ctnProperty then
FindContext.Tool.RaiseException(20170421202114, FindContext.Tool.RaiseException(20170421202114,
APropertyPath+' is not a property.' APropertyPath+' is not a property.'
+' See '+FindContext.Tool.MainFilename +' See '+FindContext.Tool.MainFilename
+' '+FindContext.Tool.CleanPosToStr(FindContext.Node.StartPos)); +' '+FindContext.Tool.CleanPosToStr(FindContext.Node.StartPos));
// find type // find type
{$IFDEF VerboseMethodPropEdit}
debugln(['FindPropertyType ATypeInfo^.Name=',ATypeInfo^.Name]);
{$ENDIF}
FindContext:=(FindContext.Tool as TEventsCodeTool) FindContext:=(FindContext.Tool as TEventsCodeTool)
.FindMethodTypeInfo(ATypeInfo,''); .FindMethodTypeInfo(ATypeInfo,'');
{$IFDEF VerboseMethodPropEdit}
debugln(['FindPropertyType SUCCESS Found MethodTypeInfo="',FindContextToString(FindContext),'"']);
{$ENDIF}
end else end else
FindContext:=FindMethodTypeInfo(ATypeInfo,APropertyUnitName); FindContext:=FindMethodTypeInfo(ATypeInfo,APropertyUnitName);
Result:=true; Result:=true;
@ -931,7 +947,10 @@ begin
Result:=false; Result:=false;
try try
if (ClassNode=nil) or (not (ClassNode.Desc in [ctnClass,ctnObjCClass])) or (AMethodName='') if (ClassNode=nil) or (not (ClassNode.Desc in [ctnClass,ctnObjCClass])) or (AMethodName='')
or (ATypeInfo=nil) or (SourceChangeCache=nil) or (Scanner=nil) then exit; or (ATypeInfo=nil) or (SourceChangeCache=nil) or (Scanner=nil) then begin
debugln(['TEventsCodeTool.CreateMethod failed, missing parameter']);
exit;
end;
if CallAncestorMethod<>'' then if CallAncestorMethod<>'' then
AddOverride:=true; AddOverride:=true;
{$IFDEF VerboseMethodPropEdit} {$IFDEF VerboseMethodPropEdit}
@ -949,13 +968,23 @@ begin
if UseTypeInfoForParameters then begin if UseTypeInfoForParameters then begin
// do not lookup the declaration in the source, use RTTI instead // do not lookup the declaration in the source, use RTTI instead
ATypeData:=GetTypeData(ATypeInfo); ATypeData:=GetTypeData(ATypeInfo);
if ATypeData=nil then exit(false); if ATypeData=nil then begin
{$IFDEF VerboseMethodPropEdit}
DebugLn('ERROR: [TEventsCodeTool.CreateMethod] GetTypeData failed');
{$ENDIF}
exit;
end;
CleanMethodDefinition:=UpperCaseStr(AMethodName) CleanMethodDefinition:=UpperCaseStr(AMethodName)
+MethodTypeDataToStr(ATypeData, +MethodTypeDataToStr(ATypeData,
[phpWithoutClassName, phpWithoutName, phpInUpperCase]); [phpWithoutClassName, phpWithoutName, phpInUpperCase]);
end else begin end else begin
// search typeinfo in source // search typeinfo in source
if not FindPropertyType(FindContext) then exit; if not FindPropertyType(FindContext) then begin
{$IFDEF VerboseMethodPropEdit}
DebugLn('ERROR: [TEventsCodeTool.CreateMethod] FindPropertyType failed');
{$ENDIF}
exit;
end;
AddNeededUnits(FindContext); AddNeededUnits(FindContext);
CleanMethodDefinition:=UpperCaseStr(AMethodName) CleanMethodDefinition:=UpperCaseStr(AMethodName)
+FindContext.Tool.ExtractProcHead(FindContext.Node, +FindContext.Tool.ExtractProcHead(FindContext.Node,

View File

@ -12813,8 +12813,8 @@ begin
Result.Code:=nil; Result.Code:=nil;
Result.Data:=nil; Result.Data:=nil;
ActiveSrcEdit:=nil; ActiveSrcEdit:=nil;
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource]) if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource]) then
then exit; exit;
{$IFDEF VerboseOnPropHookCreateMethod} {$IFDEF VerboseOnPropHookCreateMethod}
debugln(''); debugln('');
debugln('[TMainIDE.OnPropHookCreateMethod] ************ ',AMethodName); debugln('[TMainIDE.OnPropHookCreateMethod] ************ ',AMethodName);