Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to support a such a different overloading which is different from Java(overloading in all scopes (including local scope and global scope))
How to support a such a different overloading which is different from Java [message #1220306] Wed, 11 December 2013 01:28 Go to next message
Matthew Liu is currently offline Matthew LiuFriend
Messages: 9
Registered: March 2013
Junior Member
Dear all,

As we known, in Java world, overloading only exists in ONE scope (with in one class). Please see the following Java snippet (the method with name "meth").

public class OuterCLass {
	class InnerClass{
		public void meth(int a){}  // 1: in "InnerClass" scope
		public void meth(){ }    // 2: in InnerClass scope
		public void call(){
			meth(4);     //<--- 3: method call, Java editor finds correct reference
		}
	}
}


The scoping of Xtext works in the same way. In Xtext world cross-references are established via names. When doing cross-referencing, it looks from the current scope where the the code locates. If the expected name could be found, then it would stop. If not, it would look from the next outer scope until the name is found. Or the expected name still can NOT be found from the outer-most scope, the an error would appear. This imply that the name in the outer scope is shadowed by the same name in the inner scope.

However, In our DSL, we need to support the overloading in all scopes (including local scope and global scope). The following code should be supported:

public class OuterCLass {
	public void meth(int a){}  // 1: in "OuterCLass" scope
	class InnerClass{
		public void meth(){ }    // 2: in InnerClass scope
		public void call(){
			meth(4);     //<--- 3: method call, Java editor shows an error: The method meth() in the type OuterCLass.InnerClass is not applicable for the arguments (int)
		}
	}
}


That is, if Xtext find the expected name ("meth"), it should NOT stop; it should continue to find other expect names ( all "meth"s) until the outer-most scope.
Could anyone give me some advice about this? Thanks in advance!

Best Regards,
Matthew


[Updated on: Wed, 11 December 2013 01:31]

Report message to a moderator

Re: How to support a such a different overloading which is different from Java [message #1220319 is a reply to message #1220306] Wed, 11 December 2013 06:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
Hi are you using xbase/jem model inferred? If not have a look (debug)
importednamespaceawarelocalscopeprovider

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to support a such a different overloading which is different from Java [message #1220475 is a reply to message #1220319] Thu, 12 December 2013 03:45 Go to previous messageGo to next message
Matthew Liu is currently offline Matthew LiuFriend
Messages: 9
Registered: March 2013
Junior Member
Dear Christian,

Thanks for your response!

I did NOT use the xbase. After debugging the source. I find that the following method in AbstractScope.java would stop if ONE expected name is find. It will not continue to find in the outer scope. How could I make it to find other names in all the scopes (all the local scopes and global scopes)? Could you please give me some hints?

Thanks in advance!

	public Iterable<IEObjectDescription> getElements(final QualifiedName name) {
		Iterable<IEObjectDescription> localElements = getLocalElementsByName(name);
		if (localElements instanceof Collection) {
			if (((Collection<?>) localElements).isEmpty())
				return getParent().getElements(name);
		}
		Iterable<IEObjectDescription> parentElements = getParentElements(new Provider<Iterable<IEObjectDescription>>() {
			public Iterable<IEObjectDescription> get() {
				return getParent().getElements(name);
			}
		});
		Iterable<IEObjectDescription> result = Iterables.concat(localElements, parentElements);
		return result;
	}


Best Regards,
Matthew

[Updated on: Thu, 12 December 2013 03:46]

Report message to a moderator

Re: How to support a such a different overloading which is different from Java [message #1220484 is a reply to message #1220475] Thu, 12 December 2013 06:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
How are you inner beats outer rules? Write your own provider?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:breakpoints in xtend files
Next Topic:Extending OCL MDT using Xtext
Goto Forum:
  


Current Time: Fri Nov 27 18:44:35 GMT 2020

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

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

Back to the top