generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context): add support for annotations in ClassContext
This commit adds support for annotations in the ClassContext class. The KotlinClassContextBuilder now retrieves the annotation entries from the PsiElement and maps them to a list of strings. The ClassContext constructor is updated to include the annotations parameter. The ClassContext's format() method is also updated to include the annotations in the output. A new test case is added to verify the functionality.
- Loading branch information
Showing
4 changed files
with
71 additions
and
4 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
57 changes: 57 additions & 0 deletions
57
kotlin/src/test/kotlin/cc/unitmesh/kotlin/context/KotlinClassContextBuilderTest.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,57 @@ | ||
package cc.unitmesh.kotlin.context; | ||
|
||
import cc.unitmesh.devti.context.ClassContext | ||
import cc.unitmesh.devti.context.builder.ClassContextBuilder | ||
import cc.unitmesh.idea.context.JavaContextCollection | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiNameIdentifierOwner | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import com.intellij.testFramework.LightPlatformTestCase | ||
import junit.framework.TestCase | ||
import org.jetbrains.annotations.Nullable | ||
import org.jetbrains.kotlin.psi.KtClassOrObject | ||
import org.jetbrains.kotlin.psi.KtFunction | ||
import org.jetbrains.kotlin.psi.KtParameter | ||
import org.jetbrains.kotlin.psi.KtPsiFactory | ||
|
||
class KotlinClassContextBuilderTest: LightPlatformTestCase() { | ||
|
||
fun testShould_return_functions_from_kt_class_or_object() { | ||
val code = """ | ||
package cc.unitmesh.untitled.demo.controller | ||
import org.springframework.web.bind.annotation.* | ||
@RestController | ||
@RequestMapping("/user") | ||
class UserController() { | ||
@GetMapping | ||
fun getUsers(): UserDTO { | ||
return UserDTO(1L, "username", "email", "name", "surname") | ||
} | ||
} | ||
data class UserDTO( | ||
val id: Long? = null, | ||
val username: String, | ||
val email: String, | ||
val name: String, | ||
val surname: String? = null, | ||
) | ||
""".trimIndent() | ||
|
||
val createFile = KtPsiFactory(project).createFile("UserController.kt", code) | ||
val controller = PsiTreeUtil.findChildOfType(createFile, KtClassOrObject::class.java)!! | ||
// given | ||
val builder = KotlinClassContextBuilder() | ||
|
||
// then | ||
val classContext = builder.getClassContext(controller, false)!! | ||
TestCase.assertEquals(classContext.format(), "'package: cc.unitmesh.untitled.demo.controller.UserController\n" + | ||
"'@RestController, @RequestMapping(\"/user\")\n" + | ||
"class UserController {\n" + | ||
" \n" + | ||
" \n" + | ||
"}") | ||
} | ||
} |
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