Bug 499663 - [aa] Single quotes are escaped in annotation String values
Summary: [aa] Single quotes are escaped in annotation String values
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.8.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-15 09:57 EDT by Oliver Libutzki CLA
Modified: 2017-09-27 04:51 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Libutzki CLA 2016-08-15 09:57:00 EDT
Passing single quotes as part of an annotation string value doesn't work as expected as the quote is escaped.

This code in the annotation processor:
addAnnotation(Value.newAnnotationReference [
	setStringValue("value", "#{@'myBean'}")
]))

leads to this generated annotation:
@Value(value = "#{@\'myBean\'}")

The expected result is:
@Value(value = "#{@'myBean'}")
Comment 1 Christian Dietrich CLA 2017-02-09 06:12:51 EST
The generated Xtend code of the annotation processor class contains

 
it.setStringValue("value", "#{@\'myBean\'}");

which is normal xtend behaviour

so the same problem can be reproduced with a normal inferrer as well

members += entity.toToStringMethod(it) => [ m |
	m.annotations += SuppressWarnings.annotationRef() => [ a |
		a.explicitValues += TypesFactory.eINSTANCE.createJvmStringAnnotationValue => [
			operation = a.annotation.members.filter[simpleName=='value'].head as JvmOperation
			values += "'Hello'"
		]
	]
]

=> The Question is:

why do we escape the ' in the first place

org.eclipse.xtext.util.Strings.convertToJavaString(String, boolean)

imho the escaping is a null op.
Comment 2 Christian Dietrich CLA 2017-09-27 04:51:53 EDT
cc @sven