mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 15:09:26 +02:00
Converter: Add variables in class when components (like menu item) are only in LFM. Changed also CheckLFM. Issue #24473.
git-svn-id: trunk@41948 -
This commit is contained in:
parent
8ae11e18a5
commit
1182ff0df2
components/codetools
converter
@ -239,10 +239,6 @@ type
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
protected
|
||||
procedure DoDeleteNodes(StartNode: TCodeTreeNode); override;
|
||||
property CodeCompleteClassNode: TCodeTreeNode
|
||||
read FCodeCompleteClassNode write SetCodeCompleteClassNode;
|
||||
property CodeCompleteSrcChgCache: TSourceChangeCache
|
||||
read FSourceChangeCache write SetCodeCompleteSrcChgCache;
|
||||
public
|
||||
constructor Create;
|
||||
function CompleteCode(CursorPos: TCodeXYPosition; OldTopLine: integer;
|
||||
@ -373,6 +369,10 @@ type
|
||||
property AddInheritedCodeToOverrideMethod: boolean
|
||||
read FAddInheritedCodeToOverrideMethod
|
||||
write FAddInheritedCodeToOverrideMethod;
|
||||
property CodeCompleteClassNode: TCodeTreeNode
|
||||
read FCodeCompleteClassNode write SetCodeCompleteClassNode;
|
||||
property CodeCompleteSrcChgCache: TSourceChangeCache
|
||||
read FSourceChangeCache write SetCodeCompleteSrcChgCache;
|
||||
|
||||
procedure CalcMemSize(Stats: TCTMemStats); override;
|
||||
end;
|
||||
@ -532,7 +532,7 @@ procedure TCodeCompletionCodeTool.AddClassInsertion(
|
||||
{ add an insert request entry to the list of insertions
|
||||
For example: a request to insert a new variable or a new method to the class
|
||||
|
||||
CleanDef: The sceleton of the new insertion. e.g. the variablename or the
|
||||
CleanDef: The skeleton of the new insertion. e.g. the variablename or the
|
||||
method header without parameter names.
|
||||
Def: The insertion code.
|
||||
IdentifierName: e.g. the variablename or the method name
|
||||
|
@ -202,11 +202,12 @@ type
|
||||
lfmeParseError,
|
||||
lfmeMissingRoot,
|
||||
lfmeIdentifierNotFound,
|
||||
lfmeIdentifierNotPublished,
|
||||
lfmeIdentifierMissingInCode,
|
||||
lfmeObjectNameMissing,
|
||||
lfmeObjectIncompatible,
|
||||
lfmePropertyNameMissing,
|
||||
lfmePropertyHasNoSubProperties,
|
||||
lfmeIdentifierNotPublished,
|
||||
lfmeEndNotFound
|
||||
);
|
||||
TLFMErrorTypes = set of TLFMErrorType;
|
||||
@ -304,11 +305,12 @@ const
|
||||
'ParseError',
|
||||
'MissingRoot',
|
||||
'IdentifierNotFound',
|
||||
'IdentifierNotPublished',
|
||||
'IdentifierMissingInCode',
|
||||
'ObjectNameMissing',
|
||||
'ObjectIncompatible',
|
||||
'PropertyNameMissing',
|
||||
'PropertyHasNoSubProperties',
|
||||
'IdentifierNotPublished',
|
||||
'EndNotFound'
|
||||
);
|
||||
|
||||
|
@ -2269,17 +2269,16 @@ var
|
||||
end;
|
||||
end;
|
||||
if (not Result) and ErrorOnNotFound then begin
|
||||
if (IdentContext.Node<>nil) and (not IsPublished) then begin
|
||||
if (IdentContext.Node<>nil) and (not IsPublished) then
|
||||
LFMTree.AddError(lfmeIdentifierNotPublished,LFMNode,
|
||||
'identifier '+IdentName+' is not published in class '
|
||||
+'"'+ClassContext.Tool.ExtractClassName(ClassContext.Node,false,true)+'"',
|
||||
DefaultErrorPosition);
|
||||
end else begin
|
||||
LFMTree.AddError(lfmeIdentifierNotFound,LFMNode,
|
||||
'identifier '+IdentName+' not found in class '
|
||||
+'"'+ClassContext.Tool.ExtractClassName(ClassContext.Node,false,true)+'"',
|
||||
DefaultErrorPosition);
|
||||
end;
|
||||
//else -- CheckLFMChildObject adds lfmeIdentifierMissingInCode error for this.
|
||||
// LFMTree.AddError(lfmeIdentifierNotFound,LFMNode,
|
||||
// 'identifier '+IdentName+' not found in class '
|
||||
// +'"'+ClassContext.Tool.ExtractClassName(ClassContext.Node,false,true)+'"',
|
||||
// DefaultErrorPosition);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -2478,12 +2477,16 @@ var
|
||||
end else begin
|
||||
// try the object type
|
||||
ClassContext:=FindClassContext(LFMObject.TypeName);
|
||||
if ClassContext.Node=nil then begin
|
||||
if ClassContext.Node=nil then
|
||||
// object type not found
|
||||
LFMTree.AddError(lfmeIdentifierNotFound,LFMObject,
|
||||
'type '+LFMObject.TypeName+' not found',
|
||||
LFMObject.TypeNamePosition);
|
||||
end;
|
||||
LFMObject.TypeNamePosition)
|
||||
else
|
||||
// object type found but has no variable in code
|
||||
LFMTree.AddError(lfmeIdentifierMissingInCode,LFMObject,
|
||||
'no variable in code for '+LFMObjectName+', type '+LFMObject.TypeName,
|
||||
LFMObject.TypeNamePosition);
|
||||
end;
|
||||
// check child LFM nodes
|
||||
if ClassContext.Node<>nil then
|
||||
@ -2493,8 +2496,7 @@ var
|
||||
end;
|
||||
|
||||
function FindClassNodeForPropertyType(LFMProperty: TLFMPropertyNode;
|
||||
DefaultErrorPosition: integer; const PropertyContext: TFindContext
|
||||
): TFindContext;
|
||||
DefaultErrorPosition: integer; const PropertyContext: TFindContext): TFindContext;
|
||||
var
|
||||
Params: TFindDeclarationParams;
|
||||
begin
|
||||
|
@ -342,9 +342,9 @@ var
|
||||
OldType, NewType: String;
|
||||
begin
|
||||
Result:=false;
|
||||
if fCTLink.CodeTool=nil then exit;
|
||||
Assert(Assigned(fCTLink.CodeTool));
|
||||
with fCTLink.CodeTool do begin
|
||||
if Scanner=nil then exit;
|
||||
Assert(Assigned(Scanner));
|
||||
BuildTree(lsrImplementationStart);
|
||||
// Find the class name that the main class inherits from.
|
||||
ANode:=FindClassNodeInUnit(AClassName,true,false,false,false);
|
||||
|
@ -27,12 +27,12 @@ object FixLFMDialog: TFixLFMDialog
|
||||
Width = 408
|
||||
Align = alLeft
|
||||
Caption = 'LFM file'
|
||||
ClientHeight = 450
|
||||
ClientHeight = 449
|
||||
ClientWidth = 404
|
||||
TabOrder = 0
|
||||
inline LFMSynEdit: TSynEdit
|
||||
Left = 0
|
||||
Height = 450
|
||||
Height = 449
|
||||
Top = 0
|
||||
Width = 404
|
||||
Align = alClient
|
||||
@ -460,17 +460,31 @@ object FixLFMDialog: TFixLFMDialog
|
||||
)
|
||||
VisibleSpecialChars = [vscSpace, vscTabAtLast]
|
||||
ReadOnly = True
|
||||
SelectedColor.FrameEdges = sfeAround
|
||||
SelectedColor.BackPriority = 50
|
||||
SelectedColor.ForePriority = 50
|
||||
SelectedColor.FramePriority = 50
|
||||
SelectedColor.BoldPriority = 50
|
||||
SelectedColor.ItalicPriority = 50
|
||||
SelectedColor.UnderlinePriority = 50
|
||||
SelectedColor.StrikeOutPriority = 50
|
||||
IncrementColor.FrameEdges = sfeAround
|
||||
HighlightAllColor.FrameEdges = sfeAround
|
||||
BracketHighlightStyle = sbhsBoth
|
||||
BracketMatchColor.Background = clNone
|
||||
BracketMatchColor.Foreground = clNone
|
||||
BracketMatchColor.FrameEdges = sfeAround
|
||||
BracketMatchColor.Style = [fsBold]
|
||||
FoldedCodeColor.Background = clNone
|
||||
FoldedCodeColor.Foreground = clGray
|
||||
FoldedCodeColor.FrameColor = clGray
|
||||
FoldedCodeColor.FrameEdges = sfeAround
|
||||
MouseLinkColor.Background = clNone
|
||||
MouseLinkColor.Foreground = clBlue
|
||||
MouseLinkColor.FrameEdges = sfeAround
|
||||
LineHighlightColor.Background = clNone
|
||||
LineHighlightColor.Foreground = clNone
|
||||
LineHighlightColor.FrameEdges = sfeAround
|
||||
OnSpecialLineMarkup = LFMSynEditSpecialLineMarkup
|
||||
inline TSynGutterPartList
|
||||
object TSynGutterMarks
|
||||
@ -482,6 +496,7 @@ object FixLFMDialog: TFixLFMDialog
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clBtnFace
|
||||
MarkupInfo.Foreground = clNone
|
||||
MarkupInfo.FrameEdges = sfeAround
|
||||
DigitCount = 2
|
||||
ShowOnlyLineNumbersMultiplesOf = 1
|
||||
ZeroStart = False
|
||||
@ -496,6 +511,9 @@ object FixLFMDialog: TFixLFMDialog
|
||||
object TSynGutterSeparator
|
||||
Width = 2
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clWhite
|
||||
MarkupInfo.Foreground = clGray
|
||||
MarkupInfo.FrameEdges = sfeAround
|
||||
end
|
||||
object TSynGutterCodeFolding
|
||||
MouseActions = <
|
||||
@ -526,6 +544,7 @@ object FixLFMDialog: TFixLFMDialog
|
||||
end>
|
||||
MarkupInfo.Background = clNone
|
||||
MarkupInfo.Foreground = clGray
|
||||
MarkupInfo.FrameEdges = sfeAround
|
||||
MouseActionsExpanded = <
|
||||
item
|
||||
ClickCount = ccAny
|
||||
@ -558,12 +577,12 @@ object FixLFMDialog: TFixLFMDialog
|
||||
Width = 756
|
||||
Align = alBottom
|
||||
Caption = 'Errors'
|
||||
ClientHeight = 86
|
||||
ClientHeight = 85
|
||||
ClientWidth = 752
|
||||
TabOrder = 1
|
||||
object ErrorsListBox: TListBox
|
||||
Left = 0
|
||||
Height = 86
|
||||
Height = 85
|
||||
Top = 0
|
||||
Width = 752
|
||||
Align = alClient
|
||||
@ -584,10 +603,10 @@ object FixLFMDialog: TFixLFMDialog
|
||||
ClientWidth = 756
|
||||
TabOrder = 2
|
||||
object CancelButton: TBitBtn
|
||||
Left = 668
|
||||
Left = 660
|
||||
Height = 33
|
||||
Top = 6
|
||||
Width = 82
|
||||
Width = 90
|
||||
Align = alRight
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
@ -595,18 +614,16 @@ object FixLFMDialog: TFixLFMDialog
|
||||
Caption = 'Cancel'
|
||||
Kind = bkCancel
|
||||
ModalResult = 2
|
||||
NumGlyphs = 0
|
||||
TabOrder = 0
|
||||
end
|
||||
object ReplaceAllButton: TBitBtn
|
||||
Left = 6
|
||||
Height = 25
|
||||
Height = 26
|
||||
Top = 6
|
||||
Width = 182
|
||||
Width = 224
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Fix unknown properties and types'
|
||||
NumGlyphs = 0
|
||||
OnClick = ReplaceAllButtonClick
|
||||
TabOrder = 1
|
||||
end
|
||||
@ -618,7 +635,7 @@ object FixLFMDialog: TFixLFMDialog
|
||||
Width = 343
|
||||
Align = alClient
|
||||
Caption = 'Replacements'
|
||||
ClientHeight = 450
|
||||
ClientHeight = 449
|
||||
ClientWidth = 339
|
||||
TabOrder = 3
|
||||
object PropReplaceGrid: TStringGrid
|
||||
@ -669,7 +686,7 @@ object FixLFMDialog: TFixLFMDialog
|
||||
end
|
||||
object TypeReplaceGrid: TStringGrid
|
||||
Left = 0
|
||||
Height = 224
|
||||
Height = 223
|
||||
Top = 226
|
||||
Width = 339
|
||||
Align = alClient
|
||||
|
@ -38,7 +38,7 @@ uses
|
||||
// components
|
||||
SynHighlighterLFM, SynEdit, SynEditMiscClasses, LFMTrees,
|
||||
// codetools
|
||||
BasicCodeTools, CodeCache, CodeToolManager, CodeToolsStructs,
|
||||
BasicCodeTools, CodeCache, CodeToolManager, CodeToolsStructs, CodeCompletionTool,
|
||||
// IDE
|
||||
IDEDialogs, ComponentReg, PackageIntf, IDEWindowIntf, DialogProcs,
|
||||
CustomFormEditor, LazarusIDEStrConsts, IDEProcs, OutputFilter,
|
||||
@ -273,6 +273,16 @@ var
|
||||
Result:=AIdent;
|
||||
end;
|
||||
|
||||
procedure InitClassCompletion;
|
||||
begin
|
||||
with fCTLink.CodeTool do begin
|
||||
CodeCompleteClassNode:=FindClassNodeInInterface(TLFMObjectNode(fLFMTree.Root).TypeName,
|
||||
true,false,true);
|
||||
CodeCompleteSrcChgCache:=fCTLink.SrcCache;
|
||||
//BuildTree(lsrImplementationStart);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
CurError: TLFMError;
|
||||
TheNode: TLFMTreeNode;
|
||||
@ -284,9 +294,11 @@ var
|
||||
ChgEntryRepl: TObjectList;
|
||||
OldIdent, NewIdent: string;
|
||||
StartPos, EndPos: integer;
|
||||
HasCodeChanges: Boolean;
|
||||
begin
|
||||
Result:=mrOK;
|
||||
AutoInc:=0;
|
||||
HasCodeChanges:=False;
|
||||
ChgEntryRepl:=TObjectList.Create;
|
||||
PropReplacements:=TStringToStringTree.Create(false);
|
||||
TypeReplacements:=TStringToStringTree.Create(false);
|
||||
@ -298,8 +310,20 @@ begin
|
||||
CurError:=fLFMTree.LastError;
|
||||
while CurError<>nil do begin
|
||||
TheNode:=CurError.FindContextNode;
|
||||
if (TheNode<>nil) and (TheNode.Parent<>nil) then begin
|
||||
if IsMissingType(CurError) then begin
|
||||
if (TheNode<>nil) and (TheNode.Parent<>nil) then
|
||||
begin
|
||||
if CurError.ErrorType=lfmeIdentifierMissingInCode then
|
||||
begin
|
||||
// Missing component variable
|
||||
ObjNode:=CurError.Node as TLFMObjectNode;
|
||||
if not HasCodeChanges then
|
||||
InitClassCompletion;
|
||||
fCTLink.CodeTool.AddClassInsertion(UpperCase(ObjNode.Name),
|
||||
ObjNode.Name+':'+ObjNode.TypeName+';',ObjNode.Name, ncpPublishedVars);
|
||||
HasCodeChanges:=True;
|
||||
end
|
||||
else if IsMissingType(CurError) then
|
||||
begin
|
||||
// Object type
|
||||
ObjNode:=CurError.Node as TLFMObjectNode;
|
||||
OldIdent:=ObjNode.TypeName;
|
||||
@ -338,6 +362,9 @@ begin
|
||||
// Apply replacements to LFM.
|
||||
if not ApplyReplacements(ChgEntryRepl) then
|
||||
exit(mrCancel);
|
||||
if HasCodeChanges then
|
||||
if not fCTLink.CodeTool.ApplyClassCompletion(false) then
|
||||
exit(mrCancel);
|
||||
// Apply replacement types also to pascal source.
|
||||
if TypeReplacements.Tree.Count>0 then
|
||||
if not CodeToolBoss.RetypeClassVariables(fPascalBuffer,
|
||||
@ -552,7 +579,8 @@ begin
|
||||
until (Result in [mrOK, mrAbort]) or (LoopCount>MaxLoopCount);
|
||||
|
||||
// Fix top offsets of some components in visual containers
|
||||
if (Result=mrOK) and (fSettings.CoordOffsMode=rsEnabled) then begin
|
||||
if (Result=mrOK) and (fSettings.CoordOffsMode=rsEnabled) then
|
||||
begin
|
||||
FormFileTool:=TFormFileConverter.Create(fCTLink, fLFMBuffer);
|
||||
SrcCoordOffs:=TObjectList.Create;
|
||||
SrcNewProps:=TObjectList.Create;
|
||||
|
Loading…
Reference in New Issue
Block a user