public static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) { TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal); TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal); if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType)); method.setVisibility(visibility); method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE)); method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()); CodeTreeBuilder body = method.createBuilder(); body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock(); body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end(); body.end(); body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end(); return method; }
static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) { TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal); TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal); if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType)); method.setVisibility(visibility); method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE)); method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()); CodeTreeBuilder body = method.createBuilder(); body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock(); body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end(); body.end(); body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end(); return method; }