fix: UI Bug

This commit is contained in:
Kagura 2024-11-01 09:14:07 +08:00
parent 3460f3133d
commit 0e461e1419
3 changed files with 61 additions and 35 deletions

View file

@ -4,6 +4,9 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="PWA">
<option name="wasEnabledAtLeastOnce" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>

View file

@ -21,6 +21,10 @@ import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import core.* import core.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import ui.TextfieldWithLineNumber import ui.TextfieldWithLineNumber
import utils.* import utils.*
@ -47,39 +51,43 @@ fun App() {
}) { }) {
AlertDialog( AlertDialog(
title = { title = {
Text( Column(modifier = Modifier.fillMaxWidth(),
text = when (page) { horizontalAlignment = Alignment.CenterHorizontally) {
0 -> "函数定义的变量" Text(
1 -> "函数内每条语句的定义和使用" text = when (page) {
2 -> "函数内每个变量 def-use 链" 0 -> "函数定义的变量"
3 -> "函数间每个变量 def-use 链" 1 -> "函数内每条语句的定义和使用"
else -> "出错了" 2 -> "函数内每个变量 def-use 链"
}, 3 -> "函数间每个变量 def-use 链"
color = Color.Black, else -> "出错了"
fontWeight = FontWeight.Bold, },
fontSize = 24.sp, color = Color.Black,
textAlign = TextAlign.Center, fontWeight = FontWeight.Bold,
modifier = Modifier.padding(top = 10.dp) fontSize = 24.sp,
) textAlign = TextAlign.Center
)
}
}, },
text = { text = {
Text( Box(modifier = Modifier.fillMaxWidth()
text = when (page) { .fillMaxHeight(0.8f)) {
0 -> defineList Text(
1 -> useList text = when (page) {
2 -> traceTree 0 -> defineList
3 -> funcTraceTree 1 -> useList
else -> "出错了(ง •̀_•́)ง" 2 -> traceTree
}, 3 -> funcTraceTree
modifier = Modifier else -> "出错了(ง •̀_•́)ง"
.fillMaxSize() },
.verticalScroll(rememberScrollState()) modifier = Modifier
.wrapContentHeight(), .fillMaxSize()
textAlign = TextAlign.Start, .verticalScroll(rememberScrollState()),
color = Color.Black, textAlign = TextAlign.Start,
fontSize = 18.sp, color = Color.Black,
fontFamily = FontFamily("monospace") fontSize = 18.sp,
) fontFamily = FontFamily("monospace")
)
}
}, },
onDismissRequest = { onDismissRequest = {
showResult.value = false showResult.value = false
@ -157,6 +165,7 @@ fun App() {
val def = getDefineList(sf.getDef()) val def = getDefineList(sf.getDef())
def.ifEmpty { def.ifEmpty {
"分析失败:可能输入有错误!" "分析失败:可能输入有错误!"
return@TextfieldWithLineNumber
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace().toString() e.printStackTrace().toString()
@ -166,12 +175,26 @@ fun App() {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace().toString() e.printStackTrace().toString()
} }
// 异步获取 traceTree
val relations = mutableMapOf<String, List<Relation>>() val relations = mutableMapOf<String, List<Relation>>()
val traceTreeStr = StringBuilder() val traceTreeStr = StringBuilder()
sf.functions.forEach { func -> runBlocking {
traceTreeStr.append(getTraceTreeString(func.getTraceTree().getStringRepr(),func.name)) val deferredResults = sf.functions.map { func ->
relations.putAll(parseRelation(func.name,func.getTraceTree().getStringRepr())) async(Dispatchers.Default) {
val traceStr = getTraceTreeString(func.getTraceTree().getStringRepr(), func.name)
val parsedRelations = parseRelation(func.name, func.getTraceTree().getStringRepr())
Pair(traceStr, parsedRelations)
}
}
// 等待所有协程结束
deferredResults.awaitAll().forEach { (traceStr, parsedRelations) ->
traceTreeStr.append(traceStr)
relations.putAll(parsedRelations)
}
} }
traceTree = traceTreeStr.toString() traceTree = traceTreeStr.toString()
funcTraceTree = funcTraceTree =

View file

@ -182,7 +182,7 @@ class SourceFile {
} }
/** /**
* 任务1获取使用的值的情况 * 获取使用的值的情况
* @return Map of<函数 to List<使用值的情况>> * @return Map of<函数 to List<使用值的情况>>
* @see utils.getUseList 获取要求的格式 * @see utils.getUseList 获取要求的格式
*/ */