public static String sanitizeIdentifierName(String identifier) {
        if ( identifier != null && identifier.length() > 0 ) {

            int firstAlphabeticIndex = 0;
            while ( firstAlphabeticIndex < identifier.length() &&
                ( identifier.charAt( firstAlphabeticIndex ) == UNDERSCORE ||
                    Character.isDigit( identifier.charAt( firstAlphabeticIndex ) ) ) ) {
                firstAlphabeticIndex++;
            }

            if ( firstAlphabeticIndex < identifier.length()) {
                // If it is not consisted of only underscores
                String firstAlphaString = identifier.substring( firstAlphabeticIndex ).replace( "[]", "Array" );

                StringBuilder sb = new StringBuilder( firstAlphaString.length() );
                for ( int i = 0; i < firstAlphaString.length(); i++ ) {
                    int codePoint = firstAlphaString.codePointAt( i );
                    if ( Character.isJavaIdentifierPart( codePoint ) || codePoint == '.') {
                        sb.appendCodePoint( codePoint );
                    }
                    else {
                        sb.append( '_' );
                    }
                }
                return sb.toString();
            }

            return identifier.replace( "[]", "Array" );
        }
        return identifier;
    }
@Test
    public void testSanitizeIdentifierName() {
        assertThat( Strings.sanitizeIdentifierName( "test" ) ).isEqualTo( "test" );
        assertThat( Strings.sanitizeIdentifierName( "int[]" ) ).isEqualTo( "intArray" );
        assertThat( Strings.sanitizeIdentifierName( "_Test" ) ).isEqualTo( "Test" );
        assertThat( Strings.sanitizeIdentifierName( "_int[]" ) ).isEqualTo( "intArray" );
        assertThat( Strings.sanitizeIdentifierName( "__int[]" ) ).isEqualTo( "intArray" );
        assertThat( Strings.sanitizeIdentifierName( "test_" ) ).isEqualTo( "test_" );
        assertThat( Strings.sanitizeIdentifierName( "___" ) ).isEqualTo( "___" );
        assertThat( Strings.sanitizeIdentifierName( "_0Test" ) ).isEqualTo( "Test" );
        assertThat( Strings.sanitizeIdentifierName( "_0123456789Test" ) ).isEqualTo( "Test" );
        assertThat( Strings.sanitizeIdentifierName( "_0int[]" ) ).isEqualTo( "intArray" );
        assertThat( Strings.sanitizeIdentifierName( "__0int[]" ) ).isEqualTo( "intArray" );
        assertThat( Strings.sanitizeIdentifierName( "___0" ) ).isEqualTo( "___0" );
        assertThat( Strings.sanitizeIdentifierName( "bad/test" ) ).isEqualTo( "bad_test" );
    }