private static ThrowUnchecked generateImpl() { RuntimeClassFile cf = new RuntimeClassFile(null, ThrowUnchecked.class.getName()); cf.addDefaultConstructor(); CodeBuilder b = new CodeBuilder (cf.addMethod(Modifiers.PROTECTED, "doFire", null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)})); b.loadLocal(b.getParameter(0)); b.throwObject(); try { return (ThrowUnchecked) cf.defineClass().newInstance(); } catch (Exception e) { throw new Error(e); } }
CodeBuilder b = new CodeBuilder(cf.addMethod(method)); b.newObject(TypeDesc.forClass(objectType)); b.dup();
mi = cf.addMethod(Modifiers.PUBLIC, "fillMatchResults", null, params); mBuilder = new CodeBuilder(mi);
private Class<?> generateClass(ScoreFormulaLexer lexer, int funcNum) throws Exception { // initialize the code generator RuntimeClassFile cf = new RuntimeClassFile("UserDefinedFunction_"+funcNum); cf.addInterface("com.flaptor.indextank.index.scorer.ScoreFunction"); cf.addDefaultConstructor(); docVarType = TypeDesc.forClass("com.flaptor.indextank.index.scorer.Boosts"); // DocVariables queryVarType = TypeDesc.forClass("com.flaptor.indextank.query.QueryVariables"); // Variables params = new TypeDesc[] {TypeDesc.DOUBLE, TypeDesc.INT, docVarType, queryVarType}; MethodInfo mi = cf.addMethod(Modifiers.PUBLIC, "score", TypeDesc.DOUBLE, params); b = new CodeBuilder(mi); scoreParam = b.getParameter(0); ageParam = b.getParameter(1); docVarParam = b.getParameter(2); queryVarParam = b.getParameter(3); // parse and generate code start(); error = error == null ? lexer.getError() : error; if (null != error) { throw error; } // return the generated class Class<?> clazz = cf.defineClass(); return clazz; }
MethodInfo mi = cf.addMethod(compareMethod); mi.markSynthetic(); builder = new CodeBuilder(mi);
private static ThrowUnchecked generateImpl() { RuntimeClassFile cf = new RuntimeClassFile(null, ThrowUnchecked.class.getName()); cf.addDefaultConstructor(); CodeBuilder b = new CodeBuilder (cf.addMethod(Modifiers.PROTECTED, "doFire", null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)})); b.loadLocal(b.getParameter(0)); b.throwObject(); try { return (ThrowUnchecked) cf.defineClass().newInstance(); } catch (Exception e) { throw new Error(e); } }
CodeBuilder b = new CodeBuilder(cf.addMethod(method)); b.newObject(TypeDesc.forClass(objectType)); b.dup();
CodeBuilder b = new CodeBuilder(cf.addMethod(abstractMethod)); b.loadThis(); b.loadField("delegate", delegateDesc);
cf.addMethod(Modifiers.PUBLIC_ABSTRACT, name, desc.getReturnType(), desc.getParameterTypes()) .addException(exType);
mi = cf.addMethod(Modifiers.PUBLIC, "fillMatchResults", null, params); mBuilder = new CodeBuilder(mi);
MethodInfo mi = cf.addMethod(compareMethod); mi.markSynthetic(); builder = new CodeBuilder(mi);
MethodInfo mi = cf.addMethod (Modifiers.PUBLIC, method.getName(), returnDesc, paramDescs); TypeDesc[] paramDescs = getTypeDescs(localMethod.getParameterTypes()); MethodInfo mi = cf.addMethod (Modifiers.PUBLIC, localMethod.getName(), returnDesc, paramDescs); MethodInfo mi = cf.addMethod(Modifiers.PUBLIC, "hashCode", TypeDesc.INT, null); CodeBuilder b = new CodeBuilder(mi); MethodInfo mi = cf.addMethod(Modifiers.PUBLIC, "equals", TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.OBJECT}); CodeBuilder b = new CodeBuilder(mi); MethodInfo mi = cf.addMethod(Modifiers.PUBLIC, "toString", TypeDesc.STRING, null); CodeBuilder b = new CodeBuilder(mi); MethodInfo mi = cf.addMethod (Modifiers.PUBLIC.toStatic(true), "sessionLink", LINK_TYPE, new TypeDesc[] {cf.getType()});
MethodInfo mi = cf.addMethod (Modifiers.PUBLIC, "getRemoteServer", TypeDesc.forClass(Remote.class), null); CodeBuilder b = new CodeBuilder(mi); MethodInfo mi = cf.addMethod (Modifiers.PUBLIC, "invoke", TypeDesc.INT, new TypeDesc[] {LINK_TYPE, TypeDesc.INT, INV_CHANNEL_TYPE, BATCH_INV_EX_TYPE}); MethodInfo innerMethod = cf.addMethod (Modifiers.PRIVATE, name, TypeDesc.INT, params); b = new CodeBuilder(innerMethod); (cf.addMethod(Modifiers.PUBLIC, "unreferenced", null, null));