use of org.apache.camel.language.simple.types.BinaryOperatorType in project camel by apache.
the class SimplePredicateParser method binaryOperator.
protected boolean binaryOperator() {
if (accept(TokenType.binaryOperator)) {
// remember the binary operator
BinaryOperatorType operatorType = BinaryOperatorType.asOperator(token.getText());
nextToken();
// there should be at least one whitespace after the operator
expectAndAcceptMore(TokenType.whiteSpace);
// okay a binary operator may not support all kind if preceding parameters, so we need to limit this
BinaryOperatorType.ParameterType[] types = BinaryOperatorType.supportedParameterTypes(operatorType);
// based on the parameter types the binary operator support, we need to set this state into
// the following booleans so we know how to proceed in the grammar
boolean literalWithFunctionsSupported = false;
boolean literalSupported = false;
boolean functionSupported = false;
boolean numericSupported = false;
boolean booleanSupported = false;
boolean nullSupported = false;
if (types == null || types.length == 0) {
literalWithFunctionsSupported = true;
// favor literal with functions over literals without functions
literalSupported = false;
functionSupported = true;
numericSupported = true;
booleanSupported = true;
nullSupported = true;
} else {
for (BinaryOperatorType.ParameterType parameterType : types) {
literalSupported |= parameterType.isLiteralSupported();
literalWithFunctionsSupported |= parameterType.isLiteralWithFunctionSupport();
functionSupported |= parameterType.isFunctionSupport();
nullSupported |= parameterType.isNumericValueSupported();
booleanSupported |= parameterType.isBooleanValueSupported();
nullSupported |= parameterType.isNullValueSupported();
}
}
//CHECKSTYLE:OFF
if ((literalWithFunctionsSupported && singleQuotedLiteralWithFunctionsText()) || (literalWithFunctionsSupported && doubleQuotedLiteralWithFunctionsText()) || (literalSupported && singleQuotedLiteralText()) || (literalSupported && doubleQuotedLiteralText()) || (functionSupported && functionText()) || (numericSupported && numericValue()) || (booleanSupported && booleanValue()) || (nullSupported && nullValue())) {
// then after the right hand side value, there should be a whitespace if there is more tokens
nextToken();
if (!token.getType().isEol()) {
expect(TokenType.whiteSpace);
}
} else {
throw new SimpleParserException("Binary operator " + operatorType + " does not support token " + token, token.getIndex());
}
//CHECKSTYLE:ON
return true;
}
return false;
}
Aggregations