Class OperatorHelper
java.lang.Object
de.firemage.autograder.core.integrated.evaluator.OperatorHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetOperatorText(spoon.reflect.code.BinaryOperatorKind operatorKind) Gets the representation of the operator in the source code.static StringgetOperatorText(spoon.reflect.code.UnaryOperatorKind operatorKind) Gets the representation of the operator in the source code.static Optional<spoon.reflect.reference.CtTypeReference<?>>getPromotedType(spoon.reflect.code.BinaryOperatorKind operator, spoon.reflect.code.CtExpression<?> left, spoon.reflect.code.CtExpression<?> right) Get the promoted type of the binary operator, as defined by the Java Language Specification.static Optional<spoon.reflect.reference.CtTypeReference<?>>getPromotedType(spoon.reflect.code.UnaryOperatorKind operator, spoon.reflect.code.CtExpression<?> operand) Gets the promoted type of the unary operator, as defined by the Java Language Specification.
-
Method Details
-
getOperatorText
Gets the representation of the operator in the source code. For example, POS will return "+".- Parameters:
operatorKind- the operator- Returns:
- java source code representation of a pre or post unary operator.
-
getOperatorText
Gets the representation of the operator in the source code. For example, OR will return "||".- Parameters:
operatorKind- the operator- Returns:
- java source code representation of a binary operator.
-
getPromotedType
public static Optional<spoon.reflect.reference.CtTypeReference<?>> getPromotedType(spoon.reflect.code.BinaryOperatorKind operator, spoon.reflect.code.CtExpression<?> left, spoon.reflect.code.CtExpression<?> right) Get the promoted type of the binary operator, as defined by the Java Language Specification.Before an operator is applied, the type of the operands might be changed. This is called promotion. For example
1 + 1.0has an int and a double as operands. The left operand is promoted to a double, so that the left and right operand have the same type.- Parameters:
operator- the operatorleft- the left operand,FactoryAccessor.getFactory()must not returnnull.right- the right operand- Returns:
- the promoted type or
Optional.empty()if promotion does not apply or the operation is invalid. Not every operator is defined for every combination of operands. For example1 << 1.0is invalid. In this case,Optional.empty()is returned. - Throws:
UnsupportedOperationException- if the operator isBinaryOperatorKind.INSTANCEOFor an unknown operator.- See Also:
-
getPromotedType
public static Optional<spoon.reflect.reference.CtTypeReference<?>> getPromotedType(spoon.reflect.code.UnaryOperatorKind operator, spoon.reflect.code.CtExpression<?> operand) Gets the promoted type of the unary operator, as defined by the Java Language Specification.Before an operator is applied, the type of the operand might be changed. This is called promotion. For example
-((short) 1)has an operand of type short. The operand is promoted to an int, before the operator is applied.- Parameters:
operator- the operatoroperand- the operand,FactoryAccessor.getFactory()must not returnnull.- Returns:
- the promoted type or
Optional.empty()if promotion does not apply or the operation is invalid. Not every operator is defined for every combination of operands. For example!1is invalid. In this case,Optional.empty()is returned. - Throws:
UnsupportedOperationException- if the operator is an unknown operator.- See Also:
-