Skip to content

Commit 1b3e4be

Browse files
committed
Return of the <inheritdoc /> (#2379)
* reimplemented <inheritdoc /> * rename target file and make inheritdoc part of normal build
1 parent d984dc0 commit 1b3e4be

File tree

6 files changed

+114
-33
lines changed

6 files changed

+114
-33
lines changed

build/scripts/InheritDoc.fsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

build/scripts/Paths.fsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module Projects =
2929

3030
type PrivateProject =
3131
| Tests
32+
33+
3234

3335
type DotNetProject =
3436
| Project of Project
@@ -58,6 +60,13 @@ module Projects =
5860
DotNetProject.All
5961
|> Seq.map(fun p -> p.Name)
6062
|> Seq.tryFind(fun p -> p.ToLowerInvariant() = name.ToLowerInvariant())
63+
64+
type DotNetFrameworkProject = { framework: DotNetFramework; project: DotNetProject }
65+
let AllPublishableProjectsWithSupportedFrameworks = seq {
66+
for framework in DotNetFramework.All do
67+
for project in DotNetProject.AllPublishable do
68+
yield { framework = framework; project= project}
69+
}
6170

6271

6372
module Paths =
@@ -71,7 +80,7 @@ module Paths =
7180

7281
let ProjectOutputFolder (project:DotNetProject) (framework:DotNetFramework) =
7382
sprintf "%s/%s/%s" BuildOutput framework.Identifier.MSBuild project.Name
74-
83+
7584
let Tool tool = sprintf "packages/build/%s" tool
7685
let CheckedInToolsFolder = "build/Tools"
7786
let KeysFolder = sprintf "%s/keys" BuildFolder

build/scripts/Targets.fsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#load @"Documentation.fsx"
77
#load @"Releasing.fsx"
88
#load @"Profiling.fsx"
9+
#load @"XmlDocPatcher.fsx"
910

1011
open System
1112

@@ -17,6 +18,7 @@ open Signing
1718
open Versioning
1819
open Releasing
1920
open Profiling
21+
open XmlDocPatcher
2022

2123
// Default target
2224
Target "Build" <| fun _ -> traceHeader "STARTING BUILD"
@@ -27,6 +29,8 @@ Target "BuildApp" <| fun _ -> Build.Compile()
2729

2830
Target "Test" <| fun _ -> Tests.RunUnitTests()
2931

32+
Target "InheritDoc" <| fun _ -> InheritDoc.patchInheritDocs()
33+
3034
Target "TestForever" <| fun _ -> Tests.RunUnitTestsForever()
3135

3236
Target "QuickTest" <| fun _ -> Tests.RunUnitTests()
@@ -59,6 +63,7 @@ Target "Canary" <| fun _ ->
5963
=?> ("Version", hasBuildParam "version")
6064
==> "BuildApp"
6165
=?> ("Test", (not ((getBuildParam "skiptests") = "1")))
66+
==> "InheritDoc"
6267
==> "Build"
6368

6469
"Clean"

build/scripts/XmlDocPatcher.fsx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#I @"../../packages/build/FAKE/tools"
2+
#r @"FakeLib.dll"
3+
#r "System.Xml.Linq.dll"
4+
5+
#load @"Paths.fsx"
6+
7+
namespace XmlDocPatcher
8+
9+
open System.Linq
10+
open System.Text.RegularExpressions
11+
open System.Xml
12+
open System.Xml.Linq
13+
open System.Xml.XPath
14+
15+
open Paths
16+
open Projects
17+
open Fake
18+
19+
20+
module InheritDoc =
21+
22+
let private apiName n = Regex.Replace(n, @"^\w\:(.+?)(?:\(.+$|$)", "$1")
23+
let private relatedInterface n = Regex.Replace(n, @"\.([^.]+\.[^.]+)$", ".I$1")
24+
let private relatedInterfaceAsync n = (relatedInterface n).Replace("Async", "")
25+
let private relatedInterfaceDescriptor n = Regex.Replace(n, @"\.([^.]+)Descriptor\.([^.]+)$", ".I$1.$2")
26+
let private relatedInterfaceDescriptorRequest n = Regex.Replace(n, @"\.([^.]+)Descriptor\.([^.]+)$", ".I$1Request.$2")
27+
let private relatedInterfaceDescriptorGeneric n = Regex.Replace(n, @"\.([^.]+)Descriptor[^.]+.([^.]+)$", ".I$1.$2")
28+
let private manualMapping (n : string) =
29+
//this sucks but untill roslyn gets coderewriting API's this is the best we got without making it
30+
//a bigger thing than it already is
31+
match n with
32+
| n when n.Contains("PutMapping") -> n.Replace("PutMapping", "TypeMapping")
33+
| _ -> n
34+
let private relatedApiLookups = [
35+
relatedInterface;
36+
relatedInterfaceAsync;
37+
relatedInterfaceDescriptor;
38+
relatedInterfaceDescriptorRequest;
39+
relatedInterfaceDescriptorGeneric;
40+
manualMapping
41+
];
42+
43+
let private documentedApis = fun (file : string) ->
44+
use reader = XmlReader.Create file
45+
seq {
46+
while reader.ReadToFollowing("member") do
47+
let name = apiName(reader.GetAttribute("name"))
48+
let innerXml = reader.ReadInnerXml().Trim();
49+
if (isNotNullOrEmpty innerXml && not (innerXml.Contains("<inheritdoc"))) then
50+
let xdoc = XDocument.Parse("<x>" + innerXml + "</x>")
51+
yield (name, xdoc)
52+
} |> Map.ofSeq
53+
54+
let private patchInheritDoc = fun file ->
55+
traceFAKE "Rewriting xmldoc: %s" file
56+
57+
let mapOfDocumentedApis = documentedApis file
58+
59+
let findDocumentation (apiElement:string) =
60+
relatedApiLookups
61+
|> Seq.map (fun f -> f apiElement)
62+
|> (Seq.map <| mapOfDocumentedApis.TryFind)
63+
|> Seq.choose id
64+
|> Seq.tryHead
65+
66+
let xml = XDocument.Load file
67+
68+
xml.XPathSelectElements("//inheritdoc")
69+
|> Seq.iter (fun inheritDocElement ->
70+
let parent =inheritDocElement.Parent
71+
let name = apiName (parent.Attribute(XName.Get "name").Value)
72+
let documentation = findDocumentation name
73+
74+
match documentation with
75+
| Some d ->
76+
let elements = d.Element(XName.Get("x")).Elements().ToList();
77+
inheritDocElement.AddBeforeSelf(elements)
78+
| _ ->
79+
//unignore the following to find undocumented/badly inherited methods
80+
//tracefn "not inherited: %s" apiElement
81+
ignore()
82+
)
83+
84+
use writer = new XmlTextWriter(file,null)
85+
writer.Formatting <- Formatting.Indented;
86+
xml.Save(writer);
87+
88+
let patchInheritDocs = fun () ->
89+
AllPublishableProjectsWithSupportedFrameworks
90+
|> Seq.map (fun p ->
91+
let folder = Paths.ProjectOutputFolder p.project p.framework
92+
folder @@ p.project.Name + ".xml"
93+
)
94+
|> Seq.filter fileExists
95+
|> Seq.iter patchInheritDoc

build/scripts/scripts.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<None Include="Releasing.fsx" />
6666
<None Include="Versioning.fsx" />
6767
<None Include="Profiling.fsx" />
68-
<None Include="InheritDoc.fsx" />
68+
<None Include="XmlDocPatcher.fsx" />
6969
<None Include="Building.fsx" />
7070
<None Include="Signing.fsx" />
7171
<None Include="Testing.fsx" />
@@ -85,4 +85,4 @@
8585
<Private>True</Private>
8686
</Reference>
8787
</ItemGroup>
88-
</Project>
88+
</Project>

src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class CommonTermsQuery : FieldNameQueryBase, ICommonTermsQuery
4646
internal static bool IsConditionless(ICommonTermsQuery q) => q.Field.IsConditionless() || q.Query.IsNullOrEmpty();
4747
}
4848

49-
public class CommonTermsQueryDescriptor<T>
49+
public class CommonTermsQueryDescriptor<T>
5050
: FieldNameQueryDescriptorBase<CommonTermsQueryDescriptor<T>, ICommonTermsQuery, T>
51-
, ICommonTermsQuery
51+
, ICommonTermsQuery
5252
where T : class
5353
{
5454
string IQuery.Name { get; set; }

0 commit comments

Comments
 (0)