List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:illab.nabal.util.Util.java
/** * Get how many APIs given network delegate has. * /*from www . j av a 2 s . c om*/ * @param networkDelegate * @return how many APIs given network delegate has */ public static int getHowManyApis(Delegate networkDelegate) { // method names to be exculded when counting String[] excludedMethodNames = { // inherited from JDK "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait" // inherited from Delegate , "isSessionValid", "fetchSession", "purgeSession", "hasNoJobs", "getBitmapFromUrl" }; // determine which socail network this delegate class represents Delegate delegate = networkDelegate; Class<? extends Delegate> thisClass = null; if (networkDelegate instanceof FacebookDelegate) { thisClass = ((FacebookDelegate) delegate).getClass(); } else if (networkDelegate instanceof TwitterDelegate) { thisClass = ((TwitterDelegate) delegate).getClass(); } else if (networkDelegate instanceof WeiboDelegate) { thisClass = ((WeiboDelegate) delegate).getClass(); } // get max of method index int maxMethodIndex = 0; String thisClassName = thisClass.getName(); ClassLoader classLoader = thisClass.getClassLoader(); try { for (Method method : classLoader.loadClass(thisClassName).getMethods()) { if (Arrays.asList(excludedMethodNames).contains(method.getName()) == false) { //Log.v(TAG, "indexing... " + method.getName() + " : added"); maxMethodIndex++; } else { //Log.v(TAG, "indexing... " + method.getName() + " : pass"); } } } catch (ClassNotFoundException e) { // if error occurrs let's set 100 to prevent the shortage of the index maxMethodIndex = 100; } return maxMethodIndex; }
From source file:net.radai.beanz.util.ReflectionUtil.java
public static String prettyPrint(Method method) { StringBuilder sb = new StringBuilder(); Class<?> declaredOn = method.getDeclaringClass(); sb.append(prettyPrint(declaredOn)).append(".").append(method.getName()).append("("); if (method.getParameterCount() > 0) { for (Type paramType : method.getGenericParameterTypes()) { sb.append(prettyPrint(paramType)).append(", "); }//from w w w. j av a2s.com sb.delete(sb.length() - 2, sb.length()); } sb.append(")"); return sb.toString(); }
From source file:com.zc.util.refelect.Reflector.java
/** * ?, ?DeclaredMethod,?./* ww w . j a v a2s. com*/ * ?Object?, null. * ???? * * ?. ?Method,?Method.invoke(Object obj, Object... args) */ public static Method getAccessibleMethodByName(final Object obj, final String methodName) { for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType .getSuperclass()) { Method[] methods = searchType.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { makeAccessible(method); return method; } } } return null; }
From source file:com.medallia.spider.api.StRenderer.java
/** @return the action method of the given class; throws AssertionError if no such method exists */ private static Method findActionMethod(Class<?> clazz) { Method am = ACTION_METHOD_MAP.get(clazz); if (am != null) return am; for (Method m : CollUtils.concat(Arrays.asList(clazz.getMethods()), Arrays.asList(clazz.getDeclaredMethods()))) { if (m.getName().equals("action")) { int modifiers = m.getModifiers(); if (Modifier.isPrivate(modifiers) || Modifier.isStatic(modifiers)) continue; m.setAccessible(true);//www. j a va 2 s. co m ACTION_METHOD_MAP.put(clazz, m); return m; } } throw new AssertionError("No action method found in " + clazz); }
From source file:io.fabric8.spring.boot.AbstractServiceRegistar.java
private static Class getSourceType(Method method) { Annotation[][] annotations = method.getParameterAnnotations(); for (int i = 0; i < annotations.length; i++) { for (int j = 0; j < annotations[i].length; j++) { if (ServiceName.class.equals(annotations[i][j].annotationType())) { return method.getParameterTypes()[i]; }/*from ww w .j av a 2 s .c o m*/ } } throw new IllegalStateException("No source type found for @Factory:" + method.getName()); }
From source file:com.haulmont.cuba.core.config.ConfigUtil.java
/** * Get the property name associated with a configuration interface method. * If a {@link Property} annotation is present, that value is returned. * Otherwise the {@link #getPropertyPrefix interface prefix} is concatenated * with the {@link #extendedUncapitalize uncapitalized} property name. * * @param configInterface The configuration interface. * @param method The method.//from w w w .j a va 2s . c om * @return The property name. */ public static String getPropertyName(Class<?> configInterface, Method method) { Property property = getAnnotation(configInterface, method, Property.class, false); if (property != null) { return property.value(); } else { String prefix = getPropertyPrefix(configInterface); String methodName = method.getName(); Matcher matcher; if (((matcher = ACCESS_RE.matcher(methodName)).matches() || (matcher = LISTENER_RE.matcher(methodName)).matches()) && !"".equals(matcher.group(2))) { String prop = matcher.group(2); return prefix + extendedUncapitalize(prop); } else { throw new IllegalArgumentException("Unsupported method name: " + method); } } }
From source file:Mopex.java
/** * Return a string that represents the signature of the specified method. * /*from www.j av a 2s .co m*/ * @return String * @param m * java.lang.Method */ //start extract signatureToString public static String signatureToString(Method m) { return m.getName() + "(" + formalParametersToString(m.getParameterTypes()) + ")"; }
From source file:com.github.dozermapper.core.util.ReflectionUtils.java
private static String prepareExceptionMessage(Method method, Object[] args) { StringBuffer message = new StringBuffer( "Illegal object type for the method '" + method.getName() + "'. \n "); message.append("Expected types: \n"); for (Class<?> type : method.getParameterTypes()) { message.append(type.getName());/*from ww w .ja va 2s . c o m*/ } message.append("\n Actual types: \n"); for (Object param : args) { message.append(param.getClass().getName()); } return message.toString(); }
From source file:com.taobao.rpc.doclet.RPCAPIInfoHelper.java
/** * ?//from ww w . java 2s . co m * * @param method * @return */ public static Object buildTypeStructure(Class<?> type, Type genericType, Type oriGenericType) { if ("void".equalsIgnoreCase(type.getName()) || ClassUtils.isPrimitiveOrWrapper(type) || String.class.isAssignableFrom(type) || Date.class.isAssignableFrom(type) || URL.class.isAssignableFrom(type)) { // return type.getName().replaceAll("java.lang.", "").replaceAll("java.util.", "").replaceAll("java.sql.", ""); } // end if if (type.isArray()) { // return new Object[] { buildTypeStructure(type.getComponentType(), type.getComponentType(), genericType) }; } // end if if (ClassUtils.isAssignable(Map.class, type)) { // Map return Map.class.getName(); } // end if if (type.isEnum()) { // Enum return Enum.class.getName(); } // end if boolean isCollection = type != null ? Collection.class.isAssignableFrom(type) : false; if (isCollection) { Type rawType = type; if (genericType != null) { if (genericType instanceof ParameterizedType) { ParameterizedType _type = (ParameterizedType) genericType; Type[] actualTypeArguments = _type.getActualTypeArguments(); rawType = actualTypeArguments[0]; } else if (genericType instanceof GenericArrayType) { rawType = ((GenericArrayType) genericType).getGenericComponentType(); } if (genericType instanceof WildcardType) { rawType = ((WildcardType) genericType).getUpperBounds()[0]; } } if (rawType == type) { return new Object[] { rawType.getClass().getName() }; } else { if (rawType.getClass().isAssignableFrom(TypeVariableImpl.class)) { return new Object[] { buildTypeStructure( (Class<?>) ((ParameterizedType) oriGenericType).getActualTypeArguments()[0], rawType, genericType) }; } else { if (rawType instanceof ParameterizedType) { if (((ParameterizedType) rawType).getRawType() == Map.class) { return new Object[] { Map.class.getName() }; } } if (oriGenericType == rawType) { return new Object[] { rawType.getClass().getName() }; } return new Object[] { buildTypeStructure((Class<?>) rawType, rawType, genericType) }; } } } if (type.isInterface()) { return type.getName(); } ClassInfo paramClassInfo = RPCAPIDocletUtil.getClassInfo(type.getName()); //added if (null == paramClassInfo) { System.out.println("failed to get paramClassInfo for :" + type.getName()); return null; } List<FieldInfo> typeConstructure = new ArrayList<FieldInfo>(); BeanWrapper bean = new BeanWrapperImpl(type); PropertyDescriptor[] propertyDescriptors = bean.getPropertyDescriptors(); Method readMethod; String name; for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { readMethod = propertyDescriptor.getReadMethod(); if (readMethod == null || "getClass".equals(readMethod.getName())) { continue; } name = propertyDescriptor.getName(); FieldInfo fieldInfo = paramClassInfo.getFieldInfo(name); if (readMethod.getReturnType().isAssignableFrom(type)) { String comment = "structure is the same with parent."; typeConstructure .add(FieldInfo.create(name, fieldInfo != null ? fieldInfo.getComment() : "", comment)); } else { typeConstructure.add( FieldInfo.create(name, fieldInfo != null ? fieldInfo.getComment() : "", buildTypeStructure( readMethod.getReturnType(), readMethod.getGenericReturnType(), genericType))); } // end if } return typeConstructure; }
From source file:kilim.Task.java
private static Method getWovenMethod(Method m) { Class<?>[] ptypes = m.getParameterTypes(); if (!(ptypes.length > 0 && ptypes[ptypes.length - 1].getName().equals("kilim.Fiber"))) { // The last param is not "Fiber", so m is not woven. // Get the woven method corresponding to m(..., Fiber) boolean found = false; LOOP: for (Method wm : m.getDeclaringClass().getDeclaredMethods()) { if (wm != m && wm.getName().equals(m.getName())) { // names match. Check if the wm has the exact parameter types as m, plus a fiber. Class<?>[] wptypes = wm.getParameterTypes(); if (wptypes.length != ptypes.length + 1 || !(wptypes[wptypes.length - 1].getName().equals("kilim.Fiber"))) continue LOOP; for (int i = 0; i < ptypes.length; i++) { if (ptypes[i] != wptypes[i]) continue LOOP; }/*from w w w . j av a 2 s .co m*/ m = wm; found = true; break; } } if (!found) { throw new IllegalArgumentException( "Found no pausable method corresponding to supplied method: " + m); } } return m; }