Skip to content

Commit

Permalink
feat: init dt model ext
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 16, 2023
1 parent 548681a commit 08e81f6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/analysis/DtAnalysisModel.kt
@@ -0,0 +1,17 @@
package cc.unitmesh.devti.analysis

class DtClass(
val name: String,
val methods: List<DtMethod>
)

class DtMethod(
val name: String,
val returnType: String,
val parameters: List<DtParameter>
)

class DtParameter(
val name: String,
val type: String
)
32 changes: 32 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/analysis/DtModelExt.kt
@@ -0,0 +1,32 @@
package cc.unitmesh.devti.analysis

import com.intellij.psi.PsiClass
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil

fun DtClass.fromPsiClass(psiClass: PsiClass): DtClass {
val methods = psiClass.methods.map { method ->
DtMethod(
name = method.name,
returnType = method.returnType.toString(),
parameters = method.parameters.map { parameter ->
DtParameter(
name = parameter.name ?: "",
type = parameter.type.toString()
)
}
)
}
return DtClass(
name = psiClass.name ?: "",
methods = methods
)
}

fun DtClass.fromPsiFile(psiFile: PsiFile): DtClass? {
val psiClass = PsiTreeUtil.findChildrenOfType(psiFile, PsiClass::class.java)
.firstOrNull()

return psiClass?.let { fromPsiClass(it) }
}

Expand Up @@ -27,7 +27,7 @@ class DtRunConfiguration(project: Project, name: String, factory: ConfigurationF
}

override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState {
return DtRunState(environment, this, storyConfig)
return DtRunState(environment, this, storyConfig, project)
}

override fun writeExternal(element: Element) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/runconfig/DtRunState.kt
Expand Up @@ -8,11 +8,13 @@ import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.ProgramRunner
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project

class DtRunState(
val environment: ExecutionEnvironment,
private val configuration: DtRunConfiguration,
private val createStory: DevtiCreateStoryConfigure?
private val createStory: DevtiCreateStoryConfigure?,
val project: Project
) : RunProfileState {
override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult? {
log.warn(configuration.toString())
Expand Down

0 comments on commit 08e81f6

Please sign in to comment.