| 326 | } |
| 327 | |
| 328 | DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::replaceOldText(CodeRepresentation* repr, |
| 329 | const QString& newText, |
| 330 | const ChangesList& sortedChangesList) |
| 331 | { |
| 332 | auto* dynamic = dynamic_cast<DynamicCodeRepresentation*>(repr); |
| 333 | if (dynamic) { |
| 334 | auto transaction = dynamic->makeEditTransaction(); |
| 335 | //Replay the changes one by one |
| 336 | |
| 337 | for (int pos = sortedChangesList.size() - 1; pos >= 0; --pos) { |
| 338 | const DocumentChange& change(*sortedChangesList[pos]); |
| 339 | if (!dynamic->replace(change.m_range, change.m_oldText, change.m_newText, change.m_ignoreOldText)) { |
| 340 | QString warningString = i18nc( |
| 341 | "Inconsistent change in <filename> between <range>, found <oldText> (encountered <foundText>) -> <newText>", |
| 342 | "Inconsistent change in %1 between %2, found %3 (encountered \"%4\") -> \"%5\"", |
| 343 | change.m_document.str(), |
| 344 | printRange(change.m_range), |
| 345 | change.m_oldText, |
| 346 | dynamic->rangeText(change.m_range), |
| 347 | change.m_newText); |
| 348 | |
| 349 | if (replacePolicy == DocumentChangeSet::WarnOnFailedChange) { |
| 350 | qCWarning(LANGUAGE) << warningString; |
| 351 | } else if (replacePolicy == DocumentChangeSet::StopOnFailedChange) { |
| 352 | return DocumentChangeSet::ChangeResult(warningString); |
| 353 | } |
| 354 | //If set to ignore failed changes just continue with the others |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | return DocumentChangeSet::ChangeResult::successfulResult(); |
| 359 | } |
| 360 | |
| 361 | //For files on disk |
| 362 | if (!repr->setText(newText)) { |
| 363 | QString warningString = i18n("Could not replace text in the document: %1", |
| 364 | sortedChangesList.begin()->data()->m_document.str()); |
| 365 | if (replacePolicy == DocumentChangeSet::WarnOnFailedChange) { |
| 366 | qCWarning(LANGUAGE) << warningString; |
| 367 | } |
| 368 | |
| 369 | return DocumentChangeSet::ChangeResult(warningString); |
| 370 | } |
| 371 | |
| 372 | return DocumentChangeSet::ChangeResult::successfulResult(); |
| 373 | } |
| 374 | |
| 375 | DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::generateNewText(const IndexedString& file, |
| 376 | ChangesList& sortedChanges, |
no test coverage detected