diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt index b9e0e6525f6..412afc62dcf 100644 --- a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt +++ b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt @@ -240,30 +240,3 @@ class org.elasticsearch.index.query.IntervalFilterScript$Interval { int getEnd() int getGaps() } - -# for testing -class org.elasticsearch.painless.FeatureTest no_import { - int z - () - (int,int) - int getX() - int getY() - Integer getI() - void setX(int) - void setY(int) - void setI(Integer) - boolean overloadedStatic() - boolean overloadedStatic(boolean) - int staticNumberTest(Number) - Double mixedAdd(int, Byte, char, Float) - Object twoFunctionsOfX(Function,Function) - void listInput(List) - int org.elasticsearch.painless.FeatureTestAugmentation getTotal() - int org.elasticsearch.painless.FeatureTestAugmentation addToTotal(int) -} - -# for testing -static_import { - int staticAddIntsTest(int, int) from_class org.elasticsearch.painless.StaticTest - float staticAddFloatsTest(float, float) from_class org.elasticsearch.painless.FeatureTest -} diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java index 8618194028b..a0d1c5a5891 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java @@ -190,13 +190,13 @@ public class AugmentationTests extends ScriptTestCase { } public void testFeatureTest() { - assertEquals(5, exec("org.elasticsearch.painless.FeatureTest ft = new org.elasticsearch.painless.FeatureTest();" + + assertEquals(5, exec("org.elasticsearch.painless.FeatureTestObject ft = new org.elasticsearch.painless.FeatureTestObject();" + " ft.setX(3); ft.setY(2); return ft.getTotal()")); - assertEquals(5, exec("def ft = new org.elasticsearch.painless.FeatureTest();" + + assertEquals(5, exec("def ft = new org.elasticsearch.painless.FeatureTestObject();" + " ft.setX(3); ft.setY(2); return ft.getTotal()")); - assertEquals(8, exec("org.elasticsearch.painless.FeatureTest ft = new org.elasticsearch.painless.FeatureTest();" + + assertEquals(8, exec("org.elasticsearch.painless.FeatureTestObject ft = new org.elasticsearch.painless.FeatureTestObject();" + " ft.setX(3); ft.setY(2); return ft.addToTotal(3)")); - assertEquals(8, exec("def ft = new org.elasticsearch.painless.FeatureTest();" + + assertEquals(8, exec("def ft = new org.elasticsearch.painless.FeatureTestObject();" + " ft.setX(3); ft.setY(2); return ft.addToTotal(3)")); } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java index 6a775825117..371c3a5a3e5 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java @@ -127,7 +127,7 @@ public class BasicAPITests extends ScriptTestCase { } public void testPublicMemberAccess() { - assertEquals(5, exec("org.elasticsearch.painless.FeatureTest ft = new org.elasticsearch.painless.FeatureTest();" + + assertEquals(5, exec("org.elasticsearch.painless.FeatureTestObject ft = new org.elasticsearch.painless.FeatureTestObject();" + "ft.z = 5; return ft.z;")); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicExpressionTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicExpressionTests.java index b729c6769c5..4269a93e4dc 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicExpressionTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicExpressionTests.java @@ -191,11 +191,11 @@ public class BasicExpressionTests extends ScriptTestCase { assertNull( exec("def a = null; return a?.length()")); assertEquals(3, exec("def a = 'foo'; return a?.length()")); // Read shortcut - assertMustBeNullable( "org.elasticsearch.painless.FeatureTest a = null; return a?.x"); + assertMustBeNullable( "org.elasticsearch.painless.FeatureTestObject a = null; return a?.x"); assertMustBeNullable( - "org.elasticsearch.painless.FeatureTest a = new org.elasticsearch.painless.FeatureTest(); return a?.x"); + "org.elasticsearch.painless.FeatureTestObject a = new org.elasticsearch.painless.FeatureTestObject(); return a?.x"); assertNull( exec("def a = null; return a?.x")); - assertEquals(0, exec("def a = new org.elasticsearch.painless.FeatureTest(); return a?.x")); + assertEquals(0, exec("def a = new org.elasticsearch.painless.FeatureTestObject(); return a?.x")); // Maps // Call @@ -222,7 +222,7 @@ public class BasicExpressionTests extends ScriptTestCase { assertEquals(2, exec("def a = new int[] {2, 3}; return a?.length")); // Results from maps (should just work but let's test anyway) - FeatureTest t = new FeatureTest(); + FeatureTestObject t = new FeatureTestObject(); assertNull( exec("Map a = ['thing': params.t]; return a.other?.getX()", singletonMap("t", t), true)); assertNull( exec("Map a = ['thing': params.t]; return a.other?.x", singletonMap("t", t), true)); assertNull( exec("def a = ['thing': params.t]; return a.other?.getX()", singletonMap("t", t), true)); @@ -254,8 +254,8 @@ public class BasicExpressionTests extends ScriptTestCase { + "return a.missing_length", true)); // Writes, all unsupported at this point -// assertEquals(null, exec("org.elasticsearch.painless.FeatureTest a = null; return a?.x")); // Read field -// assertEquals(null, exec("org.elasticsearch.painless.FeatureTest a = null; a?.x = 7; return a?.x")); // Write field +// assertEquals(null, exec("org.elasticsearch.painless.FeatureTestObject a = null; return a?.x")); // Read field +// assertEquals(null, exec("org.elasticsearch.painless.FeatureTestObject a = null; a?.x = 7; return a?.x")); // Write field // assertEquals(null, exec("Map a = null; a?.other = 'wow'; return a?.other")); // Write shortcut // assertEquals(null, exec("def a = null; a?.other = 'cat'; return a?.other")); // Write shortcut // assertEquals(null, exec("Map a = ['thing': 'bar']; a.other?.cat = 'no'; return a.other?.cat")); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FeatureTestAugmentation.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FeatureTestAugmentationObject.java similarity index 81% rename from modules/lang-painless/src/main/java/org/elasticsearch/painless/FeatureTestAugmentation.java rename to modules/lang-painless/src/test/java/org/elasticsearch/painless/FeatureTestAugmentationObject.java index c1ea19defb9..ca9fef97df2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FeatureTestAugmentation.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FeatureTestAugmentationObject.java @@ -19,14 +19,14 @@ package org.elasticsearch.painless; -public class FeatureTestAugmentation { - public static int getTotal(FeatureTest ft) { +public class FeatureTestAugmentationObject { + public static int getTotal(FeatureTestObject ft) { return ft.getX() + ft.getY(); } - public static int addToTotal(FeatureTest ft, int add) { + public static int addToTotal(FeatureTestObject ft, int add) { return getTotal(ft) + add; } - private FeatureTestAugmentation() {} + private FeatureTestAugmentationObject() {} } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FeatureTest.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FeatureTestObject.java similarity index 95% rename from modules/lang-painless/src/main/java/org/elasticsearch/painless/FeatureTest.java rename to modules/lang-painless/src/test/java/org/elasticsearch/painless/FeatureTestObject.java index 8806a388745..59a1a62d7b8 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/FeatureTest.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FeatureTestObject.java @@ -23,7 +23,7 @@ import java.util.function.Function; */ /** Currently just a dummy class for testing a few features not yet exposed by whitelist! */ -public class FeatureTest { +public class FeatureTestObject { /** static method that returns true */ public static boolean overloadedStatic() { return true; @@ -51,11 +51,11 @@ public class FeatureTest { private Integer i; /** empty ctor */ - public FeatureTest() { + public FeatureTestObject() { } /** ctor with params */ - public FeatureTest(int x, int y) { + public FeatureTestObject(int x, int y) { this.x = x; this.y = y; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java index 96360a62868..2aa6be428ee 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java @@ -46,12 +46,12 @@ public class FunctionRefTests extends ScriptTestCase { public void testQualifiedStaticMethodReference() { assertEquals(true, - exec("List l = [true]; l.stream().map(org.elasticsearch.painless.FeatureTest::overloadedStatic).findFirst().get()")); + exec("List l = [true]; l.stream().map(org.elasticsearch.painless.FeatureTestObject::overloadedStatic).findFirst().get()")); } public void testQualifiedStaticMethodReferenceDef() { assertEquals(true, - exec("def l = [true]; l.stream().map(org.elasticsearch.painless.FeatureTest::overloadedStatic).findFirst().get()")); + exec("def l = [true]; l.stream().map(org.elasticsearch.painless.FeatureTestObject::overloadedStatic).findFirst().get()")); } public void testQualifiedVirtualMethodReference() { @@ -133,7 +133,7 @@ public class FunctionRefTests extends ScriptTestCase { assertEquals("testingcdefg", exec( "String x = 'testing';" + "String y = 'abcdefg';" + - "org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" + + "org.elasticsearch.painless.FeatureTestObject test = new org.elasticsearch.painless.FeatureTestObject(2,3);" + "return test.twoFunctionsOfX(x::concat, y::substring);")); } @@ -141,7 +141,7 @@ public class FunctionRefTests extends ScriptTestCase { assertEquals("testingcdefg", exec( "def x = 'testing';" + "def y = 'abcdefg';" + - "org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" + + "org.elasticsearch.painless.FeatureTestObject test = new org.elasticsearch.painless.FeatureTestObject(2,3);" + "return test.twoFunctionsOfX(x::concat, y::substring);")); } @@ -149,7 +149,7 @@ public class FunctionRefTests extends ScriptTestCase { assertEquals("testingcdefg", exec( "String x = 'testing';" + "String y = 'abcdefg';" + - "def test = new org.elasticsearch.painless.FeatureTest(2,3);" + + "def test = new org.elasticsearch.painless.FeatureTestObject(2,3);" + "return test.twoFunctionsOfX(x::concat, y::substring);")); } @@ -157,7 +157,7 @@ public class FunctionRefTests extends ScriptTestCase { assertEquals("testingcdefg", exec( "def x = 'testing';" + "def y = 'abcdefg';" + - "def test = new org.elasticsearch.painless.FeatureTest(2,3);" + + "def test = new org.elasticsearch.painless.FeatureTestObject(2,3);" + "return test.twoFunctionsOfX(x::concat, y::substring);")); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/GeneralCastTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/GeneralCastTests.java index 353146211f3..f1bb849b20c 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/GeneralCastTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/GeneralCastTests.java @@ -333,15 +333,15 @@ public class GeneralCastTests extends ScriptTestCase { assertEquals(1, exec("def y = 2.0; y.compareTo(1);")); assertEquals(1, exec("int x = 1; def y = 2.0; y.compareTo(x);")); assertEquals(-1, exec("Integer x = Integer.valueOf(3); def y = 2.0; y.compareTo(x);")); - assertEquals(2, exec("def f = new org.elasticsearch.painless.FeatureTest(); f.i = (byte)2; f.i")); + assertEquals(2, exec("def f = new org.elasticsearch.painless.FeatureTestObject(); f.i = (byte)2; f.i")); assertEquals(4.0, exec( - "def x = new org.elasticsearch.painless.FeatureTest(); " + + "def x = new org.elasticsearch.painless.FeatureTestObject(); " + "Byte i = Byte.valueOf(3); " + "byte j = 1;" + "Short s = Short.valueOf(-2);" + "x.mixedAdd(j, i, (char)2, s)" )); - assertNull(exec("def f = new org.elasticsearch.painless.FeatureTest(); f.i = null; f.i")); + assertNull(exec("def f = new org.elasticsearch.painless.FeatureTestObject(); f.i = null; f.i")); expectScriptThrows(ClassCastException.class, () -> exec("def x = 2.0; def y = 1; y.compareTo(x);")); expectScriptThrows(ClassCastException.class, () -> exec("float f = 1.0f; def y = 1; y.compareTo(f);")); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index 184e97c4a47..e55edc123c8 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -112,7 +112,7 @@ public class LambdaTests extends ScriptTestCase { public void testTwoLambdas() { assertEquals("testingcdefg", exec( - "org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" + + "org.elasticsearch.painless.FeatureTestObject test = new org.elasticsearch.painless.FeatureTestObject(2,3);" + "return test.twoFunctionsOfX(x -> 'testing'.concat(x), y -> 'abcdefg'.substring(y))")); } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/OverloadTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/OverloadTests.java index 52c28799fae..24abc840868 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/OverloadTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/OverloadTests.java @@ -41,14 +41,14 @@ public class OverloadTests extends ScriptTestCase { } public void testConstructor() { - assertEquals(true, exec("org.elasticsearch.painless.FeatureTest f = new org.elasticsearch.painless.FeatureTest();" + + assertEquals(true, exec("org.elasticsearch.painless.FeatureTestObject f = new org.elasticsearch.painless.FeatureTestObject();" + "return f.x == 0 && f.y == 0;")); - assertEquals(true, exec("org.elasticsearch.painless.FeatureTest f = new org.elasticsearch.painless.FeatureTest(1, 2);" + + assertEquals(true, exec("org.elasticsearch.painless.FeatureTestObject f = new org.elasticsearch.painless.FeatureTestObject(1, 2);" + "return f.x == 1 && f.y == 2;")); } public void testStatic() { - assertEquals(true, exec("return org.elasticsearch.painless.FeatureTest.overloadedStatic();")); - assertEquals(false, exec("return org.elasticsearch.painless.FeatureTest.overloadedStatic(false);")); + assertEquals(true, exec("return org.elasticsearch.painless.FeatureTestObject.overloadedStatic();")); + assertEquals(false, exec("return org.elasticsearch.painless.FeatureTestObject.overloadedStatic(false);")); } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessDocGenerator.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessDocGenerator.java index ac76a8c0408..c1ba6bfbe1c 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessDocGenerator.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessDocGenerator.java @@ -19,8 +19,8 @@ package org.elasticsearch.painless; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.painless.lookup.PainlessClass; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java index 37b3c3d8cb8..0f04fa92194 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java @@ -22,14 +22,14 @@ package org.elasticsearch.painless; import junit.framework.AssertionFailedError; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.painless.antlr.Walker; -import org.elasticsearch.painless.lookup.PainlessLookup; -import org.elasticsearch.painless.lookup.PainlessLookupBuilder; import org.elasticsearch.painless.spi.Whitelist; +import org.elasticsearch.painless.spi.WhitelistLoader; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptException; import org.elasticsearch.test.ESTestCase; import org.junit.Before; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -45,8 +45,6 @@ import static org.hamcrest.Matchers.hasSize; * Typically just asserts the output of {@code exec()} */ public abstract class ScriptTestCase extends ESTestCase { - private static final PainlessLookup PAINLESS_LOOKUP = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS); - protected PainlessScriptEngine scriptEngine; @Before @@ -66,7 +64,9 @@ public abstract class ScriptTestCase extends ESTestCase { */ protected Map, List> scriptContexts() { Map, List> contexts = new HashMap<>(); - contexts.put(PainlessTestScript.CONTEXT, Whitelist.BASE_WHITELISTS); + List whitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); + contexts.put(PainlessTestScript.CONTEXT, whitelists); return contexts; } @@ -91,12 +91,13 @@ public abstract class ScriptTestCase extends ESTestCase { public Object exec(String script, Map vars, Map compileParams, boolean picky) { // test for ambiguity errors before running the actual script if picky is true if (picky) { - ScriptClassInfo scriptClassInfo = new ScriptClassInfo(PAINLESS_LOOKUP, PainlessTestScript.class); + ScriptClassInfo scriptClassInfo = + new ScriptClassInfo(scriptEngine.getContextsToLookups().get(PainlessTestScript.CONTEXT), PainlessTestScript.class); CompilerSettings pickySettings = new CompilerSettings(); pickySettings.setPicky(true); pickySettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(scriptEngineSettings())); - Walker.buildPainlessTree( - scriptClassInfo, new MainMethodReserved(), getTestName(), script, pickySettings, PAINLESS_LOOKUP, null); + Walker.buildPainlessTree(scriptClassInfo, new MainMethodReserved(), getTestName(), script, pickySettings, + scriptEngine.getContextsToLookups().get(PainlessTestScript.CONTEXT), null); } // test actual script execution PainlessTestScript.Factory factory = scriptEngine.compile(null, script, PainlessTestScript.CONTEXT, compileParams); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/StaticTest.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/StaticTestObject.java similarity index 96% rename from modules/lang-painless/src/main/java/org/elasticsearch/painless/StaticTest.java rename to modules/lang-painless/src/test/java/org/elasticsearch/painless/StaticTestObject.java index 4a4f27b8f21..fc805317850 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/StaticTest.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/StaticTestObject.java @@ -19,7 +19,7 @@ package org.elasticsearch.painless; -public class StaticTest { +public class StaticTestObject { public static int staticAddIntsTest(int x, int y) { return x + y; } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/node/NodeToStringTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/node/NodeToStringTests.java index 08a5d0cb5fd..1b39b56286b 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/node/NodeToStringTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/node/NodeToStringTests.java @@ -20,12 +20,12 @@ package org.elasticsearch.painless.node; import org.elasticsearch.painless.CompilerSettings; -import org.elasticsearch.painless.FeatureTest; +import org.elasticsearch.painless.FeatureTestObject; import org.elasticsearch.painless.Locals.Variable; import org.elasticsearch.painless.Location; import org.elasticsearch.painless.Operation; -import org.elasticsearch.painless.action.PainlessExecuteAction.PainlessTestScript; import org.elasticsearch.painless.ScriptClassInfo; +import org.elasticsearch.painless.action.PainlessExecuteAction.PainlessTestScript; import org.elasticsearch.painless.antlr.Walker; import org.elasticsearch.painless.lookup.PainlessCast; import org.elasticsearch.painless.lookup.PainlessClass; @@ -35,8 +35,10 @@ import org.elasticsearch.painless.lookup.PainlessLookupBuilder; import org.elasticsearch.painless.lookup.PainlessLookupUtility; import org.elasticsearch.painless.lookup.PainlessMethod; import org.elasticsearch.painless.spi.Whitelist; +import org.elasticsearch.painless.spi.WhitelistLoader; import org.elasticsearch.test.ESTestCase; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -49,7 +51,6 @@ import static org.elasticsearch.painless.node.SSource.MainMethodReserved; * Tests {@link Object#toString} implementations on all extensions of {@link ANode}. */ public class NodeToStringTests extends ESTestCase { - private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS); public void testEAssignment() { assertToString( @@ -379,10 +380,11 @@ public class NodeToStringTests extends ESTestCase { + "return a.length"); assertToString( "(SSource\n" - + " (SDeclBlock (SDeclaration org.elasticsearch.painless.FeatureTest a (ENewObj org.elasticsearch.painless.FeatureTest)))\n" + + " (SDeclBlock (SDeclaration org.elasticsearch.painless.FeatureTestObject a" + + " (ENewObj org.elasticsearch.painless.FeatureTestObject)))\n" + " (SExpression (EAssignment (PField (EVariable a) x) = (ENumeric 10)))\n" + " (SReturn (PField (EVariable a) x)))", - "org.elasticsearch.painless.FeatureTest a = new org.elasticsearch.painless.FeatureTest();\n" + "org.elasticsearch.painless.FeatureTestObject a = new org.elasticsearch.painless.FeatureTestObject();\n" + "a.x = 10;\n" + "return a.x"); } @@ -497,10 +499,10 @@ public class NodeToStringTests extends ESTestCase { public void testPSubShortcut() { Location l = new Location(getTestName(), 0); - PainlessClass s = painlessLookup.lookupPainlessClass(FeatureTest.class); + PainlessClass s = painlessLookup.lookupPainlessClass(FeatureTestObject.class); PainlessMethod getter = s.methods.get(PainlessLookupUtility.buildPainlessMethodKey("getX", 0)); PainlessMethod setter = s.methods.get(PainlessLookupUtility.buildPainlessMethodKey("setX", 1)); - PSubShortcut node = new PSubShortcut(l, "x", FeatureTest.class.getName(), getter, setter); + PSubShortcut node = new PSubShortcut(l, "x", FeatureTestObject.class.getName(), getter, setter); node.prefix = new EVariable(l, "a"); assertEquals("(PSubShortcut (EVariable a) x)", node.toString()); assertEquals("(PSubNullSafeCallInvoke (PSubShortcut (EVariable a) x))", @@ -892,6 +894,14 @@ public class NodeToStringTests extends ESTestCase { + "}"); } + private final PainlessLookup painlessLookup; + + public NodeToStringTests() { + List whitelists = new ArrayList<>(Whitelist.BASE_WHITELISTS); + whitelists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.elasticsearch.painless.test")); + painlessLookup = PainlessLookupBuilder.buildFromWhitelists(whitelists); + } + private void assertToString(String expected, String code) { assertEquals(expected, walk(code).toString()); } diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.test b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.test index 71a0c0240f7..37faf50a701 100644 --- a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.test +++ b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/spi/org.elasticsearch.painless.test @@ -2,7 +2,29 @@ class org.elasticsearch.painless.BindingsTests$BindingsTestScript { } +class org.elasticsearch.painless.FeatureTestObject no_import { + int z + () + (int,int) + int getX() + int getY() + Integer getI() + void setX(int) + void setY(int) + void setI(Integer) + boolean overloadedStatic() + boolean overloadedStatic(boolean) + int staticNumberTest(Number) + Double mixedAdd(int, Byte, char, Float) + Object twoFunctionsOfX(Function,Function) + void listInput(List) + int org.elasticsearch.painless.FeatureTestAugmentationObject getTotal() + int org.elasticsearch.painless.FeatureTestAugmentationObject addToTotal(int) +} + static_import { + int staticAddIntsTest(int, int) from_class org.elasticsearch.painless.StaticTestObject + float staticAddFloatsTest(float, float) from_class org.elasticsearch.painless.FeatureTestObject int addWithState(int, int, int, double) bound_to org.elasticsearch.painless.BindingsTests$BindingTestClass int addThisWithState(BindingsTests.BindingsTestScript, int, int, int, double) bound_to org.elasticsearch.painless.BindingsTests$ThisBindingTestClass int addEmptyThisWithState(BindingsTests.BindingsTestScript, int) bound_to org.elasticsearch.painless.BindingsTests$EmptyThisBindingTestClass