beginRefactor("Convert Literals To C-style Quote Literals");
List<ATEToken> tokens = window.getTokens();
for(int index = tokens.size()-1; index>0; index--) {
ATEToken token = tokens.get(index);
String attribute;
String stripped;
String replaced = null;
if(token.type == ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING || token.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
attribute = token.getAttribute();
stripped = attribute.substring(1, attribute.length()-1);
} else
continue;
if(token.type == ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING) {
// Only one character allowed
if(stripped.length() == 1)
continue;
else if(stripped.length() == 2 && stripped.charAt(0) == '\\')
continue;
if(stripped.indexOf('"') != -1 || stripped.indexOf('\'') != -1)
stripped = escapeStringQuote(stripped, '"', '\'');
replaced = '"'+stripped+'"';
} else if(token.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
// String with one character should be converted to single-quote
if(stripped.length() > 1 && stripped.charAt(0) != '\\')
continue;
if(stripped.indexOf('\'') != -1 || stripped.indexOf('"') != -1)
stripped = escapeStringQuote(stripped, '\'', '"');
replaced = '\''+stripped+'\'';
}
mutator.replace(token.getStartIndex(), token.getEndIndex(), replaced);
}
endRefactor();
}