private static bool IsValidExtraction(IExtractMethodInput input, SelectionTarget target) { if (target.Parents[target.Parents.Length - 1] is ClassDefinition) { input.CannotExtract("Cannot extract statements from a class definition"); return(false); } string invalidExtractMsg = target.InvalidExtractionMessage; if (invalidExtractMsg != null) { input.CannotExtract(invalidExtractMsg); return(false); } var breakContinueWalker = new ContinueBreakWalker(); target.Walk(breakContinueWalker); if (breakContinueWalker.ContainsBreak) { input.CannotExtract("The selection contains a \"break\" statement, but not the enclosing loop"); return(false); } else if (breakContinueWalker.ContainsContinue) { input.CannotExtract("The selection contains a \"continue\" statement, but not the enclosing loop"); return(false); } var yieldWalker = new YieldWalker(); target.Walk(yieldWalker); if (yieldWalker.ContainsYield) { input.CannotExtract("Cannot extract code containing \"yield\" expression"); return(false); } var importStarWalker = new ImportStarWalker(); target.Walk(importStarWalker); if (importStarWalker.ContainsImportStar) { input.CannotExtract("Cannot extract method containing from ... import * statement"); return(false); } var returnWalker = new ReturnWalker(); target.Walk(returnWalker); if (returnWalker.ContainsReturn && !returnWalker.Returns) { input.CannotExtract("When the selection contains a return statement, all code paths must be terminated by a return statement too."); return(false); } target.ContainsReturn = returnWalker.ContainsReturn; return(true); }
private static bool IsValidExtraction(SelectionTarget target, out AP.CannotExtractReason failureReason) { if (target.Parents[target.Parents.Count - 1] is ClassDefinition) { failureReason = AP.CannotExtractReason.StatementsFromClassDefinition; return(false); } var breakContinueWalker = new ContinueBreakWalker(); target.Walk(breakContinueWalker); if (breakContinueWalker.ContainsBreak) { failureReason = AP.CannotExtractReason.SelectionContainsBreakButNotEnclosingLoop; return(false); } else if (breakContinueWalker.ContainsContinue) { failureReason = AP.CannotExtractReason.SelectionContainsContinueButNotEnclosingLoop; return(false); } var yieldWalker = new YieldWalker(); target.Walk(yieldWalker); if (yieldWalker.ContainsYield) { failureReason = AP.CannotExtractReason.ContainsYieldExpression; return(false); } var importStarWalker = new ImportStarWalker(); target.Walk(importStarWalker); if (importStarWalker.ContainsImportStar) { failureReason = AP.CannotExtractReason.ContainsFromImportStar; return(false); } var returnWalker = new ReturnWalker(); target.Walk(returnWalker); if (returnWalker.ContainsReturn && !returnWalker.Returns) { failureReason = AP.CannotExtractReason.SelectionContainsReturn; return(false); } target.ContainsReturn = returnWalker.ContainsReturn; failureReason = AP.CannotExtractReason.None; return(true); }
public async Task <ActionResult <ReturnWalker> > GetWalkerProfile() { var username = User.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value; var role = User.Claims.Where(c => c.Type == ClaimTypes.Role).FirstOrDefault().Value; var walker = await _repository.GetWalkerByUserName(username); if (walker == null) { return(NotFound(new { message = "not found" })); } var returnWalker = new ReturnWalker(walker); return(returnWalker); }
private static bool IsValidExtraction(SelectionTarget target, out string failureReason) { if (target.Parents[target.Parents.Count - 1] is ClassDefinition) { failureReason = Strings.ExtractMethodStatementsFromClassDefinition; return(false); } string invalidExtractMsg = target.InvalidExtractionMessage; if (invalidExtractMsg != null) { failureReason = invalidExtractMsg; return(false); } var breakContinueWalker = new ContinueBreakWalker(); target.Walk(breakContinueWalker); if (breakContinueWalker.ContainsBreak) { failureReason = Strings.ExtractMethodSelectionContainsBreakButNotEnclosingLoop; return(false); } else if (breakContinueWalker.ContainsContinue) { failureReason = Strings.ExtractMethodSelectionContainsContinueButNotEnclosingLoop; return(false); } var yieldWalker = new YieldWalker(); target.Walk(yieldWalker); if (yieldWalker.ContainsYield) { failureReason = Strings.ExtractMethodContainsYieldExpression; return(false); } var importStarWalker = new ImportStarWalker(); target.Walk(importStarWalker); if (importStarWalker.ContainsImportStar) { failureReason = Strings.ExtractMethodContainsFromImportStar; return(false); } var returnWalker = new ReturnWalker(); target.Walk(returnWalker); if (returnWalker.ContainsReturn && !returnWalker.Returns) { failureReason = Strings.ExtractMethodSelectionContainsReturn; return(false); } target.ContainsReturn = returnWalker.ContainsReturn; failureReason = null; return(true); }
private static bool IsValidExtraction(IExtractMethodInput input, SelectionTarget target) { if (target.Parents[target.Parents.Length - 1] is ClassDefinition) { input.CannotExtract("Cannot extract statements from a class definition"); return false; } string invalidExtractMsg = target.InvalidExtractionMessage; if (invalidExtractMsg != null) { input.CannotExtract(invalidExtractMsg); return false; } var breakContinueWalker = new ContinueBreakWalker(); target.Walk(breakContinueWalker); if (breakContinueWalker.ContainsBreak) { input.CannotExtract("The selection contains a \"break\" statement, but not the enclosing loop"); return false; } else if (breakContinueWalker.ContainsContinue) { input.CannotExtract("The selection contains a \"continue\" statement, but not the enclosing loop"); return false; } var yieldWalker = new YieldWalker(); target.Walk(yieldWalker); if (yieldWalker.ContainsYield) { input.CannotExtract("Cannot extract code containing \"yield\" expression"); return false; } var importStarWalker = new ImportStarWalker(); target.Walk(importStarWalker); if (importStarWalker.ContainsImportStar) { input.CannotExtract("Cannot extract method containing from ... import * statement"); return false; } var returnWalker = new ReturnWalker(); target.Walk(returnWalker); if (returnWalker.ContainsReturn && !returnWalker.Returns) { input.CannotExtract("When the selection contains a return statement, all code paths must be terminated by a return statement too."); return false; } target.ContainsReturn = returnWalker.ContainsReturn; return true; }