Skip to content

Commit

Permalink
refactor: change schema in names to specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Dec 11, 2023
1 parent 1216bc0 commit ae84430
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import com.intellij.psi.PsiElement
*/
object JsonFileXPath: PsiFileXPath<JsonFile>() {

override fun findPsi(asyncAPISchema: JsonFile?, psiXPath: String, partialMatch: Boolean): List<PsiElement> {
asyncAPISchema ?: return emptyList()
override fun findPsi(asyncAPISpecification: JsonFile?, psiXPath: String, partialMatch: Boolean): List<PsiElement> {
asyncAPISpecification ?: return emptyList()

val tokens = tokenize(psiXPath)
if (tokens.isEmpty()) {
return emptyList()
}

var elements: List<PsiElement> = asyncAPISchema.children.filterIsInstance(JsonObject::class.java).flatMap {
var elements: List<PsiElement> = asyncAPISpecification.children.filterIsInstance(JsonObject::class.java).flatMap {
it.propertyList
}

Expand All @@ -31,8 +31,8 @@ object JsonFileXPath: PsiFileXPath<JsonFile>() {
return elements
}

override fun findText(asyncAPISchema: JsonFile?, psiXPath: String, partialMatch: Boolean): List<String> {
return findPsi(asyncAPISchema, psiXPath, partialMatch).map {
override fun findText(asyncAPISpecification: JsonFile?, psiXPath: String, partialMatch: Boolean): List<String> {
return findPsi(asyncAPISpecification, psiXPath, partialMatch).map {
it.text.removePrefix("\"").removeSuffix("\"")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ abstract class PsiFileXPath<AsyncAPISchema: PsiFile> {
* Converts schema reference to PSI XPath.
* For example: #/components/messages will be compiled as $.components.messages
*
* @param schemaReference to compile as PSI xpath.
* @param specificationReference to compile as PSI xpath.
*/
fun compileXPath(schemaReference: String): String {
return schemaReference
fun compileXPath(specificationReference: String): String {
return specificationReference
.removePrefix("\"")
.removeSuffix("\"")
.replace("#/", "")
Expand All @@ -34,7 +34,7 @@ abstract class PsiFileXPath<AsyncAPISchema: PsiFile> {
*
* @return list of [PsiElement.getText] for each found [PsiElement] or empty.
*/
abstract fun findText(asyncAPISchema: AsyncAPISchema?, psiXPath: String, partialMatch: Boolean = false): List<String>
abstract fun findText(asyncAPISpecification: AsyncAPISchema?, psiXPath: String, partialMatch: Boolean = false): List<String>

/**
* Search for [PsiElement] text by given xpath.
Expand All @@ -45,7 +45,7 @@ abstract class PsiFileXPath<AsyncAPISchema: PsiFile> {
*
* @return list of found [PsiElement] or empty.
*/
abstract fun findPsi(asyncAPISchema: AsyncAPISchema?, psiXPath: String, partialMatch: Boolean = false): List<PsiElement>
abstract fun findPsi(asyncAPISpecification: AsyncAPISchema?, psiXPath: String, partialMatch: Boolean = false): List<PsiElement>

/**
* Split psiXPath to tokens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import org.jetbrains.yaml.psi.YAMLMapping
*/
object YamlFileXPath: PsiFileXPath<YAMLFile>() {

override fun findText(asyncAPISchema: YAMLFile?, psiXPath: String, partialMatch: Boolean): List<String> {
return findPsi(asyncAPISchema, psiXPath, partialMatch).map {
override fun findText(asyncAPISpecification: YAMLFile?, psiXPath: String, partialMatch: Boolean): List<String> {
return findPsi(asyncAPISpecification, psiXPath, partialMatch).map {
it.text.removePrefix("\"").removeSuffix("\"")
}
}

override fun findPsi(asyncAPISchema: YAMLFile?, psiXPath: String, partialMatch: Boolean): List<PsiElement> {
asyncAPISchema ?: return emptyList()
override fun findPsi(asyncAPISpecification: YAMLFile?, psiXPath: String, partialMatch: Boolean): List<PsiElement> {
asyncAPISpecification ?: return emptyList()

val tokens = tokenize(psiXPath)
if (tokens.isEmpty()) {
return emptyList()
}

var elements: List<PsiElement> = asyncAPISchema.documents.flatMap { it.yamlElements }
var elements: List<PsiElement> = asyncAPISpecification.documents.flatMap { it.yamlElements }

tokens.forEach { token ->
elements = exploreNodes(elements, token, partialMatch)
Expand Down

0 comments on commit ae84430

Please sign in to comment.