mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
We already had this functionality in the FixitApplyDiagnosticConsumer, but we also need it in the AST passes because different entries in the API diff data may drive identical fix-its, namely a general type rename, which can occur anywhere a DeclRef appears, but also for function overrides' parameter type changes, which are context specific. rdar://problem/32431533
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
//===--- Replacement.h - Migrator Replacements ------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_MIGRATOR_REPLACEMENT_H
|
|
#define SWIFT_MIGRATOR_REPLACEMENT_H
|
|
namespace swift {
|
|
namespace migrator {
|
|
|
|
struct Replacement {
|
|
size_t Offset;
|
|
size_t Remove;
|
|
std::string Text;
|
|
|
|
bool isRemove() const {
|
|
return Remove > 0;
|
|
}
|
|
|
|
bool isInsert() const {
|
|
return Remove == 0 && Text.size() > 0;
|
|
}
|
|
|
|
bool isReplace() const {
|
|
return Remove > 0 && Text.size() > 0;
|
|
}
|
|
|
|
size_t endOffset() const {
|
|
if (isInsert()) {
|
|
return Offset + Text.size();
|
|
} else {
|
|
return Offset + Remove;
|
|
}
|
|
}
|
|
|
|
bool operator<(const Replacement &Other) const {
|
|
return Offset < Other.Offset;
|
|
}
|
|
|
|
bool operator==(const Replacement &Other) const {
|
|
return Offset == Other.Offset && Remove == Other.Remove &&
|
|
Text == Other.Text;
|
|
}
|
|
};
|
|
|
|
} // end namespace migrator
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_MIGRATOR_REPLACEMENT_H
|