Giter Club home page Giter Club logo

j2swift's Introduction

j2swift

@author Pat Niemeyer ([email protected])

This is a very basic Java 8 to Swift 1.2 syntax converter. It handles things like flipping type arguments around and rewriting method signatures and constructors. This is by no means a complete Java to Swift translator as it does not make API updates other than in trivial cases.

The converter preserves whitespace and should leave the input untouched in places that it doesn't update, so it is somewhat useful even when it leaves work to be done. For simplistic Java code (e.g. business logic) I'd say this gets you 80% of the way there.

See test/Test.java and test/Test.swift for an idea of what is currently handled.

A few things it does

  • Rewrites static and instance field declarations
  • Rewrites method and init argument lists
  • Rewrites constructors and constructor invocations, including attempting to note convenience intializers
  • Rewrites simple array types
  • Rewrites 'this' references as 'self'
  • Rewrites for, enhanced for, and while loops
  • Maps float, int, long and boolean types
  • Maps null to nil
  • Comments out throws statements and replaces them with a placeholder method invocation throwException()
  • Maps interface to protocol
  • Maps System.out.println() to println()

A few things it could do in the future

  • Final vars should become "let" vars.
  • Method and fields with the same name should be disambiguated.
  • Static method invocations should be qualified.

Building

It's just a handful of Java files in src. The only requirement is the ANTLR runtime:

http://www.antlr.org/download/antlr-4.5-complete.jar or http://www.antlr.org/download/antlr-runtime-4.5.jar

The ANTLR grammar for Java is provided for reference but you do not have to build the parser to make changes. All updates really happen in the J2SwiftListener class.

J2Swift takes a filename or stding as input and outputs to stdout.

j2swift's People

Contributors

patniemeyer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.