-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: basic parser for queries with the java driver INTELLIJ-19 #15
Conversation
Coverage Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I understood the flow, syntax is still a little alien but I will get used to it :D
return false | ||
} | ||
|
||
override fun attachment(source: PsiElement): PsiElement = source.findMongoDbCollectionReference()!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it common to do !!
towards the end of a method call. I am assuming this is a non-null assertion. If yes, does the TS recommendation hold true here as well - to make it verbose, add some conditional check instead of doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually you don't need to do it, but in this case the check that the node exists is happening in another method (the isCandidate) so it's fine and if someone is not using the API correctly they will see a NPE really fast.
val namespace = NamespaceExtractor.extractNamespace(source) | ||
val collectionReference = namespaceComponent(namespace) | ||
|
||
val currentCall = source as PsiMethodCallExpression? ?: return Node(source, listOf(collectionReference)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question similar to above - how safe is it to do this - source as PsiMethodCallExpression
. I am assuming that this is type casting. Would it be better if we do some instanceOf check or there's no such thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This specific cast is like an instance of and cast at the same time. Being a nullable type, if the casting is not successful it will return null, going through the return expression on the right side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh that's interesting - thanks for the context
public FindIterable<Document> findBookById(ObjectId id) { | ||
return this.collection.find(Filters.eq("_id", id)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh now I understand! I was wondering when would filter be a callable expression with key and value pairs. Totally forgot that this is quite common when writing Java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah all key/value operators have the same syntax in the driver, that is really useful to just implement the pattern once without needing to check the specific operator.
} | ||
""", | ||
) | ||
fun `supports vararg operators`(psiFile: PsiFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: vararg is actually a term in Kotlin
@@ -109,10 +114,11 @@ fun Class<*>.toBsonType(): BsonType { | |||
Int::class.javaObjectType -> BsonAnyOf(BsonNull, BsonInt32) | |||
CharSequence::class.java, String::class.java -> BsonAnyOf(BsonNull, BsonString) | |||
Date::class.java, Instant::class.java, LocalDate::class.java, LocalDateTime::class.java -> | |||
BsonAnyOf(BsonNull, BsonDate) | |||
BsonAnyOf(BsonNull, BsonDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq: is there something like prettier for kotlin projects. That probably should help with the formatting changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we have spotless in the Gradle project that does the formatting for us, but for some reason I need to check, it sometimes does weird things on the precommit hook.
Description
Checklist
Open Questions