forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterfaceDeclaration.ts
61 lines (56 loc) · 2.47 KB
/
InterfaceDeclaration.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
import { InterfaceDeclarationStructure, InterfaceDeclarationSpecificStructure } from "../../../structures";
import { ts } from "../../../typescript";
import { ArrayUtils } from "../../../utils";
import { AmbientableNode, ChildOrderableNode, ExportableNode, ExtendsClauseableNode, HeritageClauseableNode, JSDocableNode, ModifierableNode, NamedNode,
TextInsertableNode, TypeElementMemberedNode, TypeParameteredNode } from "../base";
import { Type } from "../../types";
import { callBaseSet } from "../callBaseSet";
import { ClassDeclaration } from "../class";
import { NamespaceChildableNode } from "../module";
import { Statement } from "../statement";
import { ImplementationLocation } from "../../tools";
import { TypeAliasDeclaration } from "../type";
import { callBaseGetStructure } from "../callBaseGetStructure";
export const InterfaceDeclarationBase = TypeElementMemberedNode(ChildOrderableNode(TextInsertableNode(ExtendsClauseableNode(HeritageClauseableNode(
TypeParameteredNode(JSDocableNode(AmbientableNode(NamespaceChildableNode(ExportableNode(ModifierableNode(NamedNode(Statement)))))))
)))));
export class InterfaceDeclaration extends InterfaceDeclarationBase<ts.InterfaceDeclaration> {
/**
* Gets the base types.
*/
getBaseTypes(): Type[] {
return this.getType().getBaseTypes();
}
/**
* Gets the base declarations.
*/
getBaseDeclarations(): (TypeAliasDeclaration | InterfaceDeclaration | ClassDeclaration)[] {
return ArrayUtils.flatten(this.getType().getBaseTypes().map(t => {
const symbol = t.getSymbol();
return symbol == null ? [] : (symbol.getDeclarations() as (TypeAliasDeclaration | InterfaceDeclaration | ClassDeclaration)[]);
}));
}
/**
* Gets all the implementations of the interface.
*
* This is similar to "go to implementation."
*/
getImplementations(): ImplementationLocation[] {
return this.getNameNode().getImplementations();
}
/**
* Sets the node from a structure.
* @param structure - Structure to set the node with.
*/
set(structure: Partial<InterfaceDeclarationStructure>) {
callBaseSet(InterfaceDeclarationBase.prototype, this, structure);
return this;
}
/**
* Gets the structure equivalent to this node.
*/
getStructure(): InterfaceDeclarationStructure {
return callBaseGetStructure<InterfaceDeclarationSpecificStructure>(InterfaceDeclarationBase.prototype, this, {
});
}
}