Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Extension method picked over instance method
Extension method picked over instance method [message #938791] Wed, 10 October 2012 06:47 Go to next message
Alexey Romanov is currently offline Alexey RomanovFriend
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 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
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?
Re: Extension method picked over instance method [message #939046 is a reply to message #939029] Wed, 10 October 2012 11:31 Go to previous message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
Submitted: https://bugs.eclipse.org/bugs/show_bug.cgi?id=391527
Previous Topic:Xtext Checks, Markers and Quick Fixes
Next Topic:Xtext 2.3 Nature and Builder Issues
Goto Forum:
  


Current Time: Fri Mar 29 05:02:54 GMT 2024

Powered by FUDForum. Page generated in 0.05604 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top