public TextPosition shiftVertically(int numLines) { return create(line + numLines, column); }
private TextPosition startOf(String token, ASTNode node) { // try to compensate for the fact that getLastLineNumber() is sometimes wrong int lastLineIndex = Math.max(node.getLineNumber(), node.getLastLineNumber()) - 1; for (int lineIndex = lastLineIndex; lineIndex >= 0; lineIndex--) { int columnIndex = lineIndex == lastLineIndex ? lines[lineIndex].lastIndexOf(token, node.getColumnNumber() - 1) : lines[lineIndex].lastIndexOf(token); if (columnIndex != -1) return TextPosition.create(lineIndex + 1, columnIndex + 1); } throw new IllegalArgumentException(String.format("token %s not found in expression", token)); } }
public static TextPosition startOf(Token token) { return create(token.getStartLine(), token.getStartColumn()); }
public static TextPosition endOf(ASTNode node) { return create(node.getLastLineNumber(), node.getLastColumnNumber()); }
private void createExpression() { if (text == null || values == null) return; String stripAndFlattenText = stripAndFlatten(text).toString(); expression = new ExpressionInfoBuilder(stripAndFlattenText, TextPosition.create(1, 1), values, notRecordedVarNumberBecauseOfException, exception).build(); }
public static TextPosition startOf(ASTNode node) { return create(node.getLineNumber(), node.getColumnNumber()); }
public static void verifyCondition(@Nullable ErrorCollector errorCollector, @Nullable ValueRecorder recorder, @Nullable String text, int line, int column, @Nullable Object message, @Nullable Object condition) { if (!GroovyRuntimeUtil.isTruthy(condition)) { final ConditionNotSatisfiedError conditionNotSatisfiedError = new ConditionNotSatisfiedError( new Condition(getValues(recorder), text, TextPosition.create(line, column), messageToString(message), null, null)); errorCollector.collectOrThrow(conditionNotSatisfiedError); } }
void verify(@Nullable ErrorCollector errorCollector, @Nullable List<Object> values, @Nullable String text, int line, int column, @Nullable String message) { if (HamcrestFacade.matches(matcher, actual)) return; if (values != null) { CollectionUtil.setLastElement(values, shortSyntax ? actual : false); replaceMatcherValues(values); } String description = HamcrestFacade.getFailureDescription(matcher, actual, message); Condition condition = new Condition(values, text, TextPosition.create(line, column), description, null, null); errorCollector.collectOrThrow(new ConditionNotSatisfiedError(condition)); }
public static void conditionFailedWithException(@Nullable ErrorCollector errorCollector, @Nullable ValueRecorder recorder, @Nullable String text, int line, int column, @Nullable Object message, Throwable throwable){ if (throwable instanceof SpockAssertionError) { final SpockAssertionError spockAssertionError = (SpockAssertionError) throwable; errorCollector.collectOrThrow(spockAssertionError); // this is our exception - it already has good message return; } if (throwable instanceof SpockException) { final SpockException spockException = (SpockException) throwable; errorCollector.collectOrThrow(spockException); // this is our exception - it already has good message return; } final ConditionFailedWithExceptionError conditionNotSatisfiedError = new ConditionFailedWithExceptionError( new Condition( getValues(recorder), text, TextPosition.create(line, column), messageToString(message), recorder == null ? null : recorder.getCurrentRecordingVarNum(), recorder == null ? null : throwable), throwable); errorCollector.collectOrThrow(conditionNotSatisfiedError); }
public static void verifyMethodCondition(@Nullable ErrorCollector errorCollector, @Nullable ValueRecorder recorder, @Nullable String text, int line, int column, @Nullable Object message, Object target, String method, Object[] args, boolean safe, boolean explicit, int lastVariableNum) { MatcherCondition matcherCondition = MatcherCondition.parse(target, method, args, safe); if (matcherCondition != null) { matcherCondition.verify(errorCollector, getValues(recorder), text, line, column, messageToString(message)); return; } if (recorder != null) { recorder.startRecordingValue(lastVariableNum); } Object result = safe ? GroovyRuntimeUtil.invokeMethodNullSafe(target, method, args) : GroovyRuntimeUtil.invokeMethod(target, method, args); if (!explicit && result == null && isVoidMethod(target, method, args)) return; if (!GroovyRuntimeUtil.isTruthy(result)) { List<Object> values = getValues(recorder); if (values != null) CollectionUtil.setLastElement(values, result); final ConditionNotSatisfiedError conditionNotSatisfiedError = new ConditionNotSatisfiedError( new Condition(values, text, TextPosition.create(line, column), messageToString(message), null, null)); errorCollector.collectOrThrow(conditionNotSatisfiedError); } }