timowest / scalagen

Java to Scala transformation
Apache License 2.0
216 stars 32 forks source link

problem with javabean property which is also in constructor #68

Closed jmvanel closed 10 years ago

jmvanel commented 10 years ago

There is a problem when in Java source there is a javabean property "prop" which is also in constructor.

// Java: class T1 {} class C { C( T1 prop ) { setProp(prop); }; void setProp( T1 prop ) { this.prop = prop }; T1 getProp() { return prop; }; }

What SHOULD be produced is this :

class C( @BeanProperty var prop : T1 ) { }

With current translation, where @BeanProperty declaration is done outside of argument, , Scala compiler says when the property is accessed:

ambiguous reference to overloaded definition, both method setProp in class C of type ( prop: T1)Unit and method setProp in class C of type (x$1: T1)Unit match argument types (T1)

timowest commented 10 years ago

The problem here is that the setter usage is not converted

The following should work

C( T1 p ) { prop = p; }

Maybe setter usage in constructors could be replaced with field assignment?