generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/cc/unitmesh/devti/analysis/DtAnalysisModel.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,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 | ||
) |
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,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) } | ||
} | ||
|
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