[1] [2] [3] [4]

Note that passing null here essentially deletes the existing expression list and returns the expression

@param _newTail
@return
354108
public Instruction createList(final Instruction _newTail) {
      Instruction childExprHead = null;
      if (_newTail == null) {
         childExprHead = head;
         tail = head = null;
      } else {
         childExprHead = _newTail.getNextExpr();
         tail = _newTail;
         _newTail.setNextExpr(null);
         if (childExprHead != null) {
            childExprHead.setPrevExpr(null);
         }

      }
      return (childExprHead);
   }
458434
public static <T> ExpressionList<T> applyWhere(ExpressionList<T> expressionList, Object queryObject) {
        if (queryObject != null) {
            Class clz = queryObject.getClass();
            Field[] fields = clz.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                String param = field.getName();
                Object value = null;
                try {
                    value = field.get(queryObject);
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
                ExprType exprType = ExprType.DEFAULT;
                boolean ignoreCase = false;
                boolean escapeNull = true;
                boolean isString = field.getType() == String.class;
                boolean isArray = field.getType().isArray();
                if (field.isAnnotationPresent(ExprParam.class)) {
                    ExprParam exprParam = field.getAnnotation(ExprParam.class);
                    String qpv = exprParam.value();
                    String qpn = exprParam.name();
                    exprType = exprParam.expr();
                    ignoreCase = exprParam.ignoreCase();
                    escapeNull = exprParam.escapeNull();
                    if (escapeNull && value == null) {
                        break;
                    }
                    if (StringUtils.hasText(qpv)) {
                        param = qpv;
                    }
                    if (StringUtils.hasText(qpn)) {
                        param = qpn;
                    }
                }
                switch (exprType) {
                    case EQ:
                        if (isString && ignoreCase) {
                            expressionList.add(Expr.ieq(param, (String) value));
                        } else {
                            expressionList.add(Expr.eq(param, value));
                        }
                        break;
                    case NE:
                        expressionList.add(Expr.ne(param, value));
                        break;
                    case GE:
                        expressionList.add(Expr.ge(param, value));
                        break;
                    case GT:
                        expressionList.add(Expr.gt(param, value));
                        break;
                    case LE:
                        expressionList.add(Expr.le(param, value));
                        break;
                    case LT:
                        expressionList.add(Expr.lt(param, value));
                        break;
                    case LIKE:
                        if (isString) {
                            if (ignoreCase) {
                                expressionList.add(Expr.ilike(param, (String) value));
                            } else {
                                expressionList.add(Expr.like(param, (String) value));
                            }
                        }
                        break;
                    case STARTS_WITH:
                        if (isString) {
                            if (ignoreCase) {
                                expressionList.add(Expr.istartsWith(param, (String) value));
                            } else {
                                expressionList.add(Expr.startsWith(param, (String) value));
                            }
                        }
                        break;
                    case ENDS_WITH:
                        if (isString) {
                            if (ignoreCase) {
                                expressionList.add(Expr.iendsWith(param, (String) value));
                            } else {
                                expressionList.add(Expr.endsWith(param, (String) value));
                            }
                        }
                        break;
                    case CONTAINS:
                        if (isString) {
                            if (ignoreCase) {
                                expressionList.add(Expr.icontains(param, (String) value));
                            } else {
                                expressionList.add(Expr.contains(param, (String) value));
                            }
                        }
                        break;
                    case IN:
                        if (isArray) {
                            expressionList.add(Expr.in(param, (Object[]) value));
                        }
                    default:
                        if (isString) {
                            if (ignoreCase) {
                                expressionList.add(Expr.icontains(param, (String) value));
                            } else {
                                expressionList.add(Expr.contains(param, (String) value));
                            }
                        } else {
                            expressionList.add(Expr.eq(param, value));
                        }
                        break;
                }

            }
        }
        return expressionList;
    }
29587
public static Matcher<ExpressionTree> methodReturnsNonNull() {
    return anyOf(
        instanceMethod().onDescendantOf("java.lang.Object").named("toString"),
        instanceMethod().onExactClass("java.lang.String"),
        staticMethod().onClass("java.lang.String"),
        instanceMethod().onExactClass("java.util.StringTokenizer").named("nextToken"));
  }
951289
@Nullable
	public static <T> T get(T[] array, int index) {
		return array != null && index >= 0 && index < array.length ? array[index] : null;
	}
678581
@Override
	public Expression[] retractExpressions() {
		return new Expression[] {existDefaultValue ? cast(operand(2),
				typeLiteral(getResultType())) : literal(null, getResultType())};
	}
774013
@SuppressWarnings("unchecked")
	public <E> TerminalResult IN_list(E... value) {
		getPredicateExpression().setOperator(Operator.IN);
		getPredicateExpression().setValue_2(value);
		TerminalResult ret = APIAccess.createTerminalResult(this.getPredicateExpression());
		QueryRecorder.recordInvocation(this, "IN_list", ret, QueryRecorder.placeHolder(value));
		return ret;
	}
1112526
public static AllowableValues emptyToNull(AllowableValues newValue, AllowableValues current) {
    if (newValue != null) {
      if (newValue instanceof AllowableListValues) {
        return defaultIfAbsent(emptyListValuesToNull((AllowableListValues) newValue), current);
      } else {
        return defaultIfAbsent(newValue, current);
      }
    }
    return current;
  }
1084914
public static Expression compile(String exp) {
        if (Miscellaneous.isEmpty(exp) || exp.equals(".")) {
            exp = "$";
        }
        Queue<String> queue = new LinkedList<String>();
        List<String> tokens = parseTokens(exp);
        boolean isInBracket = false;
        int numInBracket = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < tokens.size(); i++) {
            String token = tokens.get(i);
            if (token.equals("[")) {
                if (isInBracket) {
                    throw new IllegalArgumentException("Error parsing expression '" + exp + "': Nested [ found");
                }
                isInBracket = true;
                numInBracket = 0;
                sb.append(token);
            } else if (token.equals("]")) {
                if (!isInBracket) {
                    throw new IllegalArgumentException("Error parsing expression '" + exp + "': Unbalanced ] found");
                }
                isInBracket = false;
                sb.append(token);
                queue.add(sb.toString());
                sb = new StringBuilder();
            } else {
                if (isInBracket) {
                    if (numInBracket > 0) {
                        throw new IllegalArgumentException("Error parsing expression '" + exp + "': Multiple tokens found inside a bracket");
                    }
                    sb.append(token);
                    numInBracket++;
                } else {
                    queue.add(token);
                }
            }
            if (i == tokens.size() - 1) {
                if (isInBracket) {
                    throw new IllegalArgumentException("Error parsing expression '" + exp + "': Unbalanced [ found");
                }
            }
        }
        return new Expression(queue, exp);
    }
523107
@Override
    public <Y> Expression<Y> nullif(Expression<Y> arg0, Expression<?> arg1)
    {
        // TODO Auto-generated method stub
        return null;
    }
128880
Expr nullSafe() {
		Expr expr = unary();
		for (Tok tok=peek(); tok.sym==Sym.NULL_SAFE; tok=peek()) {
			move();
			expr = new NullSafe(expr, unary(), location);
		}
		return expr;
	}
125497
@Override
    public Expression visitCreator(CreatorContext ctx) {
        ClassNode classNode = this.visitCreatedName(ctx.createdName());

        if (asBoolean(ctx.arguments())) { // create instance of class
            Expression arguments = this.visitArguments(ctx.arguments());
            Expression enclosingInstanceExpression = ctx.getNodeMetaData(ENCLOSING_INSTANCE_EXPRESSION);

            if (null != enclosingInstanceExpression) {
                if (arguments instanceof ArgumentListExpression) {
                    ((ArgumentListExpression) arguments).getExpressions().add(0, enclosingInstanceExpression);
                } else if (arguments instanceof TupleExpression) {
                    throw createParsingFailedException("Creating instance of non-static class does not support named parameters", arguments);
                } else if (arguments instanceof NamedArgumentListExpression) {
                    throw createParsingFailedException("Unexpected arguments", arguments);
                } else {
                    throw createParsingFailedException("Unsupported arguments", arguments); // should never reach here
                }
            }

            if (asBoolean(ctx.anonymousInnerClassDeclaration())) {
                ctx.anonymousInnerClassDeclaration().putNodeMetaData(ANONYMOUS_INNER_CLASS_SUPER_CLASS, classNode);
                InnerClassNode anonymousInnerClassNode = this.visitAnonymousInnerClassDeclaration(ctx.anonymousInnerClassDeclaration());

                List<InnerClassNode> anonymousInnerClassList = anonymousInnerClassesDefinedInMethodStack.peek();
                if (null != anonymousInnerClassList) { // if the anonymous class is created in a script, no anonymousInnerClassList is available.
                    anonymousInnerClassList.add(anonymousInnerClassNode);
                }

                ConstructorCallExpression constructorCallExpression = new ConstructorCallExpression(anonymousInnerClassNode, arguments);
                constructorCallExpression.setUsingAnonymousInnerClass(true);

                return configureAST(constructorCallExpression, ctx);
            }

            return configureAST(
                    new ConstructorCallExpression(classNode, arguments),
                    ctx);
        }

        if (asBoolean(ctx.LBRACK()) || asBoolean(ctx.dims())) { // create array
            ArrayExpression arrayExpression;
            List<List<AnnotationNode>> allDimList;

            if (asBoolean(ctx.arrayInitializer())) {
                ClassNode elementType = classNode;
                allDimList = this.visitDims(ctx.dims());

                for (int i = 0, n = allDimList.size() - 1; i < n; i++) {
                    elementType = elementType.makeArray();
                }

                arrayExpression =
                        new ArrayExpression(
                            elementType,
                            this.visitArrayInitializer(ctx.arrayInitializer()));

            } else {
                Expression[] empties;
                List<List<AnnotationNode>> emptyDimList = this.visitDimsOpt(ctx.dimsOpt());

                if (asBoolean(emptyDimList)) {
                    empties = new Expression[emptyDimList.size()];
                    Arrays.fill(empties, ConstantExpression.EMPTY_EXPRESSION);
                } else {
                    empties = Expression.EMPTY_ARRAY;
                }

                arrayExpression =
                        new ArrayExpression(
                                classNode,
                                null,
                                Stream.concat(
                                        ctx.expression().stream()
                                                .map(e -> (Expression) this.visit(e)),
                                        Arrays.stream(empties)
                                ).collect(Collectors.toList()));


                List<List<AnnotationNode>> exprDimList = ctx.annotationsOpt().stream().map(this::visitAnnotationsOpt).collect(Collectors.toList());
                allDimList = new ArrayList<>(exprDimList);
                Collections.reverse(emptyDimList);
                allDimList.addAll(emptyDimList);
                Collections.reverse(allDimList);
            }

            arrayExpression.setType(createArrayType(classNode, allDimList));

            return configureAST(arrayExpression, ctx);
        }

        throw createParsingFailedException("Unsupported creator: " + ctx.getText(), ctx);
    }
607108
private void evaluateExpressions() throws JspException {
        Object obj = null;

        /* 
         * Note: we don't check for type mismatches here; we assume
         * the expression evaluator will return the expected type
         * (by virtue of knowledge we give it about what that type is).
         * A ClassCastException here is truly unexpected, so we let it
         * propagate up.
         */

        // 'value' attribute
        if (value_ != null) {
            value = (String) ExpressionEvaluatorManager.evaluate(
                    "value", value_, String.class, this, pageContext);
        }

        // 'type' attribute
        if (type_ != null) {
            type = (String) ExpressionEvaluatorManager.evaluate(
                    "type", type_, String.class, this, pageContext);
        }

        // 'pattern' attribute
        if (pattern_ != null) {
            pattern = (String) ExpressionEvaluatorManager.evaluate(
                    "pattern", pattern_, String.class, this, pageContext);
        }

        // 'parseLocale' attribute
        if (parseLocale_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "parseLocale", parseLocale_, Object.class, this, pageContext);
            Locale locale = LocaleUtil.parseLocaleAttributeValue(obj);
            if (locale != null) {
                this.parseLocale = locale;
            }
        }

        // 'integerOnly' attribute
        if (integerOnly_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "integerOnly", integerOnly_, Boolean.class, this, pageContext);
            if (obj != null) {
                isIntegerOnly = ((Boolean) obj).booleanValue();
            }
        }
    }
305701
public Expression getFromExpression() {
        if (_fromExpression == null && _from != null) {
            _fromExpression = ExpressionFactory.INSTANCE.create(_from, null, _propertyResolver);
        }
        return _fromExpression;
    }
527710
public Expression asNonNullable() {
    if (isNonNullable()) {
      return this;
    }
    return new Expression(resultType, features.plus(Feature.NON_NULLABLE)) {
      @Override
      protected void doGen(CodeBuilder adapter) {
        Expression.this.gen(adapter);
      }
    };
  }
698324
public static <T> TemplateExpression<T> template(Class<? extends T> cl, Template template, Object... args) {
        return template(cl, template, ImmutableList.copyOf(args));
    }
1293867
private Expression parseAtomList() {
        Expression exp = parseAtom();
        if (!tokenizer.current().isSymbol(",")) {
            return exp;
        }

        ValueList atomList = new ValueList(true);
        atomList.add(exp);
        while (tokenizer.current().isSymbol(",")) {
            tokenizer.consume();
            atomList.add(parseAtom());
        }

        return atomList;
    }
425175
function toExpression(node) {
  if (t.isExpressionStatement(node)) {
    node = node.expression;
  }

  if (t.isClass(node)) {
    node.type = "ClassExpression";
  } else if (t.isFunction(node)) {
    node.type = "FunctionExpression";
  }

  if (t.isExpression(node)) {
    return node;
  } else {
    throw new Error("cannot turn " + node.type + " to an expression");
  }
}