diff --git a/docs-mdx/painless/painless-field-context.mdx b/docs-mdx/painless/painless-field-context.mdx new file mode 100644 index 0000000000000..8e3c38938b5b8 --- /dev/null +++ b/docs-mdx/painless/painless-field-context.mdx @@ -0,0 +1,136 @@ +--- +id: enElasticsearchPainlessPainlessFieldContext +slug: /en/elasticsearch/painless/painless-field-context +title: Field context +description: Description to be written +tags: [] +--- + +
+ +Use a Painless script to create a +[script field](((ref))/search-fields.html#script-fields) to return +a customized value for each document in the results of a query. + +**Variables** + +`params` (`Map`, read-only) + : User-defined parameters passed in as part of the query. + +`doc` (`Map`, read-only) + : Contains the fields of the specified document where each field is a + `List` of values. + +[`params['_source']`](((ref))/mapping-source-field.html) (`Map`, read-only) + : Contains extracted JSON in a `Map` and `List` structure for the fields + existing in a stored document. + +**Return** + +`Object` + : The customized value for each document. + +**API** + +Both the standard* bind(Service.class).toProvider(ServiceProvider.class);diff --git a/server/src/main/java/org/elasticsearch/common/inject/Binding.java b/server/src/main/java/org/elasticsearch/common/inject/Binding.java index 9f519e3daca0a..9bc446a867aa7 100644 --- a/server/src/main/java/org/elasticsearch/common/inject/Binding.java +++ b/server/src/main/java/org/elasticsearch/common/inject/Binding.java @@ -31,9 +31,7 @@ *
* bind(Service.class).annotatedWith(Red.class).to(ServiceImpl.class); * bindConstant().annotatedWith(ServerHost.class).to(args[0]);- *
- * Whenever Guice creates an instance, it performs this injection automatically (after first
- * performing constructor injection), so if you're able to let Guice create all your objects for
- * you, you'll never need to use this method.
- *
- * @param instance to inject members on. May be {@code null}.
- */
- void injectMembers(T instance);
-}
+public interface MembersInjector
* Your Module classes can use a more streamlined syntax by extending
* {@link AbstractModule} rather than implementing this interface directly.
- *
- * In addition to the bindings configured via {@link #configure}, bindings
- * will be created for all methods annotated with {@literal @}{@link Provides}.
- * Use scope and binding annotations on these methods to configure the
- * bindings.
*/
public interface Module {
@@ -36,8 +31,7 @@ public interface Module {
* Contributes bindings and other configurations for this module to {@code binder}.
*
* Do not invoke this method directly to install submodules. Instead use
- * {@link Binder#install(Module)}, which ensures that {@link Provides provider methods} are
- * discovered.
+ * {@link Binder#install(Module)}.
*/
void configure(Binder binder);
}
diff --git a/server/src/main/java/org/elasticsearch/common/inject/PrivateBinder.java b/server/src/main/java/org/elasticsearch/common/inject/PrivateBinder.java
index f1da98316465a..fd80e6271b2cf 100644
--- a/server/src/main/java/org/elasticsearch/common/inject/PrivateBinder.java
+++ b/server/src/main/java/org/elasticsearch/common/inject/PrivateBinder.java
@@ -24,11 +24,6 @@
*/
public interface PrivateBinder extends Binder {
- /**
- * Makes the binding for {@code key} available to the enclosing environment
- */
- void expose(Key> key);
-
@Override
PrivateBinder withSource(Object source);
diff --git a/server/src/main/java/org/elasticsearch/common/inject/ProvidedBy.java b/server/src/main/java/org/elasticsearch/common/inject/ProvidedBy.java
deleted file mode 100644
index 945de83cf9116..0000000000000
--- a/server/src/main/java/org/elasticsearch/common/inject/ProvidedBy.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2006 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.elasticsearch.common.inject;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * A pointer to the default provider type for a type.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-@Retention(RUNTIME)
-@Target(TYPE)
-public @interface ProvidedBy {
-
- /**
- * The implementation type.
- */
- Class extends Provider>> value();
-}
diff --git a/server/src/main/java/org/elasticsearch/common/inject/Provides.java b/server/src/main/java/org/elasticsearch/common/inject/Provides.java
deleted file mode 100644
index 587005f883574..0000000000000
--- a/server/src/main/java/org/elasticsearch/common/inject/Provides.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.elasticsearch.common.inject;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Annotates methods of a {@link Module} to create a provider method binding. The method's return
- * type is bound to its returned value. Guice will pass dependencies to the method as parameters.
- *
- * @author crazybob@google.com (Bob Lee)
- * @since 2.0
- */
-@Documented
-@Target(METHOD)
-@Retention(RUNTIME)
-public @interface Provides {
-}
diff --git a/server/src/main/java/org/elasticsearch/common/inject/SingleFieldInjector.java b/server/src/main/java/org/elasticsearch/common/inject/SingleFieldInjector.java
deleted file mode 100644
index 7e8bfed724d59..0000000000000
--- a/server/src/main/java/org/elasticsearch/common/inject/SingleFieldInjector.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.elasticsearch.common.inject;
-
-import org.elasticsearch.common.inject.internal.Errors;
-import org.elasticsearch.common.inject.internal.ErrorsException;
-import org.elasticsearch.common.inject.internal.InternalContext;
-import org.elasticsearch.common.inject.internal.InternalFactory;
-import org.elasticsearch.common.inject.spi.Dependency;
-import org.elasticsearch.common.inject.spi.InjectionPoint;
-
-import java.lang.reflect.Field;
-
-/**
- * Sets an injectable field.
- */
-class SingleFieldInjector implements SingleMemberInjector {
- final Field field;
- final InjectionPoint injectionPoint;
- final Dependency> dependency;
- final InternalFactory> factory;
-
- SingleFieldInjector(InjectorImpl injector, InjectionPoint injectionPoint, Errors errors) throws ErrorsException {
- this.injectionPoint = injectionPoint;
- this.field = (Field) injectionPoint.getMember();
- this.dependency = injectionPoint.getDependencies().get(0);
- factory = injector.getInternalFactory(dependency.getKey(), errors);
- }
-
- @Override
- public void inject(Errors errors, InternalContext context, Object o) {
- errors = errors.withSource(dependency);
-
- context.setDependency(dependency);
- try {
- Object value = factory.get(errors, context, dependency);
- field.set(o, value);
- } catch (ErrorsException e) {
- errors.withSource(injectionPoint).merge(e.getErrors());
- } catch (IllegalAccessException e) {
- throw new AssertionError(e); // a security manager is blocking us, we're hosed
- } finally {
- context.setDependency(null);
- }
- }
-}
diff --git a/server/src/main/java/org/elasticsearch/common/inject/SingleMemberInjector.java b/server/src/main/java/org/elasticsearch/common/inject/SingleMemberInjector.java
deleted file mode 100644
index a4e25f9fd000b..0000000000000
--- a/server/src/main/java/org/elasticsearch/common/inject/SingleMemberInjector.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.elasticsearch.common.inject;
-
-import org.elasticsearch.common.inject.internal.Errors;
-import org.elasticsearch.common.inject.internal.InternalContext;
-
-/**
- * Injects a field or method of a given object.
- */
-interface SingleMemberInjector {
- void inject(Errors errors, InternalContext context, Object o);
-
-}
diff --git a/server/src/main/java/org/elasticsearch/common/inject/SingleMethodInjector.java b/server/src/main/java/org/elasticsearch/common/inject/SingleMethodInjector.java
index f6d9a2eb2c396..d36bc1e623a99 100644
--- a/server/src/main/java/org/elasticsearch/common/inject/SingleMethodInjector.java
+++ b/server/src/main/java/org/elasticsearch/common/inject/SingleMethodInjector.java
@@ -16,7 +16,6 @@
package org.elasticsearch.common.inject;
-import org.elasticsearch.common.inject.InjectorImpl.MethodInvoker;
import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.internal.ErrorsException;
import org.elasticsearch.common.inject.internal.InternalContext;
@@ -28,19 +27,17 @@
/**
* Invokes an injectable method.
*/
-class SingleMethodInjector implements SingleMemberInjector {
- final MethodInvoker methodInvoker;
+class SingleMethodInjector {
+ final Method method;
final SingleParameterInjector>[] parameterInjectors;
final InjectionPoint injectionPoint;
SingleMethodInjector(InjectorImpl injector, InjectionPoint injectionPoint, Errors errors) throws ErrorsException {
this.injectionPoint = injectionPoint;
- final Method method = (Method) injectionPoint.getMember();
- methodInvoker = method::invoke;
+ method = (Method) injectionPoint.getMember();
parameterInjectors = injector.getParametersInjectors(injectionPoint.getDependencies(), errors);
}
- @Override
public void inject(Errors errors, InternalContext context, Object o) {
Object[] parameters;
try {
@@ -51,7 +48,7 @@ public void inject(Errors errors, InternalContext context, Object o) {
}
try {
- methodInvoker.invoke(o, parameters);
+ method.invoke(o, parameters);
} catch (IllegalAccessException e) {
throw new AssertionError(e); // a security manager is blocking us, we're hosed
} catch (InvocationTargetException userException) {
diff --git a/server/src/main/java/org/elasticsearch/common/inject/TypeLiteral.java b/server/src/main/java/org/elasticsearch/common/inject/TypeLiteral.java
index 72bf444d2dd3b..d39c4e44d2ff9 100644
--- a/server/src/main/java/org/elasticsearch/common/inject/TypeLiteral.java
+++ b/server/src/main/java/org/elasticsearch/common/inject/TypeLiteral.java
@@ -20,7 +20,6 @@
import org.elasticsearch.common.inject.util.Types;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
@@ -249,19 +248,6 @@ public TypeLiteral> getSupertype(Class> supertype) {
return resolve(MoreTypes.getGenericSupertype(type, rawType, supertype));
}
- /**
- * Returns the resolved generic type of {@code field}.
- *
- * @param field a field defined by this or any superclass.
- * @since 2.0
- */
- public TypeLiteral> getFieldType(Field field) {
- if (field.getDeclaringClass().isAssignableFrom(rawType) == false) {
- throw new IllegalArgumentException(field + " is not defined by a supertype of " + type);
- }
- return resolve(field.getGenericType());
- }
-
/**
* Returns the resolved generic parameter types of {@code methodOrConstructor}.
*
@@ -291,17 +277,4 @@ public List