/* * This class duplicates code in javax.el.Util. When making changes keep * the code in sync. */ private static Method getMethod(Class<?> type, Method m) { if (m == null || Modifier.isPublic(type.getModifiers())) { return m; } Class<?>[] inf = type.getInterfaces(); Method mp = null; for (int i = 0; i < inf.length; i++) { try { mp = inf[i].getMethod(m.getName(), m.getParameterTypes()); mp = getMethod(mp.getDeclaringClass(), mp); if (mp != null) { return mp; } } catch (NoSuchMethodException e) { // Ignore } } Class<?> sup = type.getSuperclass(); if (sup != null) { try { mp = sup.getMethod(m.getName(), m.getParameterTypes()); mp = getMethod(mp.getDeclaringClass(), mp); if (mp != null) { return mp; } } catch (NoSuchMethodException e) { // Ignore } } return null; }
static ShellCommandParamSpec[] forMethod(Method theMethod) { Class[] paramTypes = theMethod.getParameterTypes(); ShellCommandParamSpec[] result = new ShellCommandParamSpec[theMethod.getParameterTypes().length]; Annotation[][] annotations = theMethod.getParameterAnnotations(); assert annotations.length == result.length; for (int i = 0; i < result.length; i++) { Param paramAnnotation = null; for (Annotation a : annotations[i]) { if (a instanceof Param) { paramAnnotation = (Param) a; break; } } if (paramAnnotation != null) { assert !paramAnnotation.name().isEmpty() : "@Param.name mustn\'t be empty"; result[i] = new ShellCommandParamSpec( paramAnnotation.name(), paramTypes[i], paramAnnotation.description(), i); } else { result[i] = new ShellCommandParamSpec(String.format("p%d", i + 1), paramTypes[i], "", i); } } return result; }
// Checks whether or not the first parameter is more specific than the // second parameter. public static boolean methodMoreSpecific(Method more, Method less) { // Check that both of the parameters are non-null. if (more == null || less == null) { throw new IllegalArgumentException("Null parameter"); } // Check that they have the same names. if (!more.getName().equals(less.getName())) { throw new IllegalArgumentException("Different names"); } // Get their parameter types and check that they have the same number of // parameters. Class[] moreParamTypes = more.getParameterTypes(); Class[] lessParamTypes = less.getParameterTypes(); if (moreParamTypes.length != lessParamTypes.length) { throw new IllegalArgumentException("Different numbers of params"); } // To be more specific, more needs to have a declaring class assignable // to that of less. if (!less.getDeclaringClass().isAssignableFrom(more.getDeclaringClass())) { return false; } // To be more specific, more has to have parameters assignable to the // corresponding parameters of less. for (int i = 0; i < moreParamTypes.length; i++) { if (!lessParamTypes[i].isAssignableFrom(moreParamTypes[i])) { return false; } } return true; }
@SuppressWarnings({"unchecked"}) private <T extends Service> void applyInjection( T service, Method injectionMethod, InjectService injectService) { if (injectionMethod.getParameterTypes() == null || injectionMethod.getParameterTypes().length != 1) { throw new ServiceDependencyException( "Encountered @InjectService on method with unexpected number of parameters"); } Class dependentServiceRole = injectService.serviceRole(); if (dependentServiceRole == null || dependentServiceRole.equals(Void.class)) { dependentServiceRole = injectionMethod.getParameterTypes()[0]; } // todo : because of the use of proxies, this is no longer returning null here... final Service dependantService = getService(dependentServiceRole); if (dependantService == null) { if (injectService.required()) { throw new ServiceDependencyException( "Dependency [" + dependentServiceRole + "] declared by service [" + service + "] not found"); } } else { try { injectionMethod.invoke(service, dependantService); } catch (Exception e) { throw new ServiceDependencyException("Cannot inject dependency service", e); } } }
/** * Resolve the factory method in the specified bean definition, if possible. {@link * RootBeanDefinition#getResolvedFactoryMethod()} can be checked for the result. * * @param mbd the bean definition to check */ public void resolveFactoryMethodIfPossible(RootBeanDefinition mbd) { Class<?> factoryClass; boolean isStatic; if (mbd.getFactoryBeanName() != null) { factoryClass = this.beanFactory.getType(mbd.getFactoryBeanName()); isStatic = false; } else { factoryClass = mbd.getBeanClass(); isStatic = true; } factoryClass = ClassUtils.getUserClass(factoryClass); Method[] candidates = getCandidateMethods(factoryClass, mbd); Method uniqueCandidate = null; for (Method candidate : candidates) { if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate)) { if (uniqueCandidate == null) { uniqueCandidate = candidate; } else if (!Arrays.equals( uniqueCandidate.getParameterTypes(), candidate.getParameterTypes())) { uniqueCandidate = null; break; } } } synchronized (mbd.constructorArgumentLock) { mbd.resolvedConstructorOrFactoryMethod = uniqueCandidate; } }
public void callModelValidator(final AQuery $, final Ajax ajax) throws VolleyError { Map<Annotation, java.lang.reflect.Method> methodMap = ReflectUtils.getMethodsByAnnotation(Handler.class, getClass()); for (Map.Entry<Annotation, java.lang.reflect.Method> entry : methodMap.entrySet()) { java.lang.reflect.Method method = entry.getValue(); for (int i = 0; i < method.getParameterTypes().length; i++) { Class type = method.getParameterTypes()[i]; if (method.getParameterAnnotations()[i][0] instanceof ResponseBody && type != String.class && type != byte[].class && Checker.class.isAssignableFrom(type)) { try { Checker checker = (Checker) new Gson().fromJson(new String(ajax.getResponseBody(), "utf-8"), type); if (checker.getValidator().validate()) { $.log.i("has warning"); } } catch (UnsupportedEncodingException e) { $.log.i(e); throw new IllegalDataError("Unsupported encoding bytes"); } } } } }
private Method findRealMethodForBridgeMethod( final Method componentMethod, final ComponentConfiguration componentConfiguration, final DeploymentReflectionIndex reflectionIndex, final MethodIdentifier methodIdentifier) { final ClassReflectionIndex<?> classIndex = reflectionIndex.getClassIndex( componentMethod .getDeclaringClass()); // the non-bridge method will be on the same class as the // bridge method final Collection<Method> methods = classIndex.getAllMethods( componentMethod.getName(), componentMethod.getParameterTypes().length); for (final Method method : methods) { if ((BRIDGE & method.getModifiers()) == 0) { if (componentMethod.getReturnType().isAssignableFrom(method.getReturnType())) { boolean ok = true; for (int i = 0; i < method.getParameterTypes().length; ++i) { if (!componentMethod.getParameterTypes()[i].isAssignableFrom( method.getParameterTypes()[i])) { ok = false; break; } } if (ok) { return method; } } } } return null; }
private final boolean isAssociatorOrDissociator(Method method) { if (method.getParameterTypes().length != 1) return false; if (method.getReturnType() != void.class) return false; Class parameterType = method.getParameterTypes()[0]; if (!IDomainObject.class.isAssignableFrom(parameterType)) return false; return true; }
public int compare(Method a, Method b) { if (a == b) return 0; else if (a == null) return -1; else if (b == null) return 1; else if (a.equals(b)) return 0; int cmp = a.getName().compareTo(b.getName()); if (cmp != 0) return cmp; Class[] paramA = a.getParameterTypes(); Class[] paramB = b.getParameterTypes(); if (paramA.length < paramB.length) return -1; else if (paramB.length < paramA.length) return 1; for (int i = 0; i < paramA.length; i++) { cmp = paramA[i].getName().compareTo(paramB[i].getName()); if (cmp != 0) return cmp; } cmp = a.getDeclaringClass().getName().compareTo(b.getDeclaringClass().getName()); if (cmp != 0) return cmp; return a.getReturnType().getName().compareTo(b.getReturnType().getName()); }
// TODO document how this method converts without validation, and isValidInvocation() should be // used first public static Object[] convertParamsForVarArgsMethod(Method method, Object... newParams) { if (!method.isVarArgs()) { return newParams; } int methodParamCount = method.getParameterTypes().length; if (newParams.length > 0) { if (newParams.length > methodParamCount) { int varArgsLength = newParams.length - methodParamCount + 1; newParams = convertParams(method, varArgsLength, newParams); } else if (newParams.length == methodParamCount) { int varArgsIndex = methodParamCount - 1; if (method.getParameterTypes()[varArgsIndex].equals(newParams[varArgsIndex].getClass()) || method.getParameterTypes()[varArgsIndex].isAssignableFrom( newParams[varArgsIndex].getClass())) { // This is if an array is already provided return newParams; } newParams = convertParams(method, 1, newParams); } else if (newParams.length == methodParamCount - 1) { newParams = convertParams(method, 0, newParams); } } else { // If no new params are provided, an empty array needs to be returned. return (Object[]) Array.newInstance(method.getParameterTypes()[0], 0); } return newParams; }
private Type[] convertMethodParameterTypes(Method method) { Type[] types = new Type[method.getParameterTypes().length]; for (int i = 0; i < method.getParameterTypes().length; i++) { types[i] = new Type(method.getParameterTypes()[i].getName()); } return types; }
private static boolean validateParamsWithVarArgs(Method method, Object... newParams) { int methodParamCount = method.getParameterTypes().length; boolean result = true; for (int i = 0; i < methodParamCount; i++) { if (i < methodParamCount - 1) { // If it's not the last parameter, then it's not the varargs parameter yet if (!method.getParameterTypes()[i].isAssignableFrom(newParams[i].getClass())) { // If any parameter type is not assignable, the loop should end and method should return // false, this is not a match result = false; break; } } else { if (!isValidVarArgs( method.getParameterTypes()[i], Arrays.copyOfRange(newParams, i, newParams.length))) { // If the final param, and the newParams provided for that position, won't work as valid // varArgs, this is not a mach result = false; break; } } } return result; }
private Class<?> getType(ClassLoader loader, InjectionTarget target) { try { final Class<?> clazz = loader.loadClass(target.getInjectionTargetClass()); try { final Field field = clazz.getDeclaredField(target.getInjectionTargetName()); return field.getType(); } catch (NoSuchFieldException e) { } // TODO Technically we should match by case final String bestName = "set" + StringUtils.capitalize(target.getInjectionTargetName()); final String name = "set" + target.getInjectionTargetName().toLowerCase(); Class<?> found = null; for (Method method : clazz.getDeclaredMethods()) { if (method.getParameterTypes().length == 1) { if (method.getName().equals(bestName)) { return method.getParameterTypes()[0]; } else if (method.getName().toLowerCase().equals(name)) { found = method.getParameterTypes()[0]; } } } if (found != null) { return found; } } catch (Throwable e) { } return Object.class; }
/* ------------------------------------------------------------ */ private void doInvoke(Method method, Client fromClient, Client toClient, Message msg) { String channel = (String) msg.get(Bayeux.CHANNEL_FIELD); Object data = msg.get(Bayeux.DATA_FIELD); String id = msg.getId(); if (method != null) { try { Class<?>[] args = method.getParameterTypes(); Object arg = Message.class.isAssignableFrom(args[1]) ? msg : data; Object reply = null; switch (method.getParameterTypes().length) { case 2: reply = method.invoke(this, fromClient, arg); break; case 3: reply = method.invoke(this, fromClient, arg, id); break; case 4: reply = method.invoke(this, fromClient, channel, arg, id); break; } if (reply != null) send(fromClient, channel, reply, id); } catch (Exception e) { System.err.println(method); exception(fromClient, toClient, msg, e); } catch (Error e) { System.err.println(method); exception(fromClient, toClient, msg, e); } } }
static void emitFromNativeConversion( AsmBuilder builder, SkinnyMethodAdapter mv, FromNativeType fromNativeType, Class nativeClass) { // If there is a result converter, retrieve it and put on the stack FromNativeConverter fromNativeConverter = fromNativeType.getFromNativeConverter(); if (fromNativeConverter != null) { convertPrimitive( mv, nativeClass, unboxedType(fromNativeConverter.nativeType()), fromNativeType.getNativeType()); boxValue(builder, mv, fromNativeConverter.nativeType(), nativeClass); Method fromNativeMethod = getFromNativeMethod(fromNativeType, builder.getClassLoader()); getfield(mv, builder, builder.getFromNativeConverterField(fromNativeConverter)); mv.swap(); if (fromNativeType.getFromNativeContext() != null) { getfield( mv, builder, builder.getFromNativeContextField(fromNativeType.getFromNativeContext())); } else { mv.aconst_null(); } if (fromNativeMethod.getDeclaringClass().isInterface()) { mv.invokeinterface( fromNativeMethod.getDeclaringClass(), fromNativeMethod.getName(), fromNativeMethod.getReturnType(), fromNativeMethod.getParameterTypes()); } else { mv.invokevirtual( fromNativeMethod.getDeclaringClass(), fromNativeMethod.getName(), fromNativeMethod.getReturnType(), fromNativeMethod.getParameterTypes()); } if (fromNativeType.getDeclaredType().isPrimitive()) { // The actual return type is a primitive, but there was a converter for it - extract the // primitive value Class boxedType = getBoxedClass(fromNativeType.getDeclaredType()); if (!boxedType.isAssignableFrom(fromNativeMethod.getReturnType())) mv.checkcast(p(boxedType)); unboxNumber( mv, boxedType, fromNativeType.getDeclaredType(), fromNativeType.getNativeType()); } else if (!fromNativeType .getDeclaredType() .isAssignableFrom(fromNativeMethod.getReturnType())) { mv.checkcast(p(fromNativeType.getDeclaredType())); } } else if (!fromNativeType.getDeclaredType().isPrimitive()) { Class unboxedType = unboxedType(fromNativeType.getDeclaredType()); convertPrimitive(mv, nativeClass, unboxedType, fromNativeType.getNativeType()); boxValue(builder, mv, fromNativeType.getDeclaredType(), unboxedType); } }
private void handleCandidateWriteMethod(Method method) throws IntrospectionException { int nParams = method.getParameterTypes().length; String propertyName = propertyNameFor(method); Class<?> propertyType = method.getParameterTypes()[nParams - 1]; PropertyDescriptor existingPd = findExistingPropertyDescriptor(propertyName, propertyType); if (nParams == 1) { if (existingPd == null) { this.propertyDescriptors.add(new SimplePropertyDescriptor(propertyName, null, method)); } else { existingPd.setWriteMethod(method); } } else if (nParams == 2) { if (existingPd == null) { this.propertyDescriptors.add( new SimpleIndexedPropertyDescriptor(propertyName, null, null, null, method)); } else if (existingPd instanceof IndexedPropertyDescriptor) { ((IndexedPropertyDescriptor) existingPd).setIndexedWriteMethod(method); } else { this.propertyDescriptors.remove(existingPd); this.propertyDescriptors.add( new SimpleIndexedPropertyDescriptor( propertyName, existingPd.getReadMethod(), existingPd.getWriteMethod(), null, method)); } } else { throw new IllegalArgumentException( "Write method must have exactly 1 or 2 parameters: " + method); } }
private void expectMatchingAccessibleMethodParameterTypes( Class<?> cls, String methodName, Class<?>[] requestTypes, Class<?>[] actualTypes) { Method m = MethodUtils.getMatchingAccessibleMethod(cls, methodName, requestTypes); assertTrue( toString(m.getParameterTypes()) + " not equals " + toString(actualTypes), Arrays.equals(actualTypes, m.getParameterTypes())); }
public static <T> WeldMethod<?, ?> findDecoratorMethod( WeldDecorator<T> decorator, Map<MethodSignature, WeldMethod<?, ?>> decoratorMethods, Method method) { // try the signature first, might be simpler MethodSignature key = new MethodSignatureImpl(method); if (decoratorMethods.containsKey(key)) { return decoratorMethods.get(key); } // try all methods for (WeldMethod<?, ?> decoratorMethod : decoratorMethods.values()) { if (method.getParameterTypes().length == decoratorMethod.getParameters().size() && method.getName().equals(decoratorMethod.getName())) { boolean parameterMatch = true; for (int i = 0; parameterMatch && i < method.getParameterTypes().length; i++) { parameterMatch = parameterMatch && decoratorMethod.getParameterTypesAsArray()[i].isAssignableFrom( method.getParameterTypes()[i]); } if (parameterMatch) { return decoratorMethod; } } } return null; }
private void setDefaultInputStream(GantBinding binding) { // Gant does not initialise the default input stream for // the Ant project, so we manually do it here. AntBuilder antBuilder = (AntBuilder) binding.getVariable("ant"); Project p = antBuilder.getAntProject(); try { System.setIn(originalIn); p.setInputHandler(new CommandLineInputHandler()); p.setDefaultInputStream(originalIn); } catch (NoSuchMethodError nsme) { // will only happen due to a bug in JRockit // note - the only approach that works is to loop through the public methods for (Method m : p.getClass().getMethods()) { if ("setDefaultInputStream".equals(m.getName()) && m.getParameterTypes().length == 1 && InputStream.class.equals(m.getParameterTypes()[0])) { try { m.invoke(p, originalIn); break; } catch (Exception e) { // shouldn't happen, but let it bubble up to the catch(Throwable) throw new RuntimeException(e); } } } } }
private static void findNotImplemented(Class<?> type, Map<String, Method> result) { Class<?> superclass = type.getSuperclass(); if (superclass != null) { findNotImplemented(superclass, result); } for (Method m : type.getDeclaredMethods()) { NotImplemented ni = m.getAnnotation(NotImplemented.class); if (ni != null) { result.put(ni.value(), m); } else { BindSelector bs = m.getAnnotation(BindSelector.class); if (bs != null) { result.remove(bs.value()); } else { String mName = m.getName(); Class<?>[] mParamTypes = m.getParameterTypes(); for (Iterator<Entry<String, Method>> it = result.entrySet().iterator(); it.hasNext(); ) { Entry<String, Method> entry = it.next(); Method m2 = entry.getValue(); if (m2.getName().equals(mName) && Arrays.equals(m2.getParameterTypes(), mParamTypes)) { it.remove(); } } } } } }
/** * 根据一个字段名和字段类型获取 Setter * * @param fieldName 字段名 * @param paramType 字段类型 * @return 方法 * @throws NoSuchMethodException 没找到 Setter */ public Method getSetter(String fieldName, Class<?> paramType) throws NoSuchMethodException { try { String setterName = "set" + Strings.capitalize(fieldName); try { return klass.getMethod(setterName, paramType); } catch (Throwable e) { try { return klass.getMethod(fieldName, paramType); } catch (Throwable e1) { Mirror<?> type = Mirror.me(paramType); for (Method method : klass.getMethods()) { if (method.getParameterTypes().length == 1) if (method.getName().equals(setterName) || method.getName().equals(fieldName)) { if (null == paramType || type.canCastToDirectly(method.getParameterTypes()[0])) return method; } } // 还是没有? 会不会是包装类型啊? if (!paramType.isPrimitive()) { Class<?> p = unWrapper(); if (null != p) return getSetter(fieldName, p); } throw new RuntimeException(); } } } catch (Throwable e) { throw Lang.makeThrow( NoSuchMethodException.class, "Fail to find setter for [%s]->[%s(%s)]", klass.getName(), fieldName, paramType.getName()); } }
/** * set the value to target by method m using reflection automatic type parse for String>Date * String>Integer String>Long String>Double * * @param m * @param value * @param target */ private static void setValue(Method m, Object value, Object target) { if (value == null) { return; } Object v = null; // Parsing the data type if (value.getClass().equals(m.getParameterTypes()[0])) { v = value; } else if (value instanceof String) { if (Date.class.equals(m.getParameterTypes()[0])) { v = X.string2date((String) value, X.TIMEA); } else if (Integer.class.equals(m.getParameterTypes()[0])) { v = Integer.parseInt((String) value); } else if (Long.class.equals(m.getParameterTypes()[0])) { v = Long.parseLong((String) value); } else if (Double.class.equals(m.getParameterTypes()[0])) { v = Double.parseDouble((String) value); } } if (v != null) { try { // invoke the setter m.invoke(target, v); } catch (Exception e) { e.printStackTrace(); } } }
BoundSingleParameter(final Method method, final Class<?> type, final boolean optional) { this.type = type; int pos = -1; for (int i = 0; i < method.getParameterTypes().length; ++i) { boolean pathParam = false; for (Annotation annotation : method.getParameterAnnotations()[i]) { if (annotation.annotationType().equals(PathParam.class)) { pathParam = true; break; } } if (pathParam) { continue; } if (method.getParameterTypes()[i].equals(type)) { if (pos != -1) { throw JsrWebSocketMessages.MESSAGES.moreThanOneParameterOfType(type, method); } pos = i; } } if (pos != -1) { position = pos; } else if (optional) { position = -1; } else { throw JsrWebSocketMessages.MESSAGES.parameterNotFound(type, method); } }
@Override public void callAction(Object eventObject) { try { Method method = actionInfo.getActionMethod(); if (method.getParameterTypes().length == 0) { method.invoke(presenter); } else if (method.getParameterTypes().length == 1) { if (method.getParameterTypes()[0].equals(eventObject.getClass())) { method.invoke(presenter, eventObject); } else logger.error( "The event object " + method.getParameterTypes()[0].toString() + " is not supported " + " try this event object: " + eventObject.getClass().toString()); } else { logger.error("The action must have one parameter "); } } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private Invocation next() { if (interceptors.hasNext()) { Interceptor interceptor = interceptors.next(); Object nextInstance = interceptor.getInstance(); Method nextMethod = interceptor.getMethod(); if (nextMethod.getParameterTypes().length == 1 && nextMethod.getParameterTypes()[0] == InvocationContext.class) { return new InterceptorInvocation(nextInstance, nextMethod, this); } else { return new LifecycleInvocation(nextInstance, nextMethod, this, parameters); } } else if (method != null) { // EJB 3.1, it is allowed that timeout method does not have parameter Timer.class, // However, while invoking the timeout method, the timer value is passed, as it is also // required by InnvocationContext.getTimer() method Object[] methodParameters; if (operation.equals(Operation.TIMEOUT) && method.getParameterTypes().length == 0) { methodParameters = new Object[0]; } else { methodParameters = parameters; } return new BeanInvocation(target, method, methodParameters); } else { return new NoOpInvocation(); } }
/** * Invokes the underlying method {@code mtd} represented by this {@link Method} object, on the * specified object {@code target} with the specified parameter object {@code rsrc}. * * @param mtd Method which should be invoked to inject resource. * @param target Target object. * @param rsrc Resource object which should be injected. * @throws GridException Thrown if unable to inject resource. */ @SuppressWarnings({"ErrorNotRethrown"}) static void inject(Method mtd, Object target, Object rsrc) throws GridException { if (mtd.getParameterTypes().length != 1 || (rsrc != null && !mtd.getParameterTypes()[0].isAssignableFrom(rsrc.getClass()))) { throw new GridException( "Setter does not have single parameter of required type [type=" + rsrc.getClass().getName() + ", setter=" + mtd + ']'); } try { mtd.setAccessible(true); mtd.invoke(target, rsrc); } catch (IllegalAccessException | ExceptionInInitializerError | InvocationTargetException e) { throw new GridException( "Failed to inject resource [method=" + mtd.getName() + ", target=" + target + ", rsrc=" + rsrc + ']', e); } }
/** * Returns the property type that corresponds to the read and write method. The type precedence is * given to the readMethod. * * @return the type of the property descriptor or null if both read and write methods are null. * @throws IntrospectionException if the read or write method is invalid */ private Class findPropertyType(Method readMethod, Method writeMethod) throws IntrospectionException { Class propertyType = null; try { if (readMethod != null) { Class[] params = readMethod.getParameterTypes(); if (params.length != 0) { throw new IntrospectionException("bad read method arg count: " + readMethod); } propertyType = readMethod.getReturnType(); if (propertyType == Void.TYPE) { throw new IntrospectionException("read method " + readMethod.getName() + " returns void"); } } if (writeMethod != null) { Class params[] = writeMethod.getParameterTypes(); if (params.length != 1) { throw new IntrospectionException("bad write method arg count: " + writeMethod); } if (propertyType != null && propertyType != params[0]) { throw new IntrospectionException("type mismatch between read and write methods"); } propertyType = params[0]; } } catch (IntrospectionException ex) { throw ex; } return propertyType; }
private static List<Type> parameterTypes(TypeManager typeManager, Method method) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); ImmutableList.Builder<Type> types = ImmutableList.builder(); for (int i = 0; i < method.getParameterTypes().length; i++) { Class<?> clazz = method.getParameterTypes()[i]; // skip session parameters if (clazz == ConnectorSession.class) { continue; } // find the explicit type annotation if present SqlType explicitType = null; for (Annotation annotation : parameterAnnotations[i]) { if (annotation instanceof SqlType) { explicitType = (SqlType) annotation; break; } } checkArgument( explicitType != null, "Method %s argument %s does not have a @SqlType annotation", method, i); types.add(type(typeManager, explicitType)); } return types.build(); }
@Test public void testInheritedMethodsImplemented() throws Exception { int errors = 0; for (Method m : FileSystem.class.getDeclaredMethods()) { if (Modifier.isStatic(m.getModifiers()) || Modifier.isPrivate(m.getModifiers()) || Modifier.isFinal(m.getModifiers())) { continue; } try { MustNotImplement.class.getMethod(m.getName(), m.getParameterTypes()); try { HarFileSystem.class.getDeclaredMethod(m.getName(), m.getParameterTypes()); LOG.error("HarFileSystem MUST not implement " + m); errors++; } catch (NoSuchMethodException ex) { // Expected } } catch (NoSuchMethodException exc) { try { HarFileSystem.class.getDeclaredMethod(m.getName(), m.getParameterTypes()); } catch (NoSuchMethodException exc2) { LOG.error("HarFileSystem MUST implement " + m); errors++; } } } assertTrue((errors + " methods were not overridden correctly - see log"), errors <= 0); }
private void BuildSignature() { Var[] vars = new Var[samMethod.getParameterTypes().length]; lambdaApplyParameters = new Class<?>[samMethod.getParameterTypes().length]; for (int i = 0; i < vars.length; i++) { //noinspection unchecked Type paramType = samMethod.getGenericParameterTypes()[i]; if (paramType instanceof Class) vars[i] = new Var((Class<?>) paramType); else if (paramType instanceof TypeVariable) vars[i] = new Var(findMaterializedType(((TypeVariable) paramType).getName())); else throw new LambdaException( "unexpected param generic type [%s] for SAM [%s]", paramType, samType.getName()); lambdaApplyParameters[i] = Object.class; } Class<?> materializedRetType; Type genericRetType = samMethod.getGenericReturnType(); if (genericRetType instanceof Class<?>) materializedRetType = samMethod.getReturnType(); else if (genericRetType instanceof TypeVariable) materializedRetType = findMaterializedType(((TypeVariable) genericRetType).getName()); else throw new LambdaException( "unexpected generic return type [%s] for SAM [%s]", samMethod.getReturnType(), samType.getName()); this.lambdaSignature = new LambdaSignature<Object>(materializedRetType, vars); }