-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUParseThread.pas
More file actions
103 lines (93 loc) · 2.47 KB
/
UParseThread.pas
File metadata and controls
103 lines (93 loc) · 2.47 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
unit UParseThread;
interface
uses
Classes,
UBaseForm;
type
// this thread is parsing a java program
TParseThread = class(TThread)
private
FForm: TFForm;
FAbort: Boolean;
FAbortable: Boolean;
FState: Integer;
procedure SetAbort(Value: Boolean);
public
constructor Create(AForm: TFForm; Abortable: Boolean);
procedure Execute; override;
property Abort: Boolean read FAbort write SetAbort;
property Abortable: Boolean read FAbortable;
property State: Integer read FState write FState;
end;
implementation
uses
SysUtils,
UConfiguration,
UJavaParser,
UFileProvider,
UEditorForm,
UUtils;
constructor TParseThread.Create(AForm: TFForm; Abortable: Boolean);
const
Not_suspended = False;
begin
FForm := AForm;
FAbortable := Abortable;
FAbort := False;
FState := 1;
var EditForm := TFEditForm(AForm);
OnTerminate := EditForm.TerminateThread;
NameThreadForDebugging('ParseThread');
inherited Create(Not_suspended);
end;
procedure TParseThread.Execute;
begin
FState := 2;
var EditForm := TFEditForm(FForm);
if EditForm.IsJava and EditForm.NeedsParsing then
begin
EditForm.Model.Clear;
FConfiguration.ImportCache.Clear;
var
Importer := TJavaImporter.Create(EditForm.Model, TFileProvider.Create);
try
Importer.AddClasspath
(UnHideBlanks(FConfiguration.GetClassPathJarExpanded(EditForm.Pathname,
EditForm.GetPackage)), EditForm.Pathname);
var
Str := Importer.CodeProvider.LoadStream(EditForm.Pathname, EditForm);
if Assigned(Str) then
begin
FreeAndNil(EditForm.Parser);
EditForm.Parser := TJavaParser.Create(True);
EditForm.Parser.NeedPackage := Importer.NeedPackageHandler;
EditForm.Parser.Thread := Self;
EditForm.Parser.ParseStream(Str, EditForm.Model.ModelRoot,
EditForm.Model, EditForm.Pathname, False, False);
EditForm.Editor.Structures := EditForm.Parser.Structures.Clone;
end;
finally
FreeAndNil(Importer);
end;
// FreeAndNil(Str); handeld by Scanner
if not Abort then
begin
if FConfiguration.FixImports then
begin
EditForm.AutomatedCompleteImports;
EditForm.NeedsParsing := True;
end
else
EditForm.NeedsParsing := False;
end;
end;
FConfiguration.FixImports := False;
FState := 3;
end;
procedure TParseThread.SetAbort(Value: Boolean);
begin
FAbort := FAbortable and Value;
if FAbort then
Terminate;
end;
end.