Home » Modeling » TMF (Xtext) » Xbase refactoring for static methods
Xbase refactoring for static methods [message #1563820] |
Wed, 14 January 2015 12:23 |
|
Hi
in my Xbase DSL I can define functions that are then inferred into
static methods of a Java class (I don't even need access to definitions
in other files, I don't have an import section, and there are no other
special features in this DSL). The name of the generated Java class is
computed using the file name (similar to the Scripting example of 7
languages):
val className =
"mypackage."+script.eResource.URI.trimFileExtension.lastSegment
Refactoring works correctly but if I refactor a function name, at the
end of the refactoring all references to that function are replaced with
the fully qualified name.
For example,
MyFile.mydsl
op foo() {
return foo();
}
becomes after refactoring
op foo() {
return mypackage.MyFile.foo();
}
which is fine, but ugly to look at ;)
what should I customize to avoid this?
I debugged a little, and I noted that
DefaultReferenceUpdater class
protected void createReferenceUpdate(IReferenceDescription
referenceDescription, URI referringResourceURI,
ElementRenameArguments elementRenameArguments, ResourceSet resourceSet,
IRefactoringUpdateAcceptor updateAcceptor) {
URI referringElementNewURI = elementRenameArguments
.getNewElementURI(referenceDescription.getSourceEObjectUri());
EObject referringElement =
resourceSet.getEObject(referringElementNewURI, false);
URI targetElementNewURI =
elementRenameArguments.getNewElementURI(referenceDescription.getTargetEObjectUri());
EObject newTargetElement = resourceSet.getEObject(targetElementNewURI,
false);
createReferenceUpdate(referringElement, referringResourceURI,
referenceDescription.getEReference(),
referenceDescription.getIndexInList(), newTargetElement,
updateAcceptor);
}
newTargetElement is already fully qualified...
thanks in advance
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| |
Re: Xbase refactoring for static methods [message #1565587 is a reply to message #1565298] |
Thu, 15 January 2015 11:12 |
|
On 15/01/2015 08:39, Sebastian Zarnekow wrote:
> Hi Lorenzo,
>
> you may want to dig into
> SerializerScopeProvider.getExecutableScope(XAbstractFeatureCall,
> JvmIdentifiableElement) and see what's going wrong there.
Hi Sebastian
thank you for the hint; I tried to debug that part, and everything seems
to work correctly (or at least, it looks like it behaves the same as
Xtend does for refactoring of static methods). Note that while
refactoring is triggered, and I type the new name, all references are
being updated correctly (i.e., not fully qualified) while I'm typing,
i.e., lively. The problem takes place when I press ENTER: the
references are then textually updated with the fully qualified name...
So the problem takes place somewhere else; during the debugging I can't
seem to find the exact place where the wrong behavior takes place... I
tried to debug until the refactoring unit of work terminates...
I also tried to add a custom QualifiedNameProvider so that
MyFile.mydsl
------------
op foo() {
return foo();
}
the qualified name of foo() corresponds to the qualified name of the
inferred operation, mypackage.MyFile.foo, but this does not solve the
problem either...
thanks in advance
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| | | | | |
Goto Forum:
Current Time: Fri Apr 26 15:27:56 GMT 2024
Powered by FUDForum. Page generated in 0.03909 seconds
|