import { ClassDeclaration } from 'ts-morph'; import { ClassInfo } from './ClassInfo'; import { TypescriptCommentExtractor } from '../comment/TypescriptCommentExtractor'; import { DecoratorExtractor } from '../decorator/DecoratorExtractor'; import { ModuleExtractor } from '../module/ModuleExtractor'; import { TypeParameterExtractor } from '../type-parameter/TypeParameterExtractor'; export class ClassExtractor { public extract(node: ClassDeclaration): ClassInfo { const trailingComments = new TypescriptCommentExtractor().extract(node.getTrailingCommentRanges()); const leadingComments = new TypescriptCommentExtractor().extract(node.getLeadingCommentRanges()); const decorators = new DecoratorExtractor().extract(node); const hasComment = trailingComments.length !== 0 || leadingComments.length !== 0; return { name: node.getName(), text: node.getText(), modifiers: node.getModifiers().length === 0 ? undefined : node.getModifiers().map(x => x.getText()), extends: node.getExtends() === undefined ? undefined : node.getExtendsOrThrow().getText(), implements: node.getImplements().length === 0 ? undefined : node.getImplements().map(x => x.getText()), trailingComments: trailingComments.length === 0 ? undefined : trailingComments, leadingComments: leadingComments.length === 0 ? undefined : leadingComments, decorators: decorators, modules: new ModuleExtractor().extract(node), typeParameters: new TypeParameterExtractor().extract(node), hasComment: hasComment, }; } }