Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/main/kotlin/com/demonwav/mcdev/buildsystem/BuildSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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<ProjectConfiguration>, indicator: ProgressIndicator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object AnonymousFeedback {

data = connection.inputStream.reader().use(InputStreamReader::readCharSequence).toString()

response = gson.fromJson<List<Map<*, *>>>(data)
response = gson.fromJson(data)
list.addAll(response)

link = connection.getHeaderField("Link")
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 <T> doIfGood(method: PsiMethod, action: (AbstractModule) -> T): T? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.demonwav.mcdev.platform.MinecraftFacetEditorTab">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.demonwav.mcdev.facet.MinecraftFacetEditorTab">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="14" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="10" vgap="10">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions src/main/kotlin/com/demonwav/mcdev/nbt/Nbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import java.util.zip.ZipException
object Nbt {

private fun getActualInputStream(stream: InputStream): Pair<DataInputStream, Boolean> {
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
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@ import com.intellij.psi.PsiElement
class NbttParameterNameHints : InlayParameterHintsProvider {
override fun getParameterHints(element: PsiElement): MutableList<InlayInfo> {
val list = mutableListOf<InlayInfo>()
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ class BukkitModule<T : AbstractModuleType<*>> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading