/** * Add a method to this class. * * @param ret Is null if method returns void. * @param params May be null if method accepts no parameters. */ public MethodInfo addMethod(Modifiers modifiers, String methodName, TypeDesc ret, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(ret, params); return addMethod(modifiers, methodName, md); }
/** * Add a method to this class. This method is handy for implementing * methods defined by a pre-existing interface. */ public MethodInfo addMethod(Method method) { Modifiers modifiers = Modifiers.getInstance(method.getModifiers()).toAbstract(false); MethodInfo mi = addMethod(modifiers, method.getName(), MethodDesc.forMethod(method)); // exception stuff... Class[] exceptions = method.getExceptionTypes(); for (int i=0; i<exceptions.length; i++) { mi.addException(TypeDesc.forClass(exceptions[i])); } return mi; }
/** * Add a method to this class by declaration. * * @throws IllegalArgumentException if declaration syntax is wrong * @see MethodDeclarationParser */ public MethodInfo addMethod(String declaration) { MethodDeclarationParser p = new MethodDeclarationParser(declaration); return addMethod(p.getModifiers(), p.getMethodName(), p.getReturnType(), p.getParameters()); }
case READ_METHOD: default: { TypeDesc[] params = {TypeDesc.OBJECT, TypeDesc.STRING}; mi = cf.addMethod (Modifiers.PUBLIC, "getPropertyValue", TypeDesc.OBJECT, params); break; TypeDesc.OBJECT, TypeDesc.STRING, TypeDesc.OBJECT }; mi = cf.addMethod(Modifiers.PUBLIC, "setPropertyValue", null, params); break; mi = cf.addMethod (Modifiers.PUBLIC, "tryGetPropertyValue", TypeDesc.OBJECT, params); break; TypeDesc.OBJECT, TypeDesc.STRING, TypeDesc.OBJECT }; mi = cf.addMethod(Modifiers.PUBLIC, "trySetPropertyValue", TypeDesc.BOOLEAN, params); break; mi = cf.addMethod(Modifiers.PUBLIC, "hasReadableProperty", TypeDesc.BOOLEAN, params); break; mi = cf.addMethod(Modifiers.PUBLIC, "hasWritableProperty", TypeDesc.BOOLEAN, params); break;
/** * Add a method to this class. * * @param ret Is null if method returns void. * @param params May be null if method accepts no parameters. */ public MethodInfo addMethod(Modifiers modifiers, String methodName, TypeDesc ret, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(ret, params); return addMethod(modifiers, methodName, md); }
/** * @return MethodInfo for completing definition or null if superclass * already implements method as final. */ private MethodInfo addMethodIfNotFinal(Modifiers modifiers, String name, TypeDesc retType, TypeDesc[] params) { if (CodeBuilderUtil.isPublicMethodFinal(mStorableType, name, retType, params)) { return null; } return mClassFile.addMethod(modifiers, name, retType, params); } }
/** * @return MethodInfo for completing definition or null if superclass * already implements method as final. */ private MethodInfo addMethodIfNotFinal(Modifiers modifiers, String name, TypeDesc retType, TypeDesc[] params) { if (CodeBuilderUtil.isPublicMethodFinal(mStorableType, name, retType, params)) { return null; } return mClassFile.addMethod(modifiers, name, retType, params); } }
mi = cf.addMethod(Modifiers.PUBLIC, "hasPropertyValue", TypeDesc.BOOLEAN, params);
/** * Generates a private method which accepts a property name and returns * PROPERTY_STATE_UNINITIALIZED, PROPERTY_STATE_DIRTY, or * PROPERTY_STATE_CLEAN. */ private void addPropertyStateExtractMethod() { MethodInfo mi = mClassFile.addMethod(Modifiers.PRIVATE, PROPERTY_STATE_EXTRACT_METHOD_NAME, TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING}); addPropertySwitch(new CodeBuilder(mi), SWITCH_FOR_STATE); }
/** * Generates a private method which accepts a property name and returns * PROPERTY_STATE_UNINITIALIZED, PROPERTY_STATE_DIRTY, or * PROPERTY_STATE_CLEAN. */ private void addPropertyStateExtractMethod() { MethodInfo mi = mClassFile.addMethod(Modifiers.PRIVATE, PROPERTY_STATE_EXTRACT_METHOD_NAME, TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING}); addPropertySwitch(new CodeBuilder(mi), SWITCH_FOR_STATE); }
/** * Add a method to this class. This method is handy for implementing * methods defined by a pre-existing interface. */ public MethodInfo addMethod(Method method) { Modifiers modifiers = Modifiers.getInstance(method.getModifiers()).toAbstract(false); MethodInfo mi = addMethod(modifiers, method.getName(), MethodDesc.forMethod(method)); // exception stuff... Class[] exceptions = method.getExceptionTypes(); for (int i=0; i<exceptions.length; i++) { mi.addException(TypeDesc.forClass(exceptions[i])); } return mi; }
private void addPrimitiveConvertMethod(Class fromType) { Method m = getAbstractConvertMethod(fromType); if (m == null) { return; } CodeBuilder b = new CodeBuilder(mClassFile.addMethod(m)); addConversionSwitch(b, fromType); }
private void addPrimitiveConvertMethod(Class fromType) { Method m = getAbstractConvertMethod(fromType); if (m == null) { return; } CodeBuilder b = new CodeBuilder(mClassFile.addMethod(m)); addConversionSwitch(b, fromType); }
/** * Add a method to this class by declaration. * * @throws IllegalArgumentException if declaration syntax is wrong * @see MethodDeclarationParser */ public MethodInfo addMethod(String declaration) { MethodDeclarationParser p = new MethodDeclarationParser(declaration); return addMethod(p.getModifiers(), p.getMethodName(), p.getReturnType(), p.getParameters()); }
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(); } }
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 void generateDelegatedMethod(String masterMethodName, String supportMethodName) { TypeDesc triggerSupportType = TypeDesc.forClass(TriggerSupport.class); TypeDesc delegateSupportType = TypeDesc.forClass(DelegateSupport.class); TypeDesc[] storableParam = {TypeDesc.forClass(Storable.class)}; MethodInfo mi = mClassFile.addMethod (Modifiers.PROTECTED, masterMethodName, TypeDesc.BOOLEAN, null); CodeBuilder b = new CodeBuilder(mi); b.loadThis(); b.loadField(StorableGenerator.SUPPORT_FIELD_NAME, triggerSupportType); b.checkCast(delegateSupportType); b.loadThis(); b.invokeInterface(delegateSupportType, supportMethodName, TypeDesc.BOOLEAN, storableParam); b.returnValue(TypeDesc.BOOLEAN); } }
private void generateDelegatedMethod(String masterMethodName, String supportMethodName) { TypeDesc triggerSupportType = TypeDesc.forClass(TriggerSupport.class); TypeDesc delegateSupportType = TypeDesc.forClass(DelegateSupport.class); TypeDesc[] storableParam = {TypeDesc.forClass(Storable.class)}; MethodInfo mi = mClassFile.addMethod (Modifiers.PROTECTED, masterMethodName, TypeDesc.BOOLEAN, null); CodeBuilder b = new CodeBuilder(mi); b.loadThis(); b.loadField(StorableGenerator.SUPPORT_FIELD_NAME, triggerSupportType); b.checkCast(delegateSupportType); b.loadThis(); b.invokeInterface(delegateSupportType, supportMethodName, TypeDesc.BOOLEAN, storableParam); b.returnValue(TypeDesc.BOOLEAN); } }