Add static section whitelist info to api docs generation (#41870)

This change adds imported methods, class bindings, and instance bindings to the documentation generation for the Painless Context APIs.
This commit is contained in:
Jack Conradson 2019-05-08 10:29:02 -07:00
parent a2b7871f9f
commit 2c561481cd
14 changed files with 261 additions and 60 deletions

View File

@ -10,7 +10,7 @@
|Aggs Reduce | <<painless-api-reference-shared, Shared API>> |
|Analysis | <<painless-api-reference-shared, Shared API>> | <<painless-api-reference-analysis, Specialized API>>
|Bucket Aggregation | <<painless-api-reference-shared, Shared API>> |
|Field | <<painless-api-reference-shared, Shared API>> |
|Field | <<painless-api-reference-shared, Shared API>> | <<painless-api-reference-field, Specialized API>>
|Filter | <<painless-api-reference-shared, Shared API>> |
|Ingest | <<painless-api-reference-shared, Shared API>> | <<painless-api-reference-ingest, Specialized API>>
|Interval | <<painless-api-reference-shared, Shared API>> |
@ -33,6 +33,7 @@
include::painless-api-reference-shared/index.asciidoc[]
include::painless-api-reference-analysis/index.asciidoc[]
include::painless-api-reference-field/index.asciidoc[]
include::painless-api-reference-ingest/index.asciidoc[]
include::painless-api-reference-moving-function/index.asciidoc[]
include::painless-api-reference-score/index.asciidoc[]

View File

@ -7,6 +7,10 @@ The following specialized API is available in the Analysis context.
* See the <<painless-api-reference-shared, Shared API>> for further API available in all contexts.
==== Classes By Package
The following classes are available grouped by their respective packages. Click on a class to view details about the available methods and fields.
==== org.elasticsearch.analysis.common
<<painless-api-reference-analysis-org-elasticsearch-analysis-common, Expand details for org.elasticsearch.analysis.common>>

View File

@ -3,7 +3,7 @@
[role="exclude",id="painless-api-reference-analysis-org-elasticsearch-analysis-common"]
=== Analysis API for package org.elasticsearch.analysis.common
See the <<painless-api-reference-analysis, Analysis API>> for a high-level overview of all packages.
See the <<painless-api-reference-analysis, Analysis API>> for a high-level overview of all packages and classes.
[[painless-api-reference-analysis-AnalysisPredicateScript-Token]]
==== AnalysisPredicateScript.Token

View File

@ -0,0 +1,17 @@
// This file is auto-generated. Do not edit.
[[painless-api-reference-field]]
=== Field API
The following specialized API is available in the Field context.
* See the <<painless-api-reference-shared, Shared API>> for further API available in all contexts.
==== Static Methods
The following methods are directly callable without a class/instance qualifier. Note parameters denoted by a (*) are treated as read-only values.
* List domainSplit(String)
* List domainSplit(String, Map)
include::packages.asciidoc[]

View File

@ -0,0 +1,3 @@
// This file is auto-generated. Do not edit.

View File

@ -7,6 +7,10 @@ The following specialized API is available in the Ingest context.
* See the <<painless-api-reference-shared, Shared API>> for further API available in all contexts.
==== Classes By Package
The following classes are available grouped by their respective packages. Click on a class to view details about the available methods and fields.
==== org.elasticsearch.ingest.common
<<painless-api-reference-ingest-org-elasticsearch-ingest-common, Expand details for org.elasticsearch.ingest.common>>

View File

@ -3,7 +3,7 @@
[role="exclude",id="painless-api-reference-ingest-org-elasticsearch-ingest-common"]
=== Ingest API for package org.elasticsearch.ingest.common
See the <<painless-api-reference-ingest, Ingest API>> for a high-level overview of all packages.
See the <<painless-api-reference-ingest, Ingest API>> for a high-level overview of all packages and classes.
[[painless-api-reference-ingest-Processors]]
==== Processors

View File

@ -7,6 +7,10 @@ The following specialized API is available in the Moving Function context.
* See the <<painless-api-reference-shared, Shared API>> for further API available in all contexts.
==== Classes By Package
The following classes are available grouped by their respective packages. Click on a class to view details about the available methods and fields.
==== org.elasticsearch.search.aggregations.pipeline
<<painless-api-reference-moving-function-org-elasticsearch-search-aggregations-pipeline, Expand details for org.elasticsearch.search.aggregations.pipeline>>

View File

@ -3,7 +3,7 @@
[role="exclude",id="painless-api-reference-moving-function-org-elasticsearch-search-aggregations-pipeline"]
=== Moving Function API for package org.elasticsearch.search.aggregations.pipeline
See the <<painless-api-reference-moving-function, Moving Function API>> for a high-level overview of all packages.
See the <<painless-api-reference-moving-function, Moving Function API>> for a high-level overview of all packages and classes.
[[painless-api-reference-moving-function-MovingFunctions]]
==== MovingFunctions

View File

@ -7,6 +7,31 @@ The following specialized API is available in the Score context.
* See the <<painless-api-reference-shared, Shared API>> for further API available in all contexts.
==== Static Methods
The following methods are directly callable without a class/instance qualifier. Note parameters denoted by a (*) are treated as read-only values.
* double cosineSimilarity(List *, VectorScriptDocValues.DenseVectorScriptDocValues)
* double cosineSimilaritySparse(Map *, VectorScriptDocValues.SparseVectorScriptDocValues)
* double decayDateExp(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayDateGauss(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayDateLinear(String *, String *, String *, double *, JodaCompatibleZonedDateTime)
* double decayGeoExp(String *, String *, String *, double *, GeoPoint)
* double decayGeoGauss(String *, String *, String *, double *, GeoPoint)
* double decayGeoLinear(String *, String *, String *, double *, GeoPoint)
* double decayNumericExp(double *, double *, double *, double *, double)
* double decayNumericGauss(double *, double *, double *, double *, double)
* double decayNumericLinear(double *, double *, double *, double *, double)
* double dotProduct(List, VectorScriptDocValues.DenseVectorScriptDocValues)
* double dotProductSparse(Map *, VectorScriptDocValues.SparseVectorScriptDocValues)
* double randomScore(int *)
* double randomScore(int *, String *)
* double saturation(double, double)
* double sigmoid(double, double, double)
==== Classes By Package
The following classes are available grouped by their respective packages. Click on a class to view details about the available methods and fields.
==== org.elasticsearch.index.query
<<painless-api-reference-score-org-elasticsearch-index-query, Expand details for org.elasticsearch.index.query>>

View File

@ -3,7 +3,7 @@
[role="exclude",id="painless-api-reference-score-org-elasticsearch-index-query"]
=== Score API for package org.elasticsearch.index.query
See the <<painless-api-reference-score, Score API>> for a high-level overview of all packages.
See the <<painless-api-reference-score, Score API>> for a high-level overview of all packages and classes.
[[painless-api-reference-score-VectorScriptDocValues]]
==== VectorScriptDocValues

View File

@ -5,6 +5,10 @@
The following API is available in all contexts.
==== Classes By Package
The following classes are available grouped by their respective packages. Click on a class to view details about the available methods and fields.
==== java.lang
<<painless-api-reference-shared-java-lang, Expand details for java.lang>>

View File

@ -3,7 +3,7 @@
[role="exclude",id="painless-api-reference-shared-java-lang"]
=== Shared API for package java.lang
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-Appendable]]
==== Appendable
@ -1399,7 +1399,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-math"]
=== Shared API for package java.math
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-BigDecimal]]
==== BigDecimal
@ -1557,7 +1557,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-text"]
=== Shared API for package java.text
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-Annotation]]
==== Annotation
@ -2265,7 +2265,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-time"]
=== Shared API for package java.time
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-Clock]]
==== Clock
@ -3078,7 +3078,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-time-chrono"]
=== Shared API for package java.time.chrono
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-AbstractChronology]]
==== AbstractChronology
@ -3675,7 +3675,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-time-format"]
=== Shared API for package java.time.format
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-DateTimeFormatter]]
==== DateTimeFormatter
@ -3874,7 +3874,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-time-temporal"]
=== Shared API for package java.time.temporal
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-ChronoField]]
==== ChronoField
@ -4166,7 +4166,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-time-zone"]
=== Shared API for package java.time.zone
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-ZoneOffsetTransition]]
==== ZoneOffsetTransition
@ -4265,7 +4265,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-util"]
=== Shared API for package java.util
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-AbstractCollection]]
==== AbstractCollection
@ -7194,7 +7194,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-util-function"]
=== Shared API for package java.util.function
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-BiConsumer]]
==== BiConsumer
@ -7582,7 +7582,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-util-regex"]
=== Shared API for package java.util.regex
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-Matcher]]
==== Matcher
@ -7635,7 +7635,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-java-util-stream"]
=== Shared API for package java.util.stream
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-BaseStream]]
==== BaseStream
@ -7957,7 +7957,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-apache-lucene-util"]
=== Shared API for package org.apache.lucene.util
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-BytesRef]]
==== BytesRef
@ -7974,7 +7974,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-common-geo"]
=== Shared API for package org.elasticsearch.common.geo
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-GeoPoint]]
==== GeoPoint
@ -7987,7 +7987,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-index-fielddata"]
=== Shared API for package org.elasticsearch.index.fielddata
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-ScriptDocValues-Booleans]]
==== ScriptDocValues.Booleans
@ -8386,7 +8386,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-index-mapper"]
=== Shared API for package org.elasticsearch.index.mapper
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-IpFieldMapper-IpFieldType-IpScriptDocValues]]
==== IpFieldMapper.IpFieldType.IpScriptDocValues
@ -8445,7 +8445,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-index-query"]
=== Shared API for package org.elasticsearch.index.query
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-IntervalFilterScript-Interval]]
==== IntervalFilterScript.Interval
@ -8459,7 +8459,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-index-similarity"]
=== Shared API for package org.elasticsearch.index.similarity
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-ScriptedSimilarity-Doc]]
==== ScriptedSimilarity.Doc
@ -8499,7 +8499,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-painless-api"]
=== Shared API for package org.elasticsearch.painless.api
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-Debug]]
==== Debug
@ -8511,7 +8511,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-script"]
=== Shared API for package org.elasticsearch.script
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-JodaCompatibleZonedDateTime]]
==== JodaCompatibleZonedDateTime
@ -8594,7 +8594,7 @@ See the <<painless-api-reference-shared, Shared API>> for a high-level overview
[role="exclude",id="painless-api-reference-shared-org-elasticsearch-search-lookup"]
=== Shared API for package org.elasticsearch.search.lookup
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages.
See the <<painless-api-reference-shared, Shared API>> for a high-level overview of all packages and classes.
[[painless-api-reference-shared-FieldLookup]]
==== FieldLookup

View File

@ -24,10 +24,12 @@ import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.painless.action.PainlessContextClassBindingInfo;
import org.elasticsearch.painless.action.PainlessContextClassInfo;
import org.elasticsearch.painless.action.PainlessContextConstructorInfo;
import org.elasticsearch.painless.action.PainlessContextFieldInfo;
import org.elasticsearch.painless.action.PainlessContextInfo;
import org.elasticsearch.painless.action.PainlessContextInstanceBindingInfo;
import org.elasticsearch.painless.action.PainlessContextMethodInfo;
import java.io.IOException;
@ -69,26 +71,30 @@ public final class ContextDocGenerator {
public static void main(String[] args) throws IOException {
List<PainlessContextInfo> contextInfos = getContextInfos();
Set<PainlessContextClassInfo> sharedClassInfos = createShared(contextInfos);
Set<Object> sharedStaticInfos = createSharedStatics(contextInfos);
Set<PainlessContextClassInfo> sharedClassInfos = createSharedClasses(contextInfos);
Path rootDir = resetRootDir();
Path sharedDir = createSharedDir(rootDir);
List<PainlessContextClassInfo> classInfos = sortClassInfos(new ArrayList<>(sharedClassInfos), Collections.emptySet());
List<Object> staticInfos = sortStaticInfos(Collections.emptySet(), new ArrayList<>(sharedStaticInfos));
List<PainlessContextClassInfo> classInfos = sortClassInfos(Collections.emptySet(), new ArrayList<>(sharedClassInfos));
Map<String, String> javaNamesToDisplayNames = getDisplayNames(classInfos);
printSharedIndexPage(sharedDir, javaNamesToDisplayNames, classInfos);
printSharedIndexPage(sharedDir, javaNamesToDisplayNames, staticInfos, classInfos);
printSharedPackagesPages(sharedDir, javaNamesToDisplayNames, classInfos);
Set<PainlessContextInfo> isSpecialized = new HashSet<>();
for (PainlessContextInfo contextInfo : contextInfos) {
Path contextDir = createContextDir(rootDir, contextInfo);
classInfos = sortClassInfos(new ArrayList<>(contextInfo.getClasses()), sharedClassInfos);
staticInfos = createContextStatics(contextInfo);
staticInfos = sortStaticInfos(sharedStaticInfos, staticInfos);
classInfos = sortClassInfos(sharedClassInfos, new ArrayList<>(contextInfo.getClasses()));
if (classInfos.isEmpty() == false) {
if (staticInfos.isEmpty() == false || classInfos.isEmpty() == false) {
Path contextDir = createContextDir(rootDir, contextInfo);
isSpecialized.add(contextInfo);
javaNamesToDisplayNames = getDisplayNames(contextInfo.getClasses());
printContextIndexPage(contextDir, javaNamesToDisplayNames, sharedClassInfos, contextInfo, classInfos);
printContextIndexPage(contextDir, javaNamesToDisplayNames, contextInfo, staticInfos, classInfos);
printContextPackagesPages(contextDir, javaNamesToDisplayNames, sharedClassInfos, contextInfo, classInfos);
}
}
@ -123,12 +129,44 @@ public final class ContextDocGenerator {
return contextInfos;
}
private static Set<PainlessContextClassInfo> createShared(List<PainlessContextInfo> contextInfos) {
private static Set<Object> createSharedStatics(List<PainlessContextInfo> contextInfos) {
Map<Object, Integer> staticInfoCounts = new HashMap<>();
for (PainlessContextInfo contextInfo : contextInfos) {
for (PainlessContextMethodInfo methodInfo : contextInfo.getImportedMethods()) {
staticInfoCounts.merge(methodInfo, 1, Integer::sum);
}
for (PainlessContextClassBindingInfo classBindingInfo : contextInfo.getClassBindings()) {
staticInfoCounts.merge(classBindingInfo, 1, Integer::sum);
}
for (PainlessContextInstanceBindingInfo instanceBindingInfo : contextInfo.getInstanceBindings()) {
staticInfoCounts.merge(instanceBindingInfo, 1, Integer::sum);
}
}
return staticInfoCounts.entrySet().stream().filter(
e -> e.getValue() == contextInfos.size()
).map(Map.Entry::getKey).collect(Collectors.toSet());
}
private static List<Object> createContextStatics(PainlessContextInfo contextInfo) {
List<Object> staticInfos = new ArrayList<>();
staticInfos.addAll(contextInfo.getImportedMethods());
staticInfos.addAll(contextInfo.getClassBindings());
staticInfos.addAll(contextInfo.getInstanceBindings());
return staticInfos;
}
private static Set<PainlessContextClassInfo> createSharedClasses(List<PainlessContextInfo> contextInfos) {
Map<PainlessContextClassInfo, Integer> classInfoCounts = new HashMap<>();
for (PainlessContextInfo contextInfo : contextInfos) {
for (PainlessContextClassInfo classInfo : contextInfo.getClasses()) {
classInfoCounts.compute(classInfo, (k, v) -> v == null ? 1 : v + 1);
classInfoCounts.merge(classInfo, 1, Integer::sum);
}
}
@ -165,8 +203,8 @@ public final class ContextDocGenerator {
stream.println();
}
private static void printSharedIndexPage(
Path sharedDir, Map<String, String> javaNamesToDisplayNames, List<PainlessContextClassInfo> classInfos) throws IOException {
private static void printSharedIndexPage(Path sharedDir, Map<String, String> javaNamesToDisplayNames,
List<Object> staticInfos, List<PainlessContextClassInfo> classInfos) throws IOException {
Path sharedIndexPath = sharedDir.resolve("index.asciidoc");
@ -181,13 +219,12 @@ public final class ContextDocGenerator {
sharedIndexStream.println();
sharedIndexStream.println("The following API is available in all contexts.");
printIndex(sharedIndexStream, SHARED_HEADER, javaNamesToDisplayNames, Collections.emptySet(), classInfos);
printIndex(sharedIndexStream, SHARED_HEADER, javaNamesToDisplayNames, staticInfos, classInfos);
}
}
private static void printContextIndexPage(Path contextDir, Map<String, String> javaNamesToDisplayNames,
Set<PainlessContextClassInfo> excludes, PainlessContextInfo contextInfo, List<PainlessContextClassInfo> classInfos)
throws IOException {
PainlessContextInfo contextInfo, List<Object> staticInfos, List<PainlessContextClassInfo> classInfos) throws IOException {
Path contextIndexPath = contextDir.resolve("index.asciidoc");
@ -205,34 +242,58 @@ public final class ContextDocGenerator {
contextIndexStream.println(
"* See the <<" + SHARED_HEADER + ", " + SHARED_NAME + " API>> for further API available in all contexts.");
printIndex(contextIndexStream, getContextHeader(contextInfo), javaNamesToDisplayNames, excludes, classInfos);
printIndex(contextIndexStream, getContextHeader(contextInfo), javaNamesToDisplayNames, staticInfos, classInfos);
}
}
private static void printIndex(PrintStream indexStream, String contextHeader, Map<String, String> javaNamesToDisplayNames,
Set<PainlessContextClassInfo> excludes, List<PainlessContextClassInfo> classInfos) {
List<Object> staticInfos, List<PainlessContextClassInfo> classInfos) {
String currentPackageName = null;
for (PainlessContextClassInfo classInfo : classInfos) {
if (excludes.contains(classInfo)) {
continue;
if (staticInfos.isEmpty() == false) {
indexStream.println();
indexStream.println("==== Static Methods");
indexStream.println("The following methods are directly callable without a class/instance qualifier. " +
"Note parameters denoted by a (*) are treated as read-only values.");
indexStream.println();
for (Object staticInfo : staticInfos) {
if (staticInfo instanceof PainlessContextMethodInfo) {
printMethod(indexStream, javaNamesToDisplayNames, false, (PainlessContextMethodInfo)staticInfo);
} else if (staticInfo instanceof PainlessContextClassBindingInfo) {
printClassBinding(indexStream, javaNamesToDisplayNames, (PainlessContextClassBindingInfo)staticInfo);
} else if (staticInfo instanceof PainlessContextInstanceBindingInfo) {
printInstanceBinding(indexStream, javaNamesToDisplayNames, (PainlessContextInstanceBindingInfo)staticInfo);
} else {
throw new IllegalArgumentException("unexpected static info type");
}
}
}
String classPackageName = classInfo.getName().substring(0, classInfo.getName().lastIndexOf('.'));
if (classInfos.isEmpty() == false) {
indexStream.println();
indexStream.println("==== Classes By Package");
indexStream.println("The following classes are available grouped by their respective packages. Click on a class " +
"to view details about the available methods and fields.");
indexStream.println();
if (classPackageName.equals(currentPackageName) == false) {
currentPackageName = classPackageName;
for (PainlessContextClassInfo classInfo : classInfos) {
String classPackageName = classInfo.getName().substring(0, classInfo.getName().lastIndexOf('.'));
indexStream.println();
indexStream.println("==== " + currentPackageName);
indexStream.println("<<" + getPackageHeader(contextHeader, currentPackageName) + ", " +
"Expand details for " + currentPackageName + ">>");
indexStream.println();
if (classPackageName.equals(currentPackageName) == false) {
currentPackageName = classPackageName;
indexStream.println();
indexStream.println("==== " + currentPackageName);
indexStream.println("<<" + getPackageHeader(contextHeader, currentPackageName) + ", " +
"Expand details for " + currentPackageName + ">>");
indexStream.println();
}
String className = getType(javaNamesToDisplayNames, classInfo.getName());
indexStream.println("* <<" + getClassHeader(contextHeader, className) + ", " + className + ">>");
}
String className = getType(javaNamesToDisplayNames, classInfo.getName());
indexStream.println("* <<" + getClassHeader(contextHeader, className) + ", " + className + ">>");
}
indexStream.println();
@ -289,8 +350,8 @@ public final class ContextDocGenerator {
packagesStream.println();
packagesStream.println("[role=\"exclude\",id=\"" + getPackageHeader(contextHeader, currentPackageName) + "\"]");
packagesStream.println("=== " + contextName + " API for package " + currentPackageName);
packagesStream.println(
"See the <<" + contextHeader + ", " + contextName + " API>> for a high-level overview of all packages.");
packagesStream.println("See the <<" + contextHeader + ", " + contextName + " API>> " +
"for a high-level overview of all packages and classes.");
}
String className = getType(javaNamesToDisplayNames, classInfo.getName());
@ -421,6 +482,49 @@ public final class ContextDocGenerator {
stream.println(")");
}
private static void printClassBinding(
PrintStream stream, Map<String, String> javaNamesToDisplayNames, PainlessContextClassBindingInfo classBindingInfo) {
stream.print("* " + getType(javaNamesToDisplayNames, classBindingInfo.getRtn()) + " " + classBindingInfo.getName() + "(");
for (int parameterIndex = 0; parameterIndex < classBindingInfo.getParameters().size(); ++parameterIndex) {
// temporary fix to not print org.elasticsearch.script.ScoreScript parameter until
// class instance bindings are created and the information is appropriately added to the context info classes
if ("org.elasticsearch.script.ScoreScript".equals(
getType(javaNamesToDisplayNames, classBindingInfo.getParameters().get(parameterIndex)))) {
continue;
}
stream.print(getType(javaNamesToDisplayNames, classBindingInfo.getParameters().get(parameterIndex)));
if (parameterIndex < classBindingInfo.getReadOnly()) {
stream.print(" *");
}
if (parameterIndex + 1 < classBindingInfo.getParameters().size()) {
stream.print(", ");
}
}
stream.println(")");
}
private static void printInstanceBinding(
PrintStream stream, Map<String, String> javaNamesToDisplayNames, PainlessContextInstanceBindingInfo instanceBindingInfo) {
stream.print("* " + getType(javaNamesToDisplayNames, instanceBindingInfo.getRtn()) + " " + instanceBindingInfo.getName() + "(");
for (int parameterIndex = 0; parameterIndex < instanceBindingInfo.getParameters().size(); ++parameterIndex) {
stream.print(getType(javaNamesToDisplayNames, instanceBindingInfo.getParameters().get(parameterIndex)));
if (parameterIndex + 1 < instanceBindingInfo.getParameters().size()) {
stream.print(", ");
}
}
stream.println(")");
}
private static void printField(
PrintStream stream, Map<String, String> javaNamesToDisplayNames,
boolean isStatic, PainlessContextFieldInfo fieldInfo) {
@ -602,15 +706,50 @@ public final class ContextDocGenerator {
return contextNameBuilder.substring(0, contextNameBuilder.length() - 1);
}
private static List<Object> sortStaticInfos(Set<Object> staticExcludes, List<Object> staticInfos) {
staticInfos = new ArrayList<>(staticInfos);
staticInfos.removeIf(staticExcludes::contains);
staticInfos.sort((si1, si2) -> {
String sv1;
String sv2;
if (si1 instanceof PainlessContextMethodInfo) {
sv1 = ((PainlessContextMethodInfo)si1).getSortValue();
} else if (si1 instanceof PainlessContextClassBindingInfo) {
sv1 = ((PainlessContextClassBindingInfo)si1).getSortValue();
} else if (si1 instanceof PainlessContextInstanceBindingInfo) {
sv1 = ((PainlessContextInstanceBindingInfo)si1).getSortValue();
} else {
throw new IllegalArgumentException("unexpected static info type");
}
if (si2 instanceof PainlessContextMethodInfo) {
sv2 = ((PainlessContextMethodInfo)si2).getSortValue();
} else if (si2 instanceof PainlessContextClassBindingInfo) {
sv2 = ((PainlessContextClassBindingInfo)si2).getSortValue();
} else if (si2 instanceof PainlessContextInstanceBindingInfo) {
sv2 = ((PainlessContextInstanceBindingInfo)si2).getSortValue();
} else {
throw new IllegalArgumentException("unexpected static info type");
}
return sv1.compareTo(sv2);
});
return staticInfos;
}
private static List<PainlessContextClassInfo> sortClassInfos(
List<PainlessContextClassInfo> classInfos, Set<PainlessContextClassInfo> excludes) {
Set<PainlessContextClassInfo> classExcludes, List<PainlessContextClassInfo> classInfos) {
classInfos = new ArrayList<>(classInfos);
classInfos.removeIf(v ->
"void".equals(v.getName()) || "boolean".equals(v.getName()) || "byte".equals(v.getName()) ||
"short".equals(v.getName()) || "char".equals(v.getName()) || "int".equals(v.getName()) ||
"long".equals(v.getName()) || "float".equals(v.getName()) || "double".equals(v.getName()) ||
"org.elasticsearch.painless.lookup.def".equals(v.getName()) ||
isInternalClass(v.getName()) || excludes.contains(v)
isInternalClass(v.getName()) || classExcludes.contains(v)
);
classInfos.sort((c1, c2) -> {