Example #1
0
func (g *ClassGen) genWrite(v string, t *java.Type, mode varMode) {
	switch t.Kind {
	case java.Int, java.Short, java.Char, java.Byte, java.Long, java.Float, java.Double:
		g.Printf("_%s := C.%s(%s)\n", v, t.CType(), v)
	case java.Boolean:
		g.Printf("_%s := C.jboolean(C.JNI_FALSE)\n", v)
		g.Printf("if %s {\n", v)
		g.Printf("	_%s = C.jboolean(C.JNI_TRUE)\n", v)
		g.Printf("}\n")
	case java.String:
		g.Printf("_%s := encodeString(%s)\n", v, v)
	case java.Array:
		if t.Elem.Kind != java.Byte {
			panic("unsupported array type")
		}
		g.Printf("_%s := fromSlice(%s, %v)\n", v, v, mode == modeRetained)
	case java.Object:
		g.Printf("var _%s C.jint = _seq.NullRefNum\n", v)
		g.Printf("if %s != nil {\n", v)
		g.Printf("	_%s = C.jint(_seq.ToRefNum(%s))\n", v, v)
		g.Printf("}\n")
	default:
		panic("invalid kind")
	}
}
Example #2
0
func (g *ClassGen) genCToJava(v string, t *java.Type) {
	switch t.Kind {
	case java.Int, java.Short, java.Char, java.Byte, java.Long, java.Float, java.Double, java.Boolean:
		g.Printf("%s _%s = %s;\n", t.JNIType(), v, v)
	case java.String:
		g.Printf("jstring _%s = go_seq_to_java_string(env, %s);\n", v, v)
	case java.Array:
		if t.Elem.Kind != java.Byte {
			panic("unsupported array type")
		}
		g.Printf("jbyteArray _%s = go_seq_to_java_bytearray(env, %s, 0);\n", v, v)
	case java.Object:
		g.Printf("jobject _%s = go_seq_from_refnum(env, %s, NULL, NULL);\n", v, v)
	default:
		panic("invalid kind")
	}
}