Skip to content

Commit

Permalink
Built-In Functions to be customized OData#378
Browse files Browse the repository at this point in the history
* CustomUriFunctions - public API to add/remove or override builtIn functions.
* CustomUriFunctions and BuiltInFunctions tests
* Changed class name from 'BuiltInFunctions' to 'BuiltInUriFunctions'.
* The new class 'UriFunctionsHelper' contains general usage for both BuiltIn and Custom functions.
* Changed name of some methods :
'MatchSignatureToBuiltInFunction' to 'MatchSignatureToUriFunction'.
'BindAsBuiltInFunction' to 'BindAsUriFunction'.
  • Loading branch information
YogiBear52 authored and LaylaLiu committed Jan 13, 2016
1 parent 5f5ced7 commit f78ae27
Show file tree
Hide file tree
Showing 26 changed files with 1,296 additions and 219 deletions.
2 changes: 1 addition & 1 deletion src/CodeGen/ODataT4CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static class Configuration
// The use of DataServiceCollection enables entity and property tracking. The value must be set to true or false.
public const bool UseDataServiceCollection = true;

// The namespace of the client code generated. It replaces the original namspace in the metadata document,
// The namespace of the client code generated. It replaces the original namespace in the metadata document,
// unless the model has several namespaces.
public const string NamespacePrefix = "$rootnamespace$";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,9 +1174,6 @@
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\Binders\UnaryOperatorBinder.cs">
<Link>Microsoft\OData\Core\UriParser\Binders\UnaryOperatorBinder.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\BuiltInFunctions.cs">
<Link>Microsoft\OData\Core\UriParser\BuiltInFunctions.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\ExceptionUtil.cs">
<Link>Microsoft\OData\Core\UriParser\ExceptionUtil.cs</Link>
</Compile>
Expand Down Expand Up @@ -1403,11 +1400,11 @@
<Link>Microsoft\OData\Core\UriParser\SemanticAst\EntitySetSegment.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\SemanticAst\ExpandedNavigationSelectItem.cs">
<Link>Microsoft\OData\Core\UriParser\SemanticAst\ExpandedNavigationSelectItem.cs</Link>
</Compile>
<Link>Microsoft\OData\Core\UriParser\SemanticAst\ExpandedNavigationSelectItem.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\SemanticAst\ExpandedReferenceSelectItem.cs">
<Link>Microsoft\OData\Core\UriParser\SemanticAst\ExpandedReferenceSelectItem.cs</Link>
</Compile>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\SemanticAst\FilterClause.cs">
<Link>Microsoft\OData\Core\UriParser\SemanticAst\FilterClause.cs</Link>
</Compile>
Expand Down Expand Up @@ -1779,6 +1776,15 @@
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\Extensions\TreeNodeKinds\TransformationNodeKind.cs">
<Link>Microsoft\OData\Core\UriParser\Extensions\TreeNodeKinds\TransformationNodeKind.cs</Link>
</Compile>
<Compile Include="..\UriParser\BuiltInUriFunctions.cs">
<Link>Microsoft\OData\Core\UriParser\BuiltInUriFunctions.cs</Link>
</Compile>
<Compile Include="..\UriParser\CustomUriFunctions.cs">
<Link>Microsoft\OData\Core\UriParser\CustomUriFunctions.cs</Link>
</Compile>
<Compile Include="..\UriParser\UriFunctionsHelper.cs">
<Link>Microsoft\OData\Core\UriParser\UriFunctionsHelper.cs</Link>
</Compile>
<Compile Include="ShippingAssemblyAttributes.cs" />
<Compile Include="$(AssemblyKeysCSharpFilePath)">
<IncludeInOpenSource>false</IncludeInOpenSource>
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.OData.Core/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
// Normalize strings to uppercase
[module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Microsoft.OData.Core.ODataPreferenceHeader.#ReturnContent")]
[module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Microsoft.OData.Core.UriParser.Parsers.ExpandOptionParser.#BuildExpandTermToken(Microsoft.OData.Core.UriParser.Syntactic.PathSegmentToken,System.String)")]
[module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Microsoft.OData.Core.UriParser.Parsers.FunctionCallBinder.#BindAsBuiltInFunction(Microsoft.OData.Core.UriParser.Syntactic.FunctionCallToken,System.Collections.Generic.List`1<Microsoft.OData.Core.UriParser.Semantic.QueryNode>)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Microsoft.OData.Core.UriParser.Parsers.FunctionCallBinder.#BindAsUriFunction(Microsoft.OData.Core.UriParser.Syntactic.FunctionCallToken,System.Collections.Generic.List`1<Microsoft.OData.Core.UriParser.Semantic.QueryNode>)")]

[module: SuppressMessage("Microsoft.Naming", "CA1701:ResourceStringCompoundWordsShouldBeCasedCorrectly", MessageId = "NonEntity", Scope = "resource", Target = "Microsoft.OData.Core.resources")]

Expand Down Expand Up @@ -104,3 +104,4 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.OData.Core.ODataAsynchronousReader.#ParseResponseLine(System.String)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.OData.Core.JsonLight.ODataJsonLightDeltaReader.#IsTopLevel")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.OData.Core.JsonLight.ODataJsonLightDeltaWriter.#IsTopLevel")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Scope = "member", Target = "Microsoft.OData.Core.UriParser.FunctionSignature.#ArgumentTypes")]
4 changes: 3 additions & 1 deletion src/Microsoft.OData.Core/Microsoft.OData.Core.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@
<Compile Include="UriParser\Binders\SelectPathSegmentTokenBinder.cs" />
<Compile Include="UriParser\Binders\SelectTreeNormalizer.cs" />
<Compile Include="UriParser\Binders\UnaryOperatorBinder.cs" />
<Compile Include="UriParser\BuiltInFunctions.cs" />
<Compile Include="UriParser\BuiltInUriFunctions.cs" />
<Compile Include="UriParser\CustomUriFunctions.cs" />
<Compile Include="UriParser\ExceptionUtil.cs" />
<Compile Include="UriParser\ExpressionLexer.cs" />
<Compile Include="UriParser\ExpressionLexerLiteralExtensions.cs" />
Expand Down Expand Up @@ -579,6 +580,7 @@
<Compile Include="UriParser\TreeNodeKinds\RequestTargetKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\UnaryOperatorKind.cs" />
<Compile Include="UriParser\TypePromotionUtils.cs" />
<Compile Include="UriParser\UriFunctionsHelper.cs" />
<Compile Include="UriParser\UriQueryConstants.cs" />
<Compile Include="UriParser\UriUtils.cs" />
<Compile Include="UriParser\Visitors\IPathSegmentTokenVisitor.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@
<Compile Include="UriParser\Binders\SelectPathSegmentTokenBinder.cs" />
<Compile Include="UriParser\Binders\SelectTreeNormalizer.cs" />
<Compile Include="UriParser\Binders\UnaryOperatorBinder.cs" />
<Compile Include="UriParser\BuiltInFunctions.cs" />
<Compile Include="UriParser\BuiltInUriFunctions.cs" />
<Compile Include="UriParser\CustomUriFunctions.cs" />
<Compile Include="UriParser\ExceptionUtil.cs" />
<Compile Include="UriParser\ExpressionLexer.cs" />
<Compile Include="UriParser\ExpressionLexerLiteralExtensions.cs" />
Expand Down Expand Up @@ -578,6 +579,7 @@
<Compile Include="UriParser\TreeNodeKinds\RequestTargetKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\UnaryOperatorKind.cs" />
<Compile Include="UriParser\TypePromotionUtils.cs" />
<Compile Include="UriParser\UriFunctionsHelper.cs" />
<Compile Include="UriParser\UriQueryConstants.cs" />
<Compile Include="UriParser\UriUtils.cs" />
<Compile Include="UriParser\Visitors\IPathSegmentTokenVisitor.cs" />
Expand Down
5 changes: 4 additions & 1 deletion src/Microsoft.OData.Core/Microsoft.OData.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ internal sealed class TextRes {
internal const string ApplyBinder_UnsupportedType = "ApplyBinder_UnsupportedType";
internal const string ApplyBinder_UnsupportedGroupByChild = "ApplyBinder_UnsupportedGroupByChild";
internal const string FunctionCallBinder_CannotFindASuitableOverload = "FunctionCallBinder_CannotFindASuitableOverload";
internal const string FunctionCallBinder_BuiltInFunctionMustHaveHaveNullParent = "FunctionCallBinder_BuiltInFunctionMustHaveHaveNullParent";
internal const string FunctionCallBinder_UriFunctionMustHaveHaveNullParent = "FunctionCallBinder_UriFunctionMustHaveHaveNullParent";
internal const string FunctionCallBinder_CallingFunctionOnOpenProperty = "FunctionCallBinder_CallingFunctionOnOpenProperty";
internal const string FunctionCallParser_DuplicateParameterOrEntityKeyName = "FunctionCallParser_DuplicateParameterOrEntityKeyName";
internal const string ODataUriParser_InvalidCount = "ODataUriParser_InvalidCount";
Expand Down Expand Up @@ -794,6 +794,9 @@ internal sealed class TextRes {
internal const string FunctionOverloadResolver_MultipleOperationOverloads = "FunctionOverloadResolver_MultipleOperationOverloads";
internal const string FunctionOverloadResolver_FoundInvalidOperation = "FunctionOverloadResolver_FoundInvalidOperation";
internal const string FunctionOverloadResolver_FoundInvalidOperationImport = "FunctionOverloadResolver_FoundInvalidOperationImport";
internal const string CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload = "CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload";
internal const string CustomUriFunctions_AddCustomUriFunction_BuiltInExistsFullSignature = "CustomUriFunctions_AddCustomUriFunction_BuiltInExistsFullSignature";
internal const string CustomUriFunctions_AddCustomUriFunction_CustomFunctionOverloadExists = "CustomUriFunctions_AddCustomUriFunction_CustomFunctionOverloadExists";
internal const string RequestUriProcessor_InvalidValueForEntitySegment = "RequestUriProcessor_InvalidValueForEntitySegment";
internal const string RequestUriProcessor_InvalidValueForKeySegment = "RequestUriProcessor_InvalidValueForKeySegment";
internal const string RequestUriProcessor_EmptySegmentInRequestUrl = "RequestUriProcessor_EmptySegmentInRequestUrl";
Expand Down
4 changes: 3 additions & 1 deletion src/Microsoft.OData.Core/Microsoft.OData.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@
<Compile Include="UriParser\Binders\SelectPathSegmentTokenBinder.cs" />
<Compile Include="UriParser\Binders\SelectTreeNormalizer.cs" />
<Compile Include="UriParser\Binders\UnaryOperatorBinder.cs" />
<Compile Include="UriParser\BuiltInFunctions.cs" />
<Compile Include="UriParser\BuiltInUriFunctions.cs" />
<Compile Include="UriParser\CustomUriFunctions.cs" />
<Compile Include="UriParser\ExceptionUtil.cs" />
<Compile Include="UriParser\ExpressionLexer.cs" />
<Compile Include="UriParser\ExpressionLexerLiteralExtensions.cs" />
Expand Down Expand Up @@ -578,6 +579,7 @@
<Compile Include="UriParser\TreeNodeKinds\RequestTargetKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\UnaryOperatorKind.cs" />
<Compile Include="UriParser\TypePromotionUtils.cs" />
<Compile Include="UriParser\UriFunctionsHelper.cs" />
<Compile Include="UriParser\UriQueryConstants.cs" />
<Compile Include="UriParser\UriUtils.cs" />
<Compile Include="UriParser\Visitors\IPathSegmentTokenVisitor.cs" />
Expand Down
6 changes: 5 additions & 1 deletion src/Microsoft.OData.Core/Microsoft.OData.Core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ ApplyBinder_UnsupportedType=$apply clause does not support type '{0}'.
ApplyBinder_UnsupportedGroupByChild=$apply/groupby not support '{0}' as child transformation

FunctionCallBinder_CannotFindASuitableOverload=Cannot find a suitable overload for function '{0}' that takes '{1}' arguments.
FunctionCallBinder_BuiltInFunctionMustHaveHaveNullParent=Found a built-in function '{0}' with a parent token. Built-in functions cannot have parent tokens.
FunctionCallBinder_UriFunctionMustHaveHaveNullParent=Found a Uri function '{0}' with a parent token. Uri functions cannot have parent tokens.
FunctionCallBinder_CallingFunctionOnOpenProperty=Found a function '{0}' on an open property. Functions on open properties are not supported.
FunctionCallParser_DuplicateParameterOrEntityKeyName=Parameter or entity key names must be unique. There is most likely an error in the model.

Expand Down Expand Up @@ -881,6 +881,10 @@ FunctionOverloadResolver_MultipleOperationOverloads=Multiple action and function
FunctionOverloadResolver_FoundInvalidOperation=The operation overloads matching '{0}' are invalid. This is most likely an error in the IEdmModel.
FunctionOverloadResolver_FoundInvalidOperationImport=The operation import overloads matching '{0}' are invalid. This is most likely an error in the IEdmModel.

CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload=The given custom function '{0}' already exists as a Built-In function. Consider use 'addAsOverloadToBuiltInFunction = true' parameter.
CustomUriFunctions_AddCustomUriFunction_BuiltInExistsFullSignature=The given custom function '{0}' already exists as a Built-In function in one of it's overloads. Thus cannot override the Built-In function.
CustomUriFunctions_AddCustomUriFunction_CustomFunctionOverloadExists=The given function name '{0}' already exists as a custom function with the same overload.

RequestUriProcessor_InvalidValueForEntitySegment=The ODataPathSegment provided (Id = {0}) is not an EntitySetSegment.
RequestUriProcessor_InvalidValueForKeySegment=The KeySegment provided (Id = {0}) is either null, having no keys, or does not target a single resource.

Expand Down
29 changes: 25 additions & 4 deletions src/Microsoft.OData.Core/Parameterized.Microsoft.OData.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4985,7 +4985,7 @@ internal static string ApplyBinder_UnsupportedType(object p0) {
}

/// <summary>
/// A string like "$applg/groupby not support '{0}' as child transformation"
/// A string like "$apply/groupby not support '{0}' as child transformation"
/// </summary>
internal static string ApplyBinder_UnsupportedGroupByChild(object p0) {
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.ApplyBinder_UnsupportedGroupByChild, p0);
Expand All @@ -4999,10 +4999,10 @@ internal static string FunctionCallBinder_CannotFindASuitableOverload(object p0,
}

/// <summary>
/// A string like "Found a built-in function '{0}' with a parent token. Built-in functions cannot have parent tokens."
/// A string like "Found a Uri function '{0}' with a parent token. Uri functions cannot have parent tokens."
/// </summary>
internal static string FunctionCallBinder_BuiltInFunctionMustHaveHaveNullParent(object p0) {
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.FunctionCallBinder_BuiltInFunctionMustHaveHaveNullParent, p0);
internal static string FunctionCallBinder_UriFunctionMustHaveHaveNullParent(object p0) {
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.FunctionCallBinder_UriFunctionMustHaveHaveNullParent, p0);
}

/// <summary>
Expand Down Expand Up @@ -5568,6 +5568,27 @@ internal static string FunctionOverloadResolver_FoundInvalidOperationImport(obje
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.FunctionOverloadResolver_FoundInvalidOperationImport, p0);
}

/// <summary>
/// A string like "The given custom function '{0}' already exists as a Built-In function. Consider use 'addAsOverloadToBuiltInFunction = true' parameter."
/// </summary>
internal static string CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload(object p0) {
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.CustomUriFunctions_AddCustomUriFunction_BuiltInExistsNotAddingAsOverload, p0);
}

/// <summary>
/// A string like "The given custom function '{0}' already exists as a Built-In function in one of it's overloads. Thus cannot override the Built-In function."
/// </summary>
internal static string CustomUriFunctions_AddCustomUriFunction_BuiltInExistsFullSignature(object p0) {
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.CustomUriFunctions_AddCustomUriFunction_BuiltInExistsFullSignature, p0);
}

/// <summary>
/// A string like "The given function name '{0}' already exists as a custom function with the same overload."
/// </summary>
internal static string CustomUriFunctions_AddCustomUriFunction_CustomFunctionOverloadExists(object p0) {
return Microsoft.OData.Core.TextRes.GetString(Microsoft.OData.Core.TextRes.CustomUriFunctions_AddCustomUriFunction_CustomFunctionOverloadExists, p0);
}

/// <summary>
/// A string like "The ODataPathSegment provided (Id = {0}) is not an EntitySetSegment."
/// </summary>
Expand Down
Loading

0 comments on commit f78ae27

Please sign in to comment.