import { ThemeIcon , Uri , workspace } from "vscode" ; import { Explorer } from "../constants" ; import { ContainerEntryKind , IContainerNodeData } from "../java/containerNodeData" ; import { HierarchicalPackageNodeData } from "../java/hierarchicalPackageNodeData" ; import { Jdtls } from "../java/jdtls" ; import { INodeData , NodeKind } from "../java/nodeData" ; import { Settings } from "../settings" ; import { ContainerNode } from "./containerNode" ; import { DataNode } from "./dataNode" ; import { ExplorerNode } from "./explorerNode" ; import { HierarchicalPackageNode } from "./hierarchicalPackageNode" ; import { NodeFactory } from "./nodeFactory" ; import { PackageNode } from "./packageNode" ; import { PrimaryTypeNode } from "./PrimaryTypeNode" ; export class ProjectNode extends DataNode { constructor ( nodeData , parent ? ) { super ( nodeData , parent ) ; } public async revealPaths ( paths ) { if ( ! this . uri ) { return undefined ; } if ( workspace . getWorkspaceFolder ( Uri . parse ( this . uri ) ) ) { return super . revealPaths ( paths ) ; } const childNodeData = paths [ 0 ] ; const children = await this . getChildren ( ) ; if ( ! children ) { return undefined ; } const childNode = < DataNode > children . find ( ( child ) => { if ( child instanceof HierarchicalPackageNode ) { return childNodeData . name . startsWith ( child . nodeData . name + "." ) || childNodeData . name === child . nodeData . name ; } return child . nodeData . name === childNodeData . name && child . path === childNodeData . path ; } ) ; if ( ! ( childNode instanceof HierarchicalPackageNode ) ) { paths . shift ( ) ; } return ( childNode && paths . length > 0 ) ? childNode . revealPaths ( paths ) : childNode ; } protected async loadData ( ) { let result = [ ] ; return Jdtls . getPackageData ( { kind : NodeKind . Project , projectUri : this . nodeData . uri } ) . then ( ( res ) => { const sourceContainer = [ ] ; res . forEach ( ( node ) => { const containerNode = < IContainerNodeData > node ; if ( containerNode . entryKind === ContainerEntryKind . CPE_SOURCE ) { sourceContainer . push ( containerNode ) ; } else { result . push ( node ) ; } } ) ; if ( sourceContainer . length > 0 ) { return Promise . all ( sourceContainer . map ( ( c ) => Jdtls . getPackageData ( { kind : NodeKind . Container , projectUri : this . uri , path : c . path } ) ) ) . then ( ( rootPackages ) => { result = result . concat ( ... rootPackages ) ; return result ; } ) ; } else { return result ; } } ) ; } protected createChildNodeList ( ) { const result = [ ] ; const packageData = [ ] ; if ( this . nodeData . children && this . nodeData . children . length ) { this . nodeData . children . forEach ( ( data ) => { if ( data . kind === NodeKind . Container ) { result . push ( new ContainerNode ( data , this , this ) ) ; } else if ( data . kind === NodeKind . PackageRoot ) { result . push ( NodeFactory . createPackageRootNode ( data , this , this ) ) ; } else if ( data . kind === NodeKind . Package ) { packageData . push ( data ) ; } else if ( data . kind === NodeKind . PrimaryType ) { if ( data . metaData && data . metaData [ PrimaryTypeNode . K_TYPE_KIND ] ) { result . push ( new PrimaryTypeNode ( data , this , undefined ) ) ; } } } ) ; } if ( packageData . length > 0 ) { if ( Settings . isHierarchicalView ( ) ) { const data = HierarchicalPackageNodeData . createHierarchicalNodeDataByPackageList ( packageData ) ; const hierarchicalPackageNodes = data === undefined ? [ ] : data . children . map ( ( hierarchicalChildrenNode ) => new HierarchicalPackageNode ( hierarchicalChildrenNode , this , this , this ) ) ; result . push ( ... hierarchicalPackageNodes ) ; } else { result . push ( ... packageData . map ( ( data ) => new PackageNode ( data , this , this , this ) ) ) ; } } result . sort ( ( a , b ) => { return b . nodeData . kind - a . nodeData . kind ; } ) ; return result ; } protected get iconPath ( ) : ThemeIcon { return new ThemeIcon ( "project" ) ; } protected get contextValue ( ) : string { let contextValue = Explorer . ContextValueType . Project ; const natureIds = this . nodeData . metaData ?. [ NATURE_ID ] ; if ( natureIds ) { const attributeString = getProjectTypeAttributes ( natureIds ) ; contextValue += attributeString ; } return contextValue ; } } function getProjectTypeAttributes ( natureIds ) { let attributeString = "" ; for ( const natureId of natureIds ) { const readableNature = getProjectType ( natureId ) ; if ( readableNature ) { attributeString += `+${ readableNature }` ; } } return attributeString ; } function getProjectType ( natureId ) { switch ( natureId ) { case NatureId . Java : return ReadableNature . Java ; case NatureId . Maven : return ReadableNature . Maven ; case NatureId . Gradle : return ReadableNature . Gradle ; case NatureId . UnmanagedFolder : return ReadableNature . UnmanagedFolder ; default : return "" ; } } enum NatureId { Maven = "org.eclipse.m2e.core.maven2Nature" , Gradle = "org.eclipse.buildship.core.gradleprojectnature" , UnmanagedFolder = "org.eclipse.jdt.ls.core.unmanagedFolder" , Java = "org.eclipse.jdt.core.javanature" } enum ReadableNature { Maven = "maven" , Gradle = "gradle" , UnmanagedFolder = "unmanagedFolder" , Java = "java" } const NATURE_ID = "NatureId" ;