Class AssertThrowsExprGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.AbstractAssertExprGenerator
org.ek9lang.compiler.phase7.generator.AssertThrowsExprGenerator
- All Implemented Interfaces:
BiFunction<EK9Parser.AssertThrowsExpressionContext, String, List<IRInstr>>
public final class AssertThrowsExprGenerator
extends AbstractAssertExprGenerator
implements BiFunction<EK9Parser.AssertThrowsExpressionContext, String, List<IRInstr>>
IR Generation for the assertThrows expression.
Generates ASSERT_THROWS opcode for test assertions that expect a specific exception type.
Grammar: assertThrowsExpression: ASSERT_THROWS LPAREN typeDef COMMA expression RPAREN
Semantics:
- Evaluates the expression within a try block
- If expected exception type is caught, stores to result variable (success)
- If no exception thrown, throws AssertionError (failure)
- If wrong exception type thrown, rethrows it (test failure)
Used in two contexts:
- Statement form:
assertThrows(IOException, riskyOperation()) - Expression form:
ex <- assertThrows(IOException, riskyOperation())
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractAssertExprGenerator
AbstractAssertExprGenerator.AssertBodyResult -
Field Summary
Fields inherited from class AbstractAssertExprGenerator
generatorsFields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionAssertThrowsExprGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor accepting injected GeneratorSet. -
Method Summary
Modifier and TypeMethodDescriptionapply(EK9Parser.AssertThrowsExpressionContext ctx, String resultVar) Generate IR for assertThrows expression.Methods inherited from class AbstractAssertExprGenerator
buildAssertionBodyMethods inherited from class AbstractGenerator
createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, truncateMessage, truncateMessage, validateNoPreFlowStatement, validateStatementFormOnlyMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiFunction
andThen
-
Constructor Details
-
AssertThrowsExprGenerator
AssertThrowsExprGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor accepting injected GeneratorSet.
-
-
Method Details
-
apply
Generate IR for assertThrows expression.- Specified by:
applyin interfaceBiFunction<EK9Parser.AssertThrowsExpressionContext, String, List<IRInstr>>- Parameters:
ctx- The ANTLR context for the assertThrows expressionresultVar- The variable to store the caught exception (null for statement form)- Returns:
- List of IR instructions
-