![JAR search and dependency download from the Maven repository](/logo.png)
com.mitchellbosecke.pebble.node.expression.AndExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pebble Show documentation
Show all versions of pebble Show documentation
Templating engine for Java.
/*
* This file is part of Pebble.
*
* Copyright (c) 2014 by Mitchell Bösecke
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package com.mitchellbosecke.pebble.node.expression;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.EvaluationContextImpl;
import com.mitchellbosecke.pebble.template.PebbleTemplateImpl;
import static com.mitchellbosecke.pebble.utils.TypeUtils.compatibleCast;
public class AndExpression extends BinaryExpression {
@SuppressWarnings("unchecked")
@Override
public Boolean evaluate(PebbleTemplateImpl self, EvaluationContextImpl context) {
Expression leftExpression = (Expression) this.getLeftExpression();
boolean left = this.evaluateExpression(self, context, leftExpression);
if (left) {
Expression rightExpression = (Expression) this.getRightExpression();
return this.evaluateExpression(self, context, rightExpression);
}
return false;
}
private boolean evaluateExpression(PebbleTemplateImpl self, EvaluationContextImpl context,
Expression expression) {
Boolean evaluatedExpression = compatibleCast(expression.evaluate(self, context), Boolean.class);
if (evaluatedExpression == null) {
if (context.isStrictVariables()) {
throw new PebbleException(null,
"null value used in and operator and strict variables is set to true",
this.getLineNumber(),
self.getName());
}
return false;
}
return evaluatedExpression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy