/** * Adds a public, no-arg constructor with the code buffer properly defined. */ public MethodInfo addDefaultConstructor() { MethodInfo mi = addConstructor(Modifiers.PUBLIC, null); CodeBuilder builder = new CodeBuilder(mi); builder.loadThis(); builder.invokeSuperConstructor(null); builder.returnVoid(); return mi; }
b.loadLocal(b.getParameter(0)); b.storeField(REF_FIELD_NAME, atomicRefType); b.returnVoid();
private static RuntimeClassFile generateClassFile(Class beanType, PropertySet set) { BeanProperty[][] props = getBeanProperties(beanType, set); RuntimeClassFile cf = new RuntimeClassFile (BeanPropertyAccessor.class.getName(), BeanPropertyAccessor.class.getName(), beanType.getClassLoader()); cf.markSynthetic(); cf.setSourceFile(BeanPropertyAccessor.class.getName()); try { cf.setTarget(System.getProperty("java.specification.version")); } catch (Exception e) { } MethodInfo ctor = cf.addConstructor(Modifiers.PUBLIC, null); ctor.markSynthetic(); CodeBuilder b = new CodeBuilder(ctor); b.loadThis(); b.invokeSuperConstructor(null); b.returnVoid(); generateAccessMethod(cf, beanType, props[0], READ_METHOD); generateAccessMethod(cf, beanType, props[0], TRY_READ_METHOD); generateAccessMethod(cf, beanType, props[0], HAS_READ_METHOD); generateAccessMethod(cf, beanType, props[1], WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], TRY_WRITE_METHOD); generateAccessMethod(cf, beanType, props[1], HAS_WRITE_METHOD); generateSearchMethod(cf, beanType, props[0]); return cf; }
mBuilder.loadLocal(mBuilder.getParameter(0)); mBuilder.invokeSuperConstructor(params); mBuilder.returnVoid(); mBuilder.returnVoid();
public List<Filter> finishSubFilterInit() { if (mStaticInitBuilder != null) { mStaticInitBuilder.returnVoid(); } if (mSubFilterInitBuilder != null) { mSubFilterInitBuilder.returnVoid(); } if (mSubFilters == null) { return Collections.emptyList(); } return mSubFilters; }
public List<Filter> finishSubFilterInit() { if (mStaticInitBuilder != null) { mStaticInitBuilder.returnVoid(); } if (mSubFilterInitBuilder != null) { mSubFilterInitBuilder.returnVoid(); } if (mSubFilters == null) { return Collections.emptyList(); } return mSubFilters; }
b.returnVoid(); } else { b.returnValue(TypeDesc.forClass(m.getReturnType()));
/** * @param factoryRef Strong reference is kept to this object. As long as * stub or skeleton instances exist, the referenced factory will not get * reclaimed. */ static void addStaticFactoryRef(ClassFile cf, Object factoryRef) { CodeBuilder b = addStaticFactoryRefUnfinished(cf, factoryRef); if (b != null) { b.returnVoid(); } }
b.invoke(bp.getWriteMethod()); if (methodType == WRITE_METHOD) { b.returnVoid(); } else { b.loadConstant(true);
builder.loadLocal(builder.getParameter(1)); builder.storeField("mUsingComparators", comparatorArrayType); builder.returnVoid();
/** * Adds a public, no-arg constructor with the code buffer properly defined. */ public MethodInfo addDefaultConstructor() { MethodInfo mi = addConstructor(Modifiers.PUBLIC, null); CodeBuilder builder = new CodeBuilder(mi); builder.loadThis(); builder.invokeSuperConstructor(null); builder.returnVoid(); return mi; }
private void defineExtractDataMethod(Map<JDBCStorableProperty<S>, Class<?>> lobLoaderMap) throws SupportException { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE, EXTRACT_DATA_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT, TypeDesc.forClass(Lob.class).toArrayType()}); CodeBuilder b = new CodeBuilder(mi); defineExtract(b, b.getParameter(0), b.getParameter(1), b.getParameter(2), mInfo.getDataProperties().values(), lobLoaderMap); b.returnVoid(); }
private void defineExtractDataMethod(Map<JDBCStorableProperty<S>, Class<?>> lobLoaderMap) throws SupportException { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE, EXTRACT_DATA_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT, TypeDesc.forClass(Lob.class).toArrayType()}); CodeBuilder b = new CodeBuilder(mi); defineExtract(b, b.getParameter(0), b.getParameter(1), b.getParameter(2), mInfo.getDataProperties().values(), lobLoaderMap); b.returnVoid(); }
private static void addPlainConstructor(RuntimeClassFile cf, TypeDesc delegateDesc) { CodeBuilder b = new CodeBuilder (cf.addConstructor(Modifiers.PUBLIC, new TypeDesc[] {delegateDesc})); b.loadThis(); b.invokeSuperConstructor(null); b.loadThis(); b.loadLocal(b.getParameter(0)); b.storeField("delegate", delegateDesc); b.returnVoid(); }
private void addUnmatchedProperty(StorableProperty<W> wrapperProp, TypeDesc wrapperPropType) { Method m = canDefine(wrapperProp.getReadMethod()); if (m != null) { CodeBuilder b = new CodeBuilder(mClassFile.addMethod(m)); CodeBuilderUtil.blankValue(b, wrapperPropType); b.returnValue(wrapperPropType); } m = canDefine(wrapperProp.getWriteMethod()); if (m != null) { CodeBuilder b = new CodeBuilder(mClassFile.addMethod(m)); b.returnVoid(); } }
private void addUnmatchedProperty(StorableProperty<W> wrapperProp, TypeDesc wrapperPropType) { Method m = canDefine(wrapperProp.getReadMethod()); if (m != null) { CodeBuilder b = new CodeBuilder(mClassFile.addMethod(m)); CodeBuilderUtil.blankValue(b, wrapperPropType); b.returnValue(wrapperPropType); } m = canDefine(wrapperProp.getWriteMethod()); if (m != null) { CodeBuilder b = new CodeBuilder(mClassFile.addMethod(m)); b.returnVoid(); } }
/** * Generates code that verifies that all primary keys are initialized. * * @param b builder that will invoke generated method * @param methodName name to give to generated method */ private void requirePkInitialized(CodeBuilder b, String methodName) { // Add code to call method which we are about to define. b.loadThis(); b.invokeVirtual(methodName, null, null); // Now define new method, discarding original builder object. b = new CodeBuilder(mClassFile.addMethod(Modifiers.PROTECTED, methodName, null, null)); b.loadThis(); b.invokeVirtual(IS_PK_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label pkInitialized = b.createLabel(); b.ifZeroComparisonBranch(pkInitialized, "!="); CodeBuilderUtil.throwException (b, IllegalStateException.class, "Primary key not fully specified"); pkInitialized.setLocation(); b.returnVoid(); }
/** * Generates code that verifies that all primary keys are initialized. * * @param b builder that will invoke generated method * @param methodName name to give to generated method */ private void requirePkInitialized(CodeBuilder b, String methodName) { // Add code to call method which we are about to define. b.loadThis(); b.invokeVirtual(methodName, null, null); // Now define new method, discarding original builder object. b = new CodeBuilder(mClassFile.addMethod(Modifiers.PROTECTED, methodName, null, null)); b.loadThis(); b.invokeVirtual(IS_REQUIRED_PK_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label pkInitialized = b.createLabel(); b.ifZeroComparisonBranch(pkInitialized, "!="); CodeBuilderUtil.throwException (b, IllegalStateException.class, "Primary key not fully specified"); pkInitialized.setLocation(); b.returnVoid(); }
/** * Generates method which passes exception to uncaught exception handler. */ private void defineUncaughtExceptionHandler() { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE.toStatic(true), UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)}); CodeBuilder b = new CodeBuilder(mi); // Thread t = Thread.currentThread(); // t.getUncaughtExceptionHandler().uncaughtException(t, e); TypeDesc threadType = TypeDesc.forClass(Thread.class); b.invokeStatic(Thread.class.getName(), "currentThread", threadType, null); LocalVariable threadVar = b.createLocalVariable(null, threadType); b.storeLocal(threadVar); b.loadLocal(threadVar); TypeDesc handlerType = TypeDesc.forClass(Thread.UncaughtExceptionHandler.class); b.invokeVirtual(threadType, "getUncaughtExceptionHandler", handlerType, null); b.loadLocal(threadVar); b.loadLocal(b.getParameter(0)); b.invokeInterface(handlerType, "uncaughtException", null, new TypeDesc[] {threadType, TypeDesc.forClass(Throwable.class)}); b.returnVoid(); }
private void defineExtractAllMethod(Map<JDBCStorableProperty<S>, Class<?>> lobLoaderMap) throws SupportException { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE, EXTRACT_ALL_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT}); CodeBuilder b = new CodeBuilder(mi); defineExtract(b, b.getParameter(0), b.getParameter(1), null, mInfo.getPrimaryKeyProperties().values(), lobLoaderMap); // Invoke extract data method to do the rest. b.loadThis(); // Load the ResultSet var. b.loadLocal(b.getParameter(0)); // The offset variable has already been incremented by code generated // by defineExtract, except for the last property. b.loadLocal(b.getParameter(1)); b.loadConstant(1); b.math(Opcode.IADD); b.loadNull(); // No Lobs to update b.invokePrivate(EXTRACT_DATA_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(ResultSet.class), TypeDesc.INT, TypeDesc.forClass(Lob.class).toArrayType()}); b.returnVoid(); }