Skip to content

Commit f3e35b1

Browse files
committed
General clean up
1 parent 599166c commit f3e35b1

File tree

4 files changed

+37
-88
lines changed

4 files changed

+37
-88
lines changed

src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ class MinecraftFacet(module: Module, name: String, configuration: MinecraftFacet
6363

6464
fun refresh() {
6565
// Don't allow parent types with child types in auto detected set
66-
PlatformType.removeParents(configuration.state.autoDetectTypes)
66+
val allEnabled = configuration.state.run {
67+
autoDetectTypes = PlatformType.removeParents(autoDetectTypes)
6768

68-
val userEnabled = configuration.state.userChosenTypes.entries.asSequence()
69-
.filter { it.value }
70-
.map { it.key }
69+
val userEnabled = userChosenTypes.entries.asSequence()
70+
.filter { it.value }
71+
.map { it.key }
7172

72-
val autoEnabled = configuration.state.autoDetectTypes.asSequence()
73-
.filter { configuration.state.userChosenTypes[it] == null }
73+
val autoEnabled = autoDetectTypes.asSequence()
74+
.filter { userChosenTypes[it] == null }
7475

75-
val allEnabled = userEnabled + autoEnabled
76+
userEnabled + autoEnabled
77+
}
7678

7779
// Remove modules that aren't registered anymore
7880
val toBeRemoved = modules.entries.asSequence()
@@ -97,20 +99,18 @@ class MinecraftFacet(module: Module, name: String, configuration: MinecraftFacet
9799
private fun updateRoots() {
98100
roots.clear()
99101
val rootManager = ModuleRootManager.getInstance(module)
100-
for (entry in rootManager.contentEntries) {
101-
for (sourceFolder in entry.sourceFolders) {
102-
if (sourceFolder.file == null) {
103-
continue
104-
}
105102

106-
when (sourceFolder.rootType) {
107-
JavaSourceRootType.SOURCE -> roots.put(SourceType.SOURCE, sourceFolder.file)
108-
JavaSourceRootType.TEST_SOURCE -> roots.put(SourceType.TEST_SOURCE, sourceFolder.file)
109-
JavaResourceRootType.RESOURCE -> roots.put(SourceType.RESOURCE, sourceFolder.file)
110-
JavaResourceRootType.TEST_RESOURCE -> roots.put(SourceType.TEST_RESOURCE, sourceFolder.file)
103+
rootManager.contentEntries.asSequence()
104+
.flatMap { entry -> entry.sourceFolders.asSequence() }
105+
.filter { it.file == null }
106+
.forEach {
107+
when (it.rootType) {
108+
JavaSourceRootType.SOURCE -> roots.put(SourceType.SOURCE, it.file)
109+
JavaSourceRootType.TEST_SOURCE -> roots.put(SourceType.TEST_SOURCE, it.file)
110+
JavaResourceRootType.RESOURCE -> roots.put(SourceType.RESOURCE, it.file)
111+
JavaResourceRootType.TEST_RESOURCE -> roots.put(SourceType.TEST_RESOURCE, it.file)
111112
}
112113
}
113-
}
114114
}
115115

116116
private fun register(type: AbstractModuleType<*>) {

src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetConfiguration.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ class MinecraftFacetConfiguration : FacetConfiguration, PersistentStateComponent
2525
var facet: MinecraftFacet? = null
2626
private var state = MinecraftFacetConfigurationData()
2727

28-
override fun createEditorTabs(editorContext: FacetEditorContext?, validatorsManager: FacetValidatorsManager?): Array<FacetEditorTab> {
29-
return arrayOf(MinecraftFacetEditorTab(this))
30-
}
28+
override fun createEditorTabs(editorContext: FacetEditorContext?, validatorsManager: FacetValidatorsManager?) =
29+
arrayOf(MinecraftFacetEditorTab(this))
3130

3231
override fun getState() = state
3332
override fun loadState(state: MinecraftFacetConfigurationData) {

src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacetType.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class MinecraftFacetType : FacetType<MinecraftFacet, MinecraftFacetConfiguration
2222
override fun createFacet(module: Module,
2323
name: String,
2424
configuration: MinecraftFacetConfiguration,
25-
underlyingFacet: Facet<*>?): MinecraftFacet {
26-
return MinecraftFacet(module, name, configuration, underlyingFacet)
27-
}
25+
underlyingFacet: Facet<*>?) = MinecraftFacet(module, name, configuration, underlyingFacet)
2826

2927
override fun createDefaultConfiguration() = MinecraftFacetConfiguration()
3028
override fun isSuitableModuleType(moduleType: ModuleType<*>?) = moduleType is JavaModuleType

src/main/kotlin/com/demonwav/mcdev/platform/PlatformType.kt

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -57,71 +57,23 @@ enum class PlatformType(
5757

5858
companion object {
5959

60-
/**
61-
* This is legacy code which used arrays, and needed to switch to Sets...
62-
* Would certainly be better to just use Sets for everything, rather than this array business
63-
* but I'm too lazy right now. This is not hot code.
64-
*/
65-
fun removeParents(types: MutableSet<PlatformType>) {
66-
val typesArray = types.toTypedArray()
67-
val result = arrayOfNulls<PlatformType>(types.size)
60+
fun removeParents(types: MutableSet<PlatformType>) =
61+
types.filter { type -> type.children.isEmpty() || !types.any { type.children.contains(it) }}.toHashSet()
6862

69-
var count = 0
70-
for (i in typesArray.indices) {
71-
// This has no children, so add it by default and continue to the next
72-
if (typesArray[i].children.isEmpty()) {
73-
result[count++] = typesArray[i]
74-
continue
75-
}
76-
77-
// This has children, so check if it's children are also in the array
78-
var foundChild = false
79-
80-
for (j in typesArray.indices) {
81-
for (k in typesArray[i].children.indices) {
82-
if (typesArray[j] == typesArray[i].children[k]) {
83-
// It has a child in the array, stop checking
84-
foundChild = true
85-
break
86-
}
87-
}
88-
// We found a child, so don't bother checking any more
89-
if (foundChild) {
90-
break
91-
}
92-
}
93-
94-
// We found a child, we won't add this type to the result
95-
if (foundChild) {
96-
continue
97-
}
98-
99-
// This type has children, but none of them are in the array, so add it to the result
100-
result[count++] = typesArray[i]
101-
}
102-
103-
types.clear()
104-
for (i in 0 until count) {
105-
types.add(result[i]!!)
106-
}
107-
}
108-
109-
fun fromLibraryKind(kind: LibraryKind): PlatformType? {
110-
return when (kind) {
111-
BUKKIT_LIBRARY_KIND -> BUKKIT
112-
SPIGOT_LIBRARY_KIND -> SPIGOT
113-
PAPER_LIBRARY_KIND -> PAPER
114-
SPONGE_LIBRARY_KIND -> SPONGE
115-
FORGE_LIBRARY_KIND -> FORGE
116-
LITELOADER_LIBRARY_KIND -> LITELOADER
117-
MCP_LIBRARY_KIND -> MCP
118-
MIXIN_LIBRARY_KIND -> MIXIN
119-
BUNGEECORD_LIBRARY_KIND -> BUNGEECORD
120-
WATERFALL_LIBRARY_KIND -> WATERFALL
121-
CANARY_LIBRARY_KIND -> CANARY
122-
NEPTUNE_LIBRARY_KIND -> NEPTUNE
123-
else -> null
124-
}
63+
fun fromLibraryKind(kind: LibraryKind) = when (kind) {
64+
BUKKIT_LIBRARY_KIND -> BUKKIT
65+
SPIGOT_LIBRARY_KIND -> SPIGOT
66+
PAPER_LIBRARY_KIND -> PAPER
67+
SPONGE_LIBRARY_KIND -> SPONGE
68+
FORGE_LIBRARY_KIND -> FORGE
69+
LITELOADER_LIBRARY_KIND -> LITELOADER
70+
MCP_LIBRARY_KIND -> MCP
71+
MIXIN_LIBRARY_KIND -> MIXIN
72+
BUNGEECORD_LIBRARY_KIND -> BUNGEECORD
73+
WATERFALL_LIBRARY_KIND -> WATERFALL
74+
CANARY_LIBRARY_KIND -> CANARY
75+
NEPTUNE_LIBRARY_KIND -> NEPTUNE
76+
else -> null
12577
}
12678
}
12779
}

0 commit comments

Comments
 (0)