List of usage examples for java.lang.reflect Method getDeclaringClass
@Override
public Class<?> getDeclaringClass()
From source file:org.ff4j.aop.FeatureAdvisor.java
/** {@inheritDoc} */ @Override// w ww. j a va2 s . c o m public Object invoke(final MethodInvocation pMInvoc) throws Throwable { Method method = pMInvoc.getMethod(); Logger targetLogger = getLogger(method); Flip ff = null; if (method.isAnnotationPresent(Flip.class)) { ff = method.getAnnotation(Flip.class); } else if (method.getDeclaringClass().isAnnotationPresent(Flip.class)) { ff = method.getDeclaringClass().getAnnotation(Flip.class); } if (ff != null) { FlippingExecutionContext context = retrieveContext(ff, pMInvoc, targetLogger); if (shouldFlip(ff, context)) { // Required parameters if (!assertRequiredParams(ff)) { String msg = String.format("alterBeanName or alterClazz is required for {%s}", method.getDeclaringClass()); throw new IllegalArgumentException(msg); } if (shouldCallAlterBeanMethod(pMInvoc, ff.alterBean(), targetLogger)) { return callAlterBeanMethod(pMInvoc, ff.alterBean(), targetLogger); } // Test alterClazz Property of annotation if (shouldCallAlterClazzMethod(pMInvoc, ff.alterClazz(), targetLogger)) { return callAlterClazzMethodOnFirst(pMInvoc, ff, targetLogger); } } } // do not catch throwable return pMInvoc.proceed(); }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
/** * Calls a method with a set of arguments. After execution the stack may have an extra item pushed on it: the object that was returned * by this method (if any)./* www . j a va 2s .c o m*/ * @param method method to call * @param args method argument instruction lists -- each instruction list must leave one item on the stack of the type expected * by the method (note that if this is a non-static method, the first argument must always evaluate to the "this" pointer/reference) * @return instructions to invoke a method * @throws NullPointerException if any argument is {@code null} or array contains {@code null} * @throws IllegalArgumentException if the length of {@code args} doesn't match the number of parameters in {@code method} */ public static InsnList call(Method method, InsnList... args) { Validate.notNull(method); Validate.notNull(args); Validate.noNullElements(args); InsnList ret = new InsnList(); for (InsnList arg : args) { ret.add(arg); } Type clsType = Type.getType(method.getDeclaringClass()); Type methodType = Type.getType(method); if ((method.getModifiers() & Modifier.STATIC) == Modifier.STATIC) { Validate.isTrue(method.getParameterCount() == args.length); ret.add(new MethodInsnNode(Opcodes.INVOKESTATIC, clsType.getInternalName(), method.getName(), methodType.getDescriptor(), false)); } else if (method.getDeclaringClass().isInterface()) { Validate.isTrue(method.getParameterCount() + 1 == args.length); ret.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, clsType.getInternalName(), method.getName(), methodType.getDescriptor(), true)); } else { Validate.isTrue(method.getParameterCount() + 1 == args.length); ret.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, clsType.getInternalName(), method.getName(), methodType.getDescriptor(), false)); } return ret; }
From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java
@Test public void testProcessAnnotationOnMethod_Simple() throws Exception { Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest", String.class); MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method); assertEquals("/test/{id}", data.template().url()); assertEquals("GET", data.template().method()); assertEquals(MediaType.APPLICATION_JSON_VALUE, data.template().headers().get("Accept").iterator().next()); }
From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java
@Test public void testProcessAnnotations_MapParams() throws Exception { Method method = TestTemplate_MapParams.class.getDeclaredMethod("getTest", Map.class); MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method); assertEquals("/test", data.template().url()); assertEquals("GET", data.template().method()); assertNotNull(data.queryMapIndex()); assertEquals(0, data.queryMapIndex().intValue()); }
From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java
@Test public void testProcessHeaders() throws Exception { Method method = TestTemplate_Headers.class.getDeclaredMethod("getTest", String.class); MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method); assertEquals("/test/{id}", data.template().url()); assertEquals("GET", data.template().method()); assertEquals("bar", data.template().headers().get("X-Foo").iterator().next()); }
From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java
@Test public void testProcessAnnotations_Simple() throws Exception { Method method = TestTemplate_Simple.class.getDeclaredMethod("getTest", String.class); MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method); assertEquals("/test/{id}", data.template().url()); assertEquals("GET", data.template().method()); assertEquals(MediaType.APPLICATION_JSON_VALUE, data.template().headers().get("Accept").iterator().next()); assertEquals("id", data.indexToName().get(0).iterator().next()); }
From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java
@Test public void testProcessAnnotations_ListParams() throws Exception { Method method = TestTemplate_ListParams.class.getDeclaredMethod("getTest", List.class); MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method); assertEquals("/test", data.template().url()); assertEquals("GET", data.template().method()); assertEquals("[{id}]", data.template().queries().get("id").toString()); assertNotNull(data.indexToExpander().get(0)); }
From source file:org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.java
@Test public void testProcessAnnotations_SimplePost() throws Exception { Method method = TestTemplate_Simple.class.getDeclaredMethod("postTest", TestObject.class); MethodMetadata data = this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method); assertEquals("", data.template().url()); assertEquals("POST", data.template().method()); assertEquals(MediaType.APPLICATION_JSON_VALUE, data.template().headers().get("Accept").iterator().next()); }
From source file:com.google.gdt.eclipse.designer.util.GwtInvocationEvaluatorInterceptor.java
@Override public Object evaluate(EvaluationContext context, MethodInvocation invocation, IMethodBinding methodBinding, Class<?> clazz, Method method, Object[] argumentValues) { // Panel.add(Widget) throws exception, so make it fatal if (ReflectionUtils.getMethodSignature(method).equals("add(com.google.gwt.user.client.ui.Widget)")) { if (method.getDeclaringClass().getName().equals("com.google.gwt.user.client.ui.Panel")) { FatalDesignerException e = new FatalDesignerException(IExceptionConstants.PANEL_ADD_INVOCATION, invocation.toString()); e.setSourcePosition(invocation.getStartPosition()); throw e; }/*from w w w . j a v a2s. c o m*/ } return AstEvaluationEngine.UNKNOWN; }
From source file:org.apache.camel.component.bean.MethodInfo.java
/** * Finds the oneway annotation in priority order; look for method level annotations first, then the class level annotations, * then super class annotations then interface annotations * * @param method the method on which to search * @return the first matching annotation or none if it is not available *//*from w w w. jav a 2 s. c o m*/ protected Pattern findOneWayAnnotation(Method method) { Pattern answer = getPatternAnnotation(method); if (answer == null) { Class<?> type = method.getDeclaringClass(); // lets create the search order of types to scan List<Class<?>> typesToSearch = new ArrayList<Class<?>>(); addTypeAndSuperTypes(type, typesToSearch); Class<?>[] interfaces = type.getInterfaces(); for (Class<?> anInterface : interfaces) { addTypeAndSuperTypes(anInterface, typesToSearch); } // now lets scan for a type which the current declared class overloads answer = findOneWayAnnotationOnMethod(typesToSearch, method); if (answer == null) { answer = findOneWayAnnotation(typesToSearch); } } return answer; }