diff --git a/src/main/kotlin/com/demonwav/mcdev/buildsystem/BuildSystem.kt b/src/main/kotlin/com/demonwav/mcdev/buildsystem/BuildSystem.kt index 4e41c71f6..ce47a0ff4 100644 --- a/src/main/kotlin/com/demonwav/mcdev/buildsystem/BuildSystem.kt +++ b/src/main/kotlin/com/demonwav/mcdev/buildsystem/BuildSystem.kt @@ -57,8 +57,8 @@ abstract class BuildSystem { * ProjectConfiguration are provided here as well. * @param project The project - * * - * @param configurations The configuration objects for the project + * @param configuration The configuration object for the project + * @param indicator The progress indicator */ abstract fun create(project: Project, configuration: ProjectConfiguration, indicator: ProgressIndicator) @@ -71,9 +71,9 @@ abstract class BuildSystem { * It is legal for this method to have different default setups for each platform type, so the PlatformType and * ProjectConfiguration are provided here as well. - * @param module the module - * * + * @param rootModule the root module * @param configurations The configuration object for the project + * @param indicator The progress indicator */ abstract fun finishSetup(rootModule: Module, configurations: Collection, indicator: ProgressIndicator) diff --git a/src/main/kotlin/com/demonwav/mcdev/buildsystem/maven/MavenBuildSystem.kt b/src/main/kotlin/com/demonwav/mcdev/buildsystem/maven/MavenBuildSystem.kt index fa46e7ca3..8e0941ba8 100644 --- a/src/main/kotlin/com/demonwav/mcdev/buildsystem/maven/MavenBuildSystem.kt +++ b/src/main/kotlin/com/demonwav/mcdev/buildsystem/maven/MavenBuildSystem.kt @@ -80,7 +80,7 @@ class MavenBuildSystem : BuildSystem() { root.addAfter(url, properties) } - if (!configuration.description.isNullOrEmpty()) { + if (configuration.description.isNotEmpty()) { val description = root.createChildTag("description", null, configuration.description, false) root.addBefore(description, properties) } diff --git a/src/main/kotlin/com/demonwav/mcdev/creator/BuildSystemWizardStep.kt b/src/main/kotlin/com/demonwav/mcdev/creator/BuildSystemWizardStep.kt index a1b85b286..436ba41ae 100644 --- a/src/main/kotlin/com/demonwav/mcdev/creator/BuildSystemWizardStep.kt +++ b/src/main/kotlin/com/demonwav/mcdev/creator/BuildSystemWizardStep.kt @@ -72,10 +72,10 @@ class BuildSystemWizardStep(private val creator: MinecraftProjectCreator) : Modu } private fun createBuildSystem(): BuildSystem { - if (buildSystemBox.selectedIndex == 0) { - return MavenBuildSystem() + return if (buildSystemBox.selectedIndex == 0) { + MavenBuildSystem() } else { - return GradleBuildSystem() + GradleBuildSystem() } } @@ -89,7 +89,7 @@ class BuildSystemWizardStep(private val creator: MinecraftProjectCreator) : Modu throw EmptyFieldSetupException(artifactIdField) } - if (versionField.text.trim { it <= ' ' }.isEmpty()) { + if (versionField.text.isBlank()) { throw EmptyFieldSetupException(versionField) } diff --git a/src/main/kotlin/com/demonwav/mcdev/creator/ForgeProjectSettingsWizard.kt b/src/main/kotlin/com/demonwav/mcdev/creator/ForgeProjectSettingsWizard.kt index 332df1184..758bcd9c6 100644 --- a/src/main/kotlin/com/demonwav/mcdev/creator/ForgeProjectSettingsWizard.kt +++ b/src/main/kotlin/com/demonwav/mcdev/creator/ForgeProjectSettingsWizard.kt @@ -154,10 +154,10 @@ class ForgeProjectSettingsWizard(private val creator: MinecraftProjectCreator) : private val version: String? get() { - if (isSpongeForge == true || (isSpongeForge == null && settings is SpongeForgeProjectConfiguration)) { - return spongeVersion?.let { it.versions[minecraftVersionBox.selectedItem as? String] } + return if (isSpongeForge == true || (isSpongeForge == null && settings is SpongeForgeProjectConfiguration)) { + spongeVersion?.let { it.versions[minecraftVersionBox.selectedItem as? String] } } else { - return minecraftVersionBox.selectedItem as? String + minecraftVersionBox.selectedItem as? String } } diff --git a/src/main/kotlin/com/demonwav/mcdev/creator/LiteLoaderProjectSettingsWizard.kt b/src/main/kotlin/com/demonwav/mcdev/creator/LiteLoaderProjectSettingsWizard.kt index 864146f74..ca57cf9d7 100644 --- a/src/main/kotlin/com/demonwav/mcdev/creator/LiteLoaderProjectSettingsWizard.kt +++ b/src/main/kotlin/com/demonwav/mcdev/creator/LiteLoaderProjectSettingsWizard.kt @@ -152,15 +152,15 @@ class LiteLoaderProjectSettingsWizard(private val creator: MinecraftProjectCreat override fun validate(): Boolean { try { - if (modNameField.text.trim { it <= ' ' }.isEmpty()) { + if (modNameField.text.isBlank()) { throw EmptyInputSetupException(modNameField) } - if (modVersionField.text.trim { it <= ' ' }.isEmpty()) { + if (modVersionField.text.isBlank()) { throw EmptyInputSetupException(modVersionField) } - if (mainClassField.text.trim { it <= ' ' }.isEmpty()) { + if (mainClassField.text.isBlank()) { throw EmptyInputSetupException(mainClassField) } } catch (e: SetupException) { diff --git a/src/main/kotlin/com/demonwav/mcdev/creator/MinecraftModuleWizardStep.kt b/src/main/kotlin/com/demonwav/mcdev/creator/MinecraftModuleWizardStep.kt index 87387635a..2ffb0bfec 100644 --- a/src/main/kotlin/com/demonwav/mcdev/creator/MinecraftModuleWizardStep.kt +++ b/src/main/kotlin/com/demonwav/mcdev/creator/MinecraftModuleWizardStep.kt @@ -30,16 +30,16 @@ abstract class MinecraftModuleWizardStep : ModuleWizardStep() { dependField: JTextField, pattern: Regex): Boolean { try { - if (pluginNameField.text.trim { it <= ' ' }.isEmpty()) { + if (pluginNameField.text.isBlank()) { throw EmptyInputSetupException(pluginNameField) } - if (pluginVersionField.text.trim { it <= ' ' }.isEmpty()) { + if (pluginVersionField.text.isBlank()) { throw EmptyInputSetupException(pluginVersionField) } // empty - if (mainClassField.text.trim { it <= ' ' }.isEmpty()) { + if (mainClassField.text.isBlank()) { throw EmptyInputSetupException(mainClassField) } // default package diff --git a/src/main/kotlin/com/demonwav/mcdev/error/AnonymousFeedback.kt b/src/main/kotlin/com/demonwav/mcdev/error/AnonymousFeedback.kt index 162915f57..c5d80aa77 100644 --- a/src/main/kotlin/com/demonwav/mcdev/error/AnonymousFeedback.kt +++ b/src/main/kotlin/com/demonwav/mcdev/error/AnonymousFeedback.kt @@ -159,7 +159,7 @@ object AnonymousFeedback { data = connection.inputStream.reader().use(InputStreamReader::readCharSequence).toString() - response = gson.fromJson>>(data) + response = gson.fromJson(data) list.addAll(response) link = connection.getHeaderField("Link") diff --git a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt index 3640af9d4..bbe71dd93 100644 --- a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt +++ b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt @@ -140,7 +140,7 @@ class MinecraftFacet(module: Module, name: String, configuration: MinecraftFacet fun isEventClassValid(eventClass: PsiClass, method: PsiMethod): Boolean { return doIfGood(method) { it.isEventClassValid(eventClass, method) - } ?: false + } == true } @Contract(pure = true) @@ -154,14 +154,14 @@ class MinecraftFacet(module: Module, name: String, configuration: MinecraftFacet fun isStaticListenerSupported(method: PsiMethod): Boolean { return doIfGood(method) { it.isStaticListenerSupported(method) - } ?: false + } == true } @Contract(pure = true) fun suppressStaticListener(method: PsiMethod): Boolean { return doIfGood(method) { !it.isStaticListenerSupported(method) - } ?: false + } == true } private inline fun doIfGood(method: PsiMethod, action: (AbstractModule) -> T): T? { diff --git a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetConfiguration.kt b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetConfiguration.kt index 22f506e13..e688f8ab9 100644 --- a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetConfiguration.kt +++ b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetConfiguration.kt @@ -10,7 +10,6 @@ package com.demonwav.mcdev.facet -import com.demonwav.mcdev.platform.MinecraftFacetEditorTab import com.demonwav.mcdev.platform.PlatformType import com.intellij.facet.FacetConfiguration import com.intellij.facet.ui.FacetEditorContext diff --git a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.form b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.form index 5658718ea..0e820ad5d 100644 --- a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.form +++ b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.form @@ -1,5 +1,5 @@ -
+ diff --git a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.kt b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.kt index b0d7507c3..79d75c3fd 100644 --- a/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.kt +++ b/src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetEditorTab.kt @@ -8,10 +8,10 @@ * MIT License */ -package com.demonwav.mcdev.platform +package com.demonwav.mcdev.facet import com.demonwav.mcdev.asset.PlatformAssets -import com.demonwav.mcdev.facet.MinecraftFacetConfiguration +import com.demonwav.mcdev.platform.PlatformType import com.intellij.facet.ui.FacetEditorTab import com.intellij.util.ui.UIUtil import javax.swing.JCheckBox diff --git a/src/main/kotlin/com/demonwav/mcdev/nbt/Nbt.kt b/src/main/kotlin/com/demonwav/mcdev/nbt/Nbt.kt index 70a3566c2..d729b4a7b 100644 --- a/src/main/kotlin/com/demonwav/mcdev/nbt/Nbt.kt +++ b/src/main/kotlin/com/demonwav/mcdev/nbt/Nbt.kt @@ -34,11 +34,11 @@ import java.util.zip.ZipException object Nbt { private fun getActualInputStream(stream: InputStream): Pair { - try { - return DataInputStream(GZIPInputStream(stream)) to true + return try { + DataInputStream(GZIPInputStream(stream)) to true } catch (e: ZipException) { stream.reset() - return DataInputStream(stream) to false + DataInputStream(stream) to false } } @@ -134,20 +134,20 @@ object Nbt { } private fun DataInputStream.readTag(tagId: NbtTypeId, start: Long, timeout: Long): NbtTag { - when (tagId) { - NbtTypeId.END -> return TagEnd - NbtTypeId.BYTE -> return this.readByteTag(start, timeout) - NbtTypeId.SHORT -> return this.readShortTag(start, timeout) - NbtTypeId.INT -> return this.readIntTag(start, timeout) - NbtTypeId.LONG -> return this.readLongTag(start, timeout) - NbtTypeId.FLOAT -> return this.readFloatTag(start, timeout) - NbtTypeId.DOUBLE -> return this.readDoubleTag(start, timeout) - NbtTypeId.BYTE_ARRAY -> return this.readByteArrayTag(start, timeout) - NbtTypeId.STRING -> return this.readStringTag(start, timeout) - NbtTypeId.LIST -> return this.readListTag(start, timeout) - NbtTypeId.COMPOUND -> return this.readCompoundTag(start, timeout) - NbtTypeId.INT_ARRAY -> return this.readIntArrayTag(start, timeout) - NbtTypeId.LONG_ARRAY -> return this.readLongArrayTag(start, timeout) + return when (tagId) { + NbtTypeId.END -> TagEnd + NbtTypeId.BYTE -> this.readByteTag(start, timeout) + NbtTypeId.SHORT -> this.readShortTag(start, timeout) + NbtTypeId.INT -> this.readIntTag(start, timeout) + NbtTypeId.LONG -> this.readLongTag(start, timeout) + NbtTypeId.FLOAT -> this.readFloatTag(start, timeout) + NbtTypeId.DOUBLE -> this.readDoubleTag(start, timeout) + NbtTypeId.BYTE_ARRAY -> this.readByteArrayTag(start, timeout) + NbtTypeId.STRING -> this.readStringTag(start, timeout) + NbtTypeId.LIST -> this.readListTag(start, timeout) + NbtTypeId.COMPOUND -> this.readCompoundTag(start, timeout) + NbtTypeId.INT_ARRAY -> this.readIntArrayTag(start, timeout) + NbtTypeId.LONG_ARRAY -> this.readLongArrayTag(start, timeout) } } diff --git a/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttBlock.kt b/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttBlock.kt index 15edc58bb..a6f14c2b1 100644 --- a/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttBlock.kt +++ b/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttBlock.kt @@ -40,12 +40,12 @@ class NbttBlock( private val spacingBuilder = NbttFormattingModelBuilder.createSpacingBuilder(settings) init { - if (psiElement is NbttCompound) { - childWrap = Wrap.createWrap(getCustomSettings().OBJECT_WRAPPING, true) + childWrap = if (psiElement is NbttCompound) { + Wrap.createWrap(getCustomSettings().OBJECT_WRAPPING, true) } else if (psiElement is NbttList || psiElement is NbttByteArray || psiElement is NbttIntArray) { - childWrap = Wrap.createWrap(getCustomSettings().LIST_WRAPPING, true) + Wrap.createWrap(getCustomSettings().LIST_WRAPPING, true) } else { - childWrap = null + null } } diff --git a/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttFoldingBuilder.kt b/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttFoldingBuilder.kt index 9dd80d528..fce906418 100644 --- a/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttFoldingBuilder.kt +++ b/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttFoldingBuilder.kt @@ -78,22 +78,20 @@ class NbttFoldingBuilder : FoldingBuilder { override fun isCollapsedByDefault(node: ASTNode): Boolean { val psi = node.psi - val size = if (psi is NbttByteArray) { - psi.getByteParams()?.byteList?.size ?: 0 - } else if (psi is NbttIntArray) { - psi.getIntParams()?.intList?.size ?: 0 - } else if (psi is NbttList) { - psi.getListParams()?.tagList?.size ?: 0 - } else if (psi is NbttCompound) { - if (psi.getNamedTagList().size == 1) { - val tag = psi.getNamedTagList()[0].tag - if (tag.getList() == null && tag.getCompound() == null && tag.getIntArray() == null && tag.getByteArray() == null) { - return true + val size = when (psi) { + is NbttByteArray -> psi.getByteParams()?.byteList?.size ?: 0 + is NbttIntArray -> psi.getIntParams()?.intList?.size ?: 0 + is NbttList -> psi.getListParams()?.tagList?.size ?: 0 + is NbttCompound -> { + if (psi.getNamedTagList().size == 1) { + val tag = psi.getNamedTagList()[0].tag + if (tag.getList() == null && tag.getCompound() == null && tag.getIntArray() == null && tag.getByteArray() == null) { + return true + } } + psi.getNamedTagList().size } - psi.getNamedTagList().size - } else { - 0 + else -> 0 } return size > 50 // TODO arbitrary? make a setting? diff --git a/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttParameterNameHints.kt b/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttParameterNameHints.kt index 8cd7a1056..5883c8775 100644 --- a/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttParameterNameHints.kt +++ b/src/main/kotlin/com/demonwav/mcdev/nbt/lang/format/NbttParameterNameHints.kt @@ -21,26 +21,27 @@ import com.intellij.psi.PsiElement class NbttParameterNameHints : InlayParameterHintsProvider { override fun getParameterHints(element: PsiElement): MutableList { val list = mutableListOf() - if (element is NbttCompound) { - val size = element.getNamedTagList().size - - list.add(InlayInfo("$size ${if (size == 1) "child" else "children"}", element.textRange.startOffset + 1)) - } else if (element is NbttList) { - val size = element.getListParams()?.tagList?.size ?: 0 - - list.add(InlayInfo("$size ${if (size == 1) "child" else "children"}", element.textRange.startOffset + 1)) - } else if (element is NbttByteArray) { - val size = element.getByteParams()?.byteList?.size ?: 0 - - list.add(InlayInfo( - "$size ${if (size == 1) "child" else "children"}", element.node.getChildren(null)[1].textRange.startOffset + 1 - )) - } else if (element is NbttIntArray) { - val size = element.getIntParams()?.intList?.size ?: 0 - - list.add(InlayInfo( - "$size ${if (size == 1) "child" else "children"}", element.node.getChildren(null)[1].textRange.startOffset + 1 - )) + when (element) { + is NbttCompound -> { + val size = element.getNamedTagList().size + list.add(InlayInfo("$size ${if (size == 1) "child" else "children"}", element.textRange.startOffset + 1)) + } + is NbttList -> { + val size = element.getListParams()?.tagList?.size ?: 0 + list.add(InlayInfo("$size ${if (size == 1) "child" else "children"}", element.textRange.startOffset + 1)) + } + is NbttByteArray -> { + val size = element.getByteParams()?.byteList?.size ?: 0 + list.add(InlayInfo( + "$size ${if (size == 1) "child" else "children"}", element.node.getChildren(null)[1].textRange.startOffset + 1 + )) + } + is NbttIntArray -> { + val size = element.getIntParams()?.intList?.size ?: 0 + list.add(InlayInfo( + "$size ${if (size == 1) "child" else "children"}", element.node.getChildren(null)[1].textRange.startOffset + 1 + )) + } } return list } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/ProjectConfiguration.kt b/src/main/kotlin/com/demonwav/mcdev/platform/ProjectConfiguration.kt index e317fcd9d..abd92f2a1 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/ProjectConfiguration.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/ProjectConfiguration.kt @@ -41,7 +41,7 @@ abstract class ProjectConfiguration { authors.addAll(commaSplit(string)) } - fun hasDescription() = !description.isNullOrBlank() + fun hasDescription() = description.isNotBlank() protected fun commaSplit(string: String) = string.trim().replace("[\\[\\]]".toRegex(), "").split("\\s*,\\s*".toRegex()).toTypedArray() @@ -62,10 +62,10 @@ abstract class ProjectConfiguration { for (i in 0 until (files.size - 1)) { val s = files[i] val temp = movingFile.findChild(s) - if (temp != null && temp.isDirectory) { - movingFile = temp + movingFile = if (temp != null && temp.isDirectory) { + temp } else { - movingFile = movingFile.createChildDirectory(this, s) + movingFile.createChildDirectory(this, s) } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitModule.kt b/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitModule.kt index 549bd9a2b..7cc160988 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitModule.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitModule.kt @@ -116,9 +116,7 @@ class BukkitModule> constructor(facet: MinecraftFacet, val annotation = method.modifierList.findAnnotation(BukkitConstants.HANDLER_ANNOTATION) ?: return null // We are in an event method - val annotationMemberValue = annotation.findAttributeValue("ignoreCancelled") as? PsiLiteralExpression ?: return null - - val value = annotationMemberValue + val value = annotation.findAttributeValue("ignoreCancelled") as? PsiLiteralExpression ?: return null if (value.value !is Boolean) { return null } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitProjectConfiguration.kt b/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitProjectConfiguration.kt index 7f08343d2..7f09a4a20 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitProjectConfiguration.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/bukkit/BukkitProjectConfiguration.kt @@ -28,7 +28,7 @@ class BukkitProjectConfiguration : ProjectConfiguration() { var prefix = "" var minecraftVersion = "" - fun hasPrefix() = !prefix.isNullOrBlank() + fun hasPrefix() = prefix.isNotBlank() fun hasLoadBefore() = listContainsAtLeastOne(loadBefore) fun setLoadBefore(string: String) { diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/forge/ForgeModule.kt b/src/main/kotlin/com/demonwav/mcdev/platform/forge/ForgeModule.kt index d4ed04fc4..4a71be446 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/forge/ForgeModule.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/forge/ForgeModule.kt @@ -136,7 +136,7 @@ class ForgeModule internal constructor(facet: MinecraftFacet) : AbstractModule(f val psiClass = element.parent as PsiClass val modifierList = psiClass.modifierList - return modifierList != null && modifierList.findAnnotation(ForgeConstants.MOD_ANNOTATION) != null + return modifierList?.findAnnotation(ForgeConstants.MOD_ANNOTATION) != null } override fun checkUselessCancelCheck(expression: PsiMethodCallExpression) = null diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/forge/version/ForgeVersion.kt b/src/main/kotlin/com/demonwav/mcdev/platform/forge/version/ForgeVersion.kt index a8a715961..7bfd91360 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/forge/version/ForgeVersion.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/forge/version/ForgeVersion.kt @@ -10,8 +10,8 @@ package com.demonwav.mcdev.platform.forge.version -import com.demonwav.mcdev.util.gson import com.demonwav.mcdev.util.SemanticVersion +import com.demonwav.mcdev.util.gson import com.demonwav.mcdev.util.sortVersions import java.io.IOException import java.net.URL @@ -47,9 +47,8 @@ class ForgeVersion private constructor(private val map: Map<*, *>) { fun getForgeVersions(version: String): List { val list = ArrayList() val numbers = map["number"] as? Map<*, *> - numbers?.forEach { _, v -> - if (v is Map<*, *>) { - val number = v + numbers?.forEach { _, number -> + if (number is Map<*, *>) { val currentVersion = number["mcversion"] as? String if (currentVersion == version) { @@ -70,10 +69,10 @@ class ForgeVersion private constructor(private val map: Map<*, *>) { val mcVersion = number["mcversion"] as? String ?: return null val finalVersion = number["version"] as? String ?: return null - if (branch == null) { - return "$mcVersion-$finalVersion" + return if (branch == null) { + "$mcVersion-$finalVersion" } else { - return "$mcVersion-$finalVersion-$branch" + "$mcVersion-$finalVersion-$branch" } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/FindSrgMappingAction.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/FindSrgMappingAction.kt index 3a90eded8..4e4404d0d 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/FindSrgMappingAction.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/FindSrgMappingAction.kt @@ -56,20 +56,21 @@ class FindSrgMappingAction : AnAction() { parent = parent.resolve() } - if (parent is PsiField) { - val srg = srgMap.findSrgField(parent) ?: return@done showBalloon("No SRG name found", e) - - showSuccessBalloon(data.editor, data.element, srg.name) - } else if (parent is PsiMethod) { - val srg = srgMap.findSrgMethod(parent) ?: return@done showBalloon("No SRG name found", e) - - showSuccessBalloon(data.editor, data.element, srg.name + srg.descriptor) - } else if (parent is PsiClass) { - val classMcpToSrg = srgMap.findSrgClass(parent) ?: return@done showBalloon("No SRG name found", e) - - showSuccessBalloon(data.editor, data.element, classMcpToSrg) - } else { - showBalloon("Not a valid element", e) + when (parent) { + is PsiField -> { + val srg = srgMap.findSrgField(parent) ?: return@done showBalloon("No SRG name found", e) + showSuccessBalloon(data.editor, data.element, srg.name) + } + is PsiMethod -> { + val srg = srgMap.findSrgMethod(parent) ?: return@done showBalloon("No SRG name found", e) + showSuccessBalloon(data.editor, data.element, srg.name + srg.descriptor) + } + is PsiClass -> { + val classMcpToSrg = srgMap.findSrgClass(parent) ?: return@done showBalloon("No SRG name found", e) + showSuccessBalloon(data.editor, data.element, classMcpToSrg) + } + else -> + showBalloon("Not a valid element", e) } } ?: showBalloon("No mappings found", e) } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/GotoAtEntryAction.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/GotoAtEntryAction.kt index af5dd2772..af2c0ef08 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/GotoAtEntryAction.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/actions/GotoAtEntryAction.kt @@ -55,16 +55,17 @@ class GotoAtEntryAction : AnAction() { } } - if (parent is PsiField) { - val reference = srgMap.findSrgField(parent) ?: return@done showBalloon(e) - - searchForText(mcpModule, e, data, reference.name) - } else if (parent is PsiMethod) { - val reference = srgMap.findSrgMethod(parent) ?: return@done showBalloon(e) - - searchForText(mcpModule, e, data, reference.name + reference.descriptor) - } else { - showBalloon(e) + when (parent) { + is PsiField -> { + val reference = srgMap.findSrgField(parent) ?: return@done showBalloon(e) + searchForText(mcpModule, e, data, reference.name) + } + is PsiMethod -> { + val reference = srgMap.findSrgMethod(parent) ?: return@done showBalloon(e) + searchForText(mcpModule, e, data, reference.name + reference.descriptor) + } + else -> + showBalloon(e) } } ?: showBalloon(e) } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtAnnotator.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtAnnotator.kt index fa75912e6..8ff6d524f 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtAnnotator.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtAnnotator.kt @@ -55,14 +55,16 @@ class AtAnnotator : Annotator { } // We need to check the srg map, or it can't be resolved (and no underline) - if (member is AtFieldName) { - srgMap.getMcpField(reference)?.resolveMember(element.project) ?: return - underline(member, holder) - } else if (member is AtFunction) { - srgMap.getMcpMethod(reference)?.resolveMember(element.project) ?: return - underline(member.funcName, holder) - } else { - return + when (member) { + is AtFieldName -> { + srgMap.getMcpField(reference)?.resolveMember(element.project) ?: return + underline(member, holder) + } + is AtFunction -> { + srgMap.getMcpMethod(reference)?.resolveMember(element.project) ?: return + underline(member.funcName, holder) + } + else -> return } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtGotoDeclarationHandler.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtGotoDeclarationHandler.kt index 0707073ca..6b4151571 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtGotoDeclarationHandler.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtGotoDeclarationHandler.kt @@ -43,46 +43,51 @@ class AtGotoDeclarationHandler : GotoDeclarationHandler { val srgMap = mcpModule.srgManager?.srgMapNow ?: return null - if (sourceElement.node.treeParent.elementType === AtTypes.CLASS_NAME) { - val className = sourceElement.parent as AtClassName - val classSrgToMcp = srgMap.mapToMcpClass(className.classNameText) - val psiClass = findQualifiedClass(sourceElement.project, classSrgToMcp) ?: return null - return arrayOf(psiClass) - } else if (sourceElement.node.treeParent.elementType === AtTypes.FUNC_NAME) { - val funcName = sourceElement.parent as AtFuncName - val function = funcName.parent as AtFunction - val entry = function.parent as AtEntry + return when { + sourceElement.node.treeParent.elementType === AtTypes.CLASS_NAME -> { + val className = sourceElement.parent as AtClassName + val classSrgToMcp = srgMap.mapToMcpClass(className.classNameText) + val psiClass = findQualifiedClass(sourceElement.project, classSrgToMcp) ?: return null + arrayOf(psiClass) + } + sourceElement.node.treeParent.elementType === AtTypes.FUNC_NAME -> { + val funcName = sourceElement.parent as AtFuncName + val function = funcName.parent as AtFunction + val entry = function.parent as AtEntry - val reference = srgMap.mapToMcpMethod(AtMemberReference.get(entry, function) ?: return null) - val member = reference.resolveMember(sourceElement.project) ?: return null - return arrayOf(member) - } else if (sourceElement.node.treeParent.elementType === AtTypes.FIELD_NAME) { - val fieldName = sourceElement.parent as AtFieldName - val entry = fieldName.parent as AtEntry + val reference = srgMap.mapToMcpMethod(AtMemberReference.get(entry, function) ?: return null) + val member = reference.resolveMember(sourceElement.project) ?: return null + arrayOf(member) + } + sourceElement.node.treeParent.elementType === AtTypes.FIELD_NAME -> { + val fieldName = sourceElement.parent as AtFieldName + val entry = fieldName.parent as AtEntry - val reference = srgMap.mapToMcpField(AtMemberReference.get(entry, fieldName) ?: return null) - val member = reference.resolveMember(sourceElement.project) ?: return null - return arrayOf(member) - } else if (sourceElement.node.elementType === AtTypes.CLASS_VALUE) { - val className = srgMap.mapToMcpClass(parseClassDescriptor(sourceElement.text)) - val psiClass = findQualifiedClass(sourceElement.project, className) ?: return null - return arrayOf(psiClass) - } else if (sourceElement.node.elementType === AtTypes.PRIMITIVE) { - val text = sourceElement.text - if (text.length != 1) { - return null + val reference = srgMap.mapToMcpField(AtMemberReference.get(entry, fieldName) ?: return null) + val member = reference.resolveMember(sourceElement.project) ?: return null + arrayOf(member) + } + sourceElement.node.elementType === AtTypes.CLASS_VALUE -> { + val className = srgMap.mapToMcpClass(parseClassDescriptor(sourceElement.text)) + val psiClass = findQualifiedClass(sourceElement.project, className) ?: return null + arrayOf(psiClass) } + sourceElement.node.elementType === AtTypes.PRIMITIVE -> { + val text = sourceElement.text + if (text.length != 1) { + return null + } - val type = getPrimitiveType(text[0]) ?: return null + val type = getPrimitiveType(text[0]) ?: return null - val boxedType = type.boxedTypeName ?: return null + val boxedType = type.boxedTypeName ?: return null - val psiClass = JavaPsiFacade.getInstance(sourceElement.project).findClass(boxedType, - GlobalSearchScope.allScope(sourceElement.project)) ?: return null - return arrayOf(psiClass) + val psiClass = JavaPsiFacade.getInstance(sourceElement.project).findClass(boxedType, + GlobalSearchScope.allScope(sourceElement.project)) ?: return null + arrayOf(psiClass) + } + else -> null } - - return null } override fun getActionText(context: DataContext) = null diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtUsageInspection.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtUsageInspection.kt index 3b030362b..47e57a2b0 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtUsageInspection.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/AtUsageInspection.kt @@ -45,12 +45,13 @@ class AtUsageInspection : LocalInspectionTool() { val member = element.function ?: element.fieldName ?: return val reference = AtMemberReference.get(element, member) ?: return - val psi = if (member is AtFunction) { - reference.resolveMember(element.project) ?: srgMap.getMcpMethod(reference)?.resolveMember(element.project) ?: return - } else if (member is AtFieldName) { - reference.resolveMember(element.project) ?: srgMap.getMcpField(reference)?.resolveMember(element.project) ?: return - } else { - return + val psi = when (member) { + is AtFunction -> + reference.resolveMember(element.project) ?: srgMap.getMcpMethod(reference)?.resolveMember(element.project) ?: return + is AtFieldName -> + reference.resolveMember(element.project) ?: srgMap.getMcpField(reference)?.resolveMember(element.project) ?: return + else -> + return } val query = ReferencesSearch.search(psi, GlobalSearchScope.projectScope(element.project)) diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/completion/AtCompletionContributor.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/completion/AtCompletionContributor.kt index 01b0b1c81..6992ec665 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/completion/AtCompletionContributor.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/completion/AtCompletionContributor.kt @@ -67,12 +67,10 @@ class AtCompletionContributor : CompletionContributor() { val text = parent.text.let { it.substring(0, it.length - intellijPlz) } - if (AFTER_KEYWORD.accepts(parent)) { - handleAtClassName(text, parent, result) - } else if (AFTER_CLASS_NAME.accepts(parent)) { - handleAtName(text, parent, result) - } else if (AFTER_NEWLINE.accepts(parent)) { - handleNewLine(text, result) + when { + AFTER_KEYWORD.accepts(parent) -> handleAtClassName(text, parent, result) + AFTER_CLASS_NAME.accepts(parent) -> handleAtName(text, parent, result) + AFTER_NEWLINE.accepts(parent) -> handleNewLine(text, result) } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/psi/mixins/AtEntryMixin.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/psi/mixins/AtEntryMixin.kt index 91fdcb43c..be21c2986 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/psi/mixins/AtEntryMixin.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/at/psi/mixins/AtEntryMixin.kt @@ -35,14 +35,11 @@ interface AtEntryMixin : AtElement { fun replaceMember(element: AtElement) { // One of these must be true - if (fieldName != null) { - fieldName!!.replace(element) - } else if (function != null) { - function!!.replace(element) - } else if (asterisk != null) { - asterisk!!.replace(element) - } else { - addAfter(className, element) + when { + fieldName != null -> fieldName!!.replace(element) + function != null -> function!!.replace(element) + asterisk != null -> asterisk!!.replace(element) + else -> addAfter(className, element) } } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/version/McpVersionEntry.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/version/McpVersionEntry.kt index 350c510a5..6c620122c 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mcp/version/McpVersionEntry.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mcp/version/McpVersionEntry.kt @@ -13,10 +13,10 @@ package com.demonwav.mcdev.platform.mcp.version class McpVersionEntry(val text: String, val isRed: Boolean = false) { override fun toString(): String { - if (isRed) { - return RED_START + text + RED_END + return if (isRed) { + RED_START + text + RED_END } else { - return text + text } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/mixin/reference/target/TargetReference.kt b/src/main/kotlin/com/demonwav/mcdev/platform/mixin/reference/target/TargetReference.kt index 7c3c169a7..017e692c0 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/mixin/reference/target/TargetReference.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/mixin/reference/target/TargetReference.kt @@ -144,7 +144,7 @@ object TargetReference : PolyReferenceResolver(), MixinReference { protected abstract fun createLookup(targetClass: PsiClass, m: T, owner: PsiClass): LookupElementBuilder - override open fun resolveTarget(context: PsiElement): PsiElement? { + override fun resolveTarget(context: PsiElement): PsiElement? { val value = context.constantStringValue ?: return null return MixinMemberReference.parse(value)?.resolveMember(context.project, context.resolveScope) } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeModule.kt b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeModule.kt index 5309f8769..ab2d5d905 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeModule.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeModule.kt @@ -29,7 +29,6 @@ import com.intellij.psi.PsiIdentifier import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethodCallExpression import com.intellij.psi.PsiType -import com.intellij.psi.impl.compiled.ClsMethodImpl import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.annotations.Contract @@ -97,7 +96,7 @@ class SpongeModule(facet: MinecraftFacet) : AbstractModule(facet) { val psiClass = element.parent as PsiClass val modifierList = psiClass.modifierList - return modifierList != null && modifierList.findAnnotation(SpongeConstants.PLUGIN_ANNOTATION) != null + return modifierList?.findAnnotation(SpongeConstants.PLUGIN_ANNOTATION) != null } override fun checkUselessCancelCheck(expression: PsiMethodCallExpression): IsCancelled? { @@ -106,9 +105,8 @@ class SpongeModule(facet: MinecraftFacet) : AbstractModule(facet) { // Make sure this is an event listener method method.modifierList.findAnnotation(SpongeConstants.LISTENER_ANNOTATION) ?: return null - var isCancelled = false val annotation = method.modifierList.findAnnotation(SpongeConstants.IS_CANCELLED_ANNOTATION) - if (annotation != null) { + val isCancelled = if (annotation != null) { val value = annotation.findAttributeValue("value") ?: return null val text = value.text @@ -119,38 +117,27 @@ class SpongeModule(facet: MinecraftFacet) : AbstractModule(facet) { val sub = text.substring(text.lastIndexOf('.') + 1) when (sub) { - "TRUE" -> isCancelled = true - "FALSE" -> isCancelled = false + "TRUE" -> true + "FALSE" -> false else -> return null } + } else { + false } val methodExpression = expression.methodExpression - val qualifierExpression = methodExpression.qualifierExpression - val resolve = methodExpression.resolve() - - if (qualifierExpression == null) { - return null - } - if (resolve == null) { - return null - } - + val qualifierExpression = methodExpression.qualifierExpression ?: return null if (standardSkip(method, qualifierExpression)) { return null } - val content = resolve.context as? PsiClass ?: return null - - if (!content.extendsOrImplements(SpongeConstants.CANCELLABLE)) { - return null - } - - if (resolve !is ClsMethodImpl) { + val resolve = methodExpression.resolve() as? PsiMethod ?: return null + if (resolve.name != SpongeConstants.EVENT_ISCANCELLED_METHOD_NAME) { return null } - if (resolve.name != SpongeConstants.EVENT_ISCANCELLED_METHOD_NAME) { + val content = resolve.containingClass ?: return null + if (!content.extendsOrImplements(SpongeConstants.CANCELLABLE)) { return null } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeProjectConfiguration.kt b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeProjectConfiguration.kt index 434314648..3ac01027a 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeProjectConfiguration.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeProjectConfiguration.kt @@ -96,20 +96,20 @@ fun writeMainSpongeClass( annotationString + ",\nversion = ${escape(buildSystem.version)}" } - if (!description.isNullOrEmpty()) { + if (description.isNotEmpty()) { annotationString + ",\ndescription = ${escape(description)}" } - if (!website.isNullOrEmpty()) { + if (website.isNotEmpty()) { annotationString + ",\nurl = ${escape(website)}" } if (hasAuthors) { - annotationString + ",\nauthors = {\n${authors.map(::escape).joinToString(",\n")}\n}" + annotationString + ",\nauthors = {\n${authors.joinToString(",\n", transform = ::escape)}\n}" } if (hasDependencies) { - annotationString + ",\ndependencies = {\n${dependencies.map { "@Dependency(id = ${escape(it)})" }.joinToString(",\n")}\n}" + annotationString + ",\ndependencies = {\n${dependencies.joinToString(",\n") { "@Dependency(id = ${escape(it)})" }}\n}" } annotationString + "\n)" diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeVersion.kt b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeVersion.kt index 5f487624d..faf6909a6 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeVersion.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/SpongeVersion.kt @@ -58,7 +58,7 @@ data class SpongeVersion(var versions: LinkedHashMap, var select "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2" ) val text = connection.getInputStream().use { it.reader().use { it.readText() } } - return gson.fromJson(text) + return gson.fromJson(text) } } } diff --git a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/color/SpongeColorLineMarkerProvider.kt b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/color/SpongeColorLineMarkerProvider.kt index ca8056878..4567179f5 100644 --- a/src/main/kotlin/com/demonwav/mcdev/platform/sponge/color/SpongeColorLineMarkerProvider.kt +++ b/src/main/kotlin/com/demonwav/mcdev/platform/sponge/color/SpongeColorLineMarkerProvider.kt @@ -54,12 +54,10 @@ class SpongeColorLineMarkerProvider : LineMarkerProvider { val c = ColorChooser.chooseColor(editor.component, "Choose Color", color, false) if (c != null) { - if (workElement is PsiLiteralExpression) { - workElement.setColor(c.rgb and 0xFFFFFF) - } else if (workElement is PsiExpressionList) { - workElement.setColor(c.red, c.green, c.blue) - } else if (workElement is PsiNewExpression) { - (workElement.getNode().findChildByType(JavaElementType.EXPRESSION_LIST) as PsiExpressionList?) + when (workElement) { + is PsiLiteralExpression -> workElement.setColor(c.rgb and 0xFFFFFF) + is PsiExpressionList -> workElement.setColor(c.red, c.green, c.blue) + is PsiNewExpression -> (workElement.getNode().findChildByType(JavaElementType.EXPRESSION_LIST) as PsiExpressionList?) ?.setColor(c.red, c.green, c.blue) } } diff --git a/src/main/kotlin/com/demonwav/mcdev/update/ConfigurePluginUpdatesDialog.kt b/src/main/kotlin/com/demonwav/mcdev/update/ConfigurePluginUpdatesDialog.kt index 18532305c..cb4066864 100644 --- a/src/main/kotlin/com/demonwav/mcdev/update/ConfigurePluginUpdatesDialog.kt +++ b/src/main/kotlin/com/demonwav/mcdev/update/ConfigurePluginUpdatesDialog.kt @@ -37,15 +37,16 @@ class ConfigurePluginUpdatesDialog : DialogWrapper(true) { PluginUpdater.runUpdateCheck { pluginUpdateStatus -> form.updateCheckInProgressIcon.suspend() - if (pluginUpdateStatus is PluginUpdateStatus.LatestVersionInstalled) { - form.updateStatusLabel.text = "You have the latest version of the plugin (${PluginUtil.pluginVersion}) installed." - } else if (pluginUpdateStatus is PluginUpdateStatus.Update) { - update = pluginUpdateStatus - form.installButton.isVisible = true - form.updateStatusLabel.text = "A new version (${pluginUpdateStatus.pluginDescriptor.version}) is available" - } else { - // CheckFailed - form.updateStatusLabel.text = "Update check failed: " + (pluginUpdateStatus as PluginUpdateStatus.CheckFailed).message + form.updateStatusLabel.text = when (pluginUpdateStatus) { + is PluginUpdateStatus.LatestVersionInstalled -> + "You have the latest version of the plugin (${PluginUtil.pluginVersion}) installed." + is PluginUpdateStatus.Update -> { + update = pluginUpdateStatus + form.installButton.isVisible = true + "A new version (${pluginUpdateStatus.pluginDescriptor.version}) is available" + } + else -> // CheckFailed + "Update check failed: " + (pluginUpdateStatus as PluginUpdateStatus.CheckFailed).message } false diff --git a/src/main/kotlin/com/demonwav/mcdev/update/PluginUpdater.kt b/src/main/kotlin/com/demonwav/mcdev/update/PluginUpdater.kt index 9d8530766..84bf0db7e 100644 --- a/src/main/kotlin/com/demonwav/mcdev/update/PluginUpdater.kt +++ b/src/main/kotlin/com/demonwav/mcdev/update/PluginUpdater.kt @@ -93,9 +93,8 @@ object PluginUpdater { } private fun checkUpdatesInCustomRepo(host: String): PluginUpdateStatus { - val plugins: List - try { - plugins = RepositoryHelper.loadPlugins(host, null) + val plugins = try { + RepositoryHelper.loadPlugins(host, null) } catch (e: IOException) { return PluginUpdateStatus.CheckFailed("Checking custom plugin repository $host failed") } diff --git a/src/main/kotlin/com/demonwav/mcdev/util/SemanticVersion.kt b/src/main/kotlin/com/demonwav/mcdev/util/SemanticVersion.kt index 3eeb647c9..b72471110 100644 --- a/src/main/kotlin/com/demonwav/mcdev/util/SemanticVersion.kt +++ b/src/main/kotlin/com/demonwav/mcdev/util/SemanticVersion.kt @@ -19,7 +19,7 @@ import com.demonwav.mcdev.util.SemanticVersion.Companion.VersionPart.ReleasePart * to the version ranking with decreasing priority from left to right. */ class SemanticVersion(val parts: List) : Comparable { - val versionString = parts.map { it.versionString }.joinToString("."); + val versionString = parts.joinToString(".") { it.versionString } override fun compareTo(other: SemanticVersion): Int { // Zipping limits the compared parts to the shorter version, then we perform a component-wise comparison diff --git a/src/main/kotlin/com/demonwav/mcdev/util/Sorting.kt b/src/main/kotlin/com/demonwav/mcdev/util/Sorting.kt index e995b0185..7548900c8 100644 --- a/src/main/kotlin/com/demonwav/mcdev/util/Sorting.kt +++ b/src/main/kotlin/com/demonwav/mcdev/util/Sorting.kt @@ -18,7 +18,7 @@ import java.util.stream.Stream val LEXICOGRAPHICAL_ORDER: Comparator = Comparator { one, two -> val length = Math.min(one.size, two.size) - for (i in 0..length - 1) { + for (i in 0 until length) { val first = one[i] val second = two[i] diff --git a/src/test/kotlin/com/demonwav/mcdev/platform/mcp/at/AtLexerTest.kt b/src/test/kotlin/com/demonwav/mcdev/platform/mcp/at/AtLexerTest.kt index 10c6c927e..d9cc41645 100644 --- a/src/test/kotlin/com/demonwav/mcdev/platform/mcp/at/AtLexerTest.kt +++ b/src/test/kotlin/com/demonwav/mcdev/platform/mcp/at/AtLexerTest.kt @@ -31,7 +31,7 @@ class AtLexerTest : LexerTestCase() { var text = "" try { val fileText = FileUtil.loadFile(File(fileName)) - text = StringUtil.convertLineSeparators(if (shouldTrim()) fileText.trim { it <= ' ' } else fileText) + text = StringUtil.convertLineSeparators(if (shouldTrim()) fileText.trim() else fileText) } catch (e: IOException) { fail("can't load file " + fileName + ": " + e.message) }