Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bancek committed Sep 27, 2013
1 parent cfe4459 commit 50e0a59
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 19 deletions.
27 changes: 10 additions & 17 deletions .gitignore
@@ -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
6 changes: 4 additions & 2 deletions README.md
@@ -1,4 +1,6 @@
javatoscala
===========
Java to Scala
=============

Online Java to Scala converter

http://javatoscala.com
46 changes: 46 additions & 0 deletions app/controllers/Application.scala
@@ -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))
}
}
)
}

}
21 changes: 21 additions & 0 deletions app/models/Conversion.scala
@@ -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)
}

}
40 changes: 40 additions & 0 deletions app/views/convert.scala.html
@@ -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>

}
50 changes: 50 additions & 0 deletions app/views/index.scala.html
@@ -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">
}
}
67 changes: 67 additions & 0 deletions app/views/main.scala.html
@@ -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>
11 changes: 11 additions & 0 deletions build.sbt
@@ -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
59 changes: 59 additions & 0 deletions conf/application.conf
@@ -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

10 changes: 10 additions & 0 deletions conf/routes
@@ -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)
1 change: 1 addition & 0 deletions project/build.properties
@@ -0,0 +1 @@
sbt.version=0.13.0
8 changes: 8 additions & 0 deletions project/plugins.sbt
@@ -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")

0 comments on commit 50e0a59

Please sign in to comment.