Search in sources :

Example 6 with Struct

use of org.elasticsearch.painless.Definition.Struct in project elasticsearch by elastic.

the class NodeToStringTests method testPSubMapShortcut.

public void testPSubMapShortcut() {
    Location l = new Location(getTestName(), 0);
    Struct s = Definition.getType(Map.class.getSimpleName()).struct;
    PSubMapShortcut node = new PSubMapShortcut(l, s, new EConstant(l, "cat"));
    node.prefix = new EVariable(l, "a");
    assertEquals("(PSubMapShortcut (EVariable a) (EConstant String 'cat'))", node.toString());
    assertEquals("(PSubNullSafeCallInvoke (PSubMapShortcut (EVariable a) (EConstant String 'cat')))", new PSubNullSafeCallInvoke(l, node).toString());
    l = new Location(getTestName(), 1);
    s = Definition.getType(Map.class.getSimpleName()).struct;
    node = new PSubMapShortcut(l, s, new EBinary(l, Operation.ADD, new EConstant(l, 1), new EConstant(l, 4)));
    node.prefix = new EVariable(l, "a");
    assertEquals("(PSubMapShortcut (EVariable a) (EBinary (EConstant Integer 1) + (EConstant Integer 4)))", node.toString());
}
Also used : Map(java.util.Map) Location(org.elasticsearch.painless.Location) Struct(org.elasticsearch.painless.Definition.Struct)

Example 7 with Struct

use of org.elasticsearch.painless.Definition.Struct in project elasticsearch by elastic.

the class NodeToStringTests method testPSubShortcut.

public void testPSubShortcut() {
    Location l = new Location(getTestName(), 0);
    Struct s = Definition.getType(FeatureTest.class.getName()).struct;
    Method getter = s.methods.get(new MethodKey("getX", 0));
    Method setter = s.methods.get(new MethodKey("setX", 1));
    PSubShortcut node = new PSubShortcut(l, "x", FeatureTest.class.getName(), getter, setter);
    node.prefix = new EVariable(l, "a");
    assertEquals("(PSubShortcut (EVariable a) x)", node.toString());
    assertEquals("(PSubNullSafeCallInvoke (PSubShortcut (EVariable a) x))", new PSubNullSafeCallInvoke(l, node).toString());
}
Also used : FeatureTest(org.elasticsearch.painless.FeatureTest) Method(org.elasticsearch.painless.Definition.Method) Location(org.elasticsearch.painless.Location) Struct(org.elasticsearch.painless.Definition.Struct) MethodKey(org.elasticsearch.painless.Definition.MethodKey)

Example 8 with Struct

use of org.elasticsearch.painless.Definition.Struct in project elasticsearch by elastic.

the class NodeToStringTests method testPSubListShortcut.

public void testPSubListShortcut() {
    Location l = new Location(getTestName(), 0);
    Struct s = Definition.getType(List.class.getSimpleName()).struct;
    PSubListShortcut node = new PSubListShortcut(l, s, new EConstant(l, 1));
    node.prefix = new EVariable(l, "a");
    assertEquals("(PSubListShortcut (EVariable a) (EConstant Integer 1))", node.toString());
    assertEquals("(PSubNullSafeCallInvoke (PSubListShortcut (EVariable a) (EConstant Integer 1)))", new PSubNullSafeCallInvoke(l, node).toString());
    l = new Location(getTestName(), 0);
    s = Definition.getType(List.class.getSimpleName()).struct;
    node = new PSubListShortcut(l, s, new EBinary(l, Operation.ADD, new EConstant(l, 1), new EConstant(l, 4)));
    node.prefix = new EVariable(l, "a");
    assertEquals("(PSubListShortcut (EVariable a) (EBinary (EConstant Integer 1) + (EConstant Integer 4)))", node.toString());
}
Also used : Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Location(org.elasticsearch.painless.Location) Struct(org.elasticsearch.painless.Definition.Struct)

Aggregations

Struct (org.elasticsearch.painless.Definition.Struct)8 Method (org.elasticsearch.painless.Definition.Method)4 Location (org.elasticsearch.painless.Location)4 List (java.util.List)3 Map (java.util.Map)3 Field (org.elasticsearch.painless.Definition.Field)3 MethodKey (org.elasticsearch.painless.Definition.MethodKey)2 Type (org.elasticsearch.painless.Definition.Type)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Modifier (java.lang.reflect.Modifier)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1 Comparator.comparing (java.util.Comparator.comparing)1 TreeMap (java.util.TreeMap)1