Community
Participate
Working Groups
Build Identifier: N20100703-2000 Calling setLiteralValue() with a String containing a single-quote will result in the quote being escaped in the rewritten output. i.e. sl.setLiteralValue(sl.getLiteralValue() + " loves horses' manes") results in ...horses\' manes", which is correct, but ugly. Easy enough to work around by copy-pastaing the method and removing the offending case, as patch. Reproducible: Always Steps to Reproduce: 1. Execute: import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.StringLiteral; class JDTScratch { public static void main(String[] args) { StringLiteral sl = ast().newStringLiteral(); sl.setEscapedValue("\"'\""); System.out.println(sl.getEscapedValue()); // "'" sl.setLiteralValue("'"); System.out.println(sl.getEscapedValue()); // "\'" } static AST ast() { final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(new char[0]); return parser.createAST(null).getAST(); } } Observe output, as comments.
Created attachment 174331 [details] Remove the "case '" clause
The quote must be escaped only within a character literal.
Srikanth, we should fix this for 3.6.1 as we corrupt the string literal. Released for 3.7M1.
Created attachment 174405 [details] Proposed fix + regression tests
Same patch with regression tests.
Patch looks good.
Released for 3.6.1 with updated copyright for the test.
Verified for 3.7M1 using build I20100802-1800
Change status to RESOLVED as this needs to be reverified for 3.6.1.
Verified for 3.6.1 RC2 using Build id: M20100825-0800