Uploaded image for project: 're-motion'
  1. re-motion
  2. RM-3721

The code required to create a customized query parser has changed (MethodCallExpressionNodeTypeRegistry, IExpressionTreeProcessingStep, ExpressionTreeParser)

    Details

      Description

      The MethodCallExpressionNodeTypeRegistry has been replaced by an interface with three implementations: INodeTypeProvider, MethodInfoBasedNodeTypeRegistry, MethodNameBasedNodeTypeRegistry, and CompoundNodeTypeProvider. The MethodCallExpressionNodeTypeRegistry.CreateDefault method has been replaced by ExpressionTreeParser.CreateDefaultNodeTypeProvider, which now creates a CompoundNodeTypeProvider holding default instances of MethodInfoBasedNodeTypeRegistry and MethodNameBasedNodeTypeRegistry. Change the defaults by adding, inserting, or removing instances to/from the default CompoundNodeTypeProvider (see below).

      The IExpressionTreeProcessingStep interface is now called IExpressionTreeProcessor. Instead of an array of IExpressionTreeProcessors, ExpressionTreeParser now accepts a single IExpressionTreeProcessor (which can be a CompoundExpressionTreeProcessor if more than one processor is needed). The ExpressionTreeParser.CreateDefaultProcessor() method creates an instance of CompoundExpressionTreeProcessor with partial evaluation and transformation steps already included. Change the defaults by adding, inserting, or removing instances to/from the default CompoundExpressionTreeProcessor.

      Here is the recommended new way of creating a customized query parser:

      private static IQueryParser CreateQueryParser ()
      {
        var customNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry();
        // Register custom node parsers here:
        // customNodeTypeRegistry.Register (MyExpressionNode.SupportedMethods, typeof (MyExpressionNode));
        // Alternatively, use the CreateFromTypes factory method.
        // Use MethodNameBasedNodeTypeRegistry to register parsers by query operator name instead of MethodInfo.
      
        var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider ();
        nodeTypeProvider.InnerProviders.Add (customNodeTypeRegistry);
      
        var transformerRegistry = ExpressionTransformerRegistry.CreateDefault ();
        // Register custom expression transformers executed _after_ partial evaluation here (this should be the default):
        // transformerRegistry.Register (new MyExpressionTransformer());
      
        var processor = ExpressionTreeParser.CreateDefaultProcessor (transformerRegistry);
      
        // To register custom expression transformers executed _before_ partial evaluation, use this code:
        // var earlyTransformerRegistry = new ExpressionTransformerRegistry();
        // earlyTransformerRegistry.Register (new MyEarlyExpressionTransformer());
        // processor.InnerProcessors.Insert (0, new TransformingExpressionTreeProcessor (tranformationProvider));
      
        // Add custom processors here (use Insert (0, ...) to add at the beginning):
        // processor.InnerProcessors.Add (new MyExpressionTreeProcessor());
      
        var expressionTreeParser = new ExpressionTreeParser (nodeTypeProvider, processor);
        var queryParser = new QueryParser (expressionTreeParser);
      
        return queryParser;
      }
      

      These changes were made in order to provide a more consistent and extensible design.

        Attachments

          Issue Links

          There are no Sub-Tasks for this issue.

            Activity

            Hide
            fabian.schmied Fabian Schmied added a comment -

            Adapted sample code to show how to register expression transformers executed prior to partial evaluation.

            Show
            fabian.schmied Fabian Schmied added a comment - Adapted sample code to show how to register expression transformers executed prior to partial evaluation.

              People

              • Assignee:
                fabian.schmied Fabian Schmied
                Reporter:
                fabian.schmied Fabian Schmied
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: