Skip to content

Commit

Permalink
chore: implement HasChildren interface
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshusinghs committed Nov 13, 2024
1 parent 5e87e5f commit 9bdd351
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,8 @@ object JavaDriverDialectParser : DialectParser<PsiElement> {
if (currentCall.argumentList.expressionCount > 1) {
// TODO: we might want to have a component that tells this query is in a transaction
val startIndex = if (hasMongoDbSessionReference(currentCall)) 2 else 1
var updateExpression = currentCall.argumentList.expressions.getOrNull(startIndex)

if (updateExpression == null) {
return emptyList()
}
val updateExpression = currentCall.argumentList.expressions.getOrNull(startIndex)
?: return emptyList()

val argumentAsUpdates = resolveToUpdatesCall(updateExpression)
// parse only if it's a call to `updates` methods
Expand Down Expand Up @@ -200,7 +197,7 @@ object JavaDriverDialectParser : DialectParser<PsiElement> {
// - in(field, array) -> valid because of varargs
// - in(field, iterable) -> valid because of overload
val valueReference = if (filter.argumentList.expressionCount == 2) {
var secondArg = filter.argumentList.expressions[1].meaningfulExpression() as PsiExpression
val secondArg = filter.argumentList.expressions[1].meaningfulExpression() as PsiExpression
if (secondArg.type?.isJavaIterable() == true) { // case 3
filter.argumentList.inferFromSingleVarArgElement(start = 1)
} else if (secondArg.type?.isArray() == false) { // case 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ import com.mongodb.jbplugin.mql.components.HasTargetCluster
*/
interface Component

/**
* HasChildren component encapsulates the idea that a Component has children. For example:
* ```java
* Filters.and(Filters.eq("year", 1994), Filters.eq("name", "something"))
* ```
* The above query has a filter that have nested filters within it hence the Node that represents
* `Filters.and` implements `HasChildren` interface.
*/
interface HasChildren<S> : Component {
val children: List<Node<S>>
}

/**
* Represents the building block of a query in this model. Nodes don't have any semantic per se, but they can
* hold Components that will give them specific meaning.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mongodb.jbplugin.mql.components

import com.mongodb.jbplugin.mql.Component
import com.mongodb.jbplugin.mql.HasChildren
import com.mongodb.jbplugin.mql.Node

/**
* @param S
* @property children
*/
data class HasFilter<S>(
val children: List<Node<S>>,
) : Component
override val children: List<Node<S>>,
) : HasChildren<S>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mongodb.jbplugin.mql.components

import com.mongodb.jbplugin.mql.Component
import com.mongodb.jbplugin.mql.HasChildren
import com.mongodb.jbplugin.mql.Node

/**
* @param S
* @property children
*/
data class HasUpdates<S>(
val children: List<Node<S>>,
) : Component
override val children: List<Node<S>>,
) : HasChildren<S>

0 comments on commit 9bdd351

Please sign in to comment.