/******************************************************************************
 * Copyright 2021 TypeFox GmbH
 * This program and the accompanying materials are made available under the
 * terms of the MIT License, which is available in the project root.
 ******************************************************************************/ import { findNodeForFeature } from '../grammar/grammar-util' ; import { AstNode , CstNode } from '../syntax-tree' ; export interface NamedAstNode extends AstNode { name : string ; } export function isNamed ( node ) { return ( node as NamedAstNode ) . name !== undefined ; } export interface NameProvider { getName ( node ) : string | undefined ; param node getNameNode ( node ) : CstNode | undefined ; } export class DefaultNameProvider implements NameProvider { getName ( node ) { if ( isNamed ( node ) ) { return node . name ; } return undefined ; } getNameNode ( node ) { return findNodeForFeature ( node . $cstNode , 'name' ) ; } }