packages/ast-to-mmd/src/app/graph-blocks/try-catch-declaration.graph-block.ts
constructor(id: string, tryBlock?: GraphBlock[], catchBlock?: GraphBlock[], finallyBlock?: GraphBlock[], catchBlockId?: string, finallyBlockId?: string)
|
|||||||||||||||||||||
Parameters :
|
Private Static CATCH_COUNTER |
Type : number
|
Default value : 0
|
Private catchId |
Default value : TryCatchDeclarationGraphBlock.CATCH_COUNTER++
|
Private Static FINALLY_COUNTER |
Type : number
|
Default value : 0
|
Private finallyId |
Default value : TryCatchDeclarationGraphBlock.FINALLY_COUNTER++
|
Private Static TRY_CATCH_COUNTER |
Type : number
|
Default value : 0
|
Private Static TRY_COUNTER |
Type : number
|
Default value : 0
|
Private tryCatchId |
Default value : TryCatchDeclarationGraphBlock.TRY_CATCH_COUNTER++
|
Private tryId |
Default value : TryCatchDeclarationGraphBlock.TRY_COUNTER++
|
Private _lazyDependencies |
Type : string[]
|
Default value : []
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:30
|
Lazy dependencies ready to render when this node is rendered. |
Private _parent |
Type : GraphBlock | undefined
|
Default value : undefined
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:25
|
Parent of current node in graph. Can be undefined. |
Private _parentSiblingCondition |
Type : SiblingCondition
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:39
|
SiblingCondition for finding correct parent. |
Private _siblingCondition |
Type : SiblingCondition
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:35
|
Private Static Readonly EMPTY_LINE_RENDERER_MODIFIER |
Type : LineRendererModifier
|
Default value : () => {...}
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:20
|
Empty implementation of LineRendererModifier. |
Public Readonly id |
Type : string
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:46
|
Unique ID in the node graph.
|
Private Static Readonly POSITIVE_SIBLING_CONDITION |
Type : SiblingCondition
|
Default value : new PositiveSiblingCondition()
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:16
|
Positive sibling condition default for all GraphBlock. |
Private Static Readonly SHAPE_RENDERER |
Type : ShapeRenderer
|
Default value : new ShapeRenderer()
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:12
|
Shape renderer for generating different shapes in graph. |
Public render | ||||||
render(_indent: number)
|
||||||
Inherited from
GraphBlock
|
||||||
Defined in
GraphBlock:29
|
||||||
Parameters :
Returns :
string
|
Protected renderCatchBody | ||||||
renderCatchBody(indent: number)
|
||||||
Parameters :
Returns :
string
|
Protected renderDependencies | ||||||
renderDependencies(_indent: number)
|
||||||
Inherited from
BlockDeclarationGraphBlock
|
||||||
Defined in
BlockDeclarationGraphBlock:103
|
||||||
Render dependencies between internal blocks: TRY - CATCH - FINALLY
Parameters :
Returns :
string
|
Protected renderFinallyBody | ||||||
renderFinallyBody(indent: number)
|
||||||
Parameters :
Returns :
string
|
Protected renderOuterBody | ||||||
renderOuterBody(indent: number)
|
||||||
Parameters :
Returns :
string
|
Protected renderTryBody | ||||||
renderTryBody(indent: number)
|
||||||
Parameters :
Returns :
string
|
Protected createLineBuilder |
createLineBuilder(lhsId: string, rhsId: string)
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:71
|
Returns :
LineRenderer
|
Protected renderChildren | |||||||||
renderChildren(indent: number, children: GraphBlock[])
|
|||||||||
Inherited from
BlockDeclarationGraphBlock
|
|||||||||
Defined in
BlockDeclarationGraphBlock:64
|
|||||||||
Parameters :
Returns :
string
|
Private __multiFindChildIndex | ||||||||||||
__multiFindChildIndex(children: GraphBlock[][], child: GraphBlock)
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:575
|
||||||||||||
Private method for finding a child index of defined block in a multidimensional array of children.
Parameters :
Returns :
| undefined
Coordinates of child block or undefined when block is not found. |
Private __renderLines | ||||||||||||||||||||||||
__renderLines(indent: number, id: string, ids: string[], direction: "left" | "right", builderModifier: LineRendererModifier[])
|
||||||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||||||
Defined in
GraphBlock:546
|
||||||||||||||||||||||||
Private method for rendering lines between nodes in defined directions.
Parameters :
Returns :
string
Rendered line. |
Protected _assignParent | ||||||||
_assignParent(children: GraphBlock[])
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:289
|
||||||||
Helper method for assigning this parent into each children.
Parameters :
Returns :
void
|
Protected _filterChildren | ||||||||
_filterChildren(children: GraphBlock[])
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:466
|
||||||||
Helper method for filtering array of children.
Parameters :
Returns :
GraphBlock[]
|
Protected _findParentBySiblingCondition | ||||||||||||
_findParentBySiblingCondition(child: GraphBlock, siblingCondition: SiblingCondition)
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:521
|
||||||||||||
Helper method for finding an indirect parent of defined child by SiblingCondition.
Parameters :
Returns :
GraphBlock | undefined
|
Protected _findSiblingChild | ||||||||||||||||||||
_findSiblingChild(child: GraphBlock, parentSiblingCondition: SiblingCondition, siblingCondition: SiblingCondition)
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:478
|
||||||||||||||||||||
Helper method for finding a sibling of defined child in parents children.
Parameters :
Returns :
GraphBlock | undefined
|
Protected _generateSpace | ||||||||
_generateSpace(count: number)
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:301
|
||||||||
Helper method for generating space.
Parameters :
Returns :
string
Space of defined length. |
Protected _multiFilterChildren | ||||||||
_multiFilterChildren(children: GraphBlock[][])
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:456
|
||||||||
Helper method for filtering children in multidimensional array of children.
Parameters :
Returns :
[][]
|
Protected _renderConnectionWithParent | |||||||||||||||
_renderConnectionWithParent(indent: number, children: GraphBlock, lastIds: string[], priorityBuilderModifier: LineRendererModifier[])
|
|||||||||||||||
Inherited from
GraphBlock
|
|||||||||||||||
Defined in
GraphBlock:410
|
|||||||||||||||
Parameters :
Returns :
string
|
Protected _renderDependencies | ||||||||||||
_renderDependencies(indent: number, blocks: GraphBlock[])
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:346
|
||||||||||||
Helper method for rendering dependencies with defined indent between blocks.
Parameters :
Returns :
string
Dependencies of blocks. |
Protected _renderLine | ||||||||||||||||||||
_renderLine(indent: number, lhsId: string, rhsId: string, builderModifier: LineRendererModifier[])
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:314
|
||||||||||||||||||||
Helper method for generating line between two nodes.
Parameters :
Returns :
string
Line definition between two nodes. |
Protected _renderLinesL2R | ||||||||||||||||||||
_renderLinesL2R(indent: number, toId: string, fromIds: string[], builderModifier: LineRendererModifier[])
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:383
|
||||||||||||||||||||
Helper method for rendering line starting in one node and ending in multiple nodes.
Parameters :
Returns :
string
Rendered line. |
Protected _renderLinesR2L | ||||||||||||||||||||
_renderLinesR2L(indent: number, fromId: string, toIds: string[], builderModifier: LineRendererModifier[])
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:401
|
||||||||||||||||||||
Helper method for rendering line starting in multiple nodes and ending in one node.
Parameters :
Returns :
string
Rendered line. |
Protected _renderShape | ||||||||||||
_renderShape(text: string, shape: Shape)
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:335
|
||||||||||||
Helper method for rendering defined shape with text.
Parameters :
Returns :
string
Rendered shape with text. |
Protected renderInSubgraph | ||||||||||||||||||||||||||||||
renderInSubgraph(_indent: number, id: string, text: string, bodyRenderer: (indent: number) => void, direction: "TB" | "TD" | "BT" | "LR" | "RL")
|
||||||||||||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||||||||||||
Defined in
GraphBlock:86
|
||||||||||||||||||||||||||||||
Renders current node wrapped in a subgraph. Direction options:
Parameters :
Returns :
string
Graph wrapped in a subgraph. |
Public renderLazyDependencies | ||||||||
renderLazyDependencies(_indent: number)
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:63
|
||||||||
Renders lazy dependencies of current node.
Parameters :
Returns :
string
|
Public toString |
toString()
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:589
|
Returns :
string
|
blockKind |
getblockKind()
|
children |
getchildren()
|
lastBlocks |
getlastBlocks()
|
import { BlockKind } from '../block.kind';
import { BlockDeclarationGraphBlock } from './block-declaration.graph-block';
import { GraphBlock } from './graph-block';
export class TryCatchDeclarationGraphBlock extends BlockDeclarationGraphBlock {
private static TRY_CATCH_COUNTER = 0;
private static TRY_COUNTER = 0;
private static CATCH_COUNTER = 0;
private static FINALLY_COUNTER = 0;
private tryCatchId = TryCatchDeclarationGraphBlock.TRY_CATCH_COUNTER++;
private tryId = TryCatchDeclarationGraphBlock.TRY_COUNTER++;
private catchId = TryCatchDeclarationGraphBlock.CATCH_COUNTER++;
private finallyId = TryCatchDeclarationGraphBlock.FINALLY_COUNTER++;
constructor(
id: string,
private readonly tryBlock?: GraphBlock[],
private readonly catchBlock?: GraphBlock[],
private readonly finallyBlock?: GraphBlock[],
private readonly catchBlockId?: string,
private readonly finallyBlockId?: string
) {
super(id, tryBlock || []);
this._assignParent(catchBlock || []);
this._assignParent(finallyBlock || []);
}
public override render(_indent: number): string {
return this.renderInSubgraph(_indent, this.id, `TRY-CATCH_${this.tryCatchId}`, (bodyIndent: number) =>
this.renderOuterBody(bodyIndent)
);
}
public override get blockKind(): BlockKind {
return BlockKind.TRY_CATCH_DECLARATION;
}
override get children(): GraphBlock[][] {
const tryChildren = super.children;
const catchChildren = this.catchBlock || [];
const finallyChildren = this.finallyBlock || [];
return [...tryChildren, catchChildren, finallyChildren];
}
protected renderOuterBody(indent: number): string {
return `
${
this.tryBlock
? this.renderInSubgraph(indent, `TRY_${this.tryCatchId}`, `TRY_${this.tryId}`, (bodyIndent) =>
this.renderTryBody(bodyIndent)
)
: ''
}
${
this.catchBlock
? this.renderInSubgraph(indent, `CATCH_${this.catchBlockId}`, `CATCH_${this.catchId}`, (bodyIndent) =>
this.renderCatchBody(bodyIndent)
)
: ''
}
${
this.finallyBlock
? this.renderInSubgraph(
indent,
`FINALLY_${this.finallyBlockId}`,
`FINALLY_${this.finallyId}`,
(bodyIndent) => this.renderFinallyBody(bodyIndent)
)
: ''
}
${this.renderDependencies(indent)}
`;
}
protected renderTryBody(indent: number): string {
return `
${this.tryBlock ? this.renderChildren(indent, this.tryBlock) : ''}
${this.tryBlock ? this._renderDependencies(indent, this.tryBlock) : ''}
`;
}
protected renderCatchBody(indent: number): string {
return `
${this.catchBlock ? this.renderChildren(indent, this.catchBlock) : ''}
${this.catchBlock ? this._renderDependencies(indent, this.catchBlock) : ''}
`;
}
protected renderFinallyBody(indent: number): string {
return `
${this.finallyBlock ? this.renderChildren(indent, this.finallyBlock) : ''}
${this.finallyBlock ? this._renderDependencies(indent, this.finallyBlock) : ''}
`;
}
/**
* Render dependencies between internal blocks: TRY - CATCH - FINALLY
*
* @param _indent
*/
protected override renderDependencies(_indent: number): string {
let result = '';
if (this.finallyBlock) {
const filteredFinalyBlock = this._filterChildren(this.finallyBlock);
if (filteredFinalyBlock) {
if (this.tryBlock) {
const filteredTryBlock = this._filterChildren(this.tryBlock);
if (filteredTryBlock.length !== 0) {
result += this._renderLinesL2R(
_indent,
`${filteredFinalyBlock[0].firstBlock.id}`,
filteredTryBlock[filteredTryBlock.length - 1].lastBlocks
);
}
}
if (this.catchBlock) {
const filteredCatchBlock = this._filterChildren(this.catchBlock);
if (filteredCatchBlock.length !== 0) {
result += this._renderLinesL2R(
_indent,
`${filteredFinalyBlock[0].firstBlock.id}`,
filteredCatchBlock[filteredCatchBlock.length - 1].lastBlocks
);
}
}
}
}
return result;
}
public override get lastBlocks(): string[] {
if (this.finallyBlock) {
return this.finallyBlock[this.finallyBlock.length - 1].lastBlocks;
}
const tryBlockLastId = super.lastBlocks;
const catchLastId: string[] = this.catchBlock
? this.catchBlock[this.catchBlock.length - 1].lastBlocks
: [];
const allIds = [...tryBlockLastId, ...catchLastId];
if (allIds.length === 0) {
allIds.push(this.id);
}
return allIds;
}
}