This file contains hidden or 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
class InspectionSettings(project: Project) : Configurable { | |
private var component: InspectionComponent? = null | |
private val inspectionSettingState = project.service<InspectionSettingState>() | |
override fun createComponent(): JComponent? { | |
component = InspectionComponent(inspectionSettingState) | |
return component?.getPanel() | |
} |
This file contains hidden or 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
class InspectionComponent( | |
private val inspectionSettingState: InspectionSettingState | |
) { | |
// used to maintain the current state | |
private var parser: Parser = Parser.GSON | |
init { | |
// set the current state to the persisted state | |
parser = inspectionSettingState.state.parser |
This file contains hidden or 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
<extensions defaultExtensionNs="com.intellij"> | |
<!-- other configurations --> | |
<projectService | |
serviceImplementation="com.ruben.codespector.settings.InspectionSettingState" /> | |
</extensions> |
This file contains hidden or 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
@State( | |
name = "com.ruben.codespector.settings.InspectionSettingState", | |
storages = [Storage("Codespector.xml")] | |
) | |
class InspectionSettingState : | |
PersistentStateComponent<InspectionSettingState> { | |
var parser: Parser = Parser.GSON | |
override fun getState(): InspectionSettingState { |
This file contains hidden or 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
class InspectionComponent { | |
fun getPanel(): JPanel = panel { | |
titledRow("Configure Plugin Settings For Your Project") { | |
row("Select JSON parser:") { | |
buttonGroup { | |
row { | |
radioButton( | |
text = "Gson" | |
) |
This file contains hidden or 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
<extensions defaultExtensionNs="com.intellij"> | |
<!-- other configurations --> | |
<projectConfigurable | |
parentId="editor" | |
displayName="Codespector Settings" | |
nonDefaultProject="true" | |
instance="com.ruben.codespector.settings.InspectionSettings" | |
id="com.ruben.codespector.settings.InspectionSettings" /> |
This file contains hidden or 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
////////////////////////////////////////////// | |
// Activity code | |
////////////////////////////////////////////// | |
val exceptionHandler = | |
Thread.UncaughtExceptionHandler { _: Thread, e: Throwable -> | |
handleUncaughtException(e) | |
} | |
private fun attachUnhandledExceptionHandler() { |
This file contains hidden or 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
class HomeViewModel : ViewModel() { | |
fun handleException() { | |
viewModelScope.launch { runCatching { doWork() } } | |
} | |
fun unhandledException() { | |
viewModelScope.launch { doWork() } | |
} |
This file contains hidden or 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
@Composable | |
fun HomeScreen(handleException: () -> Unit, unhandledException: () -> Unit) { | |
Column(modifier = Modifier.fillMaxSize()) { | |
Button( | |
modifier = Modifier.align(Alignment.CenterHorizontally), | |
onClick = handleException | |
) { Text(text = "Handle exception") } | |
Button( | |
modifier = Modifier.align(Alignment.CenterHorizontally), |
This file contains hidden or 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
// returns the param if SerializedName annotation is missing | |
fun KtClass.getMissingAnnotationParam(): KtParameter? { | |
this.getPrimaryConstructorParameterList()?.parameters?.forEach { param -> | |
if (!param.annotationEntries.any { | |
it.shortName?.asString() == "SerializedName" | |
} | |
) { | |
return param | |
} | |
} |