func()

in bind/genclasses.go [272:357]


func (g *ClassGen) GenC() {
	g.Printf(classesCHeader)
	for _, cls := range g.classes {
		g.Printf("static jclass class_%s;\n", cls.JNIName)
		if _, ok := g.goClsMap[cls.Name]; ok {
			g.Printf("static jclass sclass_%s;\n", cls.JNIName)
		}
		for _, fs := range cls.Funcs {
			for _, f := range fs.Funcs {
				if !f.Public || !g.isFuncSupported(f) {
					continue
				}
				g.Printf("static jmethodID m_s_%s_%s;\n", cls.JNIName, f.JNIName)
			}
		}
		for _, fs := range cls.AllMethods {
			for _, f := range fs.Funcs {
				if g.isFuncSupported(f) {
					g.Printf("static jmethodID m_%s_%s;\n", cls.JNIName, f.JNIName)
					if _, ok := g.goClsMap[cls.Name]; ok {
						g.Printf("static jmethodID sm_%s_%s;\n", cls.JNIName, f.JNIName)
					}
				}
			}
		}
		g.genC(cls)
	}
	g.Printf("\n")
	g.Printf("void init_proxies() {\n")
	g.Indent()
	g.Printf("JNIEnv *env = go_seq_push_local_frame(%d);\n", len(g.classes))
	g.Printf("jclass clazz;\n")
	for _, cls := range g.classes {
		g.Printf("clazz = go_seq_find_class(%q);\n", strings.Replace(cls.FindName, ".", "/", -1))
		g.Printf("if (clazz != NULL) {\n")
		g.Indent()
		g.Printf("class_%s = (*env)->NewGlobalRef(env, clazz);\n", cls.JNIName)
		if _, ok := g.goClsMap[cls.Name]; ok {
			g.Printf("sclass_%s = (*env)->GetSuperclass(env, clazz);\n", cls.JNIName)
			g.Printf("sclass_%s = (*env)->NewGlobalRef(env, sclass_%s);\n", cls.JNIName, cls.JNIName)
		}
		for _, fs := range cls.Funcs {
			for _, f := range fs.Funcs {
				if !f.Public || !g.isFuncSupported(f) {
					continue
				}
				g.Printf("m_s_%s_%s = ", cls.JNIName, f.JNIName)
				if f.Constructor {
					g.Printf("go_seq_get_method_id(clazz, \"<init>\", %q);\n", f.Desc)
				} else {
					g.Printf("go_seq_get_static_method_id(clazz, %q, %q);\n", f.Name, f.Desc)
				}
			}
		}
		for _, fs := range cls.AllMethods {
			for _, f := range fs.Funcs {
				if g.isFuncSupported(f) {
					g.Printf("m_%s_%s = go_seq_get_method_id(clazz, %q, %q);\n", cls.JNIName, f.JNIName, f.Name, f.Desc)
					if _, ok := g.goClsMap[cls.Name]; ok {
						g.Printf("sm_%s_%s = go_seq_get_method_id(sclass_%s, %q, %q);\n", cls.JNIName, f.JNIName, cls.JNIName, f.Name, f.Desc)
					}
				}
			}
		}
		g.Outdent()
		g.Printf("}\n")
	}
	g.Printf("go_seq_pop_local_frame(env);\n")
	g.Outdent()
	g.Printf("}\n\n")
	for _, cls := range g.classes {
		for _, fs := range cls.AllMethods {
			for _, f := range fs.Funcs {
				if !g.isFuncSupported(f) {
					continue
				}
				g.genCMethodDecl("cproxy", cls.JNIName, f)
				g.genCMethodBody(cls, f, false)
				if _, ok := g.goClsMap[cls.Name]; ok {
					g.genCMethodDecl("csuper", cls.JNIName, f)
					g.genCMethodBody(cls, f, true)
				}
			}
		}
	}
}