diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/GoToRequestMappingAction.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/GoToRequestMappingAction.kt index fdb901a..ad502db 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/GoToRequestMappingAction.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/GoToRequestMappingAction.kt @@ -15,7 +15,7 @@ class GoToRequestMappingAction : GotoActionBase(), DumbAware { showNavigationPopup(e, requestMappingModel, GoToRequestMappingActionCallback(), null, true, false) } - private class GoToRequestMappingActionCallback : GotoActionBase.GotoActionCallback() { + private class GoToRequestMappingActionCallback : GotoActionCallback() { override fun elementChosen(popup: ChooseByNamePopup, element: Any) { if (element is RequestMappingItem && element.canNavigate()) { diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingItem.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingItem.kt index 1f80698..cbbdaaa 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingItem.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingItem.kt @@ -40,7 +40,7 @@ class RequestMappingItem(val psiElement: PsiElement, private val urlPath: String val fileName = psiElement.containingFile?.name when (psiElement) { is PsiMethod -> (psiElement.containingClass?.name ?: fileName ?: "unknownFile") + "." + psiElement.name + getPresentModuleName() - is PsiClass -> psiElement.name ?: fileName ?: "unknownFile" + getPresentModuleName() + is PsiClass -> psiElement.name ?: fileName ?: ("unknownFile" + getPresentModuleName()) else -> "unknownLocation" } }) diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingModel.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingModel.kt index f85b59e..757c0dd 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingModel.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/RequestMappingModel.kt @@ -1,6 +1,5 @@ package com.github.goldsubmarine.restfulhelper -import com.github.goldsubmarine.restfulhelper.RequestMappingItemProvider import com.intellij.ide.util.gotoByName.ChooseByNameItemProvider import com.intellij.ide.util.gotoByName.FilteringGotoByModel import com.intellij.navigation.ChooseByNameContributor diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxRsMappingAnnotation.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxRsMappingAnnotation.kt index b974529..bd62c05 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxRsMappingAnnotation.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxRsMappingAnnotation.kt @@ -14,7 +14,7 @@ import com.github.goldsubmarine.restfulhelper.model.PathParameter import com.github.goldsubmarine.restfulhelper.utils.fetchAnnotatedMethod abstract class JaxRsMappingAnnotation( - val psiAnnotation: PsiAnnotation, + private val psiAnnotation: PsiAnnotation, private val urlFormatter: UrlFormatter = JaxRsUrlFormatter ) : MappingAnnotation { diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxrsAnnotations.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxrsAnnotations.kt index b917c58..c27952c 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxrsAnnotations.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/jaxrs/JaxrsAnnotations.kt @@ -2,7 +2,7 @@ package com.github.goldsubmarine.restfulhelper.annotations.jaxrs import com.intellij.psi.PsiAnnotation -val JAXRS_PACKAGE_NAME = "javax.ws.rs" +const val JAXRS_PACKAGE_NAME = "javax.ws.rs" class GET(psiAnnotation: PsiAnnotation) : JaxRsMappingAnnotation(psiAnnotation) { override fun extractMethod() = "GET" diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautAnnotations.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautAnnotations.kt index 4e271c6..24dcc5c 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautAnnotations.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautAnnotations.kt @@ -2,7 +2,7 @@ package com.github.goldsubmarine.restfulhelper.annotations.micronaut import com.intellij.psi.PsiAnnotation -val MICRONAUT_PACKAGE_NAME = "io.micronaut.http.annotation" +const val MICRONAUT_PACKAGE_NAME = "io.micronaut.http.annotation" class Delete(psiAnnotation: PsiAnnotation) : MicronautMappingAnnotation(psiAnnotation) { override fun extractMethod() = "DELETE" diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautMappingAnnotation.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautMappingAnnotation.kt index 33d3a53..4111dab 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautMappingAnnotation.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/micronaut/MicronautMappingAnnotation.kt @@ -15,7 +15,7 @@ import com.github.goldsubmarine.restfulhelper.utils.fetchAnnotatedMethod import com.github.goldsubmarine.restfulhelper.utils.unquote abstract class MicronautMappingAnnotation( - val psiAnnotation: PsiAnnotation, + private val psiAnnotation: PsiAnnotation, private val urlFormatter: UrlFormatter = MicronautUrlFormatter ) : MappingAnnotation { diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringAnnotations.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringAnnotations.kt index 3f250e3..b78f569 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringAnnotations.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringAnnotations.kt @@ -2,7 +2,7 @@ package com.github.goldsubmarine.restfulhelper.annotations.spring import com.intellij.psi.PsiAnnotation -val SPRING_PACKAGE_NAME = "org.springframework.web.bind.annotation" +const val SPRING_PACKAGE_NAME = "org.springframework.web.bind.annotation" class DeleteMapping(psiAnnotation: PsiAnnotation) : RequestMapping(psiAnnotation) { override fun extractMethod() = "DELETE" diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringMappingAnnotation.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringMappingAnnotation.kt index 2c16dad..e4fa55b 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringMappingAnnotation.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/annotations/spring/SpringMappingAnnotation.kt @@ -39,7 +39,7 @@ abstract class SpringMappingAnnotation( private fun fetchMappingsParams(annotation: PsiAnnotation): List { val fetchMappingsFromAnnotation = PathAnnotation(annotation).fetchMappings(PARAMS) - return if (fetchMappingsFromAnnotation.isNotEmpty()) fetchMappingsFromAnnotation else listOf("") + return fetchMappingsFromAnnotation.ifEmpty { listOf("") } } private fun fetchMappingsFromClass(psiMethod: PsiMethod): List { @@ -50,14 +50,14 @@ abstract class SpringMappingAnnotation( ?.filterNotNull() ?.filter { it.qualifiedName == SPRING_REQUEST_MAPPING_CLASS } ?.flatMap { fetchMapping(it) } ?: emptyList() - return if (classMapping.isEmpty()) listOf("") else classMapping + return classMapping.ifEmpty { listOf("") } } private fun fetchMapping(annotation: PsiAnnotation): List { val pathMapping = PathAnnotation(annotation).fetchMappings(PATH) - return if (pathMapping.isNotEmpty()) pathMapping else { + return pathMapping.ifEmpty { val valueMapping = PathAnnotation(annotation).fetchMappings(VALUE) - if (valueMapping.isNotEmpty()) valueMapping else listOf("") + valueMapping.ifEmpty { listOf("") } } } diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/KotlinRequestMappingContributor.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/KotlinRequestMappingContributor.kt index 3b4cba7..6e7d7f7 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/KotlinRequestMappingContributor.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/KotlinRequestMappingContributor.kt @@ -9,8 +9,7 @@ import org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex class KotlinRequestMappingContributor : RequestMappingByNameContributor() { override fun getAnnotationSearchers(annotationName: String, project: Project): Sequence { - return KotlinAnnotationsIndex - .get(annotationName, project, projectScope(project)) + return KotlinAnnotationsIndex[annotationName, project, projectScope(project)] .asSequence() .mapNotNull { it.toLightAnnotation() } } diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/RequestMappingByNameContributor.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/RequestMappingByNameContributor.kt index 4290be8..acae183 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/RequestMappingByNameContributor.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/contributor/RequestMappingByNameContributor.kt @@ -36,7 +36,6 @@ abstract class RequestMappingByNameContributor( private fun findRequestMappingItems(project: Project, annotationName: String): List { return getAnnotationSearchers(annotationName, project) - .filterNotNull() .filter { it.isMethodAnnotation() } .filter { it.qualifiedName!!.contains(MICRONAUT_PACKAGE_NAME) diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/Path.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/Path.kt index 6ec0d00..2d986ee 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/Path.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/Path.kt @@ -16,40 +16,40 @@ data class Path(private val pathElements: List) { fun toFullPath() = pathElements.joinToString("/") { it.value } - companion object { - - fun isSubpathOf(sourcePath: Path, targetPath: Path): Boolean { - var sourcePathElements = sourcePath.pathElements - var targetPathElements = targetPath.pathElements - - // align by right if pattern is longer - val subtractSizeOfPath = targetPathElements.size - sourcePathElements.size - val addDrop = if (subtractSizeOfPath > 0) subtractSizeOfPath else 0 - - sourcePathElements = sourcePathElements.drop(1) - targetPathElements = targetPathElements.drop(1 + addDrop) - val allSourceElementsArePathVariables = sourcePathElements.all { it.isPathVariable } - - return containsAll(sourcePathElements, targetPathElements, allSourceElementsArePathVariables) - } - - private tailrec fun containsAll(sourcePathElements: List, targetPathElements: List, allSourceElementsArePathVariables: Boolean): Boolean { - if (sourcePathElements.size < targetPathElements.size) { - return false - } - - val hasExactMatching = sourcePathElements.subList(0, targetPathElements.size).any { !it.isPathVariable } - val pathElementsAreEqual = sourcePathElements - .zip(targetPathElements) - .all { (popupElement, searchPattern) -> - popupElement.compareToSearchPattern(searchPattern) || popupElement.value.startsWith(searchPattern.value) - } - - if (pathElementsAreEqual && (hasExactMatching || allSourceElementsArePathVariables)) { - return true - } - - return containsAll(sourcePathElements.drop(1), targetPathElements, allSourceElementsArePathVariables) - } - } +// companion object { +// +// fun isSubPathOf(sourcePath: Path, targetPath: Path): Boolean { +// var sourcePathElements = sourcePath.pathElements +// var targetPathElements = targetPath.pathElements +// +// // align by right if pattern is longer +// val subtractSizeOfPath = targetPathElements.size - sourcePathElements.size +// val addDrop = if (subtractSizeOfPath > 0) subtractSizeOfPath else 0 +// +// sourcePathElements = sourcePathElements.drop(1) +// targetPathElements = targetPathElements.drop(1 + addDrop) +// val allSourceElementsArePathVariables = sourcePathElements.all { it.isPathVariable } +// +// return containsAll(sourcePathElements, targetPathElements, allSourceElementsArePathVariables) +// } +// +// private tailrec fun containsAll(sourcePathElements: List, targetPathElements: List, allSourceElementsArePathVariables: Boolean): Boolean { +// if (sourcePathElements.size < targetPathElements.size) { +// return false +// } +// +// val hasExactMatching = sourcePathElements.subList(0, targetPathElements.size).any { !it.isPathVariable } +// val pathElementsAreEqual = sourcePathElements +// .zip(targetPathElements) +// .all { (popupElement, searchPattern) -> +// popupElement.compareToSearchPattern(searchPattern) || popupElement.value.startsWith(searchPattern.value) +// } +// +// if (pathElementsAreEqual && (hasExactMatching || allSourceElementsArePathVariables)) { +// return true +// } +// +// return containsAll(sourcePathElements.drop(1), targetPathElements, allSourceElementsArePathVariables) +// } +// } } diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PathElement.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PathElement.kt index 999352a..209491c 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PathElement.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PathElement.kt @@ -9,7 +9,7 @@ import org.apache.commons.text.StringEscapeUtils class PathElement(val value: String) { val isPathVariable: Boolean = value.inCurlyBrackets() - fun addPathVariableType(type: String) = if (isPathVariable) PathElement(value.unquoteCurlyBrackets().let { "${if (type.isBlank()) "String" else type}:$it" }.addCurlyBrackets()) + fun addPathVariableType(type: String) = if (isPathVariable) PathElement(value.unquoteCurlyBrackets().let { "${type.ifBlank { "String" }}:$it" }.addCurlyBrackets()) else this private fun compareWithPathVariable(pathElement: PathElement, searchPattern: PathElement): Boolean = @@ -70,9 +70,7 @@ class PathElement(val value: String) { other as PathElement - if (value != other.value) return false - - return true + return value == other.value } override fun hashCode(): Int { diff --git a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PopupPath.kt b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PopupPath.kt index 58804c7..2c1044f 100644 --- a/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PopupPath.kt +++ b/src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PopupPath.kt @@ -8,8 +8,6 @@ class PopupPath(popupItem: String) : Comparable { private val path = popupItem.split(' ')[1] private val method = popupItem.split(' ')[0] - fun toPath() = Path(path) - companion object : Comparator { private val comparator: java.util.Comparator = Comparator { o1: PopupPath, o2: PopupPath -> o1.method.compareTo(o2.method) } .thenComparing { o1: PopupPath, o2: PopupPath -> o1.path.length.compareTo(o2.path.length) }