Skip to content

Commit

Permalink
fix Qodana problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayacco committed Aug 8, 2024
1 parent 2578a15 commit 88e5959
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GoToRequestMappingAction : GotoActionBase(), DumbAware {
showNavigationPopup(e, requestMappingModel, GoToRequestMappingActionCallback(), null, true, false)
}

private class GoToRequestMappingActionCallback : GotoActionBase.GotoActionCallback<String>() {
private class GoToRequestMappingActionCallback : GotoActionCallback<String>() {

override fun elementChosen(popup: ChooseByNamePopup, element: Any) {
if (element is RequestMappingItem && element.canNavigate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class SpringMappingAnnotation(

private fun fetchMappingsParams(annotation: PsiAnnotation): List<String> {
val fetchMappingsFromAnnotation = PathAnnotation(annotation).fetchMappings(PARAMS)
return if (fetchMappingsFromAnnotation.isNotEmpty()) fetchMappingsFromAnnotation else listOf("")
return fetchMappingsFromAnnotation.ifEmpty { listOf("") }
}

private fun fetchMappingsFromClass(psiMethod: PsiMethod): List<String> {
Expand All @@ -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<String> {
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("") }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex
class KotlinRequestMappingContributor : RequestMappingByNameContributor() {

override fun getAnnotationSearchers(annotationName: String, project: Project): Sequence<PsiAnnotation> {
return KotlinAnnotationsIndex
.get(annotationName, project, projectScope(project))
return KotlinAnnotationsIndex[annotationName, project, projectScope(project)]
.asSequence()
.mapNotNull { it.toLightAnnotation() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ abstract class RequestMappingByNameContributor(

private fun findRequestMappingItems(project: Project, annotationName: String): List<RequestMappingItem> {
return getAnnotationSearchers(annotationName, project)
.filterNotNull()
.filter { it.isMethodAnnotation() }
.filter {
it.qualifiedName!!.contains(MICRONAUT_PACKAGE_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@ data class Path(private val pathElements: List<PathElement>) {

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<PathElement>, targetPathElements: List<PathElement>, 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<PathElement>, targetPathElements: List<PathElement>, 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)
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.apache.commons.text.StringEscapeUtils
class PathElement(val value: String) {
val isPathVariable: Boolean = value.inCurlyBrackets()

Check notice on line 10 in src/main/kotlin/com/github/goldsubmarine/restfulhelper/model/PathElement.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'isPathVariable' could be private

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 =
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class PopupPath(popupItem: String) : Comparable<PopupPath> {
private val path = popupItem.split(' ')[1]
private val method = popupItem.split(' ')[0]

fun toPath() = Path(path)

companion object : Comparator<PopupPath> {
private val comparator: java.util.Comparator<PopupPath> = Comparator { o1: PopupPath, o2: PopupPath -> o1.method.compareTo(o2.method) }
.thenComparing { o1: PopupPath, o2: PopupPath -> o1.path.length.compareTo(o2.path.length) }
Expand Down

0 comments on commit 88e5959

Please sign in to comment.