This repository has been archived by the owner on May 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
425 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
# Extracted from https://github.com/ulrich/macaron-factory/blob/master/.gitignore | ||
# Ignore all dotfiles... | ||
.* | ||
# except for .gitignore | ||
!.gitignore | ||
|
||
# Ignore Play! working directory # | ||
db | ||
eclipse | ||
lib | ||
log | ||
logs | ||
modules | ||
precompiled | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
test-result | ||
server.pid | ||
*.iml | ||
*.eml | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
javatoscala | ||
=========== | ||
Java to Scala | ||
============= | ||
|
||
Online Java to Scala converter | ||
|
||
http://javatoscala.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package controllers | ||
|
||
import scala.util._ | ||
import play.api._ | ||
import play.api.mvc._ | ||
import play.api.data._ | ||
import play.api.data.Forms._ | ||
import models.Conversion | ||
|
||
object Application extends Controller { | ||
|
||
val exampleCode = """ | ||
|package hello; | ||
| | ||
|class HelloWorldApp { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello World!"); | ||
| } | ||
|} | ||
|""".stripMargin | ||
|
||
val convertForm = Form( | ||
"original" -> nonEmptyText | ||
) | ||
|
||
def index = Action { | ||
Ok(views.html.index(convertForm.fill(exampleCode))) | ||
} | ||
|
||
def convert = Action { implicit request => | ||
convertForm.bindFromRequest.fold( | ||
errors => BadRequest(views.html.index(errors)), | ||
original => { | ||
Conversion.convert(original) match { | ||
case Success(converted) => | ||
Ok(views.html.convert(converted)) | ||
case Failure(e) => | ||
val form = convertForm.fill(original).withGlobalError(e.toString) | ||
|
||
Ok(views.html.index(form)) | ||
} | ||
} | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package models | ||
|
||
import scala.util.Try | ||
import java.io.ByteArrayInputStream | ||
import com.mysema.scalagen.Converter | ||
import japa.parser.JavaParser | ||
|
||
object Conversion { | ||
|
||
val DEFAULT_ENCODING = "UTF-8" | ||
|
||
def convert(original: String): Try[String] = Try { | ||
val bytes = original.getBytes(DEFAULT_ENCODING) | ||
val inputStream = new ByteArrayInputStream(bytes) | ||
|
||
val compilationUnit = JavaParser.parse(inputStream, DEFAULT_ENCODING) | ||
|
||
Converter.instance210.toScala(compilationUnit) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@(converted: String) | ||
|
||
@js = { | ||
var $editor = $('#converted'); | ||
|
||
var heightUpdate = function() { | ||
var newHeight = | ||
editor.getSession().getScreenLength() | ||
* editor.renderer.lineHeight | ||
+ editor.renderer.scrollBar.getWidth(); | ||
|
||
$editor.height(newHeight.toString() + "px"); | ||
|
||
editor.resize(); | ||
}; | ||
|
||
$editor.removeClass('loading'); | ||
|
||
var editor = ace.edit("converted"); | ||
editor.setFontSize(15); | ||
editor.getSession().setMode("ace/mode/scala"); | ||
|
||
editor.getSession().on('change', function(){ | ||
heightUpdate(); | ||
}); | ||
|
||
heightUpdate(); | ||
} | ||
|
||
@main(js = Some(js)) { | ||
|
||
<h4>Scala:</h4> | ||
|
||
<div class="loading" id="converted">@converted</div> | ||
|
||
<br> | ||
|
||
<a href="/" class="btn btn-default btn-lg btn-block">Do it again!</a> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@(convertForm: Form[String]) | ||
|
||
@import helper._ | ||
|
||
@js = { | ||
var $editor = $('#original'); | ||
|
||
var heightUpdate = function() { | ||
var newHeight = | ||
editor.getSession().getScreenLength() | ||
* editor.renderer.lineHeight | ||
+ editor.renderer.scrollBar.getWidth(); | ||
|
||
$editor.height(newHeight.toString() + "px"); | ||
|
||
editor.resize(); | ||
}; | ||
|
||
var editor = ace.edit("original"); | ||
$editor.show(); | ||
|
||
var textarea = $('textarea[name="original"]').hide(); | ||
|
||
editor.setFontSize(15); | ||
editor.getSession().setMode("ace/mode/java"); | ||
editor.getSession().setValue(textarea.val()); | ||
|
||
editor.getSession().on('change', function(){ | ||
heightUpdate(); | ||
textarea.val(editor.getSession().getValue()); | ||
}); | ||
|
||
heightUpdate(); | ||
} | ||
|
||
@main(js = Some(js)) { | ||
|
||
@convertForm.globalError.map { error => | ||
<div class="alert alert-danger"> | ||
@error.message | ||
</div> | ||
} | ||
|
||
@form(routes.Application.convert, args = 'id -> "convert-form") { | ||
<textarea name="original" class="form-control" rows="10">@convertForm("original").value.getOrElse("")</textarea> | ||
<div id="original"></div> | ||
<br> | ||
<input type="submit" class="btn btn-primary btn-lg btn-block" value="Convert"> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
@(js: Option[Html] = None)(content: Html) | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>Java to Scala converter</title> | ||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> | ||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> | ||
<link href='http://fonts.googleapis.com/css?family=Gudea:400,700' rel='stylesheet' type='text/css'> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="header"> | ||
<h3 class="text-muted"><a href="/">Java to Scala converter</a></h3> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-lg-12"> | ||
@content | ||
</div> | ||
</div> | ||
|
||
<div class="row marketing"> | ||
<div class="col-lg-12"> | ||
<h4>How is it working?</h4> | ||
<p><strong>Java to Scala converter</strong> is created with <a href="http://playframework.com" target="_blank">Play framework</a> and <a href="https://github.com/mysema/scalagen" target="_blank">Scalagen</a> library.</p> | ||
|
||
<h4>I don't want you to see my code</h4> | ||
<p>No problem. <a href="http://github.com/koofr/javatoscala" target="_blank"><strong>Java to Scala converter</strong></a> source code is available on <a href="http://github.com/koofr/javatoscala" target="_blank">Github</a> and has MIT license.</p> | ||
|
||
<h4>Authors</h4> | ||
<p>Crafted by highly motivated engineers at <a href="http://koofr.net" target="_blank">Koofr</a> and, hopefully, making your day just a little bit better.</p> | ||
</div> | ||
</div> | ||
|
||
<div class="footer"> | ||
<p><a href="http://koofr.net" target="_blank">Koofr</a> 2013</p> | ||
</div> | ||
</div> | ||
|
||
<a href="https://github.com/koofr/javatoscala"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png" alt="Fork me on GitHub"></a> | ||
</body> | ||
|
||
<script src="//code.jquery.com/jquery-1.10.1.min.js" type="text/javascript"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js" type="text/javascript"></script> | ||
@js.map { js => | ||
<script type="text/javascript"> | ||
$(function(){ | ||
@js | ||
}); | ||
</script> | ||
} | ||
|
||
<script type="text/javascript"> | ||
var _gaq = _gaq || []; | ||
_gaq.push(['_setAccount', 'UA-44425408-1']); | ||
_gaq.push(['_setDomainName', 'javatoscala.com']); | ||
_gaq.push(['_trackPageview']); | ||
|
||
(function() { | ||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | ||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||
})(); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name := "javatoscala" | ||
|
||
version := "1.0-SNAPSHOT" | ||
|
||
libraryDependencies ++= Seq( | ||
"com.mysema.scalagen" %% "scalagen" % "0.3.2" | ||
) | ||
|
||
resolvers += "Koofr Maven repo" at "http://koofr.github.com/repo/maven/" | ||
|
||
play.Project.playScalaSettings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This is the main configuration file for the application. | ||
# ~~~~~ | ||
|
||
# Secret key | ||
# ~~~~~ | ||
# The secret key is used to secure cryptographics functions. | ||
# If you deploy your application to several instances be sure to use the same key! | ||
application.secret="VNV00/q@Qk?]9y@AWuDygOpwG[Ufvt<j/m><]uHxgC_9@LrQpsoAkKY`bAtlOHoE" | ||
|
||
# The application languages | ||
# ~~~~~ | ||
application.langs="en" | ||
|
||
# Global object class | ||
# ~~~~~ | ||
# Define the Global object class for this application. | ||
# Default to Global in the root package. | ||
# application.global=Global | ||
|
||
# Router | ||
# ~~~~~ | ||
# Define the Router object to use for this application. | ||
# This router will be looked up first when the application is starting up, | ||
# so make sure this is the entry point. | ||
# Furthermore, it's assumed your route file is named properly. | ||
# So for an application router like `my.application.Router`, | ||
# you may need to define a router file `conf/my.application.routes`. | ||
# Default to Routes in the root package (and conf/routes) | ||
# application.router=my.application.Routes | ||
|
||
# Database configuration | ||
# ~~~~~ | ||
# You can declare as many datasources as you want. | ||
# By convention, the default datasource is named `default` | ||
# | ||
# db.default.driver=org.h2.Driver | ||
# db.default.url="jdbc:h2:mem:play" | ||
# db.default.user=sa | ||
# db.default.password="" | ||
|
||
# Evolutions | ||
# ~~~~~ | ||
# You can disable evolutions if needed | ||
# evolutionplugin=disabled | ||
|
||
# Logger | ||
# ~~~~~ | ||
# You can also configure logback (http://logback.qos.ch/), | ||
# by providing an application-logger.xml file in the conf directory. | ||
|
||
# Root logger: | ||
logger.root=ERROR | ||
|
||
# Logger used by the framework: | ||
logger.play=INFO | ||
|
||
# Logger provided to your application: | ||
logger.application=DEBUG | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Routes | ||
# This file defines all application routes (Higher priority routes first) | ||
# ~~~~ | ||
|
||
# Home page | ||
GET / controllers.Application.index | ||
POST / controllers.Application.convert | ||
|
||
# Map static resources from the /public folder to the /assets URL path | ||
GET /assets/*file controllers.Assets.at(path="/public", file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=0.13.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Comment to get more information during initialization | ||
logLevel := Level.Warn | ||
|
||
// The Typesafe repository | ||
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | ||
|
||
// Use the Play sbt plugin for Play projects | ||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0") |
Oops, something went wrong.