Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically rename parameters when mapping #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import com.intellij.openapi.ui.InputValidatorEx
import com.intellij.openapi.ui.Messages
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiParameter
import com.intellij.refactoring.RefactoringFactory
import com.intellij.ui.list.createTargetPopup
import com.intellij.util.text.nullize
import org.parchmentmc.scribe.ParchmentMappings
import org.parchmentmc.scribe.settings.ParchmentProjectSettings
import org.parchmentmc.scribe.util.findAllSuperConstructors
import org.parchmentmc.scribe.util.findAllSuperMethods

Expand All @@ -58,6 +60,17 @@ class MapParameterAction : MappingAction() {
parameterData.name = mapped
mappings.modified = true
ParchmentMappings.invalidateHints()

if (ParchmentProjectSettings.getInstance(project).renameAfterRemap) {
val file = parameter.containingFile.virtualFile
if (file != null && !file.isWritable) {
return
}

val factory = RefactoringFactory.getInstance(project)
val renameRefactoring = factory.createRename(parameter, mapped, false, false)
renameRefactoring.run()
}
}

mapParameter(e, parameter, mapFun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class ParchmentProjectConfigurable(private val project: Project) : BoundConfigur
.bindSelected(settings::remapParameters)
.comment("Determines whether Scribe should automatically remap parameters when inserting constructors and overrides.")
}

row {
checkBox("Rename Parameters When Remapping")
.bindSelected(settings::renameAfterRemap)
.comment("Determines whether Scribe should automatically rename parameters after they are remapped.")
}
}

override fun apply() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ParchmentProjectSettings : PersistentStateComponent<ParchmentProjectSettin
data class State(
var mappingsPath: String = "",
var displayHints: Boolean = true,
var remapParameters: Boolean = true
var remapParameters: Boolean = true,
var renameAfterRemap : Boolean = true
)

private var state = State()
Expand Down Expand Up @@ -72,6 +73,12 @@ class ParchmentProjectSettings : PersistentStateComponent<ParchmentProjectSettin
state.remapParameters = value
}

var renameAfterRemap: Boolean
get() = state.renameAfterRemap
set(value) {
state.renameAfterRemap = value
}

companion object {
fun getInstance(project: Project): ParchmentProjectSettings = project.getService(ParchmentProjectSettings::class.java)
}
Expand Down