Skip to content

Commit 75adef1

Browse files
committed
feat(endpoints): try to add Spring framework support for Web API views #338
- Implement Spring framework integration for Web API view generation- Add functions to retrieve Spring facets and combined Spring model for the project - Update isApplicable function to check for Spring framework usage
1 parent 143937b commit 75adef1

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

exts/ext-endpoints/src/233/main/kotlin/cc/unitmesh/endpoints/bridge/WebApiViewFunctionProvider.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@ package cc.unitmesh.endpoints.bridge
22

33
import cc.unitmesh.devti.bridge.ArchViewCommand
44
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
5+
import com.intellij.facet.FacetManager
56
import com.intellij.microservices.endpoints.EndpointsProvider
67
import com.intellij.openapi.application.runReadAction
8+
import com.intellij.openapi.module.ModuleManager
79
import com.intellij.openapi.progress.ProgressIndicator
810
import com.intellij.openapi.progress.ProgressManager
911
import com.intellij.openapi.progress.Task
1012
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
1113
import com.intellij.openapi.project.Project
1214
import com.intellij.openapi.util.NlsSafe
15+
import com.intellij.spring.SpringManager
16+
import com.intellij.spring.contexts.model.CombinedSpringModel
17+
import com.intellij.spring.contexts.model.CombinedSpringModelImpl
18+
import com.intellij.spring.contexts.model.SpringModel
19+
import com.intellij.spring.facet.SpringFacet
1320
import com.intellij.spring.mvc.mapping.UrlMappingElement
1421
import java.util.concurrent.CompletableFuture
1522

1623
class WebApiViewFunctionProvider : ToolchainFunctionProvider {
1724
override suspend fun funcNames(): List<String> = listOf(ArchViewCommand.WebApiView.name)
1825

19-
override suspend fun isApplicable(project: Project, funcName: String): Boolean = funcName == ArchViewCommand.WebApiView.name
26+
override suspend fun isApplicable(project: Project, funcName: String): Boolean =
27+
funcName == ArchViewCommand.WebApiView.name
2028

2129
override suspend fun execute(
2230
project: Project,
@@ -52,12 +60,32 @@ class WebApiViewFunctionProvider : ToolchainFunctionProvider {
5260
}
5361
}
5462

63+
// val springFacets = getAllSpringFacets(project).map {
64+
// SpringFileSetService.getInstance().getAllSets(it)
65+
// }
66+
67+
5568
ProgressManager.getInstance()
5669
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
5770

5871
return future.get()
5972
}
6073

74+
private fun getCombinedModelForProject(project: Project): CombinedSpringModel {
75+
val allCombinedModels: MutableSet<SpringModel> = LinkedHashSet<SpringModel>()
76+
for (module in ModuleManager.getInstance(project).modules) {
77+
val allModels = SpringManager.getInstance(project).getAllModelsWithoutDependencies(module)
78+
allCombinedModels.addAll(allModels!!)
79+
}
80+
return CombinedSpringModelImpl(allCombinedModels, null)
81+
}
82+
83+
fun getAllSpringFacets(project: Project): List<SpringFacet> {
84+
return ModuleManager.getInstance(project).modules.mapNotNull { module ->
85+
FacetManager.getInstance(module).getFacetByType(SpringFacet.FACET_TYPE_ID)
86+
}
87+
}
88+
6189
private fun formatUrl(url: Any): String = when (url) {
6290
is UrlMappingElement -> url.method.joinToString("\n") {
6391
"$it - ${url.urlPath.toStringWithStars()}" +

0 commit comments

Comments
 (0)