import { InputBoxOptions } from "vscode" ; import { AzureWizardPromptStep } from "vscode-azureextensionui" ; import { localize } from "../../../localize" ; import { IJavaProjectWizardContext } from "./IJavaProjectWizardContext" ; export class JavaPackageNameStep extends AzureWizardPromptStep < IJavaProjectWizardContext > { public async prompt ( context ) { const options = { placeHolder : localize ( 'packagePlaceHolder' , 'Package name' ) , prompt : localize ( 'packagePrompt' , 'Provide a package name' ) , validateInput : validatePackageName , value : context . javaGroupId || 'com.function' } ; context . javaPackageName = await context . ui . showInputBox ( options ) ; } public shouldPrompt ( context ) { return ! context . javaPackageName ; } } function validatePackageName ( packageName ) { if ( ! packageName ) { return localize ( 'emptyPackageNameError' , 'The package name cannot be empty.' ) ; } for ( const s of packageName . split ( '.' ) ) { const result = validateJavaName ( s ) ; if ( result ) { return result ; } } return undefined ; } const keywords = [ 'abstract' , 'continue' , 'for' , 'new' , 'switch' , 'assert' , 'default' , 'if' , 'package' , 'synchronized' , 'boolean' , 'do' , 'goto' , 'private' , 'this' , 'break' , 'double' , 'implements' , 'protected' , 'throw' , 'byte' , 'else' , 'import' , 'public' , 'throws' , 'case' , 'enum' , 'instanceof' , 'return' , 'transient' , 'catch' , 'extends' , 'int' , 'short' , 'try' , 'char' , 'final' , 'interface' , 'static' , 'void' , 'class' , 'finally' , 'long' , 'strictfp' , 'volatile' , 'const' , 'float' , 'native' , 'super' , 'while' , 'null' , 'true' , 'false' ] ; function validateJavaName ( name ) { if ( keywords . find ( k => k === name . toLowerCase ( ) ) ) { return localize ( 'JavaNameIsKeywordError' , '"{0}" is a reserved keyword.' , name ) ; } else if ( ! /^[a-z_$][a-z\d_$]*$/i . test ( name ) ) { return localize ( 'JavaNameNotIdentifierError' , '"{0}" is invalid. It can only contain letters, digits, "_", and "$", and cannot begin with a digit.' , name ) ; } else { return undefined ; } }