public TacticReplaceStatus SetMember(int position) { var status = RefactoringUtil.GetMemberFromPosition(_tld, position, out _member); _tacticCalls = RefactoringUtil.GetTacticCallsInMember(_member as Method); return(status); }
private void ProcessSomeMembers() { Begin(); var p = RefactoringUtil.GetNewProgram(_tb); if (p == null) { NotifyStatusbar(DeadAnnotationStatus.NoProgram); Finish(); return; } UpdateFilename(p.FullName); var notProcessedMembers = new List <MemberDecl>(); var tld = RefactoringUtil.GetTld(p); _changesSinceLastSuccessfulRun.ForEach(i => { MemberDecl md; RefactoringUtil.GetMemberFromPosition(tld, i, out md); if (md != null && !notProcessedMembers.Contains(md)) { notProcessedMembers.Add(md); } }); if (tld == null || notProcessedMembers.Count == 0) { NotifyStatusbar(DeadAnnotationStatus.NoChanges); Finish(); return; } _thread = new Thread(ProcessSomeMembersThreaded); _thread.Start(new ThreadParams { P = p, M = notProcessedMembers, S = Snapshot, Stop = _currentStopper }); }
public TacticReplaceStatus ExpandTacticByMember(out string expandedTactic) { expandedTactic = ""; var l = Microsoft.Dafny.Tacny.TacnyDriver.GetTacticResultList(); var x = _member as Method; if (x == null) { return(TacticReplaceStatus.NoTactic); } var sr = new StringWriter(); var printer = new Printer(sr); var hasTactic = false; foreach (var stmt in x.Body.SubStatements) { var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, stmt.Tok)); if (result.Key == null) { printer.PrintStatement(stmt, 0); } else { hasTactic = true; result.Value.ForEach(foundStmt => printer.PrintStatement(foundStmt, 0)); } sr.Write("\n"); } expandedTactic = hasTactic ? sr.ToString() : ""; return(TacticReplaceStatus.Success); }
public TacticReplacerActor(ITextBuffer tb, int position = -1) { Contract.Requires(tb != null); string currentFileName; LoadStatus = RefactoringUtil.LoadAndCheckDocument(tb, out currentFileName) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoDocumentPersistence; if (LoadStatus != TacticReplaceStatus.Success) { return; } var program = RefactoringUtil.GetReparsedProgram(tb, currentFileName, true); _tld = RefactoringUtil.GetTld(program); _tldMembers = _tld?.Members.GetEnumerator(); LoadStatus = _tld != null ? TacticReplaceStatus.Success : TacticReplaceStatus.NotResolved; if (LoadStatus != TacticReplaceStatus.Success) { return; } if (position == -1) { return; } SetMember(position); SetTacticCall(position); }
public TacticReplaceStatus ExpandSingleTacticCall(int tacticCallPos, out string expanded) { expanded = ""; Tuple <Statement, int, int> us; var status = RefactoringUtil.GetTacticCallAtPosition(_member as Method, tacticCallPos, out us); return(status == TacticReplaceStatus.Success ? ExpandSingleTacticCall(us.Item1, out expanded) : status); }
public void AddUpdaterForRot(IPeekSession session, Action <string> recalculate) { string file; var fileLoaded = RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file); if (fileLoaded && _activePeekSession != null && _activePeekSession.ContainsKey(file)) { _activePeekSession[file].Updater = recalculate; } }
public bool NextMemberInTld() { var isMore = _tldMembers.MoveNext(); if (!isMore) { return(false); } _member = _tldMembers.Current; _tacticCalls = RefactoringUtil.GetTacticCallsInMember(_member as Method); return(true); }
public Tuple <string, string> GetExpandedForPeekSession(IPeekSession session) { string file; var status = RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file); if (!status) { return(null); } var storedSessionData = _activePeekSession[file]; return(new Tuple <string, string>(storedSessionData.ExpandedTactic, storedSessionData.ActiveTactic)); }
public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken) { var actionList = new List <ISuggestedAction>(); var currentSnapshot = range.Snapshot; var first = _agg.GetTags(range).FirstOrDefault(); if (first != null) { actionList.Add(new RemoveDeadAnnotationSuggestedAction(currentSnapshot, first.Tag)); } Program p; RefactoringUtil.GetExistingProgram(currentSnapshot.TextBuffer, out p); if (p == null) { return(Enumerable.Empty <SuggestedActionSet>()); } var tld = RefactoringUtil.GetTld(p); MemberDecl md; RefactoringUtil.GetMemberFromPosition(tld, range.Start, out md); if (md != null) { var methodSpan = RefactoringUtil.GetRangeOfMember(currentSnapshot, md); var tagSpans = _agg.GetTags(methodSpan); var tags = (from ts in tagSpans select new RemoveDeadAnnotationSuggestedAction(currentSnapshot, ts.Tag)).ToList(); if (tags.Count > 0) { actionList.Add(new RemoveMultipleDeadAnnotationsSuggestedAction(currentSnapshot.TextBuffer, tags, DeadAnnotationLocation.Block)); } } var snapshotWideSpan = new SnapshotSpan(currentSnapshot, 0, currentSnapshot.Length); var allTags = _agg.GetTags(snapshotWideSpan); var list = allTags.Select(ts => new RemoveDeadAnnotationSuggestedAction(currentSnapshot, ts.Tag)).ToList(); if (list.Count > 0) { actionList.Add(new RemoveMultipleDeadAnnotationsSuggestedAction(currentSnapshot.TextBuffer, list, DeadAnnotationLocation.File)); } return(actionList.Count > 0 ? new [] { new SuggestedActionSet(actionList.ToArray()) } : Enumerable.Empty <SuggestedActionSet>()); }
private void ProcessProgram() { Begin(); var prog = RefactoringUtil.GetNewProgram(_tb); if (prog == null) { NotifyStatusbar(DeadAnnotationStatus.NoProgram); Finish(); return; } UpdateFilename(prog.FullName); _thread = new Thread(ProcessProgramThreaded); _thread.Start(new ThreadParams { P = prog, S = Snapshot, Stop = _currentStopper }); }
private TacticReplaceStatus ExpandSingleTacticCall(UpdateStmt us, out string expanded) { expanded = ""; var l = Interpreter.GetTacnyResultList(); var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, us.Tok)); if (result.Value == null) { return(TacticReplaceStatus.NoTactic); } var sr = new StringWriter(); var printer = new Printer(sr); result.Value.ForEach(stmt => printer.PrintStatement(stmt, 4)); expanded = sr.ToString(); return(!string.IsNullOrEmpty(expanded) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoTactic); }
private TacticReplaceStatus ExpandSingleTacticCall(Statement us, out string expanded) { expanded = ""; var l = Microsoft.Dafny.Tacny.TacnyDriver.GetTacticResultList(); var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, us.Tok)); if (result.Value == null) { return(TacticReplaceStatus.NoTactic); } var sr = new StringWriter(); var printer = new Printer(sr); foreach (var stmt in result.Value) { printer.PrintStatement(stmt, 4); sr.Write("\n"); } expanded = sr.ToString(); return(!string.IsNullOrEmpty(expanded) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoTactic); }
public bool ShowRot(IWpfTextView atv) { Contract.Assume(atv != null); string expanded; var caret = atv.Caret.Position.BufferPosition.Position; var triggerPoint = atv.TextBuffer.CurrentSnapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive); var tra = new TacticReplacerActor(atv.TextBuffer, caret); if (tra.LoadStatus != TacticReplaceStatus.Success) { return(NotifyOfReplacement(tra.LoadStatus)); } var status = tra.ExpandSingleTacticCall(caret, out expanded); if (status != TacticReplaceStatus.Success) { return(NotifyOfReplacement(status)); } string file; var fileLoaded = RefactoringUtil.LoadAndCheckDocument(atv.TextBuffer, out file); if (!fileLoaded) { return(NotifyOfReplacement(TacticReplaceStatus.NoDocumentPersistence)); } var session = _pb.CreatePeekSession(new PeekSessionCreationOptions(atv, RotPeekRelationship.SName, triggerPoint, 0, false, null, false)); _activePeekSession.Remove(file); _activePeekSession.Add(file, new ActivePeekSessionData { TriggerPoint = triggerPoint, ExpandedTactic = expanded, ActiveTactic = tra.GetActiveTacticName() }); session.Start(); return(NotifyOfReplacement(TacticReplaceStatus.Success)); }
public TacticReplaceStatus SetTacticCall(int position) { return(RefactoringUtil.GetTacticCallAtPosition(_member as Method, position, out _tacticCall)); }
public bool ClearPeekSession(IPeekSession session) { string file; return(RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file) && _activePeekSession.Remove(file)); }