jtor 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca5126acd5831041982af13ccfaa6d53a8725c6a
4
+ data.tar.gz: 8e09af5305d4109c2708563b0be9c00d9ec130ab
5
+ SHA512:
6
+ metadata.gz: c8fe1028b34ca30c698ee1732b6d97865ebac35b5e591dd60bfe93c60e8497d7397526099bd10a39009195bf0105329087c1e18067a7ec0a9d1a44921b89e064
7
+ data.tar.gz: a44d00a8f8be8c383d3964c173256b094d4cd91f203131043b93fc96a106de9d8659cd934fa32525f6fe3dd093e448df5e34112e8583e6d1c7873fd92f7a2dbe
data/bin/jtor ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env jruby
2
+ require 'jtor'
3
+
4
+ if ARGV.count != 2
5
+ puts 'Usage: jtor source_dir destination_dir'
6
+ exit
7
+ end
8
+
9
+ Jtor::Translator.run(*ARGV)
data/lib/ext/string.rb ADDED
@@ -0,0 +1,6 @@
1
+ class String
2
+ def to_constant_name
3
+ # ruby class names must start with an uppercase letter (Java types may not)
4
+ empty? ? self : "#{self[0].upcase}#{self[1..-1]}"
5
+ end
6
+ end
@@ -0,0 +1,53 @@
1
+ require 'java'
2
+ require 'jbundler'
3
+
4
+ java_import java.io.FileInputStream
5
+ java_import com.github.javaparser.JavaParser
6
+
7
+ module Jtor
8
+ class JavaParser
9
+ attr_accessor :indentator
10
+
11
+ def initialize(f)
12
+ @indentator = ' '
13
+ @f = f
14
+ end
15
+
16
+ def translate(file)
17
+ parser = ::JavaParser.parse(FileInputStream.new(file))
18
+ parser.types.each { |type| translate_type(0, type) }
19
+ end
20
+
21
+ private
22
+
23
+ def write(i_level, s)
24
+ @f.puts "#{@indentator * i_level}#{s}"
25
+ end
26
+
27
+ def translate_type(i_level, type)
28
+ write(i_level, "class #{type.name.to_constant_name}")
29
+ type.members.each { |member| translate_member(i_level + 1, member) }
30
+ write(i_level, 'end')
31
+ end
32
+
33
+ def translate_method(i_level, name, parameters)
34
+ params = if parameters.any?
35
+ "(#{parameters.map { |p| p.id.name }.join(', ')})"
36
+ else
37
+ ''
38
+ end
39
+ write(i_level, "def #{name}#{params}")
40
+ # TODO: Translate method body
41
+ write(i_level, 'end')
42
+ end
43
+
44
+ def translate_member(i_level, member)
45
+ case member
46
+ when Java::ComGithubJavaparserAstBody::MethodDeclaration
47
+ translate_method(i_level, member.name, member.parameters)
48
+ when Java::ComGithubJavaparserAstBody::ConstructorDeclaration
49
+ translate_method(i_level, 'initialize', member.parameters)
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/jtor/load.rb ADDED
@@ -0,0 +1,4 @@
1
+ warn 'Loading jtor in a non-JRuby interpreter' unless defined? JRUBY_VERSION
2
+
3
+ require 'jar-dependencies'
4
+ require_jar('com.github.javaparser', 'javaparser-core', '2.1.0')
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+
3
+ module Jtor
4
+ class Translator
5
+ def self.run(src, dest)
6
+ Dir.chdir(src)
7
+ Dir.glob('**/*.java').each do |file|
8
+ dest_file = File.join(dest, file.gsub(/java$/, 'rb'))
9
+ FileUtils.mkdir_p(File.dirname(dest_file))
10
+ File.open(dest_file, 'w') do |f|
11
+ JavaParser.new(f).translate(File.join(src, file))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/jtor.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'ext/string'
2
+
3
+ require 'jtor/load'
4
+
5
+ require 'jtor/java_parser'
6
+ require 'jtor/translator'
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jtor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: java
6
+ authors:
7
+ - Alejandro Rodríguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jar-dependencies
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.2
27
+ description: A Java to (J)Ruby translator
28
+ email: alejandroluis24@gmail.com
29
+ executables:
30
+ - jtor
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - bin/jtor
35
+ - lib/ext/string.rb
36
+ - lib/jtor.rb
37
+ - lib/jtor/java_parser.rb
38
+ - lib/jtor/load.rb
39
+ - lib/jtor/translator.rb
40
+ homepage: https://gitlab.com/eReGeBe/jtor
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements:
59
+ - jar com.github.javaparser:javaparser-core, 2.1.0
60
+ rubyforge_project:
61
+ rubygems_version: 2.5.0
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: JtoR - Java to Ruby translator
65
+ test_files: []