Today when I tried to do simple renaming refactor in JavaScript using intellij IDEA 10, I was shocked what it did. It renamed that Class attribute everywhere regardless the attribute belonged to that class or not! For example Baz.attr1
renamed to Baz.attribute1
, it also renamed Box.attr1
to Box.attribute1
. Refactor Preview does not help here because there are hundreds of places in which the same attribute name is used under different situations like this.attr1
type of references.
Eclipse does not even have JavaScript rename refactoring.
In additional to renaming I am looking to refactor a group of functions and move them to Object Literal notations such as
function foo() {
}
function bar() {
}
refactor to :
var MyCompany.Baz = {
foo: function() {
},
bar: function() {
}
}
It should refactor all references to those function calls in all the files including HTML and JSP files like foo();
changing to MyCompany.Baz.foo();
There is no such thing in either IDE.
Is there high quality plugin available for JavaScript for Eclipse (prefer) or Intellij IDEA that would do the kinds refactorings of I am talking about?
I believe that the kind of rename refactoring that you want is not possible in a dynamic language.
Let's say that you have your classes Baz
and Box
with the attr1
attribute.
If we write something like:
var b;
if (someCondition) {
b = createBox();
} else {
b = createBaz();
}
b.attr1 = "value";
What should the refactoring program do?
Given that the type of the variable is only known when the corresponding code is executed, and that this type can differ at each invocation of that code, the computer is unable to determine to which definition an invocation of the attribute 'attr1' should be linked to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With