generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 316
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
5 changed files
with
75 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cc.unitmesh.idea | ||
|
||
object MvcUtil { | ||
fun langSuffix(lang: String): String = when (lang.lowercase()) { | ||
"java" -> "java" | ||
"kotlin" -> "kt" | ||
else -> "java" | ||
} | ||
|
||
fun isController(fileName: String, lang: String = "java"): Boolean { | ||
return fileName.endsWith("Controller." + langSuffix(lang)) | ||
} | ||
|
||
fun isService(fileName: String, lang: String = "java") = | ||
fileName.endsWith("Service." + langSuffix(lang)) || fileName.endsWith("ServiceImpl." + langSuffix(lang)) | ||
} |
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
53 changes: 53 additions & 0 deletions
53
java/src/main/kotlin/cc/unitmesh/idea/provider/TestContextProvider.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,53 @@ | ||
package cc.unitmesh.idea.provider | ||
|
||
import cc.unitmesh.devti.gui.chat.ChatActionType | ||
import cc.unitmesh.devti.provider.context.ChatContextItem | ||
import cc.unitmesh.devti.provider.context.ChatContextProvider | ||
import cc.unitmesh.devti.provider.context.ChatCreationContext | ||
import cc.unitmesh.idea.MvcUtil | ||
import com.intellij.openapi.project.Project | ||
|
||
class TestContextProvider : ChatContextProvider { | ||
override fun isApplicable(project: Project, creationContext: ChatCreationContext): Boolean { | ||
return creationContext.action == ChatActionType.WRITE_TEST | ||
} | ||
|
||
override fun collect(project: Project, creationContext: ChatCreationContext): List<ChatContextItem> { | ||
val items = mutableListOf<ChatContextItem>() | ||
|
||
val isController = creationContext.sourceFile?.name?.let { | ||
MvcUtil.isController(it) | ||
} ?: false | ||
|
||
val isService = creationContext.sourceFile?.name?.let { | ||
MvcUtil.isService(it) | ||
} ?: false | ||
|
||
if (isController) { | ||
items.add( | ||
ChatContextItem( | ||
TestContextProvider::class, | ||
"""You MUST use should_xx style for test method name. | ||
| You MUST use MockMvc and test API only. | ||
| You MUST use given-when-then style. | ||
| You MUST use should_xx style for test method name.""".trimMargin() | ||
) | ||
) | ||
} | ||
|
||
if (isService) { | ||
items.add( | ||
ChatContextItem( | ||
TestContextProvider::class, | ||
"""You MUST use should_xx style for test method name. | ||
| You MUST use Mockito and test service only. | ||
| You MUST use given-when-then style. | ||
| You MUST use should_xx style for test method name. """.trimMargin() | ||
) | ||
) | ||
} | ||
|
||
return items | ||
} | ||
|
||
} |
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