package com.hubspot.jinjava.el.ext;

import de.odysseus.el.misc.TypeConverter;
import de.odysseus.el.tree.impl.Parser.ExtensionHandler;
import de.odysseus.el.tree.impl.Parser.ExtensionPoint;
import de.odysseus.el.tree.impl.Scanner;
import de.odysseus.el.tree.impl.ast.AstBinary;
import de.odysseus.el.tree.impl.ast.AstBinary.SimpleOperator;
import de.odysseus.el.tree.impl.ast.AstNode;
import java.util.Collection;
import java.util.Objects;
import javax.el.ELException;
import org.apache.commons.lang3.StringUtils;

public class CollectionMembershipOperator extends SimpleOperator {

  @Override
  public Object apply(TypeConverter converter, Object o1, Object o2) {
    if (o2 == null) {
      return Boolean.FALSE;
    }

    if (CharSequence.class.isAssignableFrom(o2.getClass())) {
      return StringUtils.contains((CharSequence) o2, Objects.toString(o1, ""));
    }

    if (Collection.class.isAssignableFrom(o2.getClass())) {
      Collection<?> collection = (Collection<?>) o2;

      for (Object value : collection) {
        if (value == null) {
          if (o1 == null) {
            return Boolean.TRUE;
          }
        } else {
          try {
            return collection.contains(converter.convert(o1, value.getClass()));
          } catch (ELException e) {
            return Boolean.FALSE;
          }
        }
      }
    }

    return Boolean.FALSE;
  }

  public static final CollectionMembershipOperator OP = new CollectionMembershipOperator();
  public static final Scanner.ExtensionToken TOKEN = new Scanner.ExtensionToken("in");

  public static final ExtensionHandler HANDLER = new ExtensionHandler(
    ExtensionPoint.CMP
  ) {

    @Override
    public AstNode createAstNode(AstNode... children) {
      return new AstBinary(children[0], children[1], OP);
    }
  };
}

@@ -643,18 +643,21 @@
  Object 
-o1
+value
 , Object
@@ -657,18 +657,24 @@
  Object 
-o2
+iterable
 ) %7B%0A    
@@ -677,18 +677,24 @@
     if (
-o2
+iterable
  == null
@@ -768,34 +768,40 @@
 sAssignableFrom(
-o2
+iterable
 .getClass())) %7B%0A
@@ -849,18 +849,24 @@
 quence) 
-o2
+iterable
 , Object
@@ -876,18 +876,21 @@
 oString(
-o1
+value
 , %22%22));%0A
@@ -938,18 +938,24 @@
 bleFrom(
-o2
+iterable
 .getClas
@@ -1015,10 +1015,16 @@
 ?%3E) 
-o2
+iterable
 ;%0A%0A 
@@ -1040,21 +1040,23 @@
 (Object 
-value
+element
  : colle
@@ -1076,21 +1076,23 @@
     if (
-value
+element
  == null
@@ -1109,18 +1109,21 @@
     if (
-o1
+value
  == null
@@ -1265,17 +1265,22 @@
 ert(
-o1, 
 value
+, element
 .get

Rename variables for clarity