Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/abstractions/api-callable-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ApiItemReference } from "../contracts/api-item-reference";
import { ApiType } from "../contracts/api-type";
import { ApiCallableDto } from "../contracts/api-callable-dto";
import { ApiTypeHelpers } from "../api-type-helpers";
import { ApiItemLocationDto } from "../contracts";

/**
* A callable api item base.
Expand All @@ -20,8 +21,12 @@ export abstract class ApiCallableBase<
protected Parameters: ApiItemReference[] = [];
protected TypeParameters: ApiItemReference[] = [];
protected ReturnType: ApiType | undefined;
protected Location: ApiItemLocationDto;

protected OnGatherData(): void {
// ApiItemLocation
this.Location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

// Overload
this.IsOverloadBase = this.TypeChecker.isImplementationOfOverload(this.Declaration as ts.FunctionLike) || false;

Expand All @@ -38,7 +43,7 @@ export abstract class ApiCallableBase<
if (signature != null) {
const type = this.TypeChecker.getReturnTypeOfSignature(signature);

this.ReturnType = ApiTypeHelpers.ResolveApiType(this.Options, type, this.Declaration.type);
this.ReturnType = ApiTypeHelpers.ResolveApiType(this.Options, this.Location, type, this.Declaration.type);
}
}
}
5 changes: 5 additions & 0 deletions src/api-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ export namespace ApiHelpers {
Logger.Log(logLevel, `${linePrefix}: ${message}`);
}

export function LogWithLocation(logLevel: LogLevel, location: ApiItemLocationDto, message: string): void {
const linePrefix = `${location.FileName}(${location.Line + 1},${location.Character + 1})`;
Logger.Log(logLevel, `${linePrefix}: ${message}`);
}

export function StandardizeRelativePath(location: string, options: ApiItemOptions): string {
const workingSep = options.ExtractorOptions.OutputPathSeparator;
const fixedLocation = location.split(path.sep).join(workingSep);
Expand Down
155 changes: 106 additions & 49 deletions src/api-type-helpers.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/contracts/api-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ts from "typescript";
import { ApiItemLocationDto } from "./api-item-location-dto";

export type ApiType = ApiBasicType |
ApiReferenceType |
Expand Down Expand Up @@ -48,6 +49,7 @@ export interface TypeScriptTypeNodeDebug {

export interface ApiBaseType {
ApiTypeKind: ApiTypeKind;
Location: ApiItemLocationDto;
Text: string;
_ts?: TypeScriptTypeNodeDebug;
}
Expand Down
4 changes: 1 addition & 3 deletions src/definitions/api-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import { ApiCallDto } from "../contracts/definitions/api-call-dto";
import { ApiItemKinds } from "../contracts/api-item-kinds";
import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiCallableBase } from "../abstractions/api-callable-base";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiCall extends ApiCallableBase<ts.CallSignatureDeclaration, ApiCallDto> {
public OnExtract(): ApiCallDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Call,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.Location,
IsOverloadBase: this.IsOverloadBase,
Parameters: this.Parameters,
ReturnType: this.ReturnType,
Expand Down
4 changes: 1 addition & 3 deletions src/definitions/api-class-constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ApiItemKinds } from "../contracts/api-item-kinds";
import { AccessModifier } from "../contracts/access-modifier";

import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiClassConstructor extends ApiCallableBase<ts.ConstructorDeclaration, ApiClassConstructorDto> {
private accessModifier: AccessModifier;
Expand All @@ -22,14 +21,13 @@ export class ApiClassConstructor extends ApiCallableBase<ts.ConstructorDeclarati
public OnExtract(): ApiClassConstructorDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ClassConstructor,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.Location,
IsOverloadBase: this.IsOverloadBase,
Parameters: this.Parameters,
AccessModifier: this.accessModifier,
Expand Down
4 changes: 1 addition & 3 deletions src/definitions/api-class-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { AccessModifier } from "../contracts/access-modifier";

import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiCallableBase } from "../abstractions/api-callable-base";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiClassMethod extends ApiCallableBase<ts.MethodDeclaration, ApiClassMethodDto> {
private accessModifier: AccessModifier;
Expand All @@ -32,14 +31,13 @@ export class ApiClassMethod extends ApiCallableBase<ts.MethodDeclaration, ApiCla
public OnExtract(): ApiClassMethodDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ClassMethod,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.Location,
IsOverloadBase: this.IsOverloadBase,
Parameters: this.Parameters,
ReturnType: this.ReturnType,
Expand Down
9 changes: 6 additions & 3 deletions src/definitions/api-class-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ApiItemLocationDto } from "../contracts/api-item-location-dto";
import { ApiTypeHelpers } from "../api-type-helpers";

export class ApiClassProperty extends ApiItem<ts.PropertyDeclaration, ApiClassPropertyDto> {
private location: ApiItemLocationDto;
private accessModifier: AccessModifier;
private isAbstract: boolean;
private isStatic: boolean;
Expand All @@ -19,6 +20,9 @@ export class ApiClassProperty extends ApiItem<ts.PropertyDeclaration, ApiClassPr
private type: ApiType;

protected OnGatherData(): void {
// ApiItemLocation
this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

// Modifiers
this.accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(this.Declaration.modifiers);
this.isAbstract = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AbstractKeyword);
Expand All @@ -30,20 +34,19 @@ export class ApiClassProperty extends ApiItem<ts.PropertyDeclaration, ApiClassPr

// Type
const type = this.TypeChecker.getTypeOfSymbolAtLocation(this.Symbol, this.Declaration);
this.type = ApiTypeHelpers.ResolveApiType(this.Options, type, this.Declaration.type);
this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type);
}

public OnExtract(): ApiClassPropertyDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ClassProperty,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.location,
AccessModifier: this.accessModifier,
IsAbstract: this.isAbstract,
IsReadonly: this.isReadonly,
Expand Down
23 changes: 17 additions & 6 deletions src/definitions/api-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ApiItemLocationDto } from "../contracts/api-item-location-dto";
import { ApiTypeHelpers } from "../api-type-helpers";

export class ApiClass extends ApiItem<ts.ClassDeclaration, ApiClassDto> {
private location: ApiItemLocationDto;
/**
* Interfaces can extend multiple interfaces.
*/
Expand All @@ -21,13 +22,20 @@ export class ApiClass extends ApiItem<ts.ClassDeclaration, ApiClassDto> {
private isAbstract: boolean = false;

protected OnGatherData(): void {
// ApiItemLocation
this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

// Members
this.members = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.members, this.Options);

// Extends
if (this.Declaration.heritageClauses != null) {
const extendingList = ApiTypeHelpers
.GetHeritageList(this.Declaration.heritageClauses, ts.SyntaxKind.ExtendsKeyword, this.Options);
const extendingList = ApiTypeHelpers.GetHeritageList(
this.Options,
this.location,
this.Declaration.heritageClauses,
ts.SyntaxKind.ExtendsKeyword
);

if (extendingList.length > 0) {
this.extends = extendingList[0];
Expand All @@ -36,8 +44,12 @@ export class ApiClass extends ApiItem<ts.ClassDeclaration, ApiClassDto> {

// Implements
if (this.Declaration.heritageClauses != null) {
this.implements = ApiTypeHelpers
.GetHeritageList(this.Declaration.heritageClauses, ts.SyntaxKind.ImplementsKeyword, this.Options);
this.implements = ApiTypeHelpers.GetHeritageList(
this.Options,
this.location,
this.Declaration.heritageClauses,
ts.SyntaxKind.ImplementsKeyword
);
}

// IsAbstract
Expand All @@ -52,14 +64,13 @@ export class ApiClass extends ApiItem<ts.ClassDeclaration, ApiClassDto> {
public OnExtract(): ApiClassDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Class,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.location,
IsAbstract: this.isAbstract,
Members: this.members,
Extends: this.extends,
Expand Down
4 changes: 1 addition & 3 deletions src/definitions/api-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ import { ApiItemKinds } from "../contracts/api-item-kinds";

import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiCallableBase } from "../abstractions/api-callable-base";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiConstruct extends ApiCallableBase<ts.ConstructSignatureDeclaration | ts.ConstructorTypeNode, ApiConstructDto> {
public OnExtract(): ApiConstructDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Construct,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.Location,
IsOverloadBase: this.IsOverloadBase,
Parameters: this.Parameters,
ReturnType: this.ReturnType,
Expand Down
8 changes: 5 additions & 3 deletions src/definitions/api-enum-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiEnumMember extends ApiItem<ts.EnumMember, ApiEnumMemberDto> {
private location: ApiItemLocationDto;

public GetValue(): string {
for (const item of this.Declaration.getChildren()) {
if (ts.isNumericLiteral(item) ||
Expand All @@ -32,21 +34,21 @@ export class ApiEnumMember extends ApiItem<ts.EnumMember, ApiEnumMemberDto> {
}

protected OnGatherData(): void {
// No gathering is needed
// ApiItemLocation
this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);
}

public OnExtract(): ApiEnumMemberDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);
const value: string = this.GetValue();

return {
ApiKind: ApiItemKinds.EnumMember,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.location,
Value: value,
_ts: this.GetTsDebugInfo()
};
Expand Down
7 changes: 5 additions & 2 deletions src/definitions/api-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiEnum extends ApiItem<ts.EnumDeclaration, ApiEnumDto> {
private location: ApiItemLocationDto;
private members: ApiItemReference[] = [];
private isConst: boolean;

protected OnGatherData(): void {
// ApiItemLocation
this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

// IsConst
this.isConst = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.ConstKeyword);

Expand All @@ -24,14 +28,13 @@ export class ApiEnum extends ApiItem<ts.EnumDeclaration, ApiEnumDto> {
public OnExtract(): ApiEnumDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Enum,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.location,
IsConst: this.isConst,
Members: this.members,
_ts: this.GetTsDebugInfo()
Expand Down
7 changes: 5 additions & 2 deletions src/definitions/api-export-specifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiExportSpecifier extends ApiItem<ts.ExportSpecifier, ApiExportSpecifierDto> {
private location: ApiItemLocationDto;
private apiItems: ApiExportSpecifierApiItems;

protected OnGatherData(): void {
// ApiItemLocation
this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

const targetSymbol = this.TypeChecker.getExportSpecifierLocalTargetSymbol(this.Declaration);
const symbolReferences = ApiHelpers.GetItemIdsFromSymbol(targetSymbol, this.Options);

Expand All @@ -25,14 +29,13 @@ export class ApiExportSpecifier extends ApiItem<ts.ExportSpecifier, ApiExportSpe
public OnExtract(): ApiExportSpecifierDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ExportSpecifier,
Name: this.Declaration.name.getText(),
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.location,
ApiItems: this.apiItems,
_ts: this.GetTsDebugInfo()
};
Expand Down
7 changes: 5 additions & 2 deletions src/definitions/api-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ApiMetadataDto } from "../contracts/api-metadata-dto";
import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiExport extends ApiItem<ts.ExportDeclaration, ApiExportDto> {
private location: ApiItemLocationDto;
private getExportPath(): string | undefined {
if (this.apiSourceFile == null) {
ApiHelpers.LogWithNodePosition(LogLevel.Warning, this.Declaration, "Exported source file is not found!");
Expand All @@ -29,6 +30,9 @@ export class ApiExport extends ApiItem<ts.ExportDeclaration, ApiExportDto> {
private apiSourceFile: ApiSourceFile | undefined;

protected OnGatherData(): void {
// ApiItemLocation
this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

// Extract members from Source file.
const sourceFileDeclaration = TSHelpers.ResolveSourceFile(this.Declaration, this.Options.Program);

Expand All @@ -46,14 +50,13 @@ export class ApiExport extends ApiItem<ts.ExportDeclaration, ApiExportDto> {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const exportPath: string | undefined = this.getExportPath();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Export,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Location: this.location,
SourceFileId: this.sourceFileId,
ExportPath: exportPath,
_ts: this.GetTsDebugInfo()
Expand Down
Loading