Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 361577 - Introduce IValueConverterExtension that allows to convert from / to a QualifiedName
Summary: Introduce IValueConverterExtension that allows to convert from / to a Qualifi...
Status: CLOSED WONTFIX
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-20 14:02 EDT by Ed Willink CLA
Modified: 2012-04-03 12:56 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 Ed Willink CLA 2011-10-20 14:02:23 EDT
In CrossReferenceSerializer.getCrossReferenceNameFromScope

String unconverted = qualifiedNameConverter.toString(desc.getName());
try {
   return valueConverter.toString(unconverted, ruleName);

first aggregates the qualified name then converts it. 

Surely each segment should be converted independently.

e.g. consider "a.reserved.word" in which "reserved" and "word" are both reserved and for which "^" is an escape should be serialized as 

"a.^reserved.^word" not as "^a.reserved.word"
Comment 1 Sebastian Zarnekow CLA 2011-10-20 22:53:22 EDT
Your value converter should take care of the segments. If we'd convert them per segment (e.g. in the other direction from parsed string to value), things like 

date: INT '/' INT '/' INT 

won't be possible.
Comment 2 Ed Willink CLA 2011-10-21 01:45:40 EDT
I think there is a misunderstanding. This is a report against the new serializer and it seems to have nothing to do with datatype rules.

If the value converter was passed the qualified name, it could handle the segments, but it isn't.

For the old serializer I had to override CrossReferenceSerializer and do some rather dirty coding to outwit the value converter.

The new serializer seems much better; all my overrides seem much more modular and in my derived IScopes. I have no need to override CrossReferenceSerializer, which now has restricted access, except to fix this bug.

Perhaps the ^ prefix in my example is confusing. Using " and ::,

The three segment logical name

a::reserved::word

must be serialized segment-wise back to and parsed from

a::"reserved"::"word" rather than "a::reserved::word"

the first is a three-segment name containing two reserved words, the second is one-segment containing punctuation.

If datatype rules need different treatment then that may need a distinct code path. I see no reason why the value converter shouldn't be given the qualified name. In my case, this then allows different sets of reserved words to be used for the first segment.
Comment 3 Sebastian Zarnekow CLA 2011-10-21 04:33:26 EDT
(In reply to comment #2)
> I think there is a misunderstanding. This is a report against the new
> serializer and it seems to have nothing to do with datatype rules.
> 

I'm afraid it's not. Your value converter is responsible for escaping the individual segments. The contract of the interface is that you split the complete string up and escape all the parts that have to be escaped. It's unlikely that we ever change that. Anyway, your example looks reasonable to me and I'll rephrase the bug's subject.

Converting from / to a qualified name directly is interesting especially for cross references.
Comment 4 Ed Willink CLA 2011-10-21 05:47:42 EDT
IValueConverterService.toString(Object value, String lexerRule) takes an Object argument, so no change is required to pass a QualifiedName as far as API-tooling is required. Of course user code may be surprised, but perhaps should be using String.valueOf() anyway.

I'm not sure about to-QualifiedName since I'm not sure how the grammar would look and it doesn't help me with decorated qualified names such as A<B,C<D::E,F>>::G.

However for from-QualifiedName with the new serializer, I'm finding it useful for A::B::C, but I'm probably going to be in trouble with decorations.

Perhaps there should be an IQualifiedName that abstracts the sequence of segments allowing arbitrary representations of each segment. The value converter could then descend hierarchically though the segments and decorations.
Comment 5 Sebastian Zarnekow CLA 2012-04-03 12:38:45 EDT
I'll close this one as won't fix. The IValueConverter is reponsible for converting values that are contained in the model to something that can be written to text. Since the model does not have an attribute of type IQualifiedName, the value converter should not have to deal with it.

Those who are concerned about a simple string concat and some indexOf operations on a char array may of course customize their own CrossReferenceSerializer. Others should not be bothered with that special case.
Comment 6 Ed Willink CLA 2012-04-03 12:56:50 EDT
When I came to debugging some bad Completion Proposals, I discovered that using QualifiedName was really unhelpful since in A::B::C there are three references but only one grammar element, so proposals did not easily differ whether replacing A or B or C. After changing to use distinct grammar elements for each qualified name fragment Completion Proposals and Scope Resolution are variously better and simpler.

Since QualifiedNames seem unhelpful, there is no need to make them clever.