@Test public void itIsIllegalToConstructForLoopContext_whenCurrentFrameContextIsNotExecutableOne() { assertThatExceptionOfType(IllegalDebugContextStateException.class) .isThrownBy(() -> ForLoopContext.findContextForLoop(mock(StackFrameContext.class))) .withMessage("For loop can only be called when already context was moved to executable call") .withNoCause(); }
public static StackFrameContext findContextForLoop(final StackFrameContext currentContext) { final URI location = currentContext.getAssociatedPath().orElse(null); final Integer line = currentContext.getFileRegion() .map(FileRegion::getStart) .map(FilePosition::getLine) .orElse(-1); if (currentContext instanceof ExecutableCallContext) { final ExecutableCallContext execContext = (ExecutableCallContext) currentContext; final ExecutableWithDescriptor currentElement = execContext.currentElement(); if (currentElement.isLoopExecutable()) { return new ForLoopContext(currentElement, location, line, currentContext.getErrorMessage().orElse(null)); } else { final String errorMsg = String.format(ErrorMessages.executableCallNotFound_foundCallButFor, currentElement.getCalledKeywordName()); return new ForLoopContext(location, line, errorMsg); } } else if (currentContext instanceof ErroneousExecutableCallContext) { return new ForLoopContext(location, line, currentContext.getErrorMessage().get()); } throw new IllegalDebugContextStateException( "For loop can only be called when already context was moved to executable call"); }
ForLoopContext extends DefaultContext { public static StackFrameContext findContextForLoop(final StackFrameContext currentContext) { final URI location = currentContext.getAssociatedPath().orElse(null); final Integer line = currentContext.getFileRegion() .map(FileRegion::getStart) .map(FilePosition::getLine) .orElse(-1); if (currentContext instanceof ExecutableCallContext) { final ExecutableCallContext execContext = (ExecutableCallContext) currentContext; final ExecutableWithDescriptor currentElement = execContext.currentElement(); if (currentElement.isLoopExecutable()) { return new ForLoopContext(currentElement, location, line, currentContext.getErrorMessage().orElse(null)); } else { final String errorMsg = String.format(ErrorMessages.executableCallNotFound_foundCallButFor, currentElement.getCalledKeywordName()); return new ForLoopContext(location, line, errorMsg); } } else if (currentContext instanceof ErroneousExecutableCallContext) { return new ForLoopContext(location, line, currentContext.getErrorMessage().get()); } throw new IllegalDebugContextStateException( "For loop can only be called when already context was moved to executable call"); } }
ForLoopContext extends DefaultContext { public static StackFrameContext findContextForLoop(final StackFrameContext currentContext) { final URI location = currentContext.getAssociatedPath().orElse(null); final Integer line = currentContext.getFileRegion() .map(FileRegion::getStart) .map(FilePosition::getLine) .orElse(-1); if (currentContext instanceof ExecutableCallContext) { final ExecutableCallContext execContext = (ExecutableCallContext) currentContext; final ExecutableWithDescriptor currentElement = execContext.currentElement(); if (currentElement.isLoopExecutable()) { return new ForLoopContext(currentElement, location, line, currentContext.getErrorMessage().orElse(null)); } else { final String errorMsg = String.format(ErrorMessages.executableCallNotFound_foundCallButFor, currentElement.getCalledKeywordName()); return new ForLoopContext(location, line, errorMsg); } } else if (currentContext instanceof ErroneousExecutableCallContext) { return new ForLoopContext(location, line, currentContext.getErrorMessage().get()); } throw new IllegalDebugContextStateException( "For loop can only be called when already context was moved to executable call"); } @VisibleForTesting  ForLoopContext(final URI locationUri, final int line, final String errorMsg); @VisibleForTesting  ForLoopContext(final ExecutableWithDescriptor forLoopExecutable, final URI locationUri, final int line,
            final String errorMsg); }
ForLoopContext extends DefaultContext { public static StackFrameContext findContextForLoop(final StackFrameContext currentContext) { final URI location = currentContext.getAssociatedPath().orElse(null); final Integer line = currentContext.getFileRegion() .map(FileRegion::getStart) .map(FilePosition::getLine) .orElse(-1); if (currentContext instanceof ExecutableCallContext) { final ExecutableCallContext execContext = (ExecutableCallContext) currentContext; final ExecutableWithDescriptor currentElement = execContext.currentElement(); if (currentElement.isLoopExecutable()) { return new ForLoopContext(currentElement, location, line, currentContext.getErrorMessage().orElse(null)); } else { final String errorMsg = String.format(ErrorMessages.executableCallNotFound_foundCallButFor, currentElement.getCalledKeywordName()); return new ForLoopContext(location, line, errorMsg); } } else if (currentContext instanceof ErroneousExecutableCallContext) { return new ForLoopContext(location, line, currentContext.getErrorMessage().get()); } throw new IllegalDebugContextStateException( "For loop can only be called when already context was moved to executable call"); } @VisibleForTesting  ForLoopContext(final URI locationUri, final int line, final String errorMsg); @VisibleForTesting  ForLoopContext(final ExecutableWithDescriptor forLoopExecutable, final URI locationUri, final int line,
            final String errorMsg); static StackFrameContext findContextForLoop(final StackFrameContext currentContext); ExecutableWithDescriptor currentElement(); @Override boolean isErroneous(); @Override Optional<String> getErrorMessage(); @Override Optional<URI> getAssociatedPath(); @Override Optional<FileRegion> getFileRegion(); @Override StackFrameContext moveTo(final RunningKeyword keyword, final RobotBreakpointSupplier breakpointSupplier); }
ForLoopContext extends DefaultContext { public static StackFrameContext findContextForLoop(final StackFrameContext currentContext) { final URI location = currentContext.getAssociatedPath().orElse(null); final Integer line = currentContext.getFileRegion() .map(FileRegion::getStart) .map(FilePosition::getLine) .orElse(-1); if (currentContext instanceof ExecutableCallContext) { final ExecutableCallContext execContext = (ExecutableCallContext) currentContext; final ExecutableWithDescriptor currentElement = execContext.currentElement(); if (currentElement.isLoopExecutable()) { return new ForLoopContext(currentElement, location, line, currentContext.getErrorMessage().orElse(null)); } else { final String errorMsg = String.format(ErrorMessages.executableCallNotFound_foundCallButFor, currentElement.getCalledKeywordName()); return new ForLoopContext(location, line, errorMsg); } } else if (currentContext instanceof ErroneousExecutableCallContext) { return new ForLoopContext(location, line, currentContext.getErrorMessage().get()); } throw new IllegalDebugContextStateException( "For loop can only be called when already context was moved to executable call"); } @VisibleForTesting  ForLoopContext(final URI locationUri, final int line, final String errorMsg); @VisibleForTesting  ForLoopContext(final ExecutableWithDescriptor forLoopExecutable, final URI locationUri, final int line,
            final String errorMsg); static StackFrameContext findContextForLoop(final StackFrameContext currentContext); ExecutableWithDescriptor currentElement(); @Override boolean isErroneous(); @Override Optional<String> getErrorMessage(); @Override Optional<URI> getAssociatedPath(); @Override Optional<FileRegion> getFileRegion(); @Override StackFrameContext moveTo(final RunningKeyword keyword, final RobotBreakpointSupplier breakpointSupplier);  }