private String convertCompletionBackIntoUserInputStyle(final String originalUserInput, final String completion) { if (denotesAbsolutePath(originalUserInput)) { // Input was originally as a fully-qualified path, so we just keep // the completion in that form return completion; } if (originalUserInput.startsWith(HOME_DIRECTORY_SYMBOL)) { // Input originally started with this symbol, so replace the user's // home directory with it again Validate.notNull(home, "Home directory could not be determined from system properties"); return HOME_DIRECTORY_SYMBOL + completion.substring(home.length()); } // The path was working directory specific, so strip the working // directory given the user never typed it return completion.substring(getWorkingDirectoryAsString().length()); }
/** * If the user input starts with a tilde character (~), replace the tilde * character with the user's home directory. If the user input does not * start with a tilde, simply return the original user input without any * changes if the input specifies an absolute path, or return an absolute * path based on the working directory if the input specifies a relative * path. * * @param userInput the user input, which may commence with a tilde * (required) * @return a string that is guaranteed to no longer contain a tilde as the * first character (never null) */ private String convertUserInputIntoAFullyQualifiedPath(final String userInput) { if (denotesAbsolutePath(userInput)) { // Input is already in a fully-qualified path form return userInput; } if (userInput.startsWith(HOME_DIRECTORY_SYMBOL)) { // Replace this symbol with the user's actual home directory Validate.notNull(home, "Home directory could not be determined from system properties"); if (userInput.length() > 1) { return home + userInput.substring(1); } } // The path is working directory specific, so prepend the working // directory final String fullPath = getWorkingDirectoryAsString() + userInput; return fullPath; }