Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@

object TempestFrameworkClasses {
const val ConsoleCommand = "\\Tempest\\Console\\ConsoleCommand"

const val ROUTER_GET = "\\Tempest\\Router\\Get"

Check notice on line 6 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_GET' could be private
const val ROUTER_POST = "\\Tempest\\Router\\Post"

Check notice on line 7 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_POST' could be private
const val ROUTER_PUT = "\\Tempest\\Router\\Put"

Check notice on line 8 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_PUT' could be private
const val ROUTER_PATCH = "\\Tempest\\Router\\Patch"

Check notice on line 9 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_PATCH' could be private
const val ROUTER_DELETE = "\\Tempest\\Router\\Delete"

Check notice on line 10 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_DELETE' could be private
const val ROUTER_OPTIONS = "\\Tempest\\Router\\Options"

Check notice on line 11 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_OPTIONS' could be private
const val ROUTER_HEAD = "\\Tempest\\Router\\Head"

Check notice on line 12 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_HEAD' could be private
const val ROUTER_CONNECT = "\\Tempest\\Router\\Connect"

Check notice on line 13 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_CONNECT' could be private
const val ROUTER_TRACE = "\\Tempest\\Router\\Trace"

Check notice on line 14 in src/main/kotlin/com/github/tempest/framework/TempestFrameworkClasses.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'ROUTER_TRACE' could be private

val ROUTES = listOf(
ROUTER_GET,
ROUTER_POST,
ROUTER_PUT,
ROUTER_PATCH,
ROUTER_DELETE,
ROUTER_OPTIONS,
ROUTER_HEAD,
ROUTER_CONNECT,
ROUTER_TRACE,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.tempest.framework.router.index

import com.github.tempest.framework.TempestFrameworkClasses
import com.github.tempest.framework.TempestFrameworkUtil
import com.github.tempest.framework.common.index.AbstractIndex
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.indexing.DataIndexer
import com.intellij.util.indexing.FileBasedIndex
import com.intellij.util.indexing.FileContent
import com.intellij.util.indexing.ID
import com.intellij.util.io.EnumeratorStringDescriptor
import com.jetbrains.php.lang.PhpFileType
import com.jetbrains.php.lang.psi.elements.Method
import com.jetbrains.php.lang.psi.elements.PhpAttribute
import com.jetbrains.php.lang.psi.elements.PhpNamedElement

private typealias RouterActionsIndexType = String

/**
* Stores uri -> controller/action association
*/
class RouterActionsIndex : AbstractIndex<RouterActionsIndexType>() {
companion object {
val key = ID.create<String, RouterActionsIndexType>("Tempest.Routes.Actions")
}

override fun getVersion() = 1

override fun getName() = key

override fun getValueExternalizer() = EnumeratorStringDescriptor.INSTANCE

Check notice on line 32 in src/main/kotlin/com/github/tempest/framework/router/index/RouterActionsIndex.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

override fun getInputFilter() = FileBasedIndex.InputFilter {
it.fileType == PhpFileType.INSTANCE &&
!it.name.endsWith(TempestFrameworkUtil.TEMPLATE_SUFFIX)
}

override fun getIndexer() = DataIndexer<String, RouterActionsIndexType, FileContent> { inputData ->
inputData
.psiFile
.let { PsiTreeUtil.findChildrenOfType(it, PhpAttribute::class.java) }
.filter { it.fqn in TempestFrameworkClasses.ROUTES }

Check notice on line 43 in src/main/kotlin/com/github/tempest/framework/router/index/RouterActionsIndex.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Call chain on collection could be converted into 'Sequence' to improve performance

Call chain on a collection could be converted into 'Sequence' to improve performance
.mapNotNull { attribute ->
attribute.owner to attribute.arguments
.firstOrNull { it.name == "uri" || it.name.isEmpty() }
?.argument
?.value
?.let { StringUtil.unquoteString(it) }
}
.filter { it.first is Method }
.filter { !it.second.isNullOrEmpty() }
.associate { it.second to (it.first as PhpNamedElement).fqn }
// .apply { println("file: ${inputData.file}, result: $this") }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.github.tempest.framework.router.index

import com.github.tempest.framework.TempestFrameworkClasses
import com.github.tempest.framework.TempestFrameworkUtil
import com.github.tempest.framework.common.index.AbstractIndex
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.indexing.DataIndexer
import com.intellij.util.indexing.FileBasedIndex
import com.intellij.util.indexing.FileContent
import com.intellij.util.indexing.ID
import com.intellij.util.io.EnumeratorStringDescriptor
import com.jetbrains.php.lang.PhpFileType
import com.jetbrains.php.lang.psi.elements.PhpAttribute

private typealias RouterMethodsIndexType = String

/**
* Stores uri -> methods association
*/
class RouterMethodsIndex : AbstractIndex<RouterMethodsIndexType>() {
companion object {
val key = ID.create<String, RouterMethodsIndexType>("Tempest.Routes.Methods")
}

override fun getVersion() = 3

override fun getName() = key

override fun getValueExternalizer() = EnumeratorStringDescriptor.INSTANCE

Check notice on line 30 in src/main/kotlin/com/github/tempest/framework/router/index/RouterMethodsIndex.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Function or property has platform type

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

override fun getInputFilter() = FileBasedIndex.InputFilter {
it.fileType == PhpFileType.INSTANCE &&
!it.name.endsWith(TempestFrameworkUtil.TEMPLATE_SUFFIX)
}

override fun getIndexer() = DataIndexer<String, RouterMethodsIndexType, FileContent> { inputData ->
inputData
.psiFile
.let { PsiTreeUtil.findChildrenOfType(it, PhpAttribute::class.java) }
.filter { it.fqn in TempestFrameworkClasses.ROUTES }
.mapNotNull { attribute ->
attribute.name to attribute.arguments
.firstOrNull { it.name == "uri" || it.name.isEmpty() }
?.argument
?.value
?.let { StringUtil.unquoteString(it) }
}
.filter { !it.first.isNullOrEmpty() && !it.second.isNullOrEmpty() }
.associate { it.second to it.first!!.lowercase() }
// .apply { println("file: ${inputData.file}, result: $this") }
}
}
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

<fileBasedIndex
implementation="com.github.tempest.framework.console.index.ConsoleCommandsIndex" />
<fileBasedIndex
implementation="com.github.tempest.framework.router.index.RouterMethodsIndex" />
<fileBasedIndex
implementation="com.github.tempest.framework.router.index.RouterActionsIndex" />
</extensions>
<extensions defaultExtensionNs="com.jetbrains.php">

Expand Down
Loading