Skip to content

Commit

Permalink
remove public attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Jul 10, 2024
1 parent 9bd4437 commit 9e4a2a9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
26 changes: 13 additions & 13 deletions Sources/EnumeratorMacro/EnumCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import SwiftDiagnostics
import SwiftSyntax
import Mustache

public struct EnumCase {
public struct Parameter {
public let name: MString?
public let type: MString
struct EnumCase {
struct Parameter {
let name: MString?
let type: MString

public init(name: String?, type: String) {
init(name: String?, type: String) {
self.name = name.map { .init($0) }
self.type = .init(type)
}
}

public struct Parameters {
struct Parameters {
fileprivate let underlying: [Parameter]

init(underlying: [Parameter]) {
self.underlying = underlying
}
}

public let name: MString
public let parameters: Parameters
let name: MString
let parameters: Parameters

public init(from element: EnumCaseElementSyntax) throws {
init(from element: EnumCaseElementSyntax) throws {
self.name = .init(element.name.trimmedDescription)
let parameters = element.parameterClause?.parameters ?? []
self.parameters = .init(underlying: parameters.map { parameter in
Expand All @@ -39,19 +39,19 @@ public struct EnumCase {
// MARK: - + Parameters

extension EnumCase.Parameters: Sequence, MustacheSequence {
public func makeIterator() -> Array<EnumCase.Parameter>.Iterator {
func makeIterator() -> Array<EnumCase.Parameter>.Iterator {
self.underlying.makeIterator()
}
}

//extension EnumCase.Parameters: CustomReflectable {
// public var customMirror: Mirror {
// var customMirror: Mirror {
// Mirror(reflecting: self.underlying)
// }
//}

extension EnumCase.Parameters: MustacheTransformable {
public func transform(_ name: String) -> Any? {
func transform(_ name: String) -> Any? {
if let defaultTransformed = self.underlying.transform(name) {
return convertToCustomTypesIfPossible(defaultTransformed)
} else {
Expand Down Expand Up @@ -97,7 +97,7 @@ extension EnumCase.Parameters: MustacheTransformable {
}

extension EnumCase.Parameters: CustomStringConvertible {
public var description: String {
var description: String {
self.underlying.description
}
}
4 changes: 2 additions & 2 deletions Sources/EnumeratorMacro/EnumeratorMacroType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SwiftSyntaxMacros
import SwiftParser
import Mustache

public enum EnumeratorMacroType {}
enum EnumeratorMacroType {}

extension EnumeratorMacroType: MemberMacro {
public static func expansion(
static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
Expand Down
10 changes: 5 additions & 5 deletions Sources/EnumeratorMacro/MArray.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Mustache

public struct MArray<Element> {
struct MArray<Element> {
fileprivate let underlying: [Element]

init(underlying: [Element]) {
Expand All @@ -9,25 +9,25 @@ public struct MArray<Element> {
}

extension MArray: Sequence, MustacheSequence {
public func makeIterator() -> Array<Element>.Iterator {
func makeIterator() -> Array<Element>.Iterator {
self.underlying.makeIterator()
}
}

extension MArray: CustomStringConvertible {
public var description: String {
var description: String {
self.underlying.description
}
}

extension MArray: CustomReflectable {
public var customMirror: Mirror {
var customMirror: Mirror {
Mirror(reflecting: self.underlying)
}
}

extension MArray: MustacheTransformable {
public func transform(_ name: String) -> Any? {
func transform(_ name: String) -> Any? {
if let defaultTransformed = self.underlying.transform(name) {
return convertToCustomTypesIfPossible(defaultTransformed)
} else {
Expand Down
10 changes: 5 additions & 5 deletions Sources/EnumeratorMacro/MOptionalsArray.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Mustache

public struct MOptionalsArray<Element> {
struct MOptionalsArray<Element> {
fileprivate let underlying: [Element?]

init(underlying: [Element?]) {
Expand All @@ -9,25 +9,25 @@ public struct MOptionalsArray<Element> {
}

extension MOptionalsArray: Sequence, MustacheSequence {
public func makeIterator() -> Array<Element?>.Iterator {
func makeIterator() -> Array<Element?>.Iterator {
self.underlying.makeIterator()
}
}

extension MOptionalsArray: CustomStringConvertible {
public var description: String {
var description: String {
self.underlying.description
}
}

extension MOptionalsArray: CustomReflectable {
public var customMirror: Mirror {
var customMirror: Mirror {
Mirror(reflecting: self.underlying)
}
}

extension MOptionalsArray: MustacheTransformable {
public func transform(_ name: String) -> Any? {
func transform(_ name: String) -> Any? {
if let defaultTransformed = self.underlying.transform(name) {
return convertToCustomTypesIfPossible(defaultTransformed)
} else {
Expand Down
62 changes: 31 additions & 31 deletions Sources/EnumeratorMacro/MString.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import Mustache

public struct MString {
struct MString {
var underlying: String

public init(_ underlying: String) {
init(_ underlying: String) {
self.underlying = underlying
}
}

extension MString: CustomStringConvertible {
public var description: String {
var description: String {
self.underlying.description
}
}

extension MString: CustomReflectable {
public var customMirror: Mirror {
var customMirror: Mirror {
self.underlying.customMirror
}
}

extension MString: MustacheTransformable {
public func transform(_ name: String) -> Any? {
func transform(_ name: String) -> Any? {
if let defaultTransformed = self.underlying.transform(name) {
return convertToCustomTypesIfPossible(defaultTransformed)
} else {
Expand All @@ -38,51 +38,51 @@ extension MString: MustacheTransformable {
}

extension MString: StringProtocol {
public typealias Index = String.Index
public typealias UTF8View = String.UTF8View
public typealias UTF16View = String.UTF16View
public typealias UnicodeScalarView = String.UnicodeScalarView
public typealias SubSequence = String.SubSequence
typealias Index = String.Index
typealias UTF8View = String.UTF8View
typealias UTF16View = String.UTF16View
typealias UnicodeScalarView = String.UnicodeScalarView
typealias SubSequence = String.SubSequence

public var utf8: String.UTF8View {
var utf8: String.UTF8View {
self.underlying.utf8
}

public var utf16: String.UTF16View {
var utf16: String.UTF16View {
self.underlying.utf16
}

public var unicodeScalars: String.UnicodeScalarView {
var unicodeScalars: String.UnicodeScalarView {
self.underlying.unicodeScalars
}

public subscript(position: String.Index) -> Character {
subscript(position: String.Index) -> Character {
_read {
yield self.underlying[position]
}
}

public subscript(bounds: Range<Index>) -> SubSequence {
subscript(bounds: Range<Index>) -> SubSequence {
self.underlying[bounds]
}

public func lowercased() -> String {
func lowercased() -> String {
self.underlying.lowercased()
}

public func uppercased() -> String {
func uppercased() -> String {
self.underlying.uppercased()
}

public func hasPrefix(_ prefix: String) -> Bool {
func hasPrefix(_ prefix: String) -> Bool {
self.underlying.hasPrefix(prefix)
}

public func hasSuffix(_ suffix: String) -> Bool {
func hasSuffix(_ suffix: String) -> Bool {
self.underlying.hasSuffix(suffix)
}

public init<C, Encoding>(
init<C, Encoding>(
decoding codeUnits: C,
as sourceEncoding: Encoding.Type = Encoding.self
) where C : Collection, Encoding : _UnicodeEncoding, C.Element == Encoding.CodeUnit {
Expand All @@ -92,11 +92,11 @@ extension MString: StringProtocol {
))
}

public init(cString nullTerminatedUTF8: UnsafePointer<CChar>) {
init(cString nullTerminatedUTF8: UnsafePointer<CChar>) {
self.init(String(cString: nullTerminatedUTF8))
}

public init<Encoding>(
init<Encoding>(
decodingCString nullTerminatedCodeUnits: UnsafePointer<Encoding.CodeUnit>,
as sourceEncoding: Encoding.Type = Encoding.self
) where Encoding : _UnicodeEncoding {
Expand All @@ -106,42 +106,42 @@ extension MString: StringProtocol {
))
}

public func withCString<Result>(_ body: (UnsafePointer<CChar>) throws -> Result) rethrows -> Result {
func withCString<Result>(_ body: (UnsafePointer<CChar>) throws -> Result) rethrows -> Result {
try self.underlying.withCString(body)
}

public func withCString<Result, Encoding>(
func withCString<Result, Encoding>(
encodedAs targetEncoding: Encoding.Type = Encoding.self,
_ body: (UnsafePointer<Encoding.CodeUnit>) throws -> Result
) rethrows -> Result where Encoding : _UnicodeEncoding {
try self.underlying.withCString(encodedAs: targetEncoding, body)
}

public func index(before i: String.Index) -> String.Index {
func index(before i: String.Index) -> String.Index {
self.underlying.index(before: i)
}

public func index(after i: String.Index) -> String.Index {
func index(after i: String.Index) -> String.Index {
self.underlying.index(after: i)
}

public var startIndex: String.Index {
var startIndex: String.Index {
self.underlying.startIndex
}

public var endIndex: String.Index {
var endIndex: String.Index {
self.underlying.endIndex
}

public mutating func write(_ string: String) {
mutating func write(_ string: String) {
self.underlying.write(string)
}

public func write<Target>(to target: inout Target) where Target : TextOutputStream {
func write<Target>(to target: inout Target) where Target : TextOutputStream {
self.underlying.write(to: &target)
}

public init(stringLiteral value: String) {
init(stringLiteral value: String) {
self.init(value)
}
}
16 changes: 8 additions & 8 deletions Tests/EnumeratorMacroTests/EnumeratorMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import Testing
}
"""
)
public enum TestEnum {
enum TestEnum {
case a
case b
}
"""#,
expandedSource: #"""
public enum TestEnum {
enum TestEnum {
case a
case b
Expand Down Expand Up @@ -53,14 +53,14 @@ import Testing
{{/cases}}
}
""")
public enum TestEnum {
enum TestEnum {
case a(val1: String, val2: Int)
case b
case testCase(testValue: String)
}
"""#,
expandedSource: #"""
public enum TestEnum {
enum TestEnum {
case a(val1: String, val2: Int)
case b
case testCase(testValue: String)
Expand Down Expand Up @@ -91,14 +91,14 @@ import Testing
}
{{/cases}}
""")
public enum TestEnum {
enum TestEnum {
case a(val1: String, val2: Int)
case b
case testCase(testValue: String)
}
"""#,
expandedSource: #"""
public enum TestEnum {
enum TestEnum {
case a(val1: String, val2: Int)
case b
case testCase(testValue: String)
Expand Down Expand Up @@ -186,7 +186,7 @@ var is{{capitalized(name)}}: Bool {
}
{{/cases}}
""")
public enum TestEnum {
enum TestEnum {
case a(value: String)
case b
case testCase(testValue: String)
Expand All @@ -206,7 +206,7 @@ var is{{capitalized(name)}}: Bool {
}
{{/cases}}
""")
public enum TestEnum3 {
enum TestEnum3 {
case a(value: String)
case b
case testCase(testValue: String)
Expand Down

0 comments on commit 9e4a2a9

Please sign in to comment.