-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathUIKitTransformPlugin.swift
50 lines (42 loc) · 1.29 KB
/
UIKitTransformPlugin.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// UIKitTransformPlugin.swift
// SwiftKotlinFramework
//
// Created by Angel Luis Garcia on 17/05/2020.
//
import Foundation
import Transform
import AST
public class UIKitTransformPlugin: TokenTransformPlugin {
public var name: String {
return "UIKit transformations"
}
public var description: String {
return "Transforms classes like UIView, UILabel,... to their Android counterpart"
}
public init() {}
public func transform(tokens: [Token], topDeclaration: TopLevelDeclaration) throws -> [Token] {
var newTokens = [Token]()
for token in tokens {
if token.kind == .identifier, let mapping = classMappings[token.value], let node = token.node {
newTokens.append(node.newToken(.identifier, mapping))
} else {
newTokens.append(token)
}
}
return newTokens
}
let classMappings = [
"UIView": "View",
"UILabel": "TextView",
"UITextField": "EditText",
"UIImageView": "ImageView",
"UIButton": "Button",
"UITableView": "RecyclerView",
"UIStackView": "LinearLayout",
"UIScrollView": "ScrollView",
"UISwitch": "Switch",
"IBOutlet": "BindView()",
"IBAction": "OnClick()"
]
}