Init initializes the embedded Generator and initializes the Java class information needed to generate structs that extend Java classes and interfaces.
(classes []*java.Class)
| 48 | // Init initializes the embedded Generator and initializes the Java class information |
| 49 | // needed to generate structs that extend Java classes and interfaces. |
| 50 | func (g *JavaGen) Init(classes []*java.Class) { |
| 51 | g.Generator.Init() |
| 52 | g.clsMap = make(map[string]*java.Class) |
| 53 | for _, cls := range classes { |
| 54 | g.clsMap[cls.Name] = cls |
| 55 | } |
| 56 | g.jstructs = make(map[*types.TypeName]*javaClassInfo) |
| 57 | g.constructors = make(map[*types.TypeName][]*types.Func) |
| 58 | for _, s := range g.structs { |
| 59 | classes := embeddedJavaClasses(s.t) |
| 60 | if len(classes) == 0 { |
| 61 | continue |
| 62 | } |
| 63 | inf := &javaClassInfo{ |
| 64 | methods: make(map[string]*java.FuncSet), |
| 65 | genNoargCon: true, // java.lang.Object has a no-arg constructor |
| 66 | } |
| 67 | for _, n := range classes { |
| 68 | cls := g.clsMap[n] |
| 69 | for _, fs := range cls.AllMethods { |
| 70 | hasMeth := false |
| 71 | for _, f := range fs.Funcs { |
| 72 | if !f.Final { |
| 73 | hasMeth = true |
| 74 | } |
| 75 | } |
| 76 | if hasMeth { |
| 77 | inf.methods[fs.GoName] = fs |
| 78 | } |
| 79 | } |
| 80 | inf.supers = append(inf.supers, cls) |
| 81 | if !cls.Interface { |
| 82 | if inf.extends != nil { |
| 83 | g.errorf("%s embeds more than one Java class; only one is allowed.", s.obj) |
| 84 | } |
| 85 | if cls.Final { |
| 86 | g.errorf("%s embeds final Java class %s", s.obj, cls.Name) |
| 87 | } |
| 88 | inf.extends = cls |
| 89 | inf.genNoargCon = cls.HasNoArgCon |
| 90 | } |
| 91 | } |
| 92 | g.jstructs[s.obj] = inf |
| 93 | } |
| 94 | for _, f := range g.funcs { |
| 95 | if t := g.constructorType(f); t != nil { |
| 96 | jinf := g.jstructs[t] |
| 97 | if jinf != nil { |
| 98 | sig := f.Type().(*types.Signature) |
| 99 | jinf.genNoargCon = jinf.genNoargCon && sig.Params().Len() > 0 |
| 100 | } |
| 101 | g.constructors[t] = append(g.constructors[t], f) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | func (j *javaClassInfo) toJavaType(T types.Type) *java.Type { |
| 107 | switch T := T.(type) { |