use of com.reprezen.swagedit.core.utils.StringUtils.QuoteStyle in project KaiZen-OpenAPI-Editor by RepreZen.
the class Proposal method asStyledCompletionProposal.
/**
* Returns a {@link CompletionProposal}.
*
* The {@link CompletionProposal} will be returned only if the prefix is null, or if the replacement string starts
* with or contains the prefix. Otherwise this method returns null.
*
* @param prefix
* @param offset
* @return proposal
*/
public StyledCompletionProposal asStyledCompletionProposal(String prefix, int offset) {
final StyledString styledString = new StyledString(displayString);
if (type != null) {
styledString.append(": ", typeStyler).append(type, typeStyler);
}
// If the replacement string has quotes
// we should know which kind is it
QuoteStyle quote = QuoteStyle.INVALID;
if (StringUtils.isQuoted(replacementString)) {
quote = StringUtils.QuoteStyle.parse(replacementString.charAt(0));
}
// If prefix is a quote, which kind is it
QuoteStyle prefixQuote = QuoteStyle.INVALID;
if (StringUtils.isQuoted(prefix)) {
prefixQuote = StringUtils.QuoteStyle.parse(prefix.charAt(0));
}
// Handle quotes
String rString = replacementString;
if (quote != QuoteStyle.INVALID && prefixQuote != QuoteStyle.INVALID) {
if (quote != prefixQuote) {
// If quotes are not same, replace quotes from replacement
// string with one from prefix
rString = rString.substring(1);
if (rString.endsWith(quote.getValue())) {
rString = rString.substring(0, rString.length() - 1);
}
rString = prefixQuote.getValue() + rString;
} else {
// remove last quote to avoid duplicates
rString = rString.substring(0, rString.length() - 1);
}
}
StyledCompletionProposal proposal = null;
if (Strings.emptyToNull(prefix) == null) {
proposal = new StyledCompletionProposal(replacementString, styledString, null, description, offset);
} else if (rString.toLowerCase().contains(prefix.toLowerCase())) {
proposal = new StyledCompletionProposal(rString, styledString, prefix, description, offset);
}
return proposal;
}
Aggregations