import * as _ from "lodash" ; import { TreeItem , TreeItemCollapsibleState } from "vscode" ; import { HierarchicalPackageNodeData } from "../java/hierarchicalPackageNodeData" ; import { INodeData , NodeKind } from "../java/nodeData" ; import { explorerLock } from "../utils/Lock" ; import { DataNode } from "./dataNode" ; import { ExplorerNode } from "./explorerNode" ; import { FileNode } from "./fileNode" ; import { PackageNode } from "./packageNode" ; import { PrimaryTypeNode } from "./PrimaryTypeNode" ; import { ProjectNode } from "./projectNode" ; export class HierarchicalPackageNode extends PackageNode { constructor ( nodeData , parent , protected _project , protected _rootNode ) { super ( nodeData , parent , _project , _rootNode ) ; } public getTreeItem ( ) { const item = new TreeItem ( this . getHierarchicalNodeData ( ) . displayName , this . hasChildren ( ) ? TreeItemCollapsibleState . Collapsed : TreeItemCollapsibleState . None ) ; return { ... super . getTreeItem ( ) , ... item } ; } public async getChildren ( ) { try { await explorerLock . acquireAsync ( ) ; const data = await this . loadData ( ) ; if ( data ) { if ( this . nodeData ?. children ) { this . nodeData . children . push ( ... data ) ; this . nodeData . children = _ . uniqBy ( this . nodeData . children , ( child ) => [ child . path , child . name ] . join ( ) ) ; } else { this . nodeData . children = data ; } } return this . createChildNodeList ( ) ; } finally { explorerLock . release ( ) ; } } public async revealPaths ( paths ) { const hierarchicalNodeData = paths [ 0 ] ; if ( hierarchicalNodeData . name === this . nodeData . name ) { paths . shift ( ) ; return super . revealPaths ( paths ) ; } else { const children = await this . getChildren ( ) ; const childNode = < DataNode > children . find ( ( child ) => hierarchicalNodeData . name . startsWith ( child . nodeData . name + "." ) || hierarchicalNodeData . name === child . nodeData . name ) ; return childNode ? childNode . revealPaths ( paths ) : undefined ; } } protected async loadData ( ) { return this . getHierarchicalNodeData ( ) . isPackage ? super . loadData ( ) : [ ] ; } protected createChildNodeList ( ) { const result = [ ] ; if ( this . nodeData . children && this . nodeData . children . length ) { this . sort ( ) ; this . nodeData . children . forEach ( ( nodeData ) => { if ( nodeData . kind === NodeKind . File ) { result . push ( new FileNode ( nodeData , this ) ) ; } else if ( nodeData instanceof HierarchicalPackageNodeData ) { result . push ( new HierarchicalPackageNode ( nodeData , this , this . _project , this . _rootNode ) ) ; } else if ( nodeData . kind === NodeKind . PrimaryType ) { if ( nodeData . metaData && nodeData . metaData [ PrimaryTypeNode . K_TYPE_KIND ] ) { result . push ( new PrimaryTypeNode ( nodeData , this , this . _rootNode ) ) ; } } } ) ; } return result ; } private getHierarchicalNodeData ( ) { return < HierarchicalPackageNodeData > this . nodeData ; } }