List of usage examples for java.lang.reflect Method isBridge
public boolean isBridge()
From source file:Main.java
public static void printMethods(Class cl) { Method[] methods = cl.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; System.out.println(m.isBridge()); }/*from w ww .j av a 2 s . co m*/ }
From source file:com.netflix.hystrix.contrib.javanica.utils.AopUtils.java
/** * Gets declared method from specified type by mame and parameters types. * * @param type the type/* www . ja va 2 s . c o m*/ * @param methodName the name of the method * @param parameterTypes the parameter array * @return a {@link Method} object or null if method doesn't exist */ public static Method getDeclaredMethod(Class<?> type, String methodName, Class<?>... parameterTypes) { Method method = null; try { method = type.getDeclaredMethod(methodName, parameterTypes); if (method.isBridge()) { method = MethodProvider.getInstance().unbride(method, type); } } catch (NoSuchMethodException e) { Class<?> superclass = type.getSuperclass(); if (superclass != null) { method = getDeclaredMethod(superclass, methodName, parameterTypes); } } catch (ClassNotFoundException e) { Throwables.propagate(e); } catch (IOException e) { Throwables.propagate(e); } return method; }
From source file:com.manydesigns.portofino.buttons.ButtonsLogic.java
public static List<ButtonInfo> computeButtonsForClass(Class<?> someClass, String list) { List<ButtonInfo> buttons = new ArrayList<ButtonInfo>(); for (Method method : someClass.getMethods()) { if (method.isBridge() || method.isSynthetic()) { continue; }/*from w w w. j a v a2 s.c o m*/ Button button = getButtonForMethod(method, list); if (button != null) { ButtonInfo buttonInfo = new ButtonInfo(button, method, someClass); buttons.add(buttonInfo); } } Collections.sort(buttons, new ButtonComparatorByOrder()); //Group together buttons of the same group for (int i = 0; i < buttons.size() - 1; i++) { ButtonInfo info = buttons.get(i); String group = info.getButton().group(); if (!StringUtils.isBlank(group)) { int count = 1; for (int j = i + 1; j < buttons.size(); j++) { ButtonInfo info2 = buttons.get(j); if (info2.getButton().group().equals(group)) { buttons.remove(j); buttons.add(i + count, info2); count++; } } } } return buttons; }
From source file:com.github.dozermapper.core.util.ReflectionUtils.java
/** * There are some nasty bugs for introspection with generics. This method addresses those nasty bugs and tries to find proper methods if available * http://bugs.sun.com/view_bug.do?bug_id=6788525 * http://bugs.sun.com/view_bug.do?bug_id=6528714 * * @param clazz type to work on/* ww w .jav a 2 s . co m*/ * @param descriptor property pair (get/set) information * @return descriptor */ private static PropertyDescriptor fixGenericDescriptor(Class<?> clazz, PropertyDescriptor descriptor) { Method readMethod = descriptor.getReadMethod(); if (readMethod != null && (readMethod.isBridge() || readMethod.isSynthetic())) { String propertyName = descriptor.getName(); //capitalize the first letter of the string; String baseName = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); String setMethodName = "set" + baseName; String getMethodName = "get" + baseName; Method getMethod = findPreferablyNonSyntheticMethod(getMethodName, clazz); Method setMethod = findPreferablyNonSyntheticMethod(setMethodName, clazz); try { return new PropertyDescriptor(propertyName, getMethod, setMethod); } catch (IntrospectionException e) { //move on } } return descriptor; }
From source file:com.github.dozermapper.core.util.ReflectionUtils.java
private static Method findPreferablyNonSyntheticMethod(String methodName, Class<?> clazz) { Method[] methods = clazz.getMethods(); Method syntheticMethod = null; for (Method method : methods) { if (method.getName().equals(methodName)) { if (!method.isBridge() && !method.isSynthetic()) { return method; } else { syntheticMethod = method; }/*w ww . j ava 2 s. co m*/ } } return syntheticMethod; }
From source file:net.jodah.typetools.TypeResolver.java
/** * Populates the {@code map} with variable/argument pairs for the {@code functionalInterface}. *///from w w w . j ava2 s.c o m private static void populateLambdaArgs(Class<?> functionalInterface, final Class<?> lambdaType, Map<TypeVariable<?>, Type> map) { if (GET_CONSTANT_POOL != null) { try { // Find SAM for (Method m : functionalInterface.getMethods()) { if (!m.isDefault() && !Modifier.isStatic(m.getModifiers()) && !m.isBridge()) { // Skip methods that override Object.class Method objectMethod = OBJECT_METHODS.get(m.getName()); if (objectMethod != null && Arrays.equals(m.getTypeParameters(), objectMethod.getTypeParameters())) continue; // Get functional interface's type params Type returnTypeVar = m.getGenericReturnType(); Type[] paramTypeVars = m.getGenericParameterTypes(); // Get lambda's type arguments ConstantPool constantPool = (ConstantPool) GET_CONSTANT_POOL.invoke(lambdaType); String[] methodRefInfo = constantPool.getMemberRefInfoAt( constantPool.getSize() - resolveMethodRefOffset(constantPool, lambdaType)); // Skip auto boxing methods if (methodRefInfo[1].equals("valueOf") && constantPool.getSize() > 22) { try { methodRefInfo = constantPool.getMemberRefInfoAt(constantPool.getSize() - resolveAutoboxedMethodRefOffset(constantPool, lambdaType)); } catch (MethodRefOffsetResolutionFailed ignore) { } } if (returnTypeVar instanceof TypeVariable) { Class<?> returnType = TypeDescriptor.getReturnType(methodRefInfo[2]) .getType(lambdaType.getClassLoader()); if (!returnType.equals(Void.class)) map.put((TypeVariable<?>) returnTypeVar, returnType); } TypeDescriptor[] arguments = TypeDescriptor.getArgumentTypes(methodRefInfo[2]); // Handle arbitrary object instance method references int paramOffset = 0; if (paramTypeVars[0] instanceof TypeVariable && paramTypeVars.length == arguments.length + 1) { Class<?> instanceType = TypeDescriptor.getObjectType(methodRefInfo[0]) .getType(lambdaType.getClassLoader()); map.put((TypeVariable<?>) paramTypeVars[0], instanceType); paramOffset = 1; } // Handle local final variables from context that are passed as arguments. int argOffset = 0; if (paramTypeVars.length < arguments.length) { argOffset = arguments.length - paramTypeVars.length; } for (int i = 0; i + argOffset < arguments.length; i++) { if (paramTypeVars[i] instanceof TypeVariable) { map.put((TypeVariable<?>) paramTypeVars[i + paramOffset], arguments[i + argOffset].getType(lambdaType.getClassLoader())); } } break; } } } catch (Exception ignore) { } } }
From source file:com.cloudera.nav.plugin.model.ValidationUtil.java
public void validateRequiredMProperties(Object mPropertyObj) { for (Method method : mPropertyObj.getClass().getMethods()) { if (!method.isBridge() && method.isAnnotationPresent(MProperty.class) && method.getAnnotation(MProperty.class).required()) { Class<?> returnType = method.getReturnType(); Object value;/*from w w w . ja v a2s.c o m*/ try { value = method.invoke(mPropertyObj); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Could not access MProperty method " + method.getName(), e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("Could not get MProperty value for " + method.getName(), e); } if (Collection.class.isAssignableFrom(returnType)) { Preconditions.checkArgument(!CollectionUtils.isEmpty((Collection) value), method.getName() + " returned empty collection"); } else if (String.class.isAssignableFrom(returnType)) { Preconditions.checkArgument(!StringUtils.isEmpty((String) value), method.getName() + " returned null or empty string"); } else { Preconditions.checkArgument(value != null, method.getName() + " returned null"); } } } }
From source file:com.astamuse.asta4d.data.DefaultContextDataFinder.java
private Method findConvertMethod(DataValueConvertor<?, ?> convertor) { Method[] methods = convertor.getClass().getMethods(); Method rtnMethod = null;/*from w w w . j a v a2 s . c o m*/ for (Method m : methods) { if (m.getName().equals("convert") && !m.isBridge()) { rtnMethod = m; break; } } return rtnMethod; }
From source file:com.swtxml.util.reflector.MethodQuery.java
/** * Same as Class.getMethods() but with private methods included. Returns all * methods of <type> and its superclasses, overwritten superclass methods * are not included.//from w w w .j a va 2 s .co m */ private Collection<Method> getAllMethods(Class<?> type) { Map<String, Method> signatureToMethod = new HashMap<String, Method>(); while (type != null) { for (Method method : type.getDeclaredMethods()) { if (method.isBridge() || method.isSynthetic()) { continue; } String signature = getSignature(method); if (!signatureToMethod.containsKey(signature)) { signatureToMethod.put(signature, method); } } type = type.getSuperclass(); } return signatureToMethod.values(); }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Determine whether the given method is declared by the user or at least pointing to * a user-declared method./*from ww w. j av a 2 s. c o m*/ * <p>Checks {@link java.lang.reflect.Method#isSynthetic()} (for implementation methods) as well as the * {@code GroovyObject} interface (for interface methods; on an implementation class, * implementations of the {@code GroovyObject} methods will be marked as synthetic anyway). * Note that, despite being synthetic, bridge methods ({@link java.lang.reflect.Method#isBridge()}) are considered * as user-level methods since they are eventually pointing to a user-declared generic method. * @param method the method to check * @return {@code true} if the method can be considered as user-declared; [@code false} otherwise */ public static boolean isUserLevelMethod(Method method) { Assert.notNull(method, "Method must not be null"); return (method.isBridge() || (!method.isSynthetic() && !isGroovyObjectMethod(method))); }