/** Compute the type of an assert expression. * * @param object the expression. * @param state the state of the type resolver. */ protected void _computeTypes(SarlAssertExpression object, ITypeComputationState state) { state.withExpectation(getTypeForName(Boolean.class, state)).computeTypes(object.getCondition()); }
/** Generate the Java code related to the expression for the assert keyword. * * @param assertExpression the expression. * @param appendable the output. */ protected void _toJavaExpression(SarlAssertExpression assertExpression, ITreeAppendable appendable) { if (!assertExpression.isIsStatic() && isAtLeastJava8(assertExpression)) { appendable.append("/* error - couldn't compile nested assert */"); //$NON-NLS-1$ } }
if (!assertExpression.isIsStatic() && assertExpression.getCondition() != null && isAtLeastJava8(assertExpression)) { final XExpression condition = assertExpression.getCondition(); final LightweightTypeReference actualType = getLightweightType(condition); if (actualType != null) { if (!Strings.isEmpty(assertExpression.getMessage())) { appendable.append(" : \""); //$NON-NLS-1$ appendable.append(Strings.convertToJavaString(assertExpression.getMessage())); appendable.append("\""); //$NON-NLS-1$
/** Generate the given object. * * @param assertStatement the assert statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(SarlAssertExpression assertStatement, IAppendable it, IExtraLanguageGeneratorContext context) { final boolean haveAssert = !assertStatement.isIsStatic() && assertStatement.getCondition() != null; if (haveAssert) { it.append("assert (lambda:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(assertStatement.getCondition(), it, context); it.decreaseIndentation().newLine(); it.append(")()"); //$NON-NLS-1$ } if (context.getExpectedExpressionType() != null) { if (haveAssert) { it.newLine(); } it.append("return ").append(toDefaultValue(context.getExpectedExpressionType().toJavaCompliantTypeReference())); //$NON-NLS-1$ } return assertStatement; }
/** Check for usage of assert keyword. * * @param expression the expression to analyze. */ @Check public void checkAssumeKeywordUse(SarlAssertExpression expression) { if (expression.isIsStatic()) { error(MessageFormat.format( Messages.SARLValidator_0, this.grammarAccess.getIsStaticAssumeKeyword()), expression, null); } }
final XExpression condition = expression.getCondition(); if (condition != null) { final LightweightTypeReference fromType = getActualType(condition);