-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
299 lines (264 loc) · 8.77 KB
/
index.d.ts
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
/*!
* Copyright (C) 2017 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
declare module "php-reflection" {
import { graph, point } from "grafine";
import { Tag, Annotation } from "doc-parser";
class EventEmitter {
addListener(type: any, listener: any): any;
emit(type: any, ...args: any[]): EventEmitter;
eventNames(): any;
getMaxListeners(): any;
listenerCount(type: any): any;
listeners(type: any): any;
on(type: any, listener: any):EventEmitter;
once(type: any, listener: any): EventEmitter;
prependListener(type: any, listener: any): any;
prependOnceListener(type: any, listener: any): any;
removeAllListeners(type: any, ...args: any[]): any;
removeListener(type: any, listener: any): any;
setMaxListeners(n: any): any;
}
export interface Options {
// enables the debug mode
debug?: Boolean;
// list of excluded directory names
exclude?: String[];
// list of included directories
include?: String[];
// list of php extension files
ext?: String[];
// extract vars from each scope (functions, classes)
// may use memory but could be usefull for resolving
// their type (on autocompletion)
scanVars?: Boolean;
// extract scopes from
scanExpr?: Boolean;
// extract documentation from
scanDocs?: Boolean;
// default parsing encoding
encoding?: String;
// should spawn a worker process to avoir blocking
// the main loop (may be slower with small projects or single cpu)
forkWorker?: Number|Boolean,
// use the file mtime property to check changes
cacheByFileDate?: Boolean;
// use the file size to detect changes
cacheByFileSize?: Boolean;
// use an hash algorithm to detect changes
// if low cache hit, may slow down the parsing
cacheByFileHash?: Boolean;
// avoid to load the full cache repository
// just loads files when they are requested
// define a function that receives the filename in argumen
// and return the file cached structure
lazyCache?: (type: String, name: String) => any;
// used in order to shard big projects into separate files
shardSize?: Number;
// used in order group together symbol from a same file
shardCapacity?: Number;
}
/**
* Defines the location of the node
*/
export class Position {
start: {
line: number;
column: number;
};
end: {
line: number;
column: number;
};
offset: {
start: number;
end: number;
};
export(): any;
import(data: any): Position;
hit(offet: number): boolean;
}
export class Comment {
summary: string;
tags: any;
annotations: Annotation[];
getAnnotation(name: string): Annotation;
getAnnotations(name: string): Annotation[];
getTag(name: string): Tag;
getTags(name: string): Tag[];
}
export class Node extends point {
position: Position;
doc: Comment;
protected consume(file:File, parent: Node, ast: any): void;
indexName(name: string): Node;
getRepository(): Repository;
getFile(): File;
getParent(): Node;
getNamespace(): Namespace;
eachChild(cb: (child: Node, index: number) => void): Node;
static extends(type: string): Node;
static create(type: string, graph: graph): Node;
}
export class Block extends Node {
/**
* Gets a list of defined variables
*/
getVariables(): Variable[];
}
export class Expr extends Block {
toPHP(): string;
static resolve(parent:Node, ast:any):Expr|string|number|boolean;
}
export class External extends Node {
once: boolean;
strict: boolean;
target: Expr|string;
getTargetFile(): Promise<File>;
}
export class UseGroup extends Node {
aliases: Map<string, string>;
}
export class Define extends Node {
caseInsensitive: boolean;
getName(): string;
getValue(): Expr|string|number|boolean;
}
export class Namespace extends Block {
/**
* Retrieves a list of classes
*/
getClasses(): Class[];
/**
* Retrieves a list of interfaces
*/
getInterfaces(): Interface[];
/**
* Retrieves a list of interfaces
*/
getTraits(): Trait[];
getFunctions(): Function[];
getUses(): UseGroup[];
getConstants(): Constant[];
getDefines(): Define[];
/**
* Converts a namespace relative object name to a fully qualified name
*/
getFQN(name:string): string;
/**
* Resolves an alias class if defined in use statements
*/
resolveAlias(alias: string): string;
/**
* Retrieves a class alias from `use` statements
*/
findAlias(name: string): string;
/**
* Resolves a class name if it's relative, using aliases
* or adding current namespace prefix.
*/
resolveClassName(name: string): string;
}
export class File extends point {
getRepository(): Repository;
setName(name: string): File;
getName(): string;
eachNode(cb: (child: Node, index: number) => void): File;
getFirstByName(type: string, name: string): Node;
getByType(type: string): Node[];
getNamespaces(): Namespace[];
getClasses(): Class[];
getInterfaces(): Interface[];
getIncludes(): External[];
getClass(name: string): Class;
getNamespace(name: string): Namespace;
getScope(offset: number): Scope;
}
export class Function extends Block {
name: string;
fullName: string;
isClosure: boolean;
getArguments(): Variable[];
getVariables(): Variable[];
}
export class Method extends Block {
name: string;
fullName: string;
isStatic: boolean;
isFinal: boolean;
isAbstract: boolean;
isPublic: boolean;
isProtected: boolean;
isPrivate: boolean;
getArguments(): Variable[];
getVariables(): Variable[];
getClass(): Class|Trait|Interface;
}
export class Class extends Node {
name: string;
fullName: string;
extends: string;
implements: string[];
isAbstract: Boolean;
isFinal: Boolean;
getExtends(): Class;
getImplements(): Interface[];
getProperties(includeParents?: boolean): Property[];
getConstants(includeParents?: boolean): Constant[];
getMethods(includeParents?: boolean): Method[];
}
export class Trait extends Node {
}
export class Interface extends Node {
}
export class Constant extends Node {
name: string;
}
export class Variable extends Node {
name: string;
}
export class Property extends Node {
name: string;
}
export class Scope {
file: File;
offset: number[];
namespace: Namespace;
class: Class;
trait: Trait;
interface: Interface;
method: Method;
function: Function;
variables: Variable[];
}
/**
* The repository
*/
export class Repository extends EventEmitter {
directory: string;
options: Options;
db: graph;
constructor(directory:string, config: Options);
constructor(directory:string);
scan(directory: string): Promise<Boolean>;
scan(): Promise<Boolean>;
parse(filename: string, encoding?: string, stat?: any): Promise<File>;
getByType(type: string): Node[];
getByName(type: string, name: string, limit?: number): Node[];
searchByName(type: string, name: string, limit?: number): Node[];
getFirstByName(type: string, name: string): Node;
getNamespace(name: string): Namespace;
sync(filename: string, contents: string, offset?: number[]): Promise<File>;
cleanAll(): Repository;
each(type: string, cb: (node:Node, name: string) => void): Repository;
getScope(filename: string, offset: any): Scope;
getFile(filename: string): File;
hasFile(filename: string): boolean;
eachFile(cb: (node:File, name: string) => void): Repository;
removeFile(filename: string): Repository;
renameFile(oldName: string, newName: string): Repository;
refresh(): Promise<File>;
}
}