private boolean checkAnnotation(Advise annotation) { return annotation != null && "id".equals(annotation.id()) && NonAnnotatedServiceInterface.class.equals(annotation.serviceInterface()); }
@Advise(id = "file", serviceInterface = NonAnnotatedServiceInterface.class) @Override public String execute2(File t) { return null; }
private void addAdvisorDef(Method method) { Advise annotation = method.getAnnotation(Advise.class); Class serviceInterface = annotation == null ? null : annotation.serviceInterface(); // TODO: methods just named "decorate" String advisorId = annotation == null ? stripMethodPrefix(method, ADVISE_METHOD_NAME_PREFIX) : extractId( serviceInterface, annotation.id()); // TODO: Check for duplicates Class returnType = method.getReturnType(); if (!returnType.equals(void.class)) throw new RuntimeException(String.format("Advise method %s does not return void.", toString(method))); boolean found = false; for (Class pt : method.getParameterTypes()) { if (pt.equals(MethodAdviceReceiver.class)) { found = true; break; } } if (!found) throw new RuntimeException(String.format("Advise method %s must take a parameter of type %s.", toString(method), MethodAdviceReceiver.class.getName())); Set<Class> markers = extractMarkers(method, Advise.class); AdvisorDef def = new AdvisorDefImpl(method, extractPatterns(advisorId, method), extractConstraints(method), proxyFactory, advisorId, serviceInterface, markers); advisorDefs.put(advisorId, def); }
@Advise(id = "int", serviceInterface = NonAnnotatedServiceInterface.class) @Override public String execute2(int t) { return null; }
private void addAdvisorDef(Method method) { Advise annotation = method.getAnnotation(Advise.class); Class serviceInterface = annotation == null ? null : annotation.serviceInterface(); // TODO: methods just named "decorate" String advisorId = annotation == null ? stripMethodPrefix(method, ADVISE_METHOD_NAME_PREFIX) : extractId( serviceInterface, annotation.id()); // TODO: Check for duplicates Class returnType = method.getReturnType(); if (!returnType.equals(void.class)) throw new RuntimeException(String.format("Advise method %s does not return void.", toString(method))); boolean found = false; for (Class pt : method.getParameterTypes()) { if (pt.equals(MethodAdviceReceiver.class)) { found = true; break; } } if (!found) throw new RuntimeException(String.format("Advise method %s must take a parameter of type %s.", toString(method), MethodAdviceReceiver.class.getName())); Set<Class> markers = extractMarkers(method, Advise.class); AdvisorDef def = new AdvisorDefImpl(method, extractPatterns(advisorId, method), extractConstraints(method), proxyFactory, advisorId, serviceInterface, markers); advisorDefs.put(advisorId, def); }
@Advise(id = "doesNotMatchAnyService") public static void doesNotMatchAnyService(MethodAdviceReceiver receiver) { Assert.fail("Unexpected invocation"); }
@Advise(serviceInterface = ComponentInstantiatorSource.class) public static void componentReplacer(MethodAdviceReceiver methodAdviceReceiver, final ComponentOverride componentReplacer) throws NoSuchMethodException, SecurityException { if (componentReplacer.hasReplacements()) { MethodAdvice advice = new MethodAdvice() { @Override public void advise(MethodInvocation invocation) { String className = (String) invocation.getParameter(0); final Class<?> replacement = componentReplacer.getReplacement(className); if (replacement != null) { invocation.setParameter(0, replacement.getName()); } invocation.proceed(); } }; methodAdviceReceiver.adviseMethod( ComponentInstantiatorSource.class.getMethod("getInstantiator", String.class), advice); } }
@Override @Advise(id = "id", serviceInterface = NonAnnotatedServiceInterface.class) public String execute2(@IntermediateType(String.class) final String t) { return null; }
@Advise(id = "right") public String duplicatedAnnotation(@IntermediateType(String.class) String parameter) { return null; }
@Override @Advise(id = "id", serviceInterface = NonAnnotatedServiceInterface.class) public String execute1(@IntermediateType(String.class) final int i) { return null; }
@Override @Advise(id = "id", serviceInterface = NonAnnotatedServiceInterface.class) public String execute3(@IntermediateType(String.class) int i) { return null; }
@Override @Advise(id = "id", serviceInterface = NonAnnotatedServiceInterface.class) public String execute2(@IntermediateType(String.class) String t, String s) { return null; }
@Advise(id = "wrong") public String duplicatedAnnotation(@IntermediateType(Object.class) String parameter);
@Advise(id = "id", serviceInterface = NonAnnotatedServiceInterface.class) public String execute(@IntermediateType(String.class) int i);
@Override @Advise(id = "id", serviceInterface = NonAnnotatedServiceInterface.class) public String execute(@IntermediateType(String.class) int i) // annotation just for checking too { // a try/catch block, as it caused some troubles with proxy class generation try { System.out.println(); } catch (Exception e) { e.printStackTrace(); } return null; }
@Advise(serviceInterface = NonAnnotatedGenericSetServiceInterface.class) public static void adviseNonAnnotatedGenericSetServiceInterface( final MethodAdviceReceiver methodAdviceReceiver) { methodAdviceReceiver.adviseAllMethods(new TestAdvice()); } }
@Advise(serviceInterface = Greeter.class) @GreenMarker public static void doAdvise(MethodAdviceReceiver receiver) { doAdvise(receiver, "alpha"); }
@Advise(serviceInterface = AnnotatedServiceInterface.class) public static void adviseAnnotatedServiceInterface(MethodAdviceReceiver methodAdviceReceiver) { methodAdviceReceiver.adviseAllMethods(new TestAdvice()); }
@Advise(serviceInterface = Greeter.class, id = "barney") @Local public static void localAdvise(MethodAdviceReceiver receiver) { doAdvise(receiver, "delta"); }
@Advise @Match("RedGreeter") public static void byMatchAnnotation(MethodAdviceReceiver receiver) { doAdvise(receiver, "alpha"); }