-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUCodeCompletion.pas
More file actions
2972 lines (2818 loc) · 90 KB
/
UCodeCompletion.pas
File metadata and controls
2972 lines (2818 loc) · 90 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit UCodeCompletion;
interface
uses
System.Classes,
Vcl.Controls,
UHTMLParser,
UScpHint,
UModel,
UEditorForm,
UJavaScanner,
SynCompletionProposal;
type
TOnResizeEvent = procedure(Sender: TObject) of object;
TSynBaseCompletionProposalFormEx = class(TSynBaseCompletionProposalForm)
private
FAge: TDateTime;
FHintForm: TFScpHint;
procedure FormMouseActivate(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y, HitTest: Integer;
var MouseActivate: TMouseActivate);
public
constructor Create(AOwner: TComponent); override;
procedure Deactivate; override;
procedure Resize; override;
procedure SetOnResize(ResizeEvent: TOnResizeEvent);
procedure KeyPressW(var Key: Char);
procedure DoFormShow(Sender: TObject);
procedure ChangeStyle;
end;
TCodeCompletion = class
private
FCCAttribute: TAttribute;
FCCClassifier: TClassifier;
FCCOperation: TOperation;
FCCParameter: TParameter;
FDocuList: TStringList;
FEditForm: TFEditForm;
FHTMLFileofJavaClass: string;
FHTMLFileFromFolder: string;
FHTMLFullClass: string;
FHtmlParser: THtmlParser;
FIndexScpJava: Integer;
FInformed: Boolean;
FWithTable: Boolean;
function SearchMFeature(MClassifier: TClassifier; SFeature: string;
IsMethod: Boolean): TFeature;
function HasAPISuperclass: Boolean;
function AddThis(const AObject: string): string;
function GetTooltipClass(AClassifier: TClassifier;
var Description: string): string;
function GetStartType(Typ, AObject: string; Line: Integer;
AsDescription: Boolean): string;
function GetType(const SClass, SObject, Args: string; IsMethod: Boolean;
AsDescription: Boolean): string;
function GetAPIType(const WhereOf, Args: string; AttrMethCons: Integer;
AsDescription: Boolean): string;
function MakeAttribute(Num: Integer; const Name, Typ: string): string;
function MakeMethod(Num: Integer;
const Name, ParameterAndType: string): string;
function GetArgTypes(Scanner: TJavaScanner; Line: Integer): string;
procedure CalculateSelfDefinedAttributesAndMethods(var Typ: string;
Line: Integer; const StartWith: string; StaticOnly: Boolean);
procedure CalculateJavaAPIAttributesAndMethods(const Objekt, Typ,
StartWith: string);
function ClassInDocFile(const AClass: string; AFile: string;
var FullClass: string): Boolean;
procedure CalculateClassesAndInterfaces(const StartWith: string);
function GetMethod(var Str: string): string;
function GetMethodname(const Str: string): string;
function GetMethodWithoutParameternames(const Str: string;
var CountParams: Integer): string;
function TypeWithoutDecoration(Str: string): string;
function GetAttribute(var Str: string): string;
procedure SplitAttributeComment(const AttributeComment: string;
var Attribute, Comment: string);
procedure SplitMethodComment(MethodComment: string;
var Method, Comment: string);
function HTMLPathnameToClass(Pathname: string): string;
function GetDescription(Pathname: string): string;
procedure GetFullClassAndPath(Line: string; out FullClass, Path: string);
procedure CheckMissingDocumentation;
procedure ChangeStyle;
function FieldsFound: Boolean;
function ConstructorsFound: Boolean;
function MethodsFound: Boolean;
function GetTagName: string;
procedure GetNextTag;
procedure PrepareScpJavaForm;
public
constructor Create;
destructor Destroy; override;
procedure ParseSourceCodes;
function GetMClassifier(SClassifier: string; var AEditForm: TFEditForm)
: TClassifier;
function GetTypeOfCode(Code: string; Line, State: Integer;
AsDescription: Boolean): string;
function GetToTypeOfObject(AObject: string; var MethodAttribute: string;
Line: Integer): string;
function IsJavaAPIClass(AClass: string; var FullClass: string)
: Boolean; overload;
function IsJavaAPIClass(const AClass: string): Boolean; overload;
function GetJavaAPIMethodParameters: TStringList;
function IsSelfDefinedClassOrInterface(var Classe, Pathname: string;
var AEditForm: TFEditForm): Boolean;
function LoadTextFromFile(var Pathname: string): string;
function GetObjectFrom(Str: string): string;
function GetLine(var SClassifier: string; const SObject: string): Integer;
function GetAPIReference(const WhereOf: string): string;
function DoScpJavaExecute(var State: Integer;
const LocLine, StartWith: string; AEditForm: TFEditForm): Boolean;
function DoScpParamsExecute(State: Integer): Boolean;
function SearchDocumentation(const JavaCode: string; Line: Integer): string;
function FormatParamList(const Str: string; CurrentIndex: Integer): string;
property CCAttribute: TAttribute read FCCAttribute;
property CCClassifier: TClassifier read FCCClassifier;
property CCOperation: TOperation read FCCOperation;
property CCParameter: TParameter read FCCParameter;
property DocuList: TStringList read FDocuList;
property EditForm: TFEditForm read FEditForm;
property HTMLFileofJavaClass: string read FHTMLFileofJavaClass;
end;
var
MyCodeCompletion: TCodeCompletion;
implementation
uses
SysUtils,
Dialogs,
Types,
Grids,
Graphics,
Themes,
DateUtils,
StrUtils,
Character,
Forms,
UUtils,
SynEditHighlighter,
SynEdit,
JvGnugettext,
UConfiguration,
UHTMLHelp,
UFileStructure,
UMessages,
UJava,
UFileProvider,
UTooltip,
UStringRessources,
UModelEntity,
UJavaParser,
UTemplates;
constructor TSynBaseCompletionProposalFormEx.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
OnMouseActivate := FormMouseActivate;
Caption := 'CodeCompletion';
end;
procedure TSynBaseCompletionProposalFormEx.SetOnResize
(ResizeEvent: TOnResizeEvent);
begin
OnResize := ResizeEvent;
end;
procedure TSynBaseCompletionProposalFormEx.Deactivate;
begin
if PtInRect(FHintForm.BoundsRect, Mouse.CursorPos) or
(MilliSecondsBetween(Now, FAge) < 1000) then
CurrentEditor.RemoveFocusControl(Self)
else
inherited Deactivate;
end;
procedure TSynBaseCompletionProposalFormEx.Resize;
begin
inherited Resize;
if Assigned(FHintForm) then
FHintForm.SetBounds(Left, Top + Height - 7, Width, FHintForm.Height);
end;
procedure TSynBaseCompletionProposalFormEx.KeyPressW(var Key: Char);
begin
if Key = #9 then
begin
var
MyMousePos := Mouse.CursorPos;
Mouse.CursorPos := Point(FHintForm.Left + 5, FHintForm.Top + 5);
FHintForm.TabActiv := False;
if FHintForm.CanFocus then
FHintForm.SetFocus;
Mouse.CursorPos := MyMousePos;
end;
// else inherited KeyPressW(Key);
end;
procedure TSynBaseCompletionProposalFormEx.DoFormShow(Sender: TObject);
begin
inherited;
FAge := Now; // due to strange behavior under Ubuntu
end;
procedure TSynBaseCompletionProposalFormEx.FormMouseActivate(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y, HitTest: Integer;
var MouseActivate: TMouseActivate);
begin
FJava.ActiveTool := 13;
end;
procedure TSynBaseCompletionProposalFormEx.ChangeStyle;
begin
if StyleServices.IsSystemStyle then
begin
ClSelect := clHighlight;
ClSelectedText := clHighlightText;
ClBackground := clWindow;
ClTitleBackground := clBtnFace;
end
else
begin
Font.Color := StyleServices.GetStyleFontColor(sfTabTextInactiveNormal);
ClSelect := StyleServices.GetSystemColor(clHighlight);
ClSelectedText := StyleServices.GetSystemColor(clHighlightText);
ClBackground := StyleServices.GetSystemColor(clWindow);
ClTitleBackground := StyleServices.GetSystemColor(clBtnFace);
end;
end;
// -----------------------------------------------------------------------------
constructor TCodeCompletion.Create;
begin
FDocuList := TStringList.Create;
FHtmlParser := THtmlParser.Create;
FInformed := False;
PrepareScpJavaForm;
end;
destructor TCodeCompletion.Destroy;
begin
FreeAndNil(FDocuList);
FreeAndNil(FHtmlParser);
inherited;
end;
procedure TCodeCompletion.PrepareScpJavaForm;
var
MyOnCancel: TNotifyEvent;
MyOnKeyPress: TKeyPressEvent;
MyOnValidate: TValidateEvent;
MyOnChange: TCompletionChange;
MyOnShow: TNotifyEvent;
MyOnClose: TNotifyEvent;
MyOptions: TSynCompletionOptions;
begin
// after reducing this a click in the FScpHint-Window raised an exception
with FJava do
begin
MyOptions := scpJava.Options;
MyOnCancel := scpJava.OnCancel;
MyOnKeyPress := scpJava.OnKeyPress;
MyOnValidate := scpJava.OnValidate;
MyOnChange := scpJava.OnChange;
MyOnShow := scpJava.OnShow;
MyOnClose := scpJava.OnClose;
//scpJava.Form := TSynBaseCompletionProposalFormEx.Create(scpJava);
TSynBaseCompletionProposalFormEx(scpJava.Form).SetOnResize(OnResize);
TSynBaseCompletionProposalFormEx(scpJava.Form).FHintForm := FScpHint;
scpJava.OnCancel := MyOnCancel;
scpJava.OnKeyPress := MyOnKeyPress;
scpJava.OnValidate := MyOnValidate;
scpJava.OnChange := MyOnChange;
scpJava.OnShow := MyOnShow;
scpJava.OnClose := MyOnClose;
scpJava.Options := [];
scpJava.Options := MyOptions;
scpJava.EndOfTokenChr := '()[]. ';
scpJava.Images := FFileStructure.vilFileStructureLight;
end;
ChangeStyle;
end;
function TCodeCompletion.AddThis(const AObject: string): string;
var
Posi: Integer;
Str: string;
begin
Posi := Pos('.', AObject);
if Posi > 0 then
Str := Copy(AObject, 1, Posi - 1)
else
Str := AObject;
Posi := Pos('(', Str);
if Posi > 1 then
Result := 'this.' + AObject
else if Str = '' then
Result := 'this'
else
Result := AObject;
end;
function TCodeCompletion.GetTooltipClass(AClassifier: TClassifier;
var Description: string): string;
var
Str, AClassname, Pathname: string;
E: TFEditForm;
begin
if not Assigned(AClassifier) or IsSimpleType(AClassifier.Name) then
Result := '<code>'
else
begin
if AClassifier is TClass then
Str := '<code><img src="' + FConfiguration.EditorFolder +
'img\class.png"> '
else
Str := '<code><img src="' + FConfiguration.EditorFolder +
'img\interface.png"> ';
AClassname := AClassifier.GetShortType;
Pathname:= AClassifier.Pathname;
if (AClassifier.Pathname <> '') or IsSelfDefinedClassOrInterface(AClassname,
Pathname, E) then
begin
AClassifier.Pathname:= Pathname;
Str := Str + AClassifier.Name;
Description := AClassifier.Documentation.Description;
FTooltip.SetFile(AClassifier.Pathname, IntToStr(AClassifier.LineS));
end
else if IsJavaAPIClass(AClassifier.Name) then
begin
Str := Str + '<a href="' + ToWeb('', FHTMLFileofJavaClass) + '">' +
AClassifier.Name + '</a>';
Description := GetDescription(FHTMLFileofJavaClass);
FTooltip.SetURL(FHTMLFileofJavaClass);
end;
Result := Str + '<br><br>';
end;
end;
function TCodeCompletion.GetStartType(Typ, AObject: string; Line: Integer;
AsDescription: Boolean): string;
var
CIte, It1, It2: IModelIterator;
// Cent: TModelEntity;
Cent, MClassifier: TClassifier;
Attr: TAttribute;
Operation: TOperation;
Param: TParameter;
StringGrid: TStringGrid;
Posi: Integer;
E: TFEditForm;
Pathname, Description, Str, AObjectCopy: string;
AClassifier: TClassifier;
function ArrayCompatibel(Attr, Objekt, Typ: string): Boolean;
var
Posi, Count1, Count2, Posi1: Integer;
begin
Result := True;
// array Brackets are possible at the variable or the type
// make Typ[] name instead of Typ name[]
Posi := Pos('[', Attr);
if Posi > 0 then
begin
Typ := Typ + Copy(Attr, Posi, Length(Attr));
Attr := Copy(Attr, 1, Posi - 1);
end
else if Objekt = Typ then
Exit;
if Attr = WithoutArray(Objekt) then
begin
Result := True;
// access to array-variable or whole array
if Attr = Objekt then
Exit;
Count1 := CountChar('[', Objekt);
Count2 := CountChar('[', Typ);
if (Count1 > 0) and (Count2 > 0) then
if Count1 = Count2 then
begin // access to array-variable
Posi1 := Pos('[', Objekt);
Objekt := Copy(Objekt, 1, Posi1 - 1);
if Attr = Objekt then
Exit;
end
else if Count2 > Count1 then
begin
while CountChar('[', Typ) <> Count2 - Count1 do
begin
Posi1 := Pos('[', Typ);
Delete(Typ, Posi1, 2);
end;
Exit;
end;
end;
Result := False;
end;
begin
FCCClassifier := nil;
FCCAttribute := nil;
FCCOperation := nil;
FCCParameter := nil;
Result := Typ;
if Result <> '' then
Exit;
try
if FMessages.InteractiveEditActive then
begin
StringGrid := FMessages.GetCurrentStringGrid;
for var I := 1 to StringGrid.RowCount - 1 do
if StringGrid.Cells[0, I] = AObject then
Result := StringGrid.Cells[1, I];
end
else if Assigned(FJava.EditorForm) then
begin
FJava.EditorForm.ParseSourceCode(False);
if Assigned(FJava.EditorForm.Model) and
Assigned(FJava.EditorForm.Model.ModelRoot) then
begin
CIte := FJava.EditorForm.Model.ModelRoot.GetAllClassifiers;
while CIte.HasNext do
begin
Cent := TClassifier(CIte.Next);
FCCClassifier := Cent;
if ((Cent.Name = AObject) or EndsWith(Cent.Name, '.' + AObject) or
EndsWith(Cent.Name, '$' + AObject)) and (Cent.LineS = Line) then
begin
if AsDescription then
begin
Str := GetTooltipClass(Cent, Description);
Result := Str + '</code>' + Description;
if Description = '' then
if Cent is TInterface then
Result := Result + 'The interface <i>' + Cent.Name + '</i>'
else
Result := Result + 'The class <i>' + Cent.Name + '</i>';
end
else
Result := Cent.Name;
Exit;
end;
if (Cent.LineS <= Line) and (Line <= Cent.LineE) then
begin
MClassifier := Cent;
if (AObject = 'this') or (AObject = '') then
begin
Result := MClassifier.Name;
Break;
end;
if AObject = 'super' then
begin
Result := MClassifier.GetAncestorName;
if Result = '' then
Result := 'Object';
Break;
end;
// Methods
It1 := MClassifier.GetOperations;
while It1.HasNext do
begin
Operation := TOperation(It1.Next);
if not((Operation.LineS <= Line) and (Line <= Operation.LineE))
then
Continue;
if Operation.Name = AObject then
begin
if Assigned(Operation.ReturnValue) then
Typ := Operation.ReturnValue.Name
else
Typ := 'void';
if AsDescription or (Operation.LineS = Line) then
begin
Result := GetTooltipClass(Cent, Description);
if Operation.OperationType = otConstructor then
Result := Result + '<img src="' +
FConfiguration.EditorFolder + 'img\constructor.png"> ' +
'<bold>' + ToHtml(Operation.ToJava) +
'</bold></code><br><br>Constructor <i>'
else
Result := Result + '<img src="' +
FConfiguration.EditorFolder + 'img\methods' +
IntToStr(Integer(Operation.Visibility)) + '.png"> ' +
'<bold>' + ToHtml(Operation.ToJava) +
'</bold></code><br><br>Method <i>';
if MClassifier is TInterface then
Result := Result + Operation.Name + '</i> of interface <i>'
+ Cent.Name + '</i>.<br><br>'
else
Result := Result + Operation.Name + '</i> of class <i>' +
Cent.Name + '</i>.<br><br>';
Result := Result + Operation.GetFormattedDescription;
end
else
Result := Typ;
FTooltip.SetFile(MClassifier.Pathname,
IntToStr(Operation.LineS));
FCCOperation := Operation;
Exit;
end;
// Parameter of a method
It2 := Operation.GetParameters;
while It2.HasNext do
begin
Param := TParameter(It2.Next);
if Param.TypeClassifier = nil then
Continue;
if ArrayCompatibel(Param.Name, AObject,
Param.TypeClassifier.ShortName) then
begin
if AsDescription then
Result := '<code><img src="' + FConfiguration.EditorFolder +
'img\param.png"> ' +
ToHtml(Param.TypeClassifier.ShortName) + ' ' + Param.Name
+ '</code>' + '<br><br><p>Parameter <i>' + Param.Name +
'</i> of method <i>' + Operation.Name + '</i>.'
else
Result := Param.TypeClassifier.Name;
FCCParameter := Param;
FTooltip.SetFile(MClassifier.Pathname, IntToStr(Param.LineS));
Exit;
end;
end;
// local variable of a method
It2 := Operation.GetAttributes;
while It2.HasNext do
begin
Attr := TAttribute(It2.Next);
if Attr.TypeClassifier = nil then
Continue;
if ArrayCompatibel(Attr.Name, AObject,
Attr.TypeClassifier.ShortName) then
begin
if AsDescription then
Result := GetTooltipClass(Attr.TypeClassifier, Description)
+ '<img src="' + FConfiguration.EditorFolder +
'img\local.png"> ' + ToHtml(Attr.ToJava) + '</code>' +
'<br><br><p>Local variable <i>' + Attr.Name +
'</i> of method <i>' + Operation.Name + '</i>.'
else
Result := Attr.TypeClassifier.Name;
FCCAttribute := Attr;
FTooltip.SetFile(MClassifier.Pathname, IntToStr(Attr.LineS));
Exit;
end;
end;
end; // end of methods
// Attributes (after method parameters and local variables)
It1 := MClassifier.GetAttributes;
while It1.HasNext do
begin
Attr := TAttribute(It1.Next);
if Attr.TypeClassifier = nil then
Continue;
if ArrayCompatibel(Attr.Name, AObject,
Attr.TypeClassifier.ShortName) then
begin
if AsDescription then
Result := GetTooltipClass(Cent, Description) +
'<img src="' + FConfiguration.EditorFolder + 'img\attribute'
+ IntToStr(Integer(Attr.Visibility)) + '.png"> ' +
ToHtml(Attr.TypeClassifier.ShortName) + ' ' + Attr.Name +
'</code>' + '<br><br><p>Attribute of class <i>' + Cent.Name
+ '</i>.' + '<br><br> ' + Attr.Documentation.Description
else
Result := Attr.TypeClassifier.Name;
FCCAttribute := Attr;
FTooltip.SetFile(MClassifier.Pathname, IntToStr(Attr.LineS));
Exit;
end;
end;
end;
end;
end;
end;
except
on E: Exception do
FConfiguration.Log('TOperation.AddAttribute', E);
end;
FCCClassifier := nil;
if Result = '' then
begin
Typ := '';
AObjectCopy := AObject;
AObject := WithoutArray(AObject);
if IsSelfDefinedClassOrInterface(AObject, Pathname, E) then
begin
AClassifier := GetMClassifier(AObjectCopy, E);
if AsDescription then
begin
Result := GetTooltipClass(AClassifier, Description) + '</code>' +
Description;
if (Description = '') and Assigned(AClassifier) then
if Pos('[]', AObjectCopy) = 0 then
if (AClassifier is TInterface) then
Result := Result + 'The interface <i>' + AClassifier.Name + '</i>'
else
Result := Result + 'The class <i>' + AClassifier.Name + '</i>'
else
Result := Result + 'Array of <i>' + AClassifier.Name + '</i>';
end
else
Result := AObject;
FCCClassifier := AClassifier;
end
else if IsJavaAPIClass(AObject, Typ) then
begin
Description := GetDescription(FHTMLFileofJavaClass);
if AsDescription then
begin
if FConfiguration.IsAPIInterface(AObject) then
Result := '<code><img src="' + FConfiguration.EditorFolder +
'img\interface.png"> ' + '<a href="' +
ToWeb('', FHTMLFileofJavaClass) + '">' + Typ + '</a></code>'
else
Result := '<code><img src="' + FConfiguration.EditorFolder +
'img\class.png"> ' + '<a href="' + ToWeb('', FHTMLFileofJavaClass) +
'">' + Typ + '</a></code>';
Result := Result + '<br><br>' + Description;
end
else
Result := Typ;
FTooltip.SetURL(ToWeb('', FHTMLFileofJavaClass));
end;
end;
if Result = '' then
if (Copy(AObject, 1, 1) = '"') and (Copy(AObject, Length(AObject), 1) = '"')
then
Result := 'String'
else if (Copy(AObject, 1, 1) = '''') and
(Copy(AObject, Length(AObject), 1) = '''') then
Result := 'char'
else if (AObject = 'true') or (AObject = 'false') then
Result := 'boolean'
else
begin
Posi := 1;
while Posi <= Length(AObject) do
begin
if CharInSet(AObject[Posi], ['(', ')', '+', '-', ' ']) then
Inc(Posi)
else if AObject[Posi].IsDigit then
begin
Inc(Posi);
while (Posi <= Length(AObject)) and AObject[Posi].IsDigit do
Inc(Posi);
if (Posi <= Length(AObject)) and (AObject[Posi] = '.') then
Result := 'double'
else
Result := 'int';
end
else
Break;
end;
end;
end;
function TCodeCompletion.HasAPISuperclass: Boolean;
var
Posi, Int: Integer;
Str, Path: string;
begin
with FHtmlParser do
begin
Int := Pos('Method Summary', Text);
Posi := Pos('extends ', Text);
if (Posi > 0) and (Posi < Int) then
begin
GotoPos(Posi);
NextTag;
if Tag.Name = 'A' then
begin // extends with Link
for var I := 0 to Tag.Params.Count - 1 do
if UpperCase(Tag.Params.Names[I]) = 'HREF' then
begin
Str := Tag.Params[I];
Str := Copy(Str, 7, Length(Str) - 7); // href="
end;
Posi := Pos('#', Str);
if Posi > 0 then
Delete(Str, Posi, Length(Str));
Posi := Pos('?', Str);
if Posi > 0 then
Delete(Str, Posi, Length(Str));
Path := ExcludeTrailingPathDelimiter(ExtractFilePath(FHTMLFileofJavaClass));
repeat
Posi := Pos('../', Str);
if Posi = 1 then
begin
Delete(Str, 1, 3);
Posi := LastDelimiter('\', Path);
Delete(Path, Posi, Length(Path));
end;
until Posi = 0;
FHTMLFullClass := Str;
Posi := Pos('/api/', FHTMLFullClass);
if Posi > 0 then
Delete(FHTMLFullClass, 1, Posi + 4);
Delete(FHTMLFullClass, Length(FHTMLFullClass) - 4, 5);
FHTMLFullClass := ReplaceStr(FHTMLFullClass, '/', '.');
Str := ReplaceStr(Str, '/', '\');
Posi := Pos('.chm\', Path);
if Posi > 0 then
begin
Delete(Path, Posi + 4, Length(Path));
Delete(Str, 1, 1);
end;
if StartsWith(Str, 'https') then
FHTMLFileofJavaClass := Str
else
FHTMLFileofJavaClass := Path + '\' + Str;
if not FConfiguration.ShowClassObject and
EndsWith(Str, 'java\lang\Object.html') then
Exit(False)
else
Result := FConfiguration.GlobalFileExists(FHTMLFileofJavaClass);
end
else
begin // extends without Link: extends java.lang.String
Str := TextBetween;
Delete(Str, 1, 8);
Posi := Pos(#13#10, Str);
if Posi > 0 then
Delete(Str, Posi, Length(Str)); // ... implements
FHTMLFullClass := Str;
Str := ReplaceStr(Str, '.', '/') + '.html';
Result := False;
end;
if not Result then
for var I := 0 to FConfiguration.AllDocumentations.Count - 1 do
begin
FHTMLFileFromFolder := FConfiguration.AllDocumentations[I];
if ClassInDocFile(Str, FHTMLFileFromFolder, FHTMLFullClass) then
begin
Result := True;
Break;
end;
end;
end
else
Result := False;
end;
end;
function TCodeCompletion.FieldsFound: Boolean;
begin
Result := False;
var Posi := Pos('Field Summary</B>', FHtmlParser.Text); // till JDK 6
if Posi = 0 then begin
Posi := Pos('Field Summary</h3>', FHtmlParser.Text); // till JDK 12
if Posi = 0 then
Posi := Pos('Field Summary</h2>', FHtmlParser.Text);
end;
if Posi > 0 then
begin
FHtmlParser.GotoPos(Posi);
Posi := 0;
repeat
Inc(Posi);
GetNextTag;
until (FHtmlParser.TextBetween = 'Fields') or
(FHtmlParser.Tag.Name = 'CODE') or (Posi = 15);
if (FHtmlParser.TextBetween = 'Fields') and (Posi < 15) then
begin
Posi := 0;
repeat
Inc(Posi);
GetNextTag;
until (FHtmlParser.Tag.Name = 'CODE') or (Posi = 40);
end;
Result := (FHtmlParser.Tag.Name = 'CODE');
end;
end;
function TCodeCompletion.ConstructorsFound: Boolean;
begin
Result := False;
var Posi := Pos('Constructor Summary</B>', FHtmlParser.Text); // till JDK 6
if Posi = 0 then begin
Posi := Pos('Constructor Summary</h3>', FHtmlParser.Text); // till JDK 12
if Posi = 0 then
Posi := Pos('Constructor Summary</h2>', FHtmlParser.Text);
end;
if Posi > 0 then
begin
FHtmlParser.GotoPos(Posi);
Posi := 0;
repeat
Inc(Posi);
GetNextTag;
until (FHtmlParser.TextBetween = 'Constructors') or
(FHtmlParser.Tag.Name = 'CODE') or (Posi = 15);
if (FHtmlParser.TextBetween = 'Constructors') and (Posi < 15) then
begin
Posi := 0;
repeat
Inc(Posi);
GetNextTag;
until (FHtmlParser.Tag.Name = 'CODE') or (Posi = 40);
end;
Result := (FHtmlParser.Tag.Name = 'CODE');
end;
end;
function TCodeCompletion.MethodsFound: Boolean;
begin
Result := False;
var Posi := Pos('Method Summary</B>', FHtmlParser.Text); // till JDK 6
if Posi = 0 then begin
Posi := Pos('Method Summary</h3>', FHtmlParser.Text); // till JDK 12
if Posi = 0 then
Posi := Pos('Method Summary</h2>', FHtmlParser.Text);
end;
if Posi > 0 then
begin
FHtmlParser.GotoPos(Posi);
Posi := 0;
repeat
Inc(Posi);
GetNextTag;
until (FHtmlParser.TextBetween = 'All Methods') or
(FHtmlParser.TextBetween = 'Methods') or
(FHtmlParser.Tag.Name = 'CODE') or (Posi = 15);
if ((FHtmlParser.TextBetween = 'All Methods') or
(FHtmlParser.TextBetween = 'Methods')) and (Posi < 15) then
begin
Posi := 0;
repeat
Inc(Posi);
GetNextTag;
until (FHtmlParser.Tag.Name = 'CODE') or (Posi = 60);
end;
Result := (FHtmlParser.Tag.Name = 'CODE');
end;
end;
function TCodeCompletion.GetTagName: string;
begin
FHtmlParser.NextTag;
FHtmlParser.NextTag;
Result := FHtmlParser.Tag.Name;
FHtmlParser.NextTag;
end;
procedure TCodeCompletion.GetNextTag;
begin
FHtmlParser.NextTag;
if (FHtmlParser.Tag.Name = 'TR') or (FHtmlParser.Tag.Name = 'TABLE') then
FWithTable := True;
end;
function TCodeCompletion.GetAPIReference(const WhereOf: string): string;
var
Posi: Integer;
Link, Path, AFile: string;
function Found(Str: string): Boolean;
begin
Result := False;
var
Posi := Pos('#' + WhereOf, Str);
if Posi = 0 then
Exit;
Delete(Str, 1, Posi + Length(WhereOf));
if (Str = '') or (Str[1] = '(') then
Result := True;
end;
begin
if FConfiguration.GlobalFileExists(FHTMLFileofJavaClass) then
begin
repeat
Link := FHtmlParser.getNextLink;
until (Link = '') or Found(Link);
if Link = '' then
Result := FHTMLFileofJavaClass
else
begin
Path := ExtractFilePath(FHTMLFileofJavaClass);
Posi := Pos('#' + WhereOf, Link);
AFile := Copy(Link, 1, Posi - 1);
Delete(Link, 1, Posi - 1);
Posi := Pos('/', AFile);
while Posi > 0 do
begin
Delete(AFile, 1, Posi);
Posi := Pos('/', AFile);
end;
Result := Path + AFile + Link;
end;
end
else
Result := '';
end;
function TCodeCompletion.GetType(const SClass, SObject, Args: string;
IsMethod: Boolean; AsDescription: Boolean): string;
var
MClassifier: TClassifier;
AClassifier, Description, STyp: string;
MFeature: TFeature;
Attr: TAttribute;
Operation: TOperation;
Posi, AttrMethCons: Integer;
Typ: string;
E: TFEditForm;
IsAPIClass: Boolean;
begin
STyp := GetShortType(SClass);
if IsMethod and ((SClass = SObject) or (STyp = SObject)) and (Args = '')
then
begin // default constructor
if AsDescription then
Result := '<img src="' + FConfiguration.EditorFolder +
'img\constructor.png"> ' + '<bold>' + STyp +
'</bold></code><br><br>Constructor <i>' + STyp + '</i>'
else
Result := SClass;
Exit;
end;
AClassifier := SClass;
MFeature := nil;
Result := '';
repeat
MClassifier := GetMClassifier(AClassifier, E);
if Assigned(MClassifier) then
begin
MFeature := SearchMFeature(MClassifier, SObject, False);
if not Assigned(MFeature) then
MFeature := SearchMFeature(MClassifier, SObject, True);
if not Assigned(MFeature) then
AClassifier := ExtractClassName(MClassifier.GetAncestorName);
end;
until Assigned(MFeature) or not Assigned(MClassifier) or (AClassifier = '');
if Assigned(MFeature) then
begin
FCCClassifier := MClassifier;
FCCOperation := nil;
FCCAttribute := nil;
FCCParameter := nil;
if MFeature is TAttribute then
begin
Attr := TAttribute(MFeature);
if AsDescription then
begin
Result := '<code><img src="' + FConfiguration.EditorFolder +
'img\attribute' + IntToStr(Integer(Attr.Visibility)) + '.png"> ' +
ToHtml(Attr.ToTypeName) + '</code>';
if MClassifier is TInterface then
Result := Result + '<br><br><p>Attribute of interface <i>' +
MClassifier.Name + '</i>.'
else
Result := Result + '<br><br><p>Attribute of class <i>' +
MClassifier.Name + '</i>.';
Result := Result + '<br><br> ' + Attr.Documentation.Description;
FTooltip.SetFile(MClassifier.Pathname, IntToStr(Attr.LineS));
end
else
Result := Attr.TypeClassifier.Name;
FCCAttribute := Attr;
Exit;
end
else if MFeature is TOperation then
begin
Operation := TOperation(MFeature);
if Assigned(Operation.ReturnValue) then
Result := Operation.ReturnValue.Name // ExtractClassname
else
Result := 'void';
if AsDescription then
begin
if Operation.OperationType = otConstructor then
Result := GetTooltipClass(MClassifier, Description) + '<img src="' +
FConfiguration.EditorFolder + 'img\constructor.png"> ' + '<bold>'
+ ToHtml(Operation.ToTypeName) + '</bold></code><br><br>' +
'Constructor <i>' + Operation.Name + '</i> of class <i>' +
MClassifier.Name + '</i>.<br><br>' +
Operation.GetFormattedDescription
else