Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve indentation of generated Java-code #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mthmulders
Copy link

Given a small input file, sample.tt:

const MY_CONSTANT = 42;
typedef long MyLongs[MY_CONSTANT];
struct MyStructure {
     MyLongs myLongs;
};

Invoking Treetop with: bundle exec xdrgen sample.tt -o generated -l java -n generated, it generates this Java source file:

// Automatically generated by xdrgen 
// DO NOT EDIT or your changes may be overwritten

package generated;


import java.io.IOException;

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

//  typedef long MyLongs[MY_CONSTANT];

//  ===========================================================================
public class MyLongs  {
  private Long[] MyLongs;
  public Long[] getMyLongs() {
    return this.MyLongs;
  }
  public void setMyLongs(Long[] value) {
    this.MyLongs = value;
  }
  public static void encode(XdrDataOutputStream stream, MyLongs  encodedMyLongs) throws IOException {
  int MyLongssize = encodedMyLongs.getMyLongs().length;
  for (int i = 0; i < MyLongssize; i++) {
    stream.writeLong(encodedMyLongs.MyLongs[i]);
  }
  }
  public static MyLongs decode(XdrDataInputStream stream) throws IOException {
    MyLongs decodedMyLongs = new MyLongs();
  int MyLongssize = MY_CONSTANT;
  decodedMyLongs.MyLongs = new Long[MyLongssize];
  for (int i = 0; i < MyLongssize; i++) {
    decodedMyLongs.MyLongs[i] = stream.readLong();
  }
    return decodedMyLongs;
  }
}

Apart from the fact that this code does not compile (#33) it also has some strange indentation choices in its encode and decode methods. This PR fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant