adl-lang/adl

Referencing types from other modules in unions results in invalid Java code

barryskal opened this issue · 2 comments

with the following example:

import foo.Bar;

union Example {
  Bar bar;
  Baz baz;
};

struct Baz {
  String value;
}

The generated java code does not import the Bar type from the foo module and you end up getting a syntax error, i.e. it generates the code as though Bar comes from the same package

Can you provide more details on how to reproduce this. Here's my attempt:

$ cat main.adl 
module main {

import foo.Bar;

union Example {
  Bar bar;
  Baz baz;
};

struct Baz {
  String value;
};

};
$ cat foo.adl 
module foo {

struct Bar {
   String value;
};

};
$ $ADLC java -I. -O java-output main.adl foo.adl 
$ head java-output/adl/main/Example.java 
/* @generated from adl module main */

package adl.main;

import adl.foo.Bar;
import com.google.gson.JsonElement;
import org.adl.runtime.Factory;
import org.adl.runtime.JsonBinding;
import org.adl.runtime.JsonBindings;
import org.adl.runtime.JsonParseException;
$ 

and in the above, Example.java does import foo.Bar

Apologies, operator error... For those that may come across this in the future, I had the following annotation on the Bar type:

annotation Bar JavaCustomType {
    "javaname" : "com.example.adl.main.Bar",
    "helpers" : "com.example.adl.custom.BarHelpers",
    "generateType" : true
};

What it should have been was:

annotation Bar JavaCustomType {
    "javaname" : "com.example.adl.foo.Bar",
    "helpers" : "com.example.adl.custom.BarHelpers",
    "generateType" : true
};