-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial framework code for the wrapper generator.
Related to #76.
- Loading branch information
Showing
6 changed files
with
138 additions
and
2 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
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,5 @@ | ||
set -e | ||
|
||
cargo test --verbose --features libjvm | ||
(cd examples/java-lib && ./test.sh) | ||
(cd generator && cargo test --verbose) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "rust-jni-generator" | ||
version = "0.1.0" | ||
authors = ["Monnoroch <[email protected]>"] | ||
|
||
[dependencies] | ||
quote = "0.6.3" | ||
proc-macro2 = "0.4.6" | ||
|
||
[lib] | ||
proc-macro = true |
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,76 @@ | ||
#![feature(proc_macro)] | ||
|
||
extern crate proc_macro; | ||
#[macro_use] | ||
extern crate quote; | ||
extern crate proc_macro2; | ||
|
||
use proc_macro2::*; | ||
|
||
/// Generate `rust-jni` wrappers for Java classes and interfaces. | ||
/// | ||
/// TODO(#76): examples. | ||
#[proc_macro] | ||
pub fn java_generate(input: proc_macro::TokenStream) -> proc_macro::TokenStream { | ||
let input: TokenStream = input.into(); | ||
java_generate_impl(input).into() | ||
} | ||
|
||
fn java_generate_impl(input: TokenStream) -> TokenStream { | ||
generate(to_generator_data(parse_java_definition(input))) | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
struct JavaDefinitions {} | ||
|
||
fn parse_java_definition(_input: TokenStream) -> JavaDefinitions { | ||
JavaDefinitions {} | ||
} | ||
|
||
#[cfg(test)] | ||
mod parse_tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn empty() { | ||
let input = quote!{}; | ||
assert_eq!(parse_java_definition(input), JavaDefinitions {}); | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
struct GeneratorData {} | ||
|
||
fn to_generator_data(_definitions: JavaDefinitions) -> GeneratorData { | ||
GeneratorData {} | ||
} | ||
|
||
#[cfg(test)] | ||
mod to_generator_data_tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn empty() { | ||
assert_eq!(to_generator_data(JavaDefinitions {}), GeneratorData {}); | ||
} | ||
} | ||
|
||
fn generate(_data: GeneratorData) -> TokenStream { | ||
TokenStream::new() | ||
} | ||
|
||
#[cfg(test)] | ||
mod generate_tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn empty() { | ||
let expected = quote!{}; | ||
assert_tokens_equals(generate(GeneratorData {}), expected); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
fn assert_tokens_equals(left: TokenStream, right: TokenStream) { | ||
assert_eq!(format!("{:?}", left), format!("{:?}", right),); | ||
} |
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,12 @@ | ||
extern crate rust_jni_generator; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[allow(unused_imports)] | ||
use rust_jni_generator::*; | ||
|
||
java_generate!{} | ||
|
||
#[test] | ||
fn test() {} | ||
} |