Java源码示例:com.apple.jobjc.JObjCRuntime

示例1
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例2
private void writeStructField(final Struct.Field field, final PrintStream out){
    if(field.type.getJType() == null || !(field.type.getJType() instanceof JStruct)){
        out.println("\t// Found bad JavaType (" + field.type.getJType() + ") for field (" + field.name + ") of type (" + field.type + ")");
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JStruct jstype = (JStruct) field.type.getJType();
    String retTypeName = jstype.getJavaReturnTypeName();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName() + ".IS64"
            + " ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\tprivate " + retTypeName + " " + privName + " = null;");
    out.println("\tpublic " + retTypeName + " " + getterName(field) + "(){");
    out.println("\t\tif(null==" + privName + "){");
    out.println("\t\t\tthis.raw.position(" + offsetName + ");");
    out.println("\t\t\t" + privName + " = " + RootJObjCClass.runtimeFrameworkInstR(struct.parent.name) + ".make" + jstype.struct.name + "(this.raw.slice());");
    out.println("\t\t}");
    out.println("\t\treturn " + privName + ";");
    out.println("\t}");
}
 
示例3
@Override public void writeBeginning(final PrintStream out) {
    out.format(
            "\tpublic %1$s(%2$s runtime) {\n" +
            "\t\tsuper(runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(String name, %2$s runtime) {\n" +
            "\t\tsuper(name, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(long ptr, %2$s runtime) {\n" +
            "\t\tsuper(ptr, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
}
 
示例4
@Override public void writeBeginning(final PrintStream out) {
    out.print(new JLField("private static", JOBJC_CLASSNAME, "instance"));
    out.print(new JLField("private final", JObjCRuntime.class.getName(), "runtime"));

    JLMethod getInstR = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance", "final JObjCRuntime runtime");
    getInstR.body.add("if(runtime == null) throw new NullPointerException(\"runtime\");");
    getInstR.body.add("if(instance == null) instance = new JObjC(runtime);");
    getInstR.body.add("return instance;");
    out.print(getInstR);

    JLMethod getInst = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance");
    getInst.body.add("return getInstance(JObjCRuntime.getInstance());");
    out.print(getInst);

    JLCtor ctor = new JLCtor("private", JOBJC_CLASSNAME, "final JObjCRuntime runtime");
    ctor.body.add("this.runtime = runtime;");
    for (final Framework f : frameworks)
        ctor.body.add("runtime.registerPackage(\"" + f.pkg + "\");");
    out.print(ctor);
}
 
示例5
@Override public void writeBeginning(final PrintStream out) {
    out.println();
    out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
            + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
    out.println();
    out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\[email protected] public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
            (struct.fields.size() > 0 ? ",\n\t\t" : ""),
            Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
                public String apply(Field a) {
                    return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
                }}, struct.fields)));
    out.format("\t\[email protected] protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
            struct.name,
            JObjCRuntime.class.getCanonicalName());
    out.println("\t};");
    out.println();
    out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
    out.println("\t\tsuper(runtime, SIZEOF);");
    out.println("\t}");
    out.println();
    out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
    out.println("\t\tsuper(runtime, buffer, SIZEOF);");
    out.println("\t}");
}
 
示例6
@Override public void writeBeginning(final PrintStream out) {
    out.println();
    out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
            + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
    out.println();
    out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\[email protected] public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
            (struct.fields.size() > 0 ? ",\n\t\t" : ""),
            Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
                public String apply(Field a) {
                    return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
                }}, struct.fields)));
    out.format("\t\[email protected] protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
            struct.name,
            JObjCRuntime.class.getCanonicalName());
    out.println("\t};");
    out.println();
    out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
    out.println("\t\tsuper(runtime, SIZEOF);");
    out.println("\t}");
    out.println();
    out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
    out.println("\t\tsuper(runtime, buffer, SIZEOF);");
    out.println("\t}");
}
 
示例7
@Override public void writeBeginning(final PrintStream out) {
    out.println();
    out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
            + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
    out.println();
    out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\[email protected] public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
            (struct.fields.size() > 0 ? ",\n\t\t" : ""),
            Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
                public String apply(Field a) {
                    return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
                }}, struct.fields)));
    out.format("\t\[email protected] protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
            struct.name,
            JObjCRuntime.class.getCanonicalName());
    out.println("\t};");
    out.println();
    out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
    out.println("\t\tsuper(runtime, SIZEOF);");
    out.println("\t}");
    out.println();
    out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
    out.println("\t\tsuper(runtime, buffer, SIZEOF);");
    out.println("\t}");
}
 
示例8
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例9
@Override public void writeBeginning(final PrintStream out) {
    out.format("\tpublic %1$s(final long objPtr, final %2$s runtime) {\n" +
            "\t\tsuper(objPtr, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    out.format("\tpublic %1$s(final %1$s obj, final %2$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    NativeObjectLifecycleManager nolm = nolmForClass.get(clazz.name);
    if(nolm != null)
        out.format("\[email protected]\n"+
                "\tprotected %1$s getNativeObjectLifecycleManager() {\n" +
                "\t\treturn %2$s.INST;\n" +
                "\t}\n",
                NativeObjectLifecycleManager.class.getCanonicalName(), nolm.getClass().getCanonicalName());
}
 
示例10
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例11
private void writeField(final Struct.Field field, final PrintStream out){
    if(field.type.type32 instanceof NBitfield){
        out.format("\t// Skipping bitfield '%1$s'\n", field.name);
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JType jtype = field.type.getJType();
    String retType = jtype.getJavaReturnTypeName();
    CoderDescriptor cdesc = jtype.getCoderDescriptor();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName()
            + ".IS64 ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\t//" + cdesc.getClass().toString());
    out.println("\tpublic " + retType + " " + getterName(field) + "(){");
    out.println(jtype.createPopAddr("getRuntime()", "this.raw.bufferPtr + " + offsetName));
    out.println(jtype.createReturn());
    out.println("\t}");
    out.println();
    out.println("\tpublic void " + setterName(field.name) + "(final " + retType + " " + privName + "){");
    out.println("\t\t" + cdesc.getPushAddrStatementFor("getRuntime()", "this.raw.bufferPtr + " + offsetName, privName));
    out.println("\t}");
}
 
示例12
@Override public void writeBeginning(final PrintStream out) {
    out.print(new JLField("private static", JOBJC_CLASSNAME, "instance"));
    out.print(new JLField("private final", JObjCRuntime.class.getName(), "runtime"));

    JLMethod getInstR = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance", "final JObjCRuntime runtime");
    getInstR.body.add("if(runtime == null) throw new NullPointerException(\"runtime\");");
    getInstR.body.add("if(instance == null) instance = new JObjC(runtime);");
    getInstR.body.add("return instance;");
    out.print(getInstR);

    JLMethod getInst = new JLMethod("public static", JOBJC_CLASSNAME, "getInstance");
    getInst.body.add("return getInstance(JObjCRuntime.getInstance());");
    out.print(getInst);

    JLCtor ctor = new JLCtor("private", JOBJC_CLASSNAME, "final JObjCRuntime runtime");
    ctor.body.add("this.runtime = runtime;");
    for (final Framework f : frameworks)
        ctor.body.add("runtime.registerPackage(\"" + f.pkg + "\");");
    out.print(ctor);
}
 
示例13
private void writeField(final Struct.Field field, final PrintStream out){
    if(field.type.type32 instanceof NBitfield){
        out.format("\t// Skipping bitfield '%1$s'\n", field.name);
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JType jtype = field.type.getJType();
    String retType = jtype.getJavaReturnTypeName();
    CoderDescriptor cdesc = jtype.getCoderDescriptor();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName()
            + ".IS64 ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\t//" + cdesc.getClass().toString());
    out.println("\tpublic " + retType + " " + getterName(field) + "(){");
    out.println(jtype.createPopAddr("getRuntime()", "this.raw.bufferPtr + " + offsetName));
    out.println(jtype.createReturn());
    out.println("\t}");
    out.println();
    out.println("\tpublic void " + setterName(field.name) + "(final " + retType + " " + privName + "){");
    out.println("\t\t" + cdesc.getPushAddrStatementFor("getRuntime()", "this.raw.bufferPtr + " + offsetName, privName));
    out.println("\t}");
}
 
示例14
private void writeStructField(final Struct.Field field, final PrintStream out){
    if(field.type.getJType() == null || !(field.type.getJType() instanceof JStruct)){
        out.println("\t// Found bad JavaType (" + field.type.getJType() + ") for field (" + field.name + ") of type (" + field.type + ")");
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JStruct jstype = (JStruct) field.type.getJType();
    String retTypeName = jstype.getJavaReturnTypeName();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName() + ".IS64"
            + " ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\tprivate " + retTypeName + " " + privName + " = null;");
    out.println("\tpublic " + retTypeName + " " + getterName(field) + "(){");
    out.println("\t\tif(null==" + privName + "){");
    out.println("\t\t\tthis.raw.position(" + offsetName + ");");
    out.println("\t\t\t" + privName + " = " + RootJObjCClass.runtimeFrameworkInstR(struct.parent.name) + ".make" + jstype.struct.name + "(this.raw.slice());");
    out.println("\t\t}");
    out.println("\t\treturn " + privName + ";");
    out.println("\t}");
}
 
示例15
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例16
@Override public void writeBeginning(final PrintStream out) {
    out.println();
    out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
            + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
    out.println();
    out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\[email protected] public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
            (struct.fields.size() > 0 ? ",\n\t\t" : ""),
            Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
                public String apply(Field a) {
                    return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
                }}, struct.fields)));
    out.format("\t\[email protected] protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
            struct.name,
            JObjCRuntime.class.getCanonicalName());
    out.println("\t};");
    out.println();
    out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
    out.println("\t\tsuper(runtime, SIZEOF);");
    out.println("\t}");
    out.println();
    out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
    out.println("\t\tsuper(runtime, buffer, SIZEOF);");
    out.println("\t}");
}
 
示例17
@Override public void writeBeginning(final PrintStream out) {
    out.format(
            "\tpublic %1$s(%2$s runtime) {\n" +
            "\t\tsuper(runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(String name, %2$s runtime) {\n" +
            "\t\tsuper(name, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(long ptr, %2$s runtime) {\n" +
            "\t\tsuper(ptr, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
}
 
示例18
@Override public void writeBeginning(final PrintStream out) {
    out.format("\tpublic %1$s(final long objPtr, final %2$s runtime) {\n" +
            "\t\tsuper(objPtr, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    out.format("\tpublic %1$s(final %1$s obj, final %2$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    NativeObjectLifecycleManager nolm = nolmForClass.get(clazz.name);
    if(nolm != null)
        out.format("\[email protected]\n"+
                "\tprotected %1$s getNativeObjectLifecycleManager() {\n" +
                "\t\treturn %2$s.INST;\n" +
                "\t}\n",
                NativeObjectLifecycleManager.class.getCanonicalName(), nolm.getClass().getCanonicalName());
}
 
示例19
@Override public void writeBeginning(final PrintStream out) {
    out.println();
    out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
            + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
    out.println();
    out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\[email protected] public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
            (struct.fields.size() > 0 ? ",\n\t\t" : ""),
            Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
                public String apply(Field a) {
                    return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
                }}, struct.fields)));
    out.format("\t\[email protected] protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
            struct.name,
            JObjCRuntime.class.getCanonicalName());
    out.println("\t};");
    out.println();
    out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
    out.println("\t\tsuper(runtime, SIZEOF);");
    out.println("\t}");
    out.println();
    out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
    out.println("\t\tsuper(runtime, buffer, SIZEOF);");
    out.println("\t}");
}
 
示例20
private void writeField(final Struct.Field field, final PrintStream out){
    if(field.type.type32 instanceof NBitfield){
        out.format("\t// Skipping bitfield '%1$s'\n", field.name);
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JType jtype = field.type.getJType();
    String retType = jtype.getJavaReturnTypeName();
    CoderDescriptor cdesc = jtype.getCoderDescriptor();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName()
            + ".IS64 ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\t//" + cdesc.getClass().toString());
    out.println("\tpublic " + retType + " " + getterName(field) + "(){");
    out.println(jtype.createPopAddr("getRuntime()", "this.raw.bufferPtr + " + offsetName));
    out.println(jtype.createReturn());
    out.println("\t}");
    out.println();
    out.println("\tpublic void " + setterName(field.name) + "(final " + retType + " " + privName + "){");
    out.println("\t\t" + cdesc.getPushAddrStatementFor("getRuntime()", "this.raw.bufferPtr + " + offsetName, privName));
    out.println("\t}");
}
 
示例21
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例22
private void writeStructField(final Struct.Field field, final PrintStream out){
    if(field.type.getJType() == null || !(field.type.getJType() instanceof JStruct)){
        out.println("\t// Found bad JavaType (" + field.type.getJType() + ") for field (" + field.name + ") of type (" + field.type + ")");
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JStruct jstype = (JStruct) field.type.getJType();
    String retTypeName = jstype.getJavaReturnTypeName();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName() + ".IS64"
            + " ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\tprivate " + retTypeName + " " + privName + " = null;");
    out.println("\tpublic " + retTypeName + " " + getterName(field) + "(){");
    out.println("\t\tif(null==" + privName + "){");
    out.println("\t\t\tthis.raw.position(" + offsetName + ");");
    out.println("\t\t\t" + privName + " = " + RootJObjCClass.runtimeFrameworkInstR(struct.parent.name) + ".make" + jstype.struct.name + "(this.raw.slice());");
    out.println("\t\t}");
    out.println("\t\treturn " + privName + ";");
    out.println("\t}");
}
 
示例23
@Override public void writeBeginning(final PrintStream out) {
    out.format(
            "\tpublic %1$s(%2$s runtime) {\n" +
            "\t\tsuper(runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(String name, %2$s runtime) {\n" +
            "\t\tsuper(name, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
    out.format(
            "\tpublic %1$s(long ptr, %2$s runtime) {\n" +
            "\t\tsuper(ptr, runtime);\n" +
            "\t}\n",
            className, JObjCRuntime.class.getCanonicalName());
}
 
示例24
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例25
@Override public void writeBeginning(final PrintStream out) {
    out.println();
    out.println("\tpublic static int SIZEOF = " + JObjCRuntime.class.getName() + ".IS64 ? "
            + ((NStruct) struct.type.type64).sizeof64() + " : " + ((NStruct) struct.type.type32).sizeof32() + ";");
    out.println();
    out.format("\tpublic final static %1$s getStructCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\[email protected] public final %1$s getCoder(){ return coder; }\n", StructCoder.class.getCanonicalName());
    out.format("\tprivate final static %1$s coder = new %1$s(SIZEOF%2$s%3$s){\n", StructCoder.class.getCanonicalName(),
            (struct.fields.size() > 0 ? ",\n\t\t" : ""),
            Fp.join(",\n\t\t", Fp.map(new Map1<Field,String>(){
                public String apply(Field a) {
                    return a.type.getJType().getCoderDescriptor().getCoderInstanceName();
                }}, struct.fields)));
    out.format("\t\[email protected] protected %1$s newInstance(%2$s runtime){ return new %1$s(runtime); }\n",
            struct.name,
            JObjCRuntime.class.getCanonicalName());
    out.println("\t};");
    out.println();
    out.println("\t" + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime){");
    out.println("\t\tsuper(runtime, SIZEOF);");
    out.println("\t}");
    out.println();
    out.println("\tpublic " + struct.name + "(final " + JObjCRuntime.class.getCanonicalName() + " runtime, final com.apple.jobjc.NativeBuffer buffer) {");
    out.println("\t\tsuper(runtime, buffer, SIZEOF);");
    out.println("\t}");
}
 
示例26
private void writeField(final Struct.Field field, final PrintStream out){
    if(field.type.type32 instanceof NBitfield){
        out.format("\t// Skipping bitfield '%1$s'\n", field.name);
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JType jtype = field.type.getJType();
    String retType = jtype.getJavaReturnTypeName();
    CoderDescriptor cdesc = jtype.getCoderDescriptor();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName()
            + ".IS64 ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\t//" + cdesc.getClass().toString());
    out.println("\tpublic " + retType + " " + getterName(field) + "(){");
    out.println(jtype.createPopAddr("getRuntime()", "this.raw.bufferPtr + " + offsetName));
    out.println(jtype.createReturn());
    out.println("\t}");
    out.println();
    out.println("\tpublic void " + setterName(field.name) + "(final " + retType + " " + privName + "){");
    out.println("\t\t" + cdesc.getPushAddrStatementFor("getRuntime()", "this.raw.bufferPtr + " + offsetName, privName));
    out.println("\t}");
}
 
示例27
private void writeStructField(final Struct.Field field, final PrintStream out){
    if(field.type.getJType() == null || !(field.type.getJType() instanceof JStruct)){
        out.println("\t// Found bad JavaType (" + field.type.getJType() + ") for field (" + field.name + ") of type (" + field.type + ")");
        return;
    }
    String privName = field.name + "__";
    String offsetName = field.name.toUpperCase() + "_OFFSET";
    JStruct jstype = (JStruct) field.type.getJType();
    String retTypeName = jstype.getJavaReturnTypeName();
    out.println();
    out.println("\tprivate static final int " + offsetName + " = " + JObjCRuntime.class.getName() + ".IS64"
            + " ? " + field.field64.offset64() + " : " + field.field32.offset32() + ";");

    out.println("\tprivate " + retTypeName + " " + privName + " = null;");
    out.println("\tpublic " + retTypeName + " " + getterName(field) + "(){");
    out.println("\t\tif(null==" + privName + "){");
    out.println("\t\t\tthis.raw.position(" + offsetName + ");");
    out.println("\t\t\t" + privName + " = " + RootJObjCClass.runtimeFrameworkInstR(struct.parent.name) + ".make" + jstype.struct.name + "(this.raw.slice());");
    out.println("\t\t}");
    out.println("\t\treturn " + privName + ";");
    out.println("\t}");
}
 
示例28
public String valueToString(){
    if(ignore == true) return "0";
    JPrimitive jprim = (JPrimitive) type.getJType();
    if(le_value == null && be_value == null){
        if(value == null && value64 != null)
            return value64 + jprim.getLiteralSuffix();
        else if(value != null && value64 == null)
            return value + jprim.getLiteralSuffix();
        else
            return String.format("(%1$s.IS64 ? %2$s%4$s : %3$s%4$s)", JObjCRuntime.class.getName(),
                    value64, value, jprim.getLiteralSuffix());
    }
    else if(value == null && value64 == null){
        return String.format("(%1$s.IS_BIG_ENDIAN ? %2$s%4$s : %3$s%4$s)",
                JObjCRuntime.class.getName(), be_value, le_value, jprim.getLiteralSuffix());
    }

    throw new RuntimeException("Unable to produce a value for enum " + name);
}
 
示例29
@Override public void writeBeginning(final PrintStream out) {
    out.format("\tpublic %1$s(final long objPtr, final %2$s runtime) {\n" +
            "\t\tsuper(objPtr, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    out.format("\tpublic %1$s(final %1$s obj, final %2$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    NativeObjectLifecycleManager nolm = nolmForClass.get(clazz.name);
    if(nolm != null)
        out.format("\[email protected]\n"+
                "\tprotected %1$s getNativeObjectLifecycleManager() {\n" +
                "\t\treturn %2$s.INST;\n" +
                "\t}\n",
                NativeObjectLifecycleManager.class.getCanonicalName(), nolm.getClass().getCanonicalName());
}
 
示例30
@Override public void writeBeginning(final PrintStream out) {
    out.format("\tpublic %1$s(final long objPtr, final %2$s runtime) {\n" +
            "\t\tsuper(objPtr, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    out.format("\tpublic %1$s(final %1$s obj, final %2$s runtime) {\n" +
            "\t\tsuper(obj, runtime);\n" +
            "\t}\n",
        className, JObjCRuntime.class.getCanonicalName());

    NativeObjectLifecycleManager nolm = nolmForClass.get(clazz.name);
    if(nolm != null)
        out.format("\[email protected]\n"+
                "\tprotected %1$s getNativeObjectLifecycleManager() {\n" +
                "\t\treturn %2$s.INST;\n" +
                "\t}\n",
                NativeObjectLifecycleManager.class.getCanonicalName(), nolm.getClass().getCanonicalName());
}