I am relatively new to using IntelliJ Idea Ultimate 2020 and I am currently exploring the refactoring functionalities within the software.
Is there a way to extract a method from a section of code and apply it to all instances easily and exclusively within the IDE?
Here is an example:
let a = 0;
let b = 2;
if (b === 2) {
// Code snippet to be extracted into a method
if (a === 0) {
1 + 1;
}
// Another code snippet to be extracted as the same function
if (a === 0) {
1 + 1;
}
b = a + 1;
}
After extracting the method, the result looks like this:
let extracted = function (a) {
if (a === 0) {
1 + 1;
}
};
let a = 0;
let b = 2;
if (b === 2) {
extracted(a);
if (a === 0) {
1 + 1;
}
b = a + 1;
}
Is there a way for IntelliJ to automatically implement this extraction on all instances?
let extracted = function (a) {
if (a === 0) {
1 + 1;
}
};
let a = 0;
let b = 2;
if (b === 2) {
extracted(a);
extracted(a);
b = a + 1;
}
If you have any insight on achieving this solely through the IDE for safer practices, thank you so much! :D