public boolean matchMethod(MethodSignature sig) { return sig.getName().equals(_name); }
public boolean matchMethod(MethodSignature sig) { return sig.getName().indexOf(_nameSubstring) >= 0; }
public boolean matchMethod(MethodSignature sig) { return sig.getName().startsWith(_namePrefix); }
public boolean matchMethod(MethodSignature sig) { return sig.getName().endsWith(_nameSuffix); }
/** * Finds a public or protected method in the base class. */ private Method findMethod(MethodSignature sig) { // Finding a public method is easy: try { return _baseClass.getMethod(sig.getName(), sig.getParameterTypes()); } catch (NoSuchMethodException ex) { // Good; no super-implementation to invoke. } Class c = _baseClass; while(c != Object.class) { try { return c.getDeclaredMethod(sig.getName(), sig .getParameterTypes()); } catch (NoSuchMethodException ex) { // Ok, continue loop up to next base class. } c = c.getSuperclass(); } return null; }
/** * Finds a public or protected method in the base class. */ private Method findMethod(MethodSignature sig) { // Finding a public method is easy: try { return _baseClass.getMethod(sig.getName(), sig.getParameterTypes()); } catch (NoSuchMethodException ex) { // Good; no super-implementation to invoke. } Class c = _baseClass; while(c != Object.class) { try { return c.getDeclaredMethod(sig.getName(), sig .getParameterTypes()); } catch (NoSuchMethodException ex) { // Ok, continue loop up to next base class. } c = c.getSuperclass(); } return null; }
private BodyBuilder createIncompleteMethod(MethodSignature sig) { BodyBuilder result = new BodyBuilder(); // Matched inside finalizeIncompleteMethods() result.begin(); if (existingImplementation(sig)) result.addln("super.{0}($$);", sig.getName()); return result; }
private BodyBuilder createIncompleteMethod(MethodSignature sig) { BodyBuilder result = new BodyBuilder(); // Matched inside finalizeIncompleteMethods() result.begin(); if (existingImplementation(sig)) result.addln("super.{0}($$);", sig.getName()); return result; }
BodyBuilder createCacheMethod(MethodSignature sig, String cacheField) { BodyBuilder result = new BodyBuilder(); result.begin(); result.addln("if (this.{0}==null)", cacheField); result.addln("this.{0} = super.{1}($$);", cacheField, sig.getName()); result.addln("return this.{0};", cacheField); result.end(); return result; }
/** * Creates a method that delegates to the _delegate object; this is used for * methods that are not logged. */ private void addPassThruMethodImplementation(ClassFab classFab, MethodSignature sig) { BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return ($r) _delegate."); builder.add(sig.getName()); builder.addln("($$);"); builder.end(); classFab.addMethod(Modifier.PUBLIC, sig, builder.toString()); }
public MethodFab addMethod(int modifiers, MethodSignature ms, String body) { if (_methods.get(ms) != null) throw new ApplicationRuntimeException(EnhanceMessages.duplicateMethodInClass(ms, this)); if (body.indexOf("isWrapperFor") > 0 || body.indexOf("unwrap") > 0) return new MethodFabImpl(null, ms, null, "{ throw new UnsupportedOperationException(\"Method not implemented\"); }"); CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(modifiers); method.setBody(body); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod(ms, getCtClass(), ex), ex); } // Return a MethodFab so the caller can add catches. MethodFab result = new MethodFabImpl(getSource(), ms, method, body); _methods.put(ms, result); return result; }
public MethodFab addMethod(int modifiers, MethodSignature ms, String body) { if (_methods.get(ms) != null) throw new ApplicationRuntimeException(EnhanceMessages.duplicateMethodInClass(ms, this)); if (body.indexOf("isWrapperFor") > 0 || body.indexOf("unwrap") > 0) return new MethodFabImpl(null, ms, null, "{ throw new UnsupportedOperationException(\"Method not implemented\"); }"); CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(modifiers); method.setBody(body); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod(ms, getCtClass(), ex), ex); } // Return a MethodFab so the caller can add catches. MethodFab result = new MethodFabImpl(getSource(), ms, method, body); _methods.put(ms, result); return result; }
public void addMethod(MethodSignature ms) { CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(ServiceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } _methods.add(ms); }
public void addMethod(MethodSignature ms) { CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } _methods.add(ms); }
public void addMethod(MethodSignature ms) { CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } _methods.add(ms); }
public MethodFab addMethod(int modifiers, MethodSignature ms, String body) { if (_methods.get(ms) != null) throw new ApplicationRuntimeException(ServiceMessages.duplicateMethodInClass(ms, this)); CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(modifiers); method.setBody(body); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(ServiceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } // Return a MethodFab so the caller can add catches. MethodFab result = new MethodFabImpl(getSource(), ms, method, body); _methods.put(ms, result); return result; }
builder.add(indirection); builder.add("."); builder.add(m.getName()); builder.addln("($$);"); builder.end();
protected void addServiceMethodImplementation(ClassFab classFab, MethodSignature sig) String methodName = sig.getName();