Class OperatorHelper

java.lang.Object
de.firemage.autograder.core.integrated.evaluator.OperatorHelper

public final class OperatorHelper extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    getOperatorText(spoon.reflect.code.BinaryOperatorKind operatorKind)
    Gets the representation of the operator in the source code.
    static String
    getOperatorText(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getOperatorText

      public static String getOperatorText(spoon.reflect.code.UnaryOperatorKind operatorKind)
      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

      public static String getOperatorText(spoon.reflect.code.BinaryOperatorKind operatorKind)
      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.0 has 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 operator
      left - the left operand, FactoryAccessor.getFactory() must not return null.
      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 example 1 << 1.0 is invalid. In this case, Optional.empty() is returned.
      Throws:
      UnsupportedOperationException - if the operator is BinaryOperatorKind.INSTANCEOF or 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 operator
      operand - the operand, FactoryAccessor.getFactory() must not return null.
      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 !1 is invalid. In this case, Optional.empty() is returned.
      Throws:
      UnsupportedOperationException - if the operator is an unknown operator.
      See Also: