Skip to main content



      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] Tue, 10 December 2013 20:28 Go to next message
Eclipse UserFriend
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: Tue, 10 December 2013 20:31] by 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 01:29 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: How to support a such a different overloading which is different from Java [message #1220475 is a reply to message #1220319] Wed, 11 December 2013 22:45 Go to previous messageGo to next message
Eclipse UserFriend
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: Wed, 11 December 2013 22:46] by 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 01:44 Go to previous message
Eclipse UserFriend
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
Previous Topic:breakpoints in xtend files
Next Topic:Extending OCL MDT using Xtext
Goto Forum:
  


Current Time: Wed Jul 23 19:07:07 EDT 2025

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

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

Back to the top