Skip to content

Commit

Permalink
Java: show the XDR source code in the javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed May 15, 2024
1 parent 6b73afa commit 8cc560e
Show file tree
Hide file tree
Showing 40 changed files with 414 additions and 326 deletions.
26 changes: 15 additions & 11 deletions lib/xdrgen/generators/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ def render_definition(defn, constants_container)
def render_nested_definitions(defn, out, post_name="implements XdrElement")
return unless defn.respond_to? :nested_definitions
defn.nested_definitions.each{|ndefn|
render_source_comment out, ndefn
case ndefn
when AST::Definitions::Struct ;
name = name ndefn

out.puts "public static class #{name} #{post_name} {"
out.indent do
render_struct ndefn, out
Expand Down Expand Up @@ -699,17 +701,12 @@ def render_top_matter(out)
def render_source_comment(out, defn)
return if defn.is_a?(AST::Definitions::Namespace)

out.puts <<-EOS.strip_heredoc
// === xdr source ============================================================
EOS

out.puts "// " + defn.text_value.split("\n").join("\n// ")

out.puts <<-EOS.strip_heredoc
// ===========================================================================
EOS
out.puts "/**"
out.puts " * #{name defn}'s original definition in the XDR file is:"
out.puts " * <pre>"
out.puts " * " + escape_html(defn.text_value).split("\n").join("\n * ")
out.puts " * </pre>"
out.puts " */"
end

def render_base64(return_type, out)
Expand Down Expand Up @@ -961,6 +958,13 @@ def name(named)
def name_string(name)
name.camelize
end

def escape_html(value)
value.to_s
.gsub('&', '&amp;')
.gsub('<', '&lt;')
.gsub('>', '&gt;')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

// === xdr source ============================================================

// enum AccountFlags
// { // masks for each flag
// AUTH_REQUIRED_FLAG = 0x1
// };

// ===========================================================================
/**
* AccountFlags's original definition in the XDR file is:
* <pre>
* enum AccountFlags
* { // masks for each flag
* AUTH_REQUIRED_FLAG = 0x1
* };
* </pre>
*/
public enum AccountFlags implements XdrElement {
AUTH_REQUIRED_FLAG(1),
;
Expand Down
11 changes: 6 additions & 5 deletions spec/output/generator_spec_java/const.x/TestArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import java.io.ByteArrayOutputStream;
import java.util.Arrays;

// === xdr source ============================================================

// typedef int TestArray[FOO];

// ===========================================================================
/**
* TestArray's original definition in the XDR file is:
* <pre>
* typedef int TestArray[FOO];
* </pre>
*/
public class TestArray implements XdrElement {
private Integer[] TestArray;

Expand Down
11 changes: 6 additions & 5 deletions spec/output/generator_spec_java/const.x/TestArray2.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import java.io.ByteArrayOutputStream;
import java.util.Arrays;

// === xdr source ============================================================

// typedef int TestArray2<FOO>;

// ===========================================================================
/**
* TestArray2's original definition in the XDR file is:
* <pre>
* typedef int TestArray2&lt;FOO&gt;;
* </pre>
*/
public class TestArray2 implements XdrElement {
private Integer[] TestArray2;

Expand Down
19 changes: 10 additions & 9 deletions spec/output/generator_spec_java/enum.x/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

// === xdr source ============================================================

// enum Color {
// RED=0,
// GREEN=1,
// BLUE=2
// };

// ===========================================================================
/**
* Color's original definition in the XDR file is:
* <pre>
* enum Color {
* RED=0,
* GREEN=1,
* BLUE=2
* };
* </pre>
*/
public enum Color implements XdrElement {
RED(0),
GREEN(1),
Expand Down
19 changes: 10 additions & 9 deletions spec/output/generator_spec_java/enum.x/Color2.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

// === xdr source ============================================================

// enum Color2 {
// RED2=RED,
// GREEN2=1,
// BLUE2=2
// };

// ===========================================================================
/**
* Color2's original definition in the XDR file is:
* <pre>
* enum Color2 {
* RED2=RED,
* GREEN2=1,
* BLUE2=2
* };
* </pre>
*/
public enum Color2 implements XdrElement {
RED2(0),
GREEN2(1),
Expand Down
55 changes: 28 additions & 27 deletions spec/output/generator_spec_java/enum.x/MessageType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

// === xdr source ============================================================

// enum MessageType
// {
// ERROR_MSG,
// HELLO,
// DONT_HAVE,
//
// GET_PEERS, // gets a list of peers this guy knows about
// PEERS,
//
// GET_TX_SET, // gets a particular txset by hash
// TX_SET,
//
// GET_VALIDATIONS, // gets validations for a given ledger hash
// VALIDATIONS,
//
// TRANSACTION, //pass on a tx you have heard about
// JSON_TRANSACTION,
//
// // FBA
// GET_FBA_QUORUMSET,
// FBA_QUORUMSET,
// FBA_MESSAGE
// };

// ===========================================================================
/**
* MessageType's original definition in the XDR file is:
* <pre>
* enum MessageType
* {
* ERROR_MSG,
* HELLO,
* DONT_HAVE,
*
* GET_PEERS, // gets a list of peers this guy knows about
* PEERS,
*
* GET_TX_SET, // gets a particular txset by hash
* TX_SET,
*
* GET_VALIDATIONS, // gets validations for a given ledger hash
* VALIDATIONS,
*
* TRANSACTION, //pass on a tx you have heard about
* JSON_TRANSACTION,
*
* // FBA
* GET_FBA_QUORUMSET,
* FBA_QUORUMSET,
* FBA_MESSAGE
* };
* </pre>
*/
public enum MessageType implements XdrElement {
ERROR_MSG(0),
HELLO(1),
Expand Down
11 changes: 6 additions & 5 deletions spec/output/generator_spec_java/nesting.x/Foo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import java.io.ByteArrayOutputStream;
import java.util.Objects;

// === xdr source ============================================================

// typedef int Foo;

// ===========================================================================
/**
* Foo's original definition in the XDR file is:
* <pre>
* typedef int Foo;
* </pre>
*/
public class Foo implements XdrElement {
private Integer Foo;

Expand Down
58 changes: 38 additions & 20 deletions spec/output/generator_spec_java/nesting.x/MyUnion.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@
import java.io.ByteArrayOutputStream;
import java.util.Objects;

// === xdr source ============================================================

// union MyUnion switch (UnionKey type)
// {
// case ONE:
// struct {
// int someInt;
// } one;
//
// case TWO:
// struct {
// int someInt;
// Foo foo;
// } two;
//
// case OFFER:
// void;
// };

// ===========================================================================
/**
* MyUnion's original definition in the XDR file is:
* <pre>
* union MyUnion switch (UnionKey type)
* {
* case ONE:
* struct {
* int someInt;
* } one;
*
* case TWO:
* struct {
* int someInt;
* Foo foo;
* } two;
*
* case OFFER:
* void;
* };
* </pre>
*/
public class MyUnion implements XdrElement {
public MyUnion () {}
UnionKey type;
Expand Down Expand Up @@ -155,6 +156,14 @@ public static MyUnion fromXdrByteArray(byte[] xdr) throws IOException {
return decode(xdrDataInputStream);
}

/**
* MyUnionOne's original definition in the XDR file is:
* <pre>
* struct {
* int someInt;
* }
* </pre>
*/
public static class MyUnionOne implements XdrElement {
public MyUnionOne () {}
private Integer someInt;
Expand Down Expand Up @@ -228,6 +237,15 @@ public MyUnionOne build() {
}

}
/**
* MyUnionTwo's original definition in the XDR file is:
* <pre>
* struct {
* int someInt;
* Foo foo;
* }
* </pre>
*/
public static class MyUnionTwo implements XdrElement {
public MyUnionTwo () {}
private Integer someInt;
Expand Down
19 changes: 10 additions & 9 deletions spec/output/generator_spec_java/nesting.x/UnionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

// === xdr source ============================================================

// enum UnionKey {
// ONE = 1,
// TWO = 2,
// OFFER = 3
// };

// ===========================================================================
/**
* UnionKey's original definition in the XDR file is:
* <pre>
* enum UnionKey {
* ONE = 1,
* TWO = 2,
* OFFER = 3
* };
* </pre>
*/
public enum UnionKey implements XdrElement {
ONE(1),
TWO(2),
Expand Down
11 changes: 6 additions & 5 deletions spec/output/generator_spec_java/optional.x/Arr.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import java.io.ByteArrayOutputStream;
import java.util.Arrays;

// === xdr source ============================================================

// typedef int Arr[2];

// ===========================================================================
/**
* Arr's original definition in the XDR file is:
* <pre>
* typedef int Arr[2];
* </pre>
*/
public class Arr implements XdrElement {
private Integer[] Arr;

Expand Down
21 changes: 11 additions & 10 deletions spec/output/generator_spec_java/optional.x/HasOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
import java.io.ByteArrayOutputStream;
import java.util.Objects;

// === xdr source ============================================================

// struct HasOptions
// {
// int* firstOption;
// int *secondOption;
// Arr *thirdOption;
// };

// ===========================================================================
/**
* HasOptions's original definition in the XDR file is:
* <pre>
* struct HasOptions
* {
* int* firstOption;
* int *secondOption;
* Arr *thirdOption;
* };
* </pre>
*/
public class HasOptions implements XdrElement {
public HasOptions () {}
private Integer firstOption;
Expand Down
Loading

0 comments on commit 8cc560e

Please sign in to comment.