I have a `data class Entity` that I would like to ...
# random
t
I have a
data class Entity
that I would like to refactor. in this class there are a lots of method like
Copy code
fun promote() : Entity {
  require(state == States.Initial) { "Cannot promote entity in state $state" }
  return copy(state = States.Promoted)
}

fun demote() : Entity = ... same pattern
I would like to turn this into a type system of sort
Copy code
sealed class Entity

data class Initial : Entity { fun promote() = Promoted(...) }

data class Promoted : Entity { fun demote() = ... }
however there are like a lot and a lot and a lot of usages of current
Entity
data class features, especially copy method and equals. how would intellij help me with this refactor? I feel like this is one of those more complex refactor some ide magicians can do in a matter of half a day but would take me forever. I am not worried of taking a long time, since even if there is some magic refactor technique I would not be expert with it and would need to learn it, but I would like to learn it so next time it will be faster.
m
In this case, since it is a restructuring change and there are many usages involved, you should look into using Intellij’s “Replace structurally” command. It will let you search and replace based on AST nodes, not on simple text or regex.