New J2K: reformat JavaToKotlinAction.kt
This commit is contained in:
@@ -79,7 +79,8 @@ class JavaToKotlinAction : AnAction() {
|
|||||||
try {
|
try {
|
||||||
val document = PsiDocumentManager.getInstance(psiFile.project).getDocument(psiFile)
|
val document = PsiDocumentManager.getInstance(psiFile.project).getDocument(psiFile)
|
||||||
if (document == null) {
|
if (document == null) {
|
||||||
MessagesEx.error(psiFile.project, "Failed to save conversion result: couldn't find document for " + psiFile.name).showLater()
|
MessagesEx.error(psiFile.project, "Failed to save conversion result: couldn't find document for " + psiFile.name)
|
||||||
|
.showLater()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
document.replaceString(0, document.textLength, text)
|
document.replaceString(0, document.textLength, text)
|
||||||
@@ -89,14 +90,12 @@ class JavaToKotlinAction : AnAction() {
|
|||||||
if (ScratchRootType.getInstance().containsFile(virtualFile)) {
|
if (ScratchRootType.getInstance().containsFile(virtualFile)) {
|
||||||
val mapping = ScratchFileService.getInstance().scratchesMapping
|
val mapping = ScratchFileService.getInstance().scratchesMapping
|
||||||
mapping.setMapping(virtualFile, KotlinFileType.INSTANCE.language)
|
mapping.setMapping(virtualFile, KotlinFileType.INSTANCE.language)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val fileName = uniqueKotlinFileName(virtualFile)
|
val fileName = uniqueKotlinFileName(virtualFile)
|
||||||
virtualFile.pathBeforeJ2K = virtualFile.path
|
virtualFile.pathBeforeJ2K = virtualFile.path
|
||||||
virtualFile.rename(this, fileName)
|
virtualFile.rename(this, fileName)
|
||||||
}
|
}
|
||||||
}
|
} catch (e: IOException) {
|
||||||
catch (e: IOException) {
|
|
||||||
MessagesEx.error(psiFile.project, e.message ?: "").showLater()
|
MessagesEx.error(psiFile.project, e.message ?: "").showLater()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,25 +127,35 @@ class JavaToKotlinAction : AnAction() {
|
|||||||
::convert,
|
::convert,
|
||||||
title,
|
title,
|
||||||
true,
|
true,
|
||||||
project)) return emptyList()
|
project
|
||||||
|
)
|
||||||
|
) return emptyList()
|
||||||
|
|
||||||
|
|
||||||
var externalCodeUpdate: (() -> Unit)? = null
|
var externalCodeUpdate: (() -> Unit)? = null
|
||||||
|
|
||||||
if (enableExternalCodeProcessing && converterResult!!.externalCodeProcessing != null) {
|
if (enableExternalCodeProcessing && converterResult!!.externalCodeProcessing != null) {
|
||||||
val question = "Some code in the rest of your project may require corrections after performing this conversion. Do you want to find such code and correct it too?"
|
val question =
|
||||||
if (!askExternalCodeProcessing || (Messages.showYesNoDialog(project, question, title, Messages.getQuestionIcon()) == Messages.YES)) {
|
"Some code in the rest of your project may require corrections after performing this conversion. Do you want to find such code and correct it too?"
|
||||||
|
if (!askExternalCodeProcessing || (Messages.showYesNoDialog(
|
||||||
|
project,
|
||||||
|
question,
|
||||||
|
title,
|
||||||
|
Messages.getQuestionIcon()
|
||||||
|
) == Messages.YES)
|
||||||
|
) {
|
||||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||||
{
|
{
|
||||||
runReadAction {
|
runReadAction {
|
||||||
externalCodeUpdate = converterResult!!.externalCodeProcessing!!.prepareWriteOperation(
|
externalCodeUpdate = converterResult!!.externalCodeProcessing!!.prepareWriteOperation(
|
||||||
ProgressManager.getInstance().progressIndicator!!
|
ProgressManager.getInstance().progressIndicator!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title,
|
title,
|
||||||
true,
|
true,
|
||||||
project)
|
project
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,8 +198,8 @@ class JavaToKotlinAction : AnAction() {
|
|||||||
if (firstSyntaxError != null) {
|
if (firstSyntaxError != null) {
|
||||||
val count = javaFiles.filter { PsiTreeUtil.hasErrorElements(it) }.count()
|
val count = javaFiles.filter { PsiTreeUtil.hasErrorElements(it) }.count()
|
||||||
val question = firstSyntaxError.containingFile.name +
|
val question = firstSyntaxError.containingFile.name +
|
||||||
(if (count > 1) " and ${count - 1} more Java files" else " file") +
|
(if (count > 1) " and ${count - 1} more Java files" else " file") +
|
||||||
" contain syntax errors, the conversion result may be incorrect"
|
" contain syntax errors, the conversion result may be incorrect"
|
||||||
|
|
||||||
val okText = "Investigate Errors"
|
val okText = "Investigate Errors"
|
||||||
val cancelText = "Proceed with Conversion"
|
val cancelText = "Proceed with Conversion"
|
||||||
@@ -201,7 +210,8 @@ class JavaToKotlinAction : AnAction() {
|
|||||||
okText,
|
okText,
|
||||||
cancelText,
|
cancelText,
|
||||||
Messages.getWarningIcon()
|
Messages.getWarningIcon()
|
||||||
) == Messages.OK) {
|
) == Messages.OK
|
||||||
|
) {
|
||||||
NavigationUtil.activateFileWithPsiElement(firstSyntaxError.navigationElement)
|
NavigationUtil.activateFileWithPsiElement(firstSyntaxError.navigationElement)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -239,8 +249,8 @@ class JavaToKotlinAction : AnAction() {
|
|||||||
private fun allJavaFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<PsiJavaFile> {
|
private fun allJavaFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<PsiJavaFile> {
|
||||||
val manager = PsiManager.getInstance(project)
|
val manager = PsiManager.getInstance(project)
|
||||||
return allFiles(filesOrDirs)
|
return allFiles(filesOrDirs)
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.mapNotNull { manager.findFile(it) as? PsiJavaFile }
|
.mapNotNull { manager.findFile(it) as? PsiJavaFile }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
||||||
|
|||||||
Reference in New Issue
Block a user