-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Javadoc for expressions #1059
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
Javadoc for expressions #1059
Conversation
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.
So far I reviewed only Expression
.
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
* The method {@link Expression#eq} should be used to compare values for | ||
* equality. | ||
*/ | ||
@Deprecated // TODO-END (?) <p>Marked deprecated to prevent erroneous use. |
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.
I've never, ever seen this done. Have you?
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.
I've seen abuses, though not the deprecation of equals in particular. I don't plan to argue for it or keep it, but I was worried that users will mistake it for eq
, and was hoping for some creative way to address 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.
(I removed this)
@@ -21,116 +21,202 @@ | |||
import java.util.function.Function; | |||
|
|||
/** |
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.
What do you plan to write 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.
I think:
A value that may be stored in or otherwise operated upon by MongoDB.
Followed by some less-dense variation on:
This API is a language binding: it is a way to use a remote system as if
it were a native Java API. It is a way to represent values and computations
in some "execution context". This API is also a Domain Specific Language: it
is the Java-native variant of MQL, which is used to query MongoDB or (more
broadly) to work with data on MongoDB.
It would be followed by a few paragraphs covering important points and gotchas.
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.
I added a long description (similar to Stream). Unsure which parts of it, if any, might be moved to the package docs (none are obviously unrelated to the type hierarchy of which this is the root).
@@ -17,45 +17,43 @@ | |||
package com.mongodb.client.model.expressions; | |||
|
|||
/** | |||
* Expresses a boolean value. | |||
* A logical boolean value, either true or false. |
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.
I know we've been over this, but I'm still having difficulty squaring this sentence with the service that this API actually provides in the context of a MongoDB application. To my ears, this sentence implies that there should be a method like boolean booleanValue()
(just like java.lang.Boolean
has) on this type, which of course makes no sense. If you had to write another paragraph expanding on what this means, what would it say?
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.
Slack discussion: https://mongodb.slack.com/archives/GCKKT44RM/p1671122088820819.
7b0fde5
to
52776b6
Compare
a1bffc6
to
47f7c61
Compare
driver-core/src/main/com/mongodb/client/model/expressions/BooleanExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/BooleanExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/IntegerExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/IntegerExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/NumberExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/NumberExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/NumberExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/DateExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/BooleanExpression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/IntegerExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/ArrayExpression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Show resolved
Hide resolved
f6e5a14
to
1fb5893
Compare
9ae661b
to
bc48a5c
Compare
Rebased. Conflicts on switch/pass (none on MqlEx, which should confirm that the correct signature was used). |
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/DateExpression.java
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/DateExpression.java
Show resolved
Hide resolved
* | ||
* | ||
* <p>Users should treat these interfaces as sealed, and should not create | ||
* implementations. | ||
* | ||
* @see Expressions | ||
*/ | ||
@Evolving | ||
public interface Expression { |
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.
We need to make sure that the following unchecked methods are documented as such (I am using the annotation from #1068 to express what the user asserts when using any of these methods):
method | annotation |
---|---|
Branches.isArray | @MqlUnchecked(TYPE_ARGUMENT) |
Branches.isMap | @MqlUnchecked(TYPE_ARGUMENT) |
BranchesIntermediary.isArray | @MqlUnchecked(TYPE_ARGUMENT) |
BranchesIntermediary.isMap | @MqlUnchecked(TYPE_ARGUMENT) |
Expressions.currentAsMap | @MqlUnchecked(TYPE_ARGUMENT) |
Expressions.ofMap(Bson) | @MqlUnchecked(TYPE_ARGUMENT) |
Expression.isArrayOr | @MqlUnchecked(TYPE_ARGUMENT) |
Expression.isMapOr | @MqlUnchecked(TYPE_ARGUMENT) |
ArrayExpression.elementAt | @MqlUnchecked(PRESENT) |
ArrayExpression.first | @MqlUnchecked(PRESENT) |
ArrayExpression.last | @MqlUnchecked(PRESENT) |
MapExpression.get(key) | @MqlUnchecked(PRESENT) |
DocumentExpression.getField | @MqlUnchecked(PRESENT) |
DocumentExpression.getBoolean(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getNumber(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getInteger(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getString(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getDate(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getDocument(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getMap(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
DocumentExpression.getArray(fieldName) | @MqlUnchecked({PRESENT, TYPE}) |
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.
I will apply this in the final doc PR which covers docs etc. (along with, for example, server version annotations).
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.
Right, the annotation may be added later. This comment is about documenting all unchecked methods with text (unless you decide not to do so and use only the annotation instead, which is what I would have preferred). The reason I used the annotation in the table is to conveniently express what a user must assert.
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.
Please leave unresolved, for easier reference.
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
1fb5893
to
458d786
Compare
125c935
to
7f00dec
Compare
driver-core/src/main/com/mongodb/client/model/expressions/Expression.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/client/model/expressions/Expressions.java
Outdated
Show resolved
Hide resolved
e01fa10
to
6713b6d
Compare
/** | ||
* Documents places where the API relies on a user asserting | ||
* something that is not checked at run-time. | ||
* If the assertion turns out to be false, the API behavior is unspecified. | ||
* | ||
* <p>This class is not part of the public API and may be removed or changed at any time</p> | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target({ElementType.METHOD, ElementType.TYPE_USE}) | ||
public @interface MqlUnchecked { |
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.
Note how this annotation is documented as not being a part of the public API despite residing in a non-internal
package and being public
. This is because we want to generate the API docs for this annotation, but we don't want users to use it either to annotate their code, or to analyze the code at compile time.
* Implement boolean expressions (#1025) JAVA-4779 * Implement filter, map, reduce (#1031) JAVA-4781 * Implement eq, ne, gt, gte, lt, lte (#1033) JAVA-4784 * Implement string expressions (#1036) JAVA-4801 * Implement arithmetic expressions (#1037) Implement arithmetic expressions (from top 50, and others) JAVA-4803 * Implement array expressions (#1043) JAVA-4805 * Implement date expressions (#1045) JAVA-4804 * Implement conversion/type expressions (#1050) JAVA-4802 * Implement document expressions (#1052) JAVA-4782 * Replace reduce with individual reductions (#1053) JAVA-4814 * Implement map expressions (#1054) JAVA-4817 * Implement switch expression (#1055) JAVA-4813 * Test expressions in context (#1057) JAVA-4820 * Add javadoc for boolean, date, number, integer, and expression (#1059) JAVA-4799 * Update and add documentation (#1059) * Fix, tests JAVA-4799 * Add `@MqlUnchecked` and a few usage examples (#1059) JAVA-4799 * Add has to document, add tests (#1070) JAVA-4799 * Add javadocs for remaining classes (#1070) JAVA-4799 * 5.2 annotations (#1070) JAVA-4799 * 5.0 annotations (#1070) JAVA-4799 * 4.4 annotations (#1070) JAVA-4799 * 4.2 annotations (#1070) JAVA-4799 * 4.0 annotations (#1070) JAVA-4799 * Update and add documentation, add tests, fix minor issues (#1070) Rename extractBsonValue Fix access modifiers Remove excess comments Update docs Fix: behaviour of get Add notNull to API, add notNullApi test Fix docs/annotations, tests Fix docs, annotations, since Fix docs Revert external Add missing MqlUnchecked Fix missing null checks Checkstyle JAVA-4799 * Rename to Mql (automated) (#1073) JAVA-3879 * Rename methods (automated) (#1073) JAVA-3879 * Update naming, terms, and missing checks and annotations (#1073) JAVA-3879 --------- Co-authored-by: Valentin Kovalenko <[email protected]>
Partial work for JAVA-4799
Covers boolean, date, number, integer, and expression, but not others, since PRs are still in progress.
There are naming changes, to parameters especially.