Bug 578006 - [Databinding] Make IConverter into a functional interface
Summary: [Databinding] Make IConverter into a functional interface
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.23   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-31 05:55 EST by Jens Lideström CLA
Modified: 2021-12-31 08:45 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Lideström CLA 2021-12-31 05:55:36 EST
It would make some parts of the databinding framework more convenient to use if lambda expressions could be used directly for IConverters.

### Example

var s = new UpdateValueStrategy<Integer, String>();

// Like this:
s.setConverter(i -> "int: " + i);

// Instead of this:
s.setConverter(IConverter.create(i -> "int: " + i));

### Implementation

This can be achieved by providing default implementations for the methods IConverter.getFromType and IConverter.getToType. The only remaining unimplemented method would be IConverter.convert, which would make it possible to implement a converter with a lambda.

### Disadvantages

To do this the API annotations @noextend and @noimplement would need to be removed from IConverter, opening up the type for direct implementation by clients. This makes it a little harder to make  additions to the IConverter in the future. This seem to be a small problem however, which is more than enough balanced by the benefits of the change. This is because modern Java versions have the default method construct, and also that IConverter is a stable interface which is unlikely to be changed in the future.
Comment 1 Eclipse Genie CLA 2021-12-31 06:18:10 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/189215
Comment 2 Jens Lideström CLA 2021-12-31 08:45:46 EST
Christoph Laeubrich wrote in the Gerrit change: (https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/189215)

> I wonder if from/to are really used anywhere if they could return null it seems a bit useless.

They don't seem to be really used in the framework itself... I think maybe the intention was that you could have a value of unknown type, then find the right comparator from its from-type and to-type.

> Beside that they should probably better return Class<..> types instead of object?

The type in the framework, for converters, observables and properties all use Object. That is because EMF uses EClassifier and related types instead of Class. The intention was that the databinding component should support EMF and other related frameworks.