Skip to content

Remove public from the extension declaration and add it to each declaration in the extension #2602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
//
//===----------------------------------------------------------------------===//

public extension StringProtocol {
var withFirstCharacterLowercased: String {
extension StringProtocol {
public var withFirstCharacterLowercased: String {
guard first?.isLetter ?? false else {
return String(first!) + dropFirst().withFirstCharacterLowercased
}
return prefix(1).lowercased() + dropFirst()
}
var withFirstCharacterUppercased: String {
public var withFirstCharacterUppercased: String {
guard first?.isLetter ?? false else {
return String(first!) + dropFirst().withFirstCharacterUppercased
}
return prefix(1).uppercased() + dropFirst()
}
var backtickedIfNeeded: String {
public var backtickedIfNeeded: String {
if Keyword.allCases.map(\.spec).contains(where: {
$0.name == self && ($0.isLexerClassified || $0.name == "Type" || $0.name == "Protocol")
}) {
Expand Down
8 changes: 4 additions & 4 deletions CodeGeneration/Sources/SyntaxSupport/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ extension SwiftSyntax.Trivia {
}
}

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

public extension TokenSyntax {
var backtickedIfNeeded: TokenSyntax {
extension TokenSyntax {
public var backtickedIfNeeded: TokenSyntax {
if Keyword.allCases.map(\.spec).contains(where: {
$0.name == self.description && ($0.isLexerClassified || $0.name == "Type" || $0.name == "Protocol")
}) {
Expand Down
14 changes: 7 additions & 7 deletions CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public enum SyntaxOrTokenNodeKind: Hashable {

/// Extension to the ``Child`` type to provide functionality specific to
/// SwiftSyntaxBuilder.
public extension Child {
extension Child {
/// The type of this child, represented by a ``SyntaxBuildableType``, which can
/// be used to create the corresponding `Buildable` and `ExpressibleAs` types.
var buildableType: SyntaxBuildableType {
public var buildableType: SyntaxBuildableType {
let buildableKind: SyntaxOrTokenNodeKind
switch kind {
case .node(kind: let kind):
Expand All @@ -44,7 +44,7 @@ public extension Child {
)
}

var parameterBaseType: TypeSyntax {
public var parameterBaseType: TypeSyntax {
switch kind {
case .nodeChoices:
return self.syntaxChoicesType
Expand All @@ -53,11 +53,11 @@ public extension Child {
}
}

var parameterType: TypeSyntax {
public var parameterType: TypeSyntax {
return self.buildableType.optionalWrapped(type: parameterBaseType)
}

var defaultValue: ExprSyntax? {
public var defaultValue: ExprSyntax? {
if isOptional || isUnexpectedNodes {
if buildableType.isBaseType && kind.isNodeChoicesEmpty {
return ExprSyntax("\(buildableType.buildable).none")
Expand Down Expand Up @@ -85,7 +85,7 @@ public extension Child {
/// If the child node has a default value, return an expression of the form
/// ` = default_value` that can be used as the default value to for a
/// function parameter. Otherwise, return `nil`.
var defaultInitialization: InitializerClauseSyntax? {
public var defaultInitialization: InitializerClauseSyntax? {
if let defaultValue {
return InitializerClauseSyntax(
equal: .equalToken(leadingTrivia: .space, trailingTrivia: .space),
Expand All @@ -99,7 +99,7 @@ public extension Child {
/// If this node is a token that can't contain arbitrary text, generate a Swift
/// `precondition` statement that verifies the variable with name var_name and of type
/// ``TokenSyntax`` contains one of the supported text options. Otherwise return `nil`.
func generateAssertStmtTextChoices(varName: String) -> FunctionCallExprSyntax? {
public func generateAssertStmtTextChoices(varName: String) -> FunctionCallExprSyntax? {
guard case .token(choices: let choices, requiresLeadingSpace: _, requiresTrailingSpace: _) = kind else {
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions CodeGeneration/Sources/Utils/SyntaxBuildableNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ import SyntaxSupport

/// Extension to the ``Node`` type to provide functionality specific to
/// SwiftSyntaxBuilder.
public extension Node {
extension Node {
/// The node's syntax kind as ``SyntaxBuildableType``.
var type: SyntaxBuildableType {
public var type: SyntaxBuildableType {
SyntaxBuildableType(kind: .node(kind: kind))
}

/// The node's syntax kind as ``SyntaxBuildableType``.
var baseType: SyntaxBuildableType {
public var baseType: SyntaxBuildableType {
if base == .syntaxCollection {
return SyntaxBuildableType(kind: .node(kind: .syntax))
} else {
return SyntaxBuildableType(kind: .node(kind: base))
}
}

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

public extension LayoutNode {
extension LayoutNode {
/// Assuming this node has a single child without a default value, that child.
var singleNonDefaultedChild: Child {
public var singleNonDefaultedChild: Child {
let nonDefaultedParams = children.filter { $0.defaultInitialization == nil }
precondition(nonDefaultedParams.count == 1)
return nonDefaultedParams[0]
}
}

public extension CollectionNode {
extension CollectionNode {
/// Assuming this node is a syntax collection, the type of its elements.
var collectionElementType: SyntaxBuildableType {
public var collectionElementType: SyntaxBuildableType {
if elementChoices.count > 1 {
return SyntaxBuildableType(kind: .node(kind: .syntax))
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftBasicFormat/SyntaxProtocol+Formatted.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public import SwiftSyntax
import SwiftSyntax
#endif

public extension SyntaxProtocol {
extension SyntaxProtocol {
/// Build a syntax node from this `Buildable` and format it with the given format.
func formatted(using format: BasicFormat = BasicFormat()) -> Syntax {
public func formatted(using format: BasicFormat = BasicFormat()) -> Syntax {
format.reset()
return format.rewrite(self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ struct UnimplementedError: Error, CustomStringConvertible {
}

/// Default implementation of 'PluginProvider' requirements.
public extension PluginProvider {
var features: [PluginFeature] {
extension PluginProvider {
public var features: [PluginFeature] {
// No optional features by default.
return []
}

func loadPluginLibrary(libraryPath: String, moduleName: String) throws {
public func loadPluginLibrary(libraryPath: String, moduleName: String) throws {
// This should be unreachable. The host should not call 'loadPluginLibrary'
// unless the feature is not declared.
throw UnimplementedError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
//===----------------------------------------------------------------------===//

/// Old compiler might send '.declaration' as "freeStandingDeclaration".
@_spi(PluginMessage)
public extension PluginMessage.MacroRole {
init(from decoder: Decoder) throws {
extension PluginMessage.MacroRole {
@_spi(PluginMessage) public init(from decoder: Decoder) throws {
let stringValue = try decoder.singleValueContainer().decode(String.self)
if let role = Self(rawValue: stringValue) {
self = role
Expand Down
14 changes: 7 additions & 7 deletions Sources/SwiftIDEUtils/SwiftIDEUtilsCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
// This file provides compatiblity aliases to keep dependents of SwiftSyntax building.
// All users of the declarations in this file should transition away from them ASAP.

public extension SyntaxClassification {
extension SyntaxClassification {
/// A `#` keyword like `#warning`.
@available(*, deprecated, renamed: "ifConfigDirective")
static var poundDirective: SyntaxClassification {
public static var poundDirective: SyntaxClassification {
return .ifConfigDirective
}

@available(*, deprecated, renamed: "ifConfigDirective")
static var buildConfigId: SyntaxClassification {
public static var buildConfigId: SyntaxClassification {
return .ifConfigDirective
}

@available(*, deprecated, message: "String interpolation anchors are now classified as .none")
static var stringInterpolationAnchor: SyntaxClassification {
public static var stringInterpolationAnchor: SyntaxClassification {
return .none
}

@available(*, deprecated, renamed: "type")
static var typeIdentifier: SyntaxClassification {
public static var typeIdentifier: SyntaxClassification {
return .type
}

@available(*, deprecated, renamed: "operator")
static var operatorIdentifier: SyntaxClassification {
public static var operatorIdentifier: SyntaxClassification {
return .operator
}

@available(*, deprecated, renamed: "floatLiteral")
static var floatingLiteral: SyntaxClassification {
public static var floatingLiteral: SyntaxClassification {
return .floatLiteral
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftIDEUtils/Syntax+Classifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public import SwiftSyntax
import SwiftSyntax
#endif

public extension SyntaxProtocol {
extension SyntaxProtocol {

/// Sequence of ``SyntaxClassifiedRange``s for this syntax node.
///
/// The provided classified ranges are consecutive and cover the full source
/// text of the node. The ranges may also span multiple tokens, if multiple
/// consecutive tokens would have the same classification then a single classified
/// range is provided for all of them.
var classifications: SyntaxClassifications {
public var classifications: SyntaxClassifications {
return SyntaxClassifications(_syntaxNode, in: self.range)
}

Expand All @@ -42,7 +42,7 @@ public extension SyntaxProtocol {
/// - Parameters:
/// - in: The range to pull ``SyntaxClassifiedRange``s from.
/// - Returns: Sequence of ``SyntaxClassifiedRange``s.
func classifications(in range: Range<AbsolutePosition>) -> SyntaxClassifications {
public func classifications(in range: Range<AbsolutePosition>) -> SyntaxClassifications {
return SyntaxClassifications(_syntaxNode, in: range)
}

Expand All @@ -52,7 +52,7 @@ public extension SyntaxProtocol {
/// - Returns: The ``SyntaxClassifiedRange`` for the offset or nil if the source text
/// at the given offset is unclassified.
@available(*, deprecated, message: "Use classification(at: AbsolutePosition) instead.")
func classification(at offset: Int) -> SyntaxClassifiedRange? {
public func classification(at offset: Int) -> SyntaxClassifiedRange? {
return classification(at: AbsolutePosition(utf8Offset: offset + self.position.utf8Offset))
}

Expand All @@ -61,7 +61,7 @@ public extension SyntaxProtocol {
/// - at: The absolute position.
/// - Returns: The ``SyntaxClassifiedRange`` for the position or `nil`` if the source text
/// at the given position is unclassified.
func classification(at position: AbsolutePosition) -> SyntaxClassifiedRange? {
public func classification(at position: AbsolutePosition) -> SyntaxClassifiedRange? {
let range = Range(position: position, length: SourceLength(utf8Length: 1))
let classifications = SyntaxClassifications(_syntaxNode, in: range)
var iterator = classifications.makeIterator()
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftParser/SwiftParserCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import SwiftSyntax
// This file provides compatibility aliases to keep dependents of SwiftSyntax building.
// All users of the declarations in this file should transition away from them ASAP.

public extension TokenSpec {
extension TokenSpec {
@available(*, deprecated, renamed: "leftSquare")
static var leftSquareBracket: TokenSpec {
public static var leftSquareBracket: TokenSpec {
return .leftSquare
}

@available(*, deprecated, renamed: "rightSquare")
static var rightSquareBracket: TokenSpec {
public static var rightSquareBracket: TokenSpec {
return .rightSquare
}
}
Expand Down
24 changes: 12 additions & 12 deletions Sources/SwiftParserDiagnostics/LexerDiagnosticMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public protocol TokenError: DiagnosticMessage {
var diagnosticID: MessageID { get }
}

public extension TokenError {
static var diagnosticID: MessageID {
extension TokenError {
public static var diagnosticID: MessageID {
return MessageID(domain: diagnosticDomain, id: "\(self)")
}

var diagnosticID: MessageID {
public var diagnosticID: MessageID {
return Self.diagnosticID
}

var severity: DiagnosticSeverity {
public var severity: DiagnosticSeverity {
return .error
}
}
Expand All @@ -46,16 +46,16 @@ public protocol TokenWarning: DiagnosticMessage {
var diagnosticID: MessageID { get }
}

public extension TokenWarning {
static var diagnosticID: MessageID {
extension TokenWarning {
public static var diagnosticID: MessageID {
return MessageID(domain: diagnosticDomain, id: "\(self)")
}

var diagnosticID: MessageID {
public var diagnosticID: MessageID {
return Self.diagnosticID
}

var severity: DiagnosticSeverity {
public var severity: DiagnosticSeverity {
return .warning
}
}
Expand Down Expand Up @@ -180,11 +180,11 @@ public struct ErrorToWarningDowngrade: TokenWarning {

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

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

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

func fixIts(in token: TokenSyntax) -> [FixIt] {
public func fixIts(in token: TokenSyntax) -> [FixIt] {
switch self.kind {
case .nonBreakingSpace:
let replaceNonBreakingSpace = { (piece: TriviaPiece) -> TriviaPiece in
Expand Down
Loading