import * as fse from 'fs-extra' ; import { localize } from "../../../localize" ; import { IFunctionTemplate } from '../../../templates/IFunctionTemplate' ; import { nonNullProp } from '../../../utils/nonNull' ; import { getJavaClassName , getJavaFunctionFilePath , getJavaPackagePath , IJavaProjectWizardContext } from '../../createNewProject/javaSteps/IJavaProjectWizardContext' ; import { FunctionNameStepBase } from '../FunctionNameStepBase' ; import { IFunctionWizardContext } from '../IFunctionWizardContext' ; export class JavaFunctionNameStep extends FunctionNameStepBase < IFunctionWizardContext & IJavaProjectWizardContext > { protected async getUniqueFunctionName ( context ) { const template = nonNullProp ( context , 'functionTemplate' ) ; const packageName = nonNullProp ( context , 'javaPackageName' ) ; return await this . getUniqueFsPath ( getJavaPackagePath ( context . projectPath , packageName ) , getJavaClassName ( template . defaultFunctionName ) , '.java' ) ; } protected async validateFunctionNameCore ( context , name ) { const packageName = nonNullProp ( context , 'javaPackageName' ) ; if ( await fse . pathExists ( getJavaFunctionFilePath ( context . projectPath , packageName , name ) ) ) { return localize ( 'existingError' , 'A function with name "{0}" already exists in package "{1}".' , getJavaClassName ( name ) , packageName ) ; } else { return undefined ; } } }