Skip to content

Commit d7bed36

Browse files
authored
Merge pull request #2611 from Matejkob/6.0-no-public-attribute-on-extension-decl
[6.0] Remove `public` from the extension declaration and add it to each declaration in the extension
2 parents d3a39e4 + 15c4bc0 commit d7bed36

25 files changed

+274
-266
lines changed

CodeGeneration/Sources/SyntaxSupport/String+Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public extension StringProtocol {
14-
var withFirstCharacterLowercased: String {
13+
extension StringProtocol {
14+
public var withFirstCharacterLowercased: String {
1515
guard first?.isLetter ?? false else {
1616
return String(first!) + dropFirst().withFirstCharacterLowercased
1717
}
1818
return prefix(1).lowercased() + dropFirst()
1919
}
20-
var withFirstCharacterUppercased: String {
20+
public var withFirstCharacterUppercased: String {
2121
guard first?.isLetter ?? false else {
2222
return String(first!) + dropFirst().withFirstCharacterUppercased
2323
}
2424
return prefix(1).uppercased() + dropFirst()
2525
}
26-
var backtickedIfNeeded: String {
26+
public var backtickedIfNeeded: String {
2727
if Keyword.allCases.map(\.spec).contains(where: {
2828
$0.name == self && ($0.isLexerClassified || $0.name == "Type" || $0.name == "Protocol")
2929
}) {

CodeGeneration/Sources/SyntaxSupport/Utils.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ extension SwiftSyntax.Trivia {
5858
}
5959
}
6060

61-
public extension Collection {
61+
extension Collection {
6262
/// If the collection contains a single element, return it, otherwise `nil`.
63-
var only: Element? {
63+
public var only: Element? {
6464
if !isEmpty && index(after: startIndex) == endIndex {
6565
return self.first!
6666
} else {
@@ -69,8 +69,8 @@ public extension Collection {
6969
}
7070
}
7171

72-
public extension TokenSyntax {
73-
var backtickedIfNeeded: TokenSyntax {
72+
extension TokenSyntax {
73+
public var backtickedIfNeeded: TokenSyntax {
7474
if Keyword.allCases.map(\.spec).contains(where: {
7575
$0.name == self.description && ($0.isLexerClassified || $0.name == "Type" || $0.name == "Protocol")
7676
}) {

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public enum SyntaxOrTokenNodeKind: Hashable {
2323

2424
/// Extension to the ``Child`` type to provide functionality specific to
2525
/// SwiftSyntaxBuilder.
26-
public extension Child {
26+
extension Child {
2727
/// The type of this child, represented by a ``SyntaxBuildableType``, which can
2828
/// be used to create the corresponding `Buildable` and `ExpressibleAs` types.
29-
var buildableType: SyntaxBuildableType {
29+
public var buildableType: SyntaxBuildableType {
3030
let buildableKind: SyntaxOrTokenNodeKind
3131
switch kind {
3232
case .node(kind: let kind):
@@ -44,7 +44,7 @@ public extension Child {
4444
)
4545
}
4646

47-
var parameterBaseType: TypeSyntax {
47+
public var parameterBaseType: TypeSyntax {
4848
switch kind {
4949
case .nodeChoices:
5050
return self.syntaxChoicesType
@@ -53,11 +53,11 @@ public extension Child {
5353
}
5454
}
5555

56-
var parameterType: TypeSyntax {
56+
public var parameterType: TypeSyntax {
5757
return self.buildableType.optionalWrapped(type: parameterBaseType)
5858
}
5959

60-
var defaultValue: ExprSyntax? {
60+
public var defaultValue: ExprSyntax? {
6161
if isOptional || isUnexpectedNodes {
6262
if buildableType.isBaseType && kind.isNodeChoicesEmpty {
6363
return ExprSyntax("\(buildableType.buildable).none")
@@ -85,7 +85,7 @@ public extension Child {
8585
/// If the child node has a default value, return an expression of the form
8686
/// ` = default_value` that can be used as the default value to for a
8787
/// function parameter. Otherwise, return `nil`.
88-
var defaultInitialization: InitializerClauseSyntax? {
88+
public var defaultInitialization: InitializerClauseSyntax? {
8989
if let defaultValue {
9090
return InitializerClauseSyntax(
9191
equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space),
@@ -99,7 +99,7 @@ public extension Child {
9999
/// If this node is a token that can't contain arbitrary text, generate a Swift
100100
/// `precondition` statement that verifies the variable with name var_name and of type
101101
/// ``TokenSyntax`` contains one of the supported text options. Otherwise return `nil`.
102-
func generateAssertStmtTextChoices(varName: String) -> FunctionCallExprSyntax? {
102+
public func generateAssertStmtTextChoices(varName: String) -> FunctionCallExprSyntax? {
103103
guard case .token(choices: let choices, requiresLeadingSpace: _, requiresTrailingSpace: _) = kind else {
104104
return nil
105105
}

CodeGeneration/Sources/Utils/SyntaxBuildableNode.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,41 @@ import SyntaxSupport
1414

1515
/// Extension to the ``Node`` type to provide functionality specific to
1616
/// SwiftSyntaxBuilder.
17-
public extension Node {
17+
extension Node {
1818
/// The node's syntax kind as ``SyntaxBuildableType``.
19-
var type: SyntaxBuildableType {
19+
public var type: SyntaxBuildableType {
2020
SyntaxBuildableType(kind: .node(kind: kind))
2121
}
2222

2323
/// The node's syntax kind as ``SyntaxBuildableType``.
24-
var baseType: SyntaxBuildableType {
24+
public var baseType: SyntaxBuildableType {
2525
if base == .syntaxCollection {
2626
return SyntaxBuildableType(kind: .node(kind: .syntax))
2727
} else {
2828
return SyntaxBuildableType(kind: .node(kind: base))
2929
}
3030
}
3131

32-
static func from(type: SyntaxBuildableType) -> Node {
32+
public static func from(type: SyntaxBuildableType) -> Node {
3333
guard case .node(kind: let kind) = type.kind, let node = SYNTAX_NODE_MAP[kind] else {
3434
fatalError("Base name \(type) does not have a syntax node")
3535
}
3636
return node
3737
}
3838
}
3939

40-
public extension LayoutNode {
40+
extension LayoutNode {
4141
/// Assuming this node has a single child without a default value, that child.
42-
var singleNonDefaultedChild: Child {
42+
public var singleNonDefaultedChild: Child {
4343
let nonDefaultedParams = children.filter { $0.defaultInitialization == nil }
4444
precondition(nonDefaultedParams.count == 1)
4545
return nonDefaultedParams[0]
4646
}
4747
}
4848

49-
public extension CollectionNode {
49+
extension CollectionNode {
5050
/// Assuming this node is a syntax collection, the type of its elements.
51-
var collectionElementType: SyntaxBuildableType {
51+
public var collectionElementType: SyntaxBuildableType {
5252
if elementChoices.count > 1 {
5353
return SyntaxBuildableType(kind: .node(kind: .syntax))
5454
} else {

Sources/SwiftBasicFormat/SyntaxProtocol+Formatted.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public import SwiftSyntax
1616
import SwiftSyntax
1717
#endif
1818

19-
public extension SyntaxProtocol {
19+
extension SyntaxProtocol {
2020
/// Build a syntax node from this `Buildable` and format it with the given format.
21-
func formatted(using format: BasicFormat = BasicFormat()) -> Syntax {
21+
public func formatted(using format: BasicFormat = BasicFormat()) -> Syntax {
2222
format.reset()
2323
return format.rewrite(self)
2424
}

Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ struct UnimplementedError: Error, CustomStringConvertible {
186186
}
187187

188188
/// Default implementation of 'PluginProvider' requirements.
189-
public extension PluginProvider {
190-
var features: [PluginFeature] {
189+
extension PluginProvider {
190+
public var features: [PluginFeature] {
191191
// No optional features by default.
192192
return []
193193
}
194194

195-
func loadPluginLibrary(libraryPath: String, moduleName: String) throws {
195+
public func loadPluginLibrary(libraryPath: String, moduleName: String) throws {
196196
// This should be unreachable. The host should not call 'loadPluginLibrary'
197197
// unless the feature is not declared.
198198
throw UnimplementedError()

Sources/SwiftCompilerPluginMessageHandling/PluginMessageCompatibility.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// Old compiler might send '.declaration' as "freeStandingDeclaration".
14-
@_spi(PluginMessage)
15-
public extension PluginMessage.MacroRole {
16-
init(from decoder: Decoder) throws {
14+
extension PluginMessage.MacroRole {
15+
@_spi(PluginMessage) public init(from decoder: Decoder) throws {
1716
let stringValue = try decoder.singleValueContainer().decode(String.self)
1817
if let role = Self(rawValue: stringValue) {
1918
self = role

Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,35 @@
1313
// This file provides compatiblity aliases to keep dependents of SwiftSyntax building.
1414
// All users of the declarations in this file should transition away from them ASAP.
1515

16-
public extension SyntaxClassification {
16+
extension SyntaxClassification {
1717
/// A `#` keyword like `#warning`.
1818
@available(*, deprecated, renamed: "ifConfigDirective")
19-
static var poundDirective: SyntaxClassification {
19+
public static var poundDirective: SyntaxClassification {
2020
return .ifConfigDirective
2121
}
2222

2323
@available(*, deprecated, renamed: "ifConfigDirective")
24-
static var buildConfigId: SyntaxClassification {
24+
public static var buildConfigId: SyntaxClassification {
2525
return .ifConfigDirective
2626
}
2727

2828
@available(*, deprecated, message: "String interpolation anchors are now classified as .none")
29-
static var stringInterpolationAnchor: SyntaxClassification {
29+
public static var stringInterpolationAnchor: SyntaxClassification {
3030
return .none
3131
}
3232

3333
@available(*, deprecated, renamed: "type")
34-
static var typeIdentifier: SyntaxClassification {
34+
public static var typeIdentifier: SyntaxClassification {
3535
return .type
3636
}
3737

3838
@available(*, deprecated, renamed: "operator")
39-
static var operatorIdentifier: SyntaxClassification {
39+
public static var operatorIdentifier: SyntaxClassification {
4040
return .operator
4141
}
4242

4343
@available(*, deprecated, renamed: "floatLiteral")
44-
static var floatingLiteral: SyntaxClassification {
44+
public static var floatingLiteral: SyntaxClassification {
4545
return .floatLiteral
4646
}
4747
}

Sources/SwiftIDEUtils/Syntax+Classifications.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public import SwiftSyntax
1616
import SwiftSyntax
1717
#endif
1818

19-
public extension SyntaxProtocol {
19+
extension SyntaxProtocol {
2020

2121
/// Sequence of ``SyntaxClassifiedRange``s for this syntax node.
2222
///
2323
/// The provided classified ranges are consecutive and cover the full source
2424
/// text of the node. The ranges may also span multiple tokens, if multiple
2525
/// consecutive tokens would have the same classification then a single classified
2626
/// range is provided for all of them.
27-
var classifications: SyntaxClassifications {
27+
public var classifications: SyntaxClassifications {
2828
let fullRange = ByteSourceRange(offset: 0, length: totalLength.utf8Length)
2929
return SyntaxClassifications(_syntaxNode, in: fullRange)
3030
}
@@ -43,7 +43,7 @@ public extension SyntaxProtocol {
4343
/// - Parameters:
4444
/// - in: The relative byte range to pull ``SyntaxClassifiedRange``s from.
4545
/// - Returns: Sequence of ``SyntaxClassifiedRange``s.
46-
func classifications(in range: ByteSourceRange) -> SyntaxClassifications {
46+
public func classifications(in range: ByteSourceRange) -> SyntaxClassifications {
4747
return SyntaxClassifications(_syntaxNode, in: range)
4848
}
4949

@@ -52,7 +52,7 @@ public extension SyntaxProtocol {
5252
/// - at: The relative to the node byte offset.
5353
/// - Returns: The ``SyntaxClassifiedRange`` for the offset or nil if the source text
5454
/// at the given offset is unclassified.
55-
func classification(at offset: Int) -> SyntaxClassifiedRange? {
55+
public func classification(at offset: Int) -> SyntaxClassifiedRange? {
5656
let classifications = SyntaxClassifications(_syntaxNode, in: ByteSourceRange(offset: offset, length: 1))
5757
var iterator = classifications.makeIterator()
5858
return iterator.next()
@@ -63,7 +63,7 @@ public extension SyntaxProtocol {
6363
/// - at: The absolute position.
6464
/// - Returns: The ``SyntaxClassifiedRange`` for the position or nil if the source text
6565
/// at the given position is unclassified.
66-
func classification(at position: AbsolutePosition) -> SyntaxClassifiedRange? {
66+
public func classification(at position: AbsolutePosition) -> SyntaxClassifiedRange? {
6767
let relativeOffset = position.utf8Offset - self.position.utf8Offset
6868
return self.classification(at: relativeOffset)
6969
}

Sources/SwiftParser/SwiftParserCompatibility.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import SwiftSyntax
1515
// This file provides compatibility aliases to keep dependents of SwiftSyntax building.
1616
// All users of the declarations in this file should transition away from them ASAP.
1717

18-
public extension TokenSpec {
18+
extension TokenSpec {
1919
@available(*, deprecated, renamed: "leftSquare")
20-
static var leftSquareBracket: TokenSpec {
20+
public static var leftSquareBracket: TokenSpec {
2121
return .leftSquare
2222
}
2323

2424
@available(*, deprecated, renamed: "rightSquare")
25-
static var rightSquareBracket: TokenSpec {
25+
public static var rightSquareBracket: TokenSpec {
2626
return .rightSquare
2727
}
2828
}

Sources/SwiftParserDiagnostics/LexerDiagnosticMessages.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ public protocol TokenError: DiagnosticMessage {
2727
var diagnosticID: MessageID { get }
2828
}
2929

30-
public extension TokenError {
31-
static var diagnosticID: MessageID {
30+
extension TokenError {
31+
public static var diagnosticID: MessageID {
3232
return MessageID(domain: diagnosticDomain, id: "\(self)")
3333
}
3434

35-
var diagnosticID: MessageID {
35+
public var diagnosticID: MessageID {
3636
return Self.diagnosticID
3737
}
3838

39-
var severity: DiagnosticSeverity {
39+
public var severity: DiagnosticSeverity {
4040
return .error
4141
}
4242
}
@@ -46,16 +46,16 @@ public protocol TokenWarning: DiagnosticMessage {
4646
var diagnosticID: MessageID { get }
4747
}
4848

49-
public extension TokenWarning {
50-
static var diagnosticID: MessageID {
49+
extension TokenWarning {
50+
public static var diagnosticID: MessageID {
5151
return MessageID(domain: diagnosticDomain, id: "\(self)")
5252
}
5353

54-
var diagnosticID: MessageID {
54+
public var diagnosticID: MessageID {
5555
return Self.diagnosticID
5656
}
5757

58-
var severity: DiagnosticSeverity {
58+
public var severity: DiagnosticSeverity {
5959
return .warning
6060
}
6161
}
@@ -180,11 +180,11 @@ public struct ErrorToWarningDowngrade: TokenWarning {
180180

181181
// MARK: - Convert TokenDiagnostic from SwiftSyntax to error messages
182182

183-
public extension SwiftSyntax.TokenDiagnostic {
183+
extension SwiftSyntax.TokenDiagnostic {
184184
/// `tokenText` is the entire text of the token in which the ``TokenDiagnostic``
185185
/// occurred, including trivia.
186186
@_spi(RawSyntax)
187-
func diagnosticMessage(in token: TokenSyntax) -> DiagnosticMessage {
187+
public func diagnosticMessage(in token: TokenSyntax) -> DiagnosticMessage {
188188
var scalarAtErrorOffset: UnicodeScalar {
189189
// Fall back to the Unicode replacement character U+FFFD in case we can't
190190
// lex the unicode character at `byteOffset`. It's the best we can do
@@ -241,7 +241,7 @@ public extension SwiftSyntax.TokenDiagnostic {
241241
}
242242
}
243243

244-
func position(in token: TokenSyntax) -> AbsolutePosition {
244+
public func position(in token: TokenSyntax) -> AbsolutePosition {
245245
switch kind {
246246
case .extraneousLeadingWhitespaceError, .extraneousLeadingWhitespaceWarning:
247247
if let previousToken = token.previousToken(viewMode: .all) {
@@ -253,7 +253,7 @@ public extension SwiftSyntax.TokenDiagnostic {
253253
return token.position.advanced(by: Int(byteOffset))
254254
}
255255

256-
func fixIts(in token: TokenSyntax) -> [FixIt] {
256+
public func fixIts(in token: TokenSyntax) -> [FixIt] {
257257
switch self.kind {
258258
case .nonBreakingSpace:
259259
let replaceNonBreakingSpace = { (piece: TriviaPiece) -> TriviaPiece in

0 commit comments

Comments
 (0)