@sap/odata-v4
Version:
OData V4.0 server library
114 lines (95 loc) • 2.91 kB
JavaScript
'use strict';
const AnnotationFactory = require('./AnnotationExpressionFactory');
const CsdlAnnotationExpression = require('../../csdl/annotationExpression/CsdlAnnotationExpression');
const EdmAnnotationExpression = require('./EdmAnnotationExpression');
const IllegalArgumentError = require('../../errors/IllegalArgumentError');
/**
*
* Abstract parent class for all mathematical binary expressions
* <a href="./../ODataSpecification/odata-v4.0-errata03-os/complete/part3-csdl/odata-v4.0-errata03-os-part3-csdl-complete.html#_Toc453752647">
* OData CSDL # 14.5.1 Comparison and Logical Operators
* </a>
*
* @extends EdmAnnotationExpression
* @hideconstructor
*/
class EdmBinaryExpression extends EdmAnnotationExpression {
/**
* @param {Edm} edm The edm itself
* @param {CsdlBinaryExpression} binary The csdl binary operator expression
*/
constructor(edm, binary) {
if (!edm) {
throw IllegalArgumentError.createForIllegalInstance('edm', 'Edm');
}
if (!binary) {
throw IllegalArgumentError.createForIllegalInstance('binary', 'CsdlBinaryExpression');
}
super(CsdlAnnotationExpression.kinds.Binary);
/**
* @type {Edm}
* @private
*/
this._edm = edm;
/**
* @type {CsdlBinaryExpression}
* @private
*/
this._binary = binary;
/**
* @type {EdmAnnotationExpression}
* @private
*/
this._left = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, this._binary.left);
/**
* @type {EdmAnnotationExpression}
* @private
*/
this._right = AnnotationFactory.createEdmExpressionFromCsdlExpression(edm, this._binary.right);
/**
* @type {EdmAnnotation[]}
* @private
*/
this._annotations = null;
}
/**
* Returns the operator
*
* @returns {CsdlBinaryExpression.ComparisonOperators} Operator
*/
getOperator() {
return this._binary.operator;
}
/**
* Returns the left operand
*
* @returns {EdmAnnotationExpression} left operand
*/
getLeft() {
return this._left;
}
/**
* Returns the right operand
*
* @returns {EdmAnnotationExpression} right operand
*/
getRight() {
return this._right;
}
/**
* Returns the annotations for this binary expression
*
* @returns {EdmAnnotation[]}
*/
getAnnotations() {
if (this._annotations) {
return this._annotations;
}
this._annotations = [];
for (let item of this._binary.annotations) {
this._annotations.push(AnnotationFactory.createAnnotation(this._edm, item));
}
return this._annotations;
}
}
module.exports = EdmBinaryExpression;