How to support a such a different overloading which is different from Java [message #1220306] |
Wed, 11 December 2013 01:28 |
Matthew Liu 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 #1220475 is a reply to message #1220319] |
Thu, 12 December 2013 03:45 |
Matthew Liu 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04239 seconds