Swift has custom operators like + etc, since Java doesn't have direct equivalent, today we drop them entirely.
Extracting
We need to start extracting operators; I think we can get them into ExtractedFunc and just give them a new .operator kind. Most of this work is done by SwiftAnalysisVisitor.
This would be done in the swift-extract layer; we should have tests that we extract all those kinds of operators.
Naming
Naming should likely have some recursive mechanism to give it a swift name ++ and we turn it into plusPlus etc. We should likely do this in makeJavaMethodName and have a special case for .operator apiKind there.
| Swift |
Java |
| + |
plus |
| - |
minus |
| * |
times |
| / |
dividedBy |
| % |
remainder |
| << |
shiftedLeft |
| >> |
shiftedRight |
| | |
bitwiseOr |
| ~ |
bitwiseNot |
| prefix - |
negated |
| == |
isEqual??? |
| != |
isNotEqual |
| < |
lessThan |
| <= |
lessThanOrEqual |
| > |
greaterThan |
| >= |
greaterThanOrEqual |
| & |
bitwiseAnd |
| ^ |
bitwiseXor |
| ?? |
coalescingNil |
| prefix ! |
logicalNot |
There are some special ones, like == IF the type conforms to Equatable which translates to equals... so we'd probably skip that one because we already handle it as equals I think 🤔
And for printing I think this should mostly just work because they are effectively like functions.
Please also add runtime tests -- we do those by adding real examples in Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary (add an Operators.swift) and add a bunch of normal java Junit tests later on.
Swift has custom operators like
+etc, since Java doesn't have direct equivalent, today we drop them entirely.Extracting
We need to start extracting operators; I think we can get them into
ExtractedFuncand just give them a new.operatorkind. Most of this work is done bySwiftAnalysisVisitor.This would be done in the swift-extract layer; we should have tests that we extract all those kinds of operators.
Naming
Naming should likely have some recursive mechanism to give it a swift name
++and we turn it intoplusPlusetc. We should likely do this inmakeJavaMethodNameand have a special case for.operatorapiKindthere.There are some special ones, like
==IF the type conforms toEquatablewhich translates toequals... so we'd probably skip that one because we already handle it as equals I think 🤔And for printing I think this should mostly just work because they are effectively like functions.
Please also add runtime tests -- we do those by adding real examples in
Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary(add anOperators.swift) and add a bunch of normal java Junit tests later on.