Skip to content

Conversation

@Ravi-Raghavan
Copy link
Collaborator

No description provided.

@Ravi-Raghavan Ravi-Raghavan requested a review from BorisDog June 17, 2024 21:22
}
}

return builderDefinitionNodes.ToArray();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just return IEnumerable<Node> or IList<>, to skip this temporary allocations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
case NodeType.Builders:
{
nodesToRewrite = GetBuildersDefinitionNodes(semanticModel, expressionNode).ToArray();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ToArray was moved to a different place. The goal was to avoid unnecessary copying of List to Array, in such transient processing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

continue;
}

.FirstOrDefault(n => semanticModel.GetTypeInfo(n).Type.IsSupportedIMongoCollection()) };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collectionNode == null logic is gone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

static DriverVersionHelper()
{
var driverVersion = Environment.GetEnvironmentVariable("DRIVER_VERSION");
DriverVersions = new[] { NuGetVersion.Parse(driverVersion) };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No-commit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Ravi-Raghavan Ravi-Raghavan requested a review from BorisDog June 20, 2024 22:06
}
rewriteContext.ConstantsMapper.FinalizeLiteralsRegistration();

//Get Node Remappings for Root Nodes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a comment in the case where it mostly repeats the method name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Skip MongoDB.Driver.Builders<T> nodes
if (node is MemberAccessExpressionSyntax memberAccessExpressionSyntax &&
semanticModel.GetSymbolInfo(memberAccessExpressionSyntax).Symbol is IPropertySymbol propertyTypeSymbol &&
propertyTypeSymbol.IsDefinedInMongoDriver() &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove property

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// limitations under the License.

//
using System;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need these usings, and '//' ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public FilterDefinitionBuilder<User> GetFilterDefinitionBuilder() => Builders<User>.Filter;
public static FilterDefinitionBuilder<User> GetFilterDefinitionBuilderStatic() => Builders<User>.Filter;

public BuildersDefinitions GetClass() => new BuildersDefinitions();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> new(); (and next line)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

var typeArguments = rootTypeArguments.Select(rootTypeArgument => SyntaxFactory.ParseTypeName(typesProcessor
.GetTypeSymbolToGeneratedTypeMapping(rootTypeArgument))).ToArray();

var buildersGenericType = SyntaxFactory.GenericName("Builders").WithTypeArgumentList(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a const in MqlGeneratorSyntaxElements.Builders.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

var rootTypeArguments = rootType.TypeArguments.ToArray();

var typeArguments = rootTypeArguments.Select(rootTypeArgument => SyntaxFactory.ParseTypeName(typesProcessor
.GetTypeSymbolToGeneratedTypeMapping(rootTypeArgument))).ToArray();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to convert to arrays at all (here and above).
Also we need to check whether type was processed by typesProcessor, and return early if it was not, like it's done in HandleRemappedType.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (symbolInfo.Symbol == null)
{
return default;
nodesRemapping.Clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of indicating an error by clearing accumulated results. Let's have this method return a boolean indicating it's success.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Ravi-Raghavan Ravi-Raghavan requested a review from BorisDog June 21, 2024 14:00

[BuildersMQL("{ \"Name\" : \"User Name1\" }")]
[BuildersMQL("{ \"Name\" : \"User Name2\" }")]
public void MethodTest()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for 'Test' suffix. Let's try come up with a better convention here. Something like

Variable_definition_projection,
Variable_definition_indexkeys,
Method_definition
Static_method_definition
...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

expressionDescendants = expressionNode.DescendantNodes(n => n != rootNode).OfType<IdentifierNameSyntax>();
rootNodeRemapped = SyntaxFactory.IdentifierName(MqlGeneratorSyntaxElements.Linq.QueryableName);
expressionDescendants = expressionNode.DescendantNodes(n => !rootNodes.Contains(n)).OfType<IdentifierNameSyntax>();
processGenerics = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node need for setting processGenerics here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Ravi-Raghavan Ravi-Raghavan requested a review from BorisDog June 21, 2024 15:58
Copy link
Collaborator

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Ravi-Raghavan Ravi-Raghavan merged commit 8e7f473 into mongodb:main Jun 21, 2024
@Ravi-Raghavan Ravi-Raghavan deleted the VS-140 branch June 21, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants