public static CtMethod addSetter(CtClass target, String field, String name) { CtField actualField = null; try { actualField = target.getField( field ); log.debugf( "Writing setter method [%s] into [%s] for field [%s]", name, target.getName(), field ); CtMethod method = CtNewMethod.setter( name, actualField ); target.addMethod( method ); return method; } catch (CannotCompileException cce) { try { // Fall back to create a getter from delegation. CtMethod method = CtNewMethod.delegator( CtNewMethod.setter( name, actualField ), target ); target.addMethod( method ); return method; } catch (CannotCompileException ignored) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, cce ); } } catch (NotFoundException nfe) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, nfe ); } }
public static CtMethod addGetter(CtClass target, String field, String name) { CtField actualField = null; try { actualField = target.getField( field ); log.debugf( "Writing getter method [%s] into [%s] for field [%s]", name, target.getName(), field ); CtMethod method = CtNewMethod.getter( name, target.getField( field ) ); target.addMethod( method ); return method; } catch (CannotCompileException cce) { try { // Fall back to create a getter from delegation. CtMethod method = CtNewMethod.delegator( CtNewMethod.getter( name, actualField ), target ); target.addMethod( method ); return method; } catch (CannotCompileException ignored) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, cce ); } } catch (NotFoundException nfe) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, nfe ); } }
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
newMethod = newGetClass; } else { newMethod = CtNewMethod.delegator(method, target);
ctChieldMethod = CtNewMethod.delegator(ctSuperMethod, ctChieldClass); ctChieldMethod.insertBefore("load(this);");
public static CtMethod addSetter(CtClass target, String field, String name) { CtField actualField = null; try { actualField = target.getField( field ); log.debugf( "Writing setter method [%s] into [%s] for field [%s]", name, target.getName(), field ); CtMethod method = CtNewMethod.setter( name, actualField ); target.addMethod( method ); return method; } catch (CannotCompileException cce) { try { // Fall back to create a getter from delegation. CtMethod method = CtNewMethod.delegator( CtNewMethod.setter( name, actualField ), target ); target.addMethod( method ); return method; } catch (CannotCompileException ignored) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, cce ); } } catch (NotFoundException nfe) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, nfe ); } }
public static CtMethod addGetter(CtClass target, String field, String name) { CtField actualField = null; try { actualField = target.getField( field ); log.debugf( "Writing getter method [%s] into [%s] for field [%s]", name, target.getName(), field ); CtMethod method = CtNewMethod.getter( name, target.getField( field ) ); target.addMethod( method ); return method; } catch (CannotCompileException cce) { try { // Fall back to create a getter from delegation. CtMethod method = CtNewMethod.delegator( CtNewMethod.getter( name, actualField ), target ); target.addMethod( method ); return method; } catch (CannotCompileException ignored) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, cce ); } } catch (NotFoundException nfe) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, nfe ); } }
private static <T> void buildNeededMethods(CtClass fullDAOCtClass, CtClass partialDAOCtClass, CtClass daoInterfaceCtClass, Class<T> modelClass, boolean accessControlEnabled, boolean metricsEnabled) throws CannotCompileException, ClassNotFoundException, NotFoundException { // Look through all methods to find which ones need to be implemented. for (CtMethod interfaceMethod : daoInterfaceCtClass.getMethods()) { try { CtMethod daoMethod = partialDAOCtClass.getMethod(interfaceMethod.getName(), interfaceMethod.getSignature()); // The method is present in the partial class. if (!Modifier.isAbstract(daoMethod.getModifiers())) { if (metricsEnabled && shouldAddMetricsToMethod(interfaceMethod, daoInterfaceCtClass)) { logger.debug("Generating metrics delegate for method " + daoMethod.getName() + "()"); CtMethod delegator = CtNewMethod.delegator(daoMethod, fullDAOCtClass); insertMetrics(fullDAOCtClass, delegator, daoInterfaceCtClass); fullDAOCtClass.addMethod(delegator); } continue; } // If we're here, the method does not have a concrete implementation. Fall through to implement it. } catch (NotFoundException ignore) { // If we're here, the method is not present in the partial class. Fall through to implement it. } CtMethod daoMethod = implementMethod(fullDAOCtClass, interfaceMethod, modelClass, accessControlEnabled); if (metricsEnabled) { insertMetrics(fullDAOCtClass, daoMethod, daoInterfaceCtClass); } } }
private void addWrapperDelegatorMethodToInstanceAdvisor(GeneratedAdvisorNameExtractor names, String updatedAdvicesFieldName) throws NotFoundException, CannotCompileException { try { genInstanceAdvisor.getDeclaredMethod(names.getWrapper().getName()); } catch(NotFoundException e) { //Method did not exist - add it CtMethod instanceAdvisorMethod = CtNewMethod.delegator(names.getWrapper(), genInstanceAdvisor); String code = CHECK_VERSION + "();" + "if (" + updatedAdvicesFieldName + ")" + "{ " + " " + names.getInfoFieldName() + ".getInterceptorChainReadWriteLock().writeLock().lock();" + " try" + " {" + " " + names.getInfoFieldName() + ".setInterceptors( " + INSTANCE_ADVISOR_MIXIN + ".getWrappers(" + PARENT + "." + names.getInfoFieldName() + ".getInterceptors()) );" + " " + names.getJoinPointField().getName() + " = null;" + " " + updatedAdvicesFieldName + " = false;" + " super.rebindJoinPointWithInstanceInformation(" + names.getInfoFieldName() + ");" + " } finally {" + " " + names.getInfoFieldName() + ".getInterceptorChainReadWriteLock().writeLock().unlock();}" + "}"; instanceAdvisorMethod.insertBefore(code); genInstanceAdvisor.addMethod(instanceAdvisorMethod); } }
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
m2 = CtNewMethod.delegator(findOriginal(m, dontSearch), clazz); m2.setModifiers(mod); clazz.addMethod(m2);
newMethod = newGetClass; } else { newMethod = CtNewMethod.delegator(method, target);