Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: JvmClassHelper isPrimitive/isPrimitiveWrapper (#121)
- Loading branch information
Showing
10 changed files
with
705 additions
and
177 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
406 changes: 406 additions & 0 deletions
406
...ij-idea/src/test/kotlin/com/itangcent/intellij/jvm/standard/StandardJvmClassHelperTest.kt
Large diffs are not rendered by default.
Oops, something went wrong.
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
77 changes: 77 additions & 0 deletions
77
intellij-jvm/src/main/kotlin/com/itangcent/intellij/jvm/ClassMateDataStorage.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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.itangcent.intellij.jvm | ||
|
||
import com.itangcent.common.utils.safeComputeIfAbsent | ||
import kotlin.reflect.KClass | ||
|
||
object ClassMateDataStorage { | ||
|
||
private val mateData = HashMap<String, ClassMateData>() | ||
|
||
private val classWithTagCache = HashMap<String, Array<String>>() | ||
|
||
fun classWithTag(tag: String): Array<String> { | ||
return classWithTagCache.safeComputeIfAbsent(tag) { | ||
mateData.entries.filter { it.value.tags?.contains(tag) == true } | ||
.map { it.key } | ||
.toTypedArray() | ||
} ?: emptyArray() | ||
} | ||
|
||
fun hasTag(className: String, tag: String): Boolean { | ||
return mateData[className]?.tags?.contains(tag) ?: false | ||
} | ||
|
||
fun addTag(className: String, vararg tags: String) { | ||
mateDataOf(className).addTags(*tags) | ||
} | ||
|
||
fun addTag(cls: Class<*>, vararg tags: String) { | ||
addTag(cls.name, *tags) | ||
addTag(cls.simpleName, *tags) | ||
} | ||
|
||
fun addTag(cls: KClass<*>, vararg tags: String) { | ||
cls.qualifiedName?.let { addTag(it, *tags) } | ||
cls.simpleName?.let { addTag(it, *tags) } | ||
} | ||
|
||
fun setDefaultValue(className: String, defaultValue: Any) { | ||
mateDataOf(className).defaultValue = defaultValue | ||
} | ||
|
||
fun setDefaultValue(cls: Class<*>, defaultValue: Any) { | ||
setDefaultValue(cls.name, defaultValue) | ||
setDefaultValue(cls.simpleName, defaultValue) | ||
} | ||
|
||
fun setDefaultValue(cls: KClass<*>, defaultValue: Any) { | ||
cls.qualifiedName?.let { setDefaultValue(it, defaultValue) } | ||
cls.simpleName?.let { setDefaultValue(it, defaultValue) } | ||
} | ||
|
||
fun getDefaultValue(className: String): Any? { | ||
return mateData[className]?.defaultValue | ||
} | ||
|
||
private fun mateDataOf(className: String): ClassMateData { | ||
return mateData.safeComputeIfAbsent(className) { | ||
ClassMateData() | ||
}!! | ||
} | ||
|
||
class ClassMateData { | ||
|
||
var tags: Array<String>? = null | ||
|
||
var defaultValue: Any? = null | ||
|
||
@Synchronized | ||
fun addTags(vararg tags: String) { | ||
if (this.tags == null) { | ||
this.tags = arrayOf(*tags) | ||
} else { | ||
this.tags = this.tags!! + tags | ||
} | ||
} | ||
} | ||
} |
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.