@@ -99,6 +99,14 @@ extension Swift2JavaTranslator {
9999 log. trace ( " Analyzing \( input. filePath) " )
100100 visitor. visit ( sourceFile: input. syntax)
101101 }
102+
103+ // If any API uses 'Foundation.Data', import 'Data' as if it's declared in
104+ // this module.
105+ if let dataDecl = self . symbolTable [ . data] {
106+ if self . isUsing ( dataDecl) {
107+ visitor. visit ( nominalDecl: dataDecl. syntax!. asNominal!, in: nil )
108+ }
109+ }
102110 }
103111
104112 package func prepareForTranslation( ) {
@@ -108,6 +116,53 @@ extension Swift2JavaTranslator {
108116 log: self . log
109117 )
110118 }
119+
120+ // Check if any of the imported decls uses the specified nominal declaration.
121+ func isUsing( _ decl: SwiftNominalTypeDeclaration ) -> Bool {
122+ func check( _ type: SwiftType ) -> Bool {
123+ switch type {
124+ case . nominal( let nominal) :
125+ return nominal. nominalTypeDecl == decl
126+ case . optional( let ty) :
127+ return check ( ty)
128+ case . tuple( let tuple) :
129+ return tuple. contains ( where: check)
130+ case . function( let fn) :
131+ return check ( fn. resultType) || fn. parameters. contains ( where: { check ( $0. type) } )
132+ case . metatype( let ty) :
133+ return check ( ty)
134+ }
135+ }
136+
137+ func check( _ fn: ImportedFunc ) -> Bool {
138+ if check ( fn. functionSignature. result. type) {
139+ return true
140+ }
141+ if fn. functionSignature. parameters. contains ( where: { check ( $0. type) } ) {
142+ return true
143+ }
144+ return false
145+ }
146+
147+ if self . importedGlobalFuncs. contains ( where: check) {
148+ return true
149+ }
150+ if self . importedGlobalVariables. contains ( where: check) {
151+ return true
152+ }
153+ for importedType in self . importedTypes. values {
154+ if importedType. initializers. contains ( where: check) {
155+ return true
156+ }
157+ if importedType. methods. contains ( where: check) {
158+ return true
159+ }
160+ if importedGlobalVariables. contains ( where: check) {
161+ return true
162+ }
163+ }
164+ return false
165+ }
111166}
112167
113168// ==== ----------------------------------------------------------------------------------------------------------------
0 commit comments