Extension method picked over instance method [message #938791] |
Wed, 10 October 2012 06:47 |
Alexey Romanov Messages: 263 Registered: May 2010 |
Senior Member |
|
|
I've tried to use ReflectExtensions, but found that it's `get` method was called instead of instance method on a Map. E.g. this works as expected:
package example
class ReflTest {
def test() {
val map = <String, String> newHashMap("a" -> "b")
map.get("a")
}
}
But if I add
extension ReflectExtensions = new ReflectExtensions
map.get is now highlighted as an extension method, hovering shows
this._reflectExtensions.get(map, "a")
and generated Java code is broken:
package ru.focusmedia.fire.idl.tests;
import java.util.HashMap;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.util.ReflectExtensions;
@SuppressWarnings("all")
public class ReflTest {
private ReflectExtensions _reflectExtensions = new Function0<ReflectExtensions>() {
public ReflectExtensions apply() {
ReflectExtensions _reflectExtensions = new ReflectExtensions();
return _reflectExtensions;
}
}.apply();
public Object test() {
try {
? _xblockexpression = null;
{
Pair<String,String> _mappedTo = Pair.<String, String>of("a", "b");
final HashMap<String,String> map = CollectionLiterals.<String, String>newHashMap(_mappedTo);
? _get = this._reflectExtensions.get(map, "a");
_xblockexpression = (_get);
}
return _xblockexpression;
} catch (Exception _e) {
throw Exceptions.sneakyThrow(_e);
}
}
}
Should I submit this as a bug?
|
|
|
Re: Extension method picked over instance method [message #939029 is a reply to message #938791] |
Wed, 10 October 2012 11:08 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Alexey,
please file a ticket. This is definitly a bug.
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 10.10.12 08:47, schrieb Alexey Romanov:
> I've tried to use ReflectExtensions, but found that it's `get` method
> was called instead of instance method on a Map. E.g. this works as
> expected:
>
> package example
>
> class ReflTest {
> def test() {
> val map = <String, String> newHashMap("a" -> "b")
> map.get("a")
> }
> }
> But if I add extension ReflectExtensions = new ReflectExtensions
> map.get is now highlighted as an extension method, hovering shows
> this._reflectExtensions.get(map, "a")
> and generated Java code is broken:
>
> package ru.focusmedia.fire.idl.tests;
>
> import java.util.HashMap;
> import org.eclipse.xtext.xbase.lib.CollectionLiterals;
> import org.eclipse.xtext.xbase.lib.Exceptions;
> import org.eclipse.xtext.xbase.lib.Functions.Function0;
> import org.eclipse.xtext.xbase.lib.Pair;
> import org.eclipse.xtext.xbase.lib.util.ReflectExtensions;
>
> @SuppressWarnings("all")
> public class ReflTest {
> private ReflectExtensions _reflectExtensions = new
> Function0<ReflectExtensions>() {
> public ReflectExtensions apply() {
> ReflectExtensions _reflectExtensions = new ReflectExtensions();
> return _reflectExtensions;
> }
> }.apply();
>
> public Object test() {
> try {
> ? _xblockexpression = null;
> {
> Pair<String,String> _mappedTo = Pair.<String, String>of("a", "b");
> final HashMap<String,String> map = CollectionLiterals.<String,
> String>newHashMap(_mappedTo);
> ? _get = this._reflectExtensions.get(map, "a");
> _xblockexpression = (_get);
> }
> return _xblockexpression;
> } catch (Exception _e) {
> throw Exceptions.sneakyThrow(_e);
> }
> }
> }
>
> Should I submit this as a bug?
|
|
|
|
Powered by
FUDForum. Page generated in 0.05604 seconds