Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @FeignClient support #275

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| Spring | JAX-RS | Micronaut |
|:-:|:-:|:-:|
| ```@RequestMapping``` | | |
| ```@FeignClient``` | | |
| ```@GetMapping``` | ```@GET``` | ```@Get``` |
| ```@PostMapping``` | ```@POST``` | ```@Post``` |
| ```@PutMapping``` | ```@PUT``` | ```@Put``` |
Expand All @@ -38,11 +39,16 @@
## Usage

- Search everywhere (```Shift``` twice)
- Keyboard shortcuts:
- MacOS: ```Cmd + Shift + Back slash```
- Linux: ```Ctrl + Shift + Back slash```
- Windows: ```Ctrl + Shift + Back slash```
- Navigate (menu bar) -> Request mapping
- Keyboard shortcuts
- for Inbound requests:
- MacOS: ```Cmd + Shift + Back slash```
- Linux: ```Ctrl + Shift + Back slash```
- Windows: ```Ctrl + Shift + Back slash```
- for Outbound requests:
- MacOS: ```Cmd + Shift + o```
- Linux: ```Ctrl + Shift + o```
- Windows: ```Ctrl + Shift + o```
- Navigate (menu bar) -> ```Inbound requests``` or ```Outbound requests```

## Contributors

Expand Down
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ buildscript {
log4j_version = '2.11.1'
mockito_kotlin = '1.6.0'
commons_lang3_version = '3.11'
spek_version = '2.0.13'
kotlinter_gradle_plugin = '3.2.0'
gradle_intellij_plugin = '0.4.26'
}
Expand Down Expand Up @@ -44,7 +43,7 @@ apply plugin: "org.junit.platform.gradle.plugin"
apply plugin: "org.jmailen.kotlinter"

group "com.viartemev.requestmapper"
version "1.0"
version "1.1"

dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
Expand Down Expand Up @@ -79,8 +78,8 @@ test {
intellij {
pluginName "Request mapper"
type 'IC'
version = '2020.1.1'
plugins = ["java", "org.jetbrains.kotlin:$kotlin_version-release-IJ2020.1-1"]
version = '2020.2.1'
plugins = ["java", "org.jetbrains.kotlin:$kotlin_version-release-IJ2020.2-1"]
}

jacoco {
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/viartemev/requestmapper/BoundType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.viartemev.requestmapper

enum class BoundType {
INBOUND, OUTBOUND
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod

class RequestMappingItem(val psiElement: PsiElement, private val urlPath: String, private val requestMethod: String) : NavigationItem {
class RequestMappingItem(
val psiElement: PsiElement,
private val urlPath: String,
private val requestMethod: String,
val boundType: Set<BoundType> = setOf(BoundType.INBOUND)
) : NavigationItem {

private val navigationElement = psiElement.navigationElement as? Navigatable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.viartemev.requestmapper

import com.intellij.ide.util.gotoByName.ChooseByNameBase
import com.intellij.ide.util.gotoByName.ChooseByNameItemProvider
import com.intellij.ide.actions.searcheverywhere.FoundItemDescriptor
import com.intellij.ide.util.gotoByName.ChooseByNameModelEx
import com.intellij.ide.util.gotoByName.ChooseByNamePopup
import com.intellij.ide.util.gotoByName.ChooseByNameViewModel
import com.intellij.ide.util.gotoByName.ContributorsBasedGotoByModel
import com.intellij.ide.util.gotoByName.DefaultChooseByNameItemProvider
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.psi.PsiElement
import com.intellij.util.CollectConsumer
import com.intellij.util.Processor
import com.intellij.util.SmartList
Expand All @@ -18,28 +20,28 @@ import com.viartemev.requestmapper.model.Path
import com.viartemev.requestmapper.model.PopupPath
import com.viartemev.requestmapper.model.RequestedUserPath

open class RequestMappingItemProvider : ChooseByNameItemProvider {
override fun filterElements(
base: ChooseByNameBase,
pattern: String,
everywhere: Boolean,
open class RequestMappingItemProvider(context: PsiElement?) : DefaultChooseByNameItemProvider(context) {

override fun filterElementsWithWeights(
base: ChooseByNameViewModel,
parameters: FindSymbolParameters,
indicator: ProgressIndicator,
consumer: Processor<Any>
consumer: Processor<in FoundItemDescriptor<*>?>
): Boolean {
return ProgressManager.getInstance().computePrioritized<Boolean, RuntimeException> { filter(base, parameters.completePattern, indicator, consumer) }
}

private fun filter(base: ChooseByNameViewModel, pattern: String, indicator: ProgressIndicator, consumer: Processor<in FoundItemDescriptor<*>?>): Boolean {
if (base.project != null) {
base.project!!.putUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN, pattern)
}
val idFilter: IdFilter? = null
val searchScope = FindSymbolParameters.searchScopeFor(base.project, everywhere)
val searchScope = FindSymbolParameters.searchScopeFor(base.project, false)
val parameters = FindSymbolParameters(pattern, pattern, searchScope, idFilter)

val namesList = getSortedResults(base, pattern, indicator, parameters)
indicator.checkCanceled()
return processByNames(base, everywhere, indicator, consumer, namesList, parameters)
}

override fun filterNames(base: ChooseByNameBase, names: Array<String>, pattern: String): List<String> {
return emptyList()
return processByNames(base, indicator, consumer, namesList, parameters)
}

companion object {
Expand Down Expand Up @@ -78,35 +80,35 @@ open class RequestMappingItemProvider : ChooseByNameItemProvider {

private fun processByNames(
base: ChooseByNameViewModel,
everywhere: Boolean,
indicator: ProgressIndicator,
consumer: Processor<Any>,
consumer: Processor<in FoundItemDescriptor<*>?>,
namesList: List<String>,
parameters: FindSymbolParameters
): Boolean {
val sameNameElements: MutableList<Any> = SmartList()
val qualifierMatchResults: MutableMap<Any, MatchResult> = ContainerUtil.newIdentityTroveMap()
val model = base.model
for (name in namesList) {
indicator.checkCanceled()
val elements = if (model is ContributorsBasedGotoByModel) model.getElementsByName(name, parameters, indicator) else model.getElementsByName(name, everywhere, parameters.completePattern)
val elements = if (model is ContributorsBasedGotoByModel) model.getElementsByName(name, parameters, indicator) else model.getElementsByName(name, false, parameters.completePattern)
if (elements.size > 1) {
sameNameElements.clear()
qualifierMatchResults.clear()
for (element in elements) {
indicator.checkCanceled()
sameNameElements.add(element)
}
if (!ContainerUtil.process(sameNameElements, consumer)) return false
val processedItems: List<FoundItemDescriptor<*>> = ContainerUtil.map(sameNameElements) {
FoundItemDescriptor(it, 0)
}

if (!ContainerUtil.process(processedItems, consumer)) return false
} else if (elements.size == 1) {
if (!consumer.process(elements[0])) return false
if (!consumer.process(FoundItemDescriptor(elements[0], 0))) return false
}
}
return true
}

fun matches(name: String?, pattern: String): Boolean {

if (name == null) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.intellij.psi.PsiElement
class RequestMappingModel(project: Project, contributors: List<ChooseByNameContributor>) : FilteringGotoByModel<FileType>(project, contributors), DumbAware {

override fun getItemProvider(context: PsiElement?): ChooseByNameItemProvider {
return RequestMappingItemProvider()
return RequestMappingItemProvider(context)
}

override fun filterValueFor(item: NavigationItem): FileType? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.viartemev.requestmapper.actions

import com.intellij.ide.actions.searcheverywhere.AbstractGotoSEContributor
import com.intellij.ide.util.NavigationItemListCellRenderer
import com.intellij.ide.util.gotoByName.FilteringGotoByModel
import com.intellij.navigation.ChooseByNameContributor
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.viartemev.requestmapper.RequestMappingModel
import javax.swing.ListCellRenderer

abstract class AbstractRequestMappingContributor(event: AnActionEvent) : AbstractGotoSEContributor(event) {

override fun createModel(project: Project): FilteringGotoByModel<*> {
return RequestMappingModel(project, getContributors())
}

abstract fun getContributors(): List<ChooseByNameContributor>

override fun showInFindResults(): Boolean {
return false
}

override fun getElementsRenderer(): ListCellRenderer<Any> {
return NavigationItemListCellRenderer()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.viartemev.requestmapper.actions

import com.intellij.ide.actions.SearchEverywhereBaseAction
import com.intellij.openapi.actionSystem.AnActionEvent

class InboundRequestMappingAction : SearchEverywhereBaseAction() {
override fun actionPerformed(e: AnActionEvent) {
showInSearchEverywherePopup(InboundRequestMappingContributor::class.java.simpleName, e, true, false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.viartemev.requestmapper.actions

import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributor
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributorFactory
import com.intellij.navigation.ChooseByNameContributor
import com.intellij.openapi.actionSystem.AnActionEvent
import com.viartemev.requestmapper.BoundType
import com.viartemev.requestmapper.contributors.CustomFilterWrapperMappingContributor
import com.viartemev.requestmapper.extensions.Extensions

class InboundRequestMappingContributor(event: AnActionEvent) : AbstractRequestMappingContributor(event) {

override fun getContributors(): List<ChooseByNameContributor> {
return Extensions.getContributors().map {
CustomFilterWrapperMappingContributor(
it,
{ requestMappingItem -> requestMappingItem.boundType.contains(BoundType.INBOUND) }
)
}
}

override fun getSortWeight(): Int {
return 1000
}

override fun getGroupName(): String {
return "In-requests"
}

class Factory : SearchEverywhereContributorFactory<Any> {
override fun createContributor(initEvent: AnActionEvent): SearchEverywhereContributor<Any> {
return InboundRequestMappingContributor(initEvent)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.viartemev.requestmapper.actions

import com.intellij.ide.actions.SearchEverywhereBaseAction
import com.intellij.openapi.actionSystem.AnActionEvent

class OutBoundRequestMappingAction : SearchEverywhereBaseAction() {
override fun actionPerformed(e: AnActionEvent) {
showInSearchEverywherePopup(OutboundRequestMappingContributor::class.java.simpleName, e, true, false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.viartemev.requestmapper.actions

import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributor
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributorFactory
import com.intellij.navigation.ChooseByNameContributor
import com.intellij.openapi.actionSystem.AnActionEvent
import com.viartemev.requestmapper.BoundType
import com.viartemev.requestmapper.contributors.CustomFilterWrapperMappingContributor
import com.viartemev.requestmapper.extensions.Extensions

class OutboundRequestMappingContributor(event: AnActionEvent) : AbstractRequestMappingContributor(event) {

override fun getContributors(): List<ChooseByNameContributor> {
return Extensions.getContributors().map {
CustomFilterWrapperMappingContributor(
it,
{ requestMappingItem -> requestMappingItem.boundType.contains(BoundType.OUTBOUND) }
)
}
}

override fun getSortWeight(): Int {
return 2000
}

override fun getGroupName(): String {
return "Out-requests"
}

class Factory : SearchEverywhereContributorFactory<Any> {
override fun createContributor(initEvent: AnActionEvent): SearchEverywhereContributor<Any> {
return OutboundRequestMappingContributor(initEvent)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.viartemev.requestmapper.annotations.spring

import com.intellij.psi.PsiAnnotation
import com.viartemev.requestmapper.annotations.PathAnnotation

fun fetchPathValueMapping(annotation: PsiAnnotation): List<String> {
val pathMapping = PathAnnotation(annotation).fetchMappings(PATH)
return if (pathMapping.isNotEmpty()) pathMapping else {
val valueMapping = PathAnnotation(annotation).fetchMappings(VALUE)
if (valueMapping.isNotEmpty()) valueMapping else listOf("")
}
}

private const val VALUE = "value"
private const val PATH = "path"
Loading