-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Apply field rules to getter and setter methods (#1044)
- Loading branch information
Showing
13 changed files
with
330 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 30 additions & 7 deletions
37
idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/MyStringRuleMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,46 @@ | ||
package com.itangcent.idea.plugin.rule | ||
|
||
import com.itangcent.common.utils.notNullOrEmpty | ||
import com.itangcent.intellij.config.rule.RuleChain | ||
import com.itangcent.intellij.config.rule.RuleMode | ||
import com.itangcent.intellij.config.rule.asSequence | ||
import kotlin.reflect.KClass | ||
|
||
enum class MyStringRuleMode : RuleMode<String> { | ||
LIST { | ||
override fun compute(rules: RuleChain<String>): Any? { | ||
return rules | ||
.asSequence() | ||
.map { it.compute() } | ||
.filter { it.notNullOrEmpty() } | ||
override fun compute(rules: RuleChain<String>): Any { | ||
return (rules as RuleChain<Any>) | ||
.mapNotNull { it() } | ||
.flatMap { | ||
it.flatten() | ||
} | ||
.mapNotNull { it as? String } | ||
.filter { it.isNotEmpty() } | ||
.toList() | ||
} | ||
}; | ||
|
||
override fun targetType(): KClass<String> { | ||
return String::class | ||
} | ||
|
||
companion object { | ||
private fun Any?.flatten(): List<Any?> { | ||
return when (this) { | ||
null -> { | ||
emptyList() | ||
} | ||
|
||
is Array<*> -> { | ||
this.toList().flatten() | ||
} | ||
|
||
is Collection<*> -> { | ||
this.flatMap { it.flatten() } | ||
} | ||
|
||
else -> { | ||
listOf(this) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.