use of org.spockframework.runtime.model.ExpressionInfo in project spock by spockframework.
the class ExpressionInfoBuilder method build.
public ExpressionInfo build() {
try {
SourceUnit unit = SourceUnit.create("Spec expression", adjustedText);
unit.parse();
unit.completePhase();
unit.convert();
BlockStatement blockStat = unit.getAST().getStatementBlock();
Assert.that(blockStat != null && blockStat.getStatements().size() == 1);
Statement stat = blockStat.getStatements().get(0);
Assert.that(stat instanceof ExpressionStatement);
Expression expr = ((ExpressionStatement) stat).getExpression();
ExpressionInfo exprInfo = new ExpressionInfoConverter(lines).convert(expr);
// IDEA: rest of this method could be moved to ExpressionInfoConverter (but: might make EIC less testable)
// IDEA: could make ExpressionInfo immutable
List<ExpressionInfo> inPostfixOrder = exprInfo.inPostfixOrder(false);
for (int variableNumber = 0; variableNumber < inPostfixOrder.size(); variableNumber++) {
ExpressionInfo info = inPostfixOrder.get(variableNumber);
info.setText(findText(info.getRegion()));
if (notRecordedVarNumberBecauseOfException != null && variableNumber == notRecordedVarNumberBecauseOfException) {
info.setValue(exception);
} else if (values.size() > variableNumber) {
//we have this value
info.setValue(values.get(variableNumber));
} else {
info.setValue(ExpressionInfo.VALUE_NOT_AVAILABLE);
}
if (startPos.getLineIndex() > 0)
info.shiftVertically(startPos.getLineIndex());
}
return exprInfo;
} catch (Throwable t) {
final ExpressionInfo expressionInfo = new ExpressionInfo(TextRegion.create(TextPosition.create(1, 1), TextPosition.create(1, 1)), TextPosition.create(1, 1), null);
expressionInfo.setText(text);
expressionInfo.setValue(lastOrNull(values));
return expressionInfo;
}
}
use of org.spockframework.runtime.model.ExpressionInfo in project spock by spockframework.
the class ExpressionInfoValueRenderer method renderAsFailedEqualityComparison.
private String renderAsFailedEqualityComparison(ExpressionInfo expr) {
if (!(Boolean.FALSE.equals(expr.getValue())))
return null;
if (!expr.isEqualityComparison())
return null;
ExpressionInfo expr1 = expr.getChildren().get(0);
ExpressionInfo expr2 = expr.getChildren().get(1);
if (expr1.getEffectiveRenderedValue().equals(expr2.getEffectiveRenderedValue())) {
addTypeHint(expr1);
addTypeHint(expr2);
}
return "false";
}
Aggregations