Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320393

Summary: AbstractDeclarativeValueConverterService.internalRegisterForClass: declarations in superclasses override re-definitions in subclasses
Product: [Modeling] TMF Reporter: Thomas Wolf <twolf>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: unspecifiedFlags: sebastian.zarnekow: helios+
Target Milestone: SR1   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Thomas Wolf CLA 2010-07-20 09:15:24 EDT
Build Identifier: I20100608-0911

Assume an xtext grammar derived from the default terminal grammar:

grammar Foo with org.eclipse.xtext.common.Terminals

which then re-defines the STRING rule, for instance to use Ada (or PL/SQL) style strings:

terminal STRING :
  ('"' ((!'"')|('"' '"'))* '"');

Then write a value converter for this:

class FooValueConverters extends org.eclipse.xtext.common.services.DefaultTerminalConverters {

@ValueConverter(rule = "STRING")
public IValueConverter<String> stringValueConverter() {
  return new AbstractNullSafeConverter<String>() {
    @Override
    protected String internalToValue(String s, AbstractNode node) {
      return return s.substring(1, s.length() - 1).replace("\"\"", "\"");;
    }

    @Override
    protected String internalToString(String value) {
      return '"' + source.replace("\"", "\"\"") + '"';
    }
  };
}

Then inject this value converter.

When this value converter is set up, the implementation in AbstractDeclarativeValueConverterService.internalRegisterForClass will first register this new STRING value converter, and then override it by the default one from org.eclipse.xtext.common.services.DefaultTerminalConverters, from which FooValueConverters is extended. As a result, a string like "bar""" cannot be serialized.

The fix is simple: in internalRegisterForClass, handle superclasses first before checking and registering the methods of the current class.

Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2010-07-21 05:31:48 EDT
Fixed in HEAD.
Comment 2 Karsten Thoms CLA 2017-09-19 16:13:11 EDT
Closing bug which were set to RESOLVED before Eclipse Neon.0.