List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:com.haulmont.cuba.core.config.type.TypeFactory.java
private static boolean isAcceptableMethod(Class<?> returnType, Method factoryMethod) { int modifiers = factoryMethod.getModifiers(); return Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && returnType.isAssignableFrom(factoryMethod.getReturnType()); }
From source file:com.agileapes.couteau.context.spring.event.impl.AbstractMappedEventsTranslationScheme.java
@Override public void fillIn(Event originalEvent, ApplicationEvent translated) throws EventTranslationException { for (Method method : originalEvent.getClass().getMethods()) { if (!method.getName().matches("set[A-Z].*") || !Modifier.isPublic(method.getModifiers()) || !method.getReturnType().equals(void.class) || method.getParameterTypes().length != 1) { continue; }//from ww w. j a v a 2 s .co m final String propertyName = StringUtils.uncapitalize(method.getName().substring(3)); final Field field = ReflectionUtils.findField(translated.getClass(), propertyName); if (field == null || !method.getParameterTypes()[0].isAssignableFrom(field.getType())) { continue; } field.setAccessible(true); try { method.invoke(originalEvent, field.get(translated)); } catch (Exception e) { throw new EventTranslationException("Failed to set property on original event: " + propertyName, e); } } }
From source file:org.caratarse.auth.model.util.BeanUtils.java
/** * Copy the not-null property values of the given source bean into the given target bean. * <p>//from w w w . ja v a 2 s . c om * Note: The source and target classes do not have to match or even be derived from each other, * as long as the properties match. Any bean properties that the source bean exposes but the * target bean does not will silently be ignored. * * @param source the source bean * @param target the target bean * @param editable the class (or interface) to restrict property setting to * @param ignoreProperties array of property names to ignore * @throws BeansException if the copying failed * @see BeanWrapper */ private static void copyNotNullProperties(Object source, Object target, Class<?> editable, String... ignoreProperties) throws BeansException { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); Class<?> actualEditable = target.getClass(); if (editable != null) { if (!editable.isInstance(target)) { throw new IllegalArgumentException("Target class [" + target.getClass().getName() + "] not assignable to Editable class [" + editable.getName() + "]"); } actualEditable = editable; } PropertyDescriptor[] targetPds = org.springframework.beans.BeanUtils.getPropertyDescriptors(actualEditable); List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null); for (PropertyDescriptor targetPd : targetPds) { Method writeMethod = targetPd.getWriteMethod(); if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { PropertyDescriptor sourcePd = org.springframework.beans.BeanUtils .getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null) { Method readMethod = sourcePd.getReadMethod(); if (readMethod != null && ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) { try { if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Object value = readMethod.invoke(source); if (value == null) { continue; } if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(target, value); } catch (Throwable ex) { throw new FatalBeanException( "Could not copy property '" + targetPd.getName() + "' from source to target", ex); } } } } } }
From source file:org.spring.guice.module.GuiceModuleMetadata.java
private boolean visible(Class<?> type) { Class<?> cls = type;// ww w . jav a2 s. com while (cls != null && cls != Object.class) { if (!Modifier.isInterface(cls.getModifiers()) && !Modifier.isPublic(cls.getModifiers()) && !Modifier.isProtected(cls.getModifiers())) { return false; } cls = cls.getDeclaringClass(); } return true; }
From source file:net.erdfelt.android.sdkfido.configer.Configer.java
private void findRawArgsMethod(Class<?> clazz) { for (Method method : clazz.getDeclaredMethods()) { ConfigArguments arg = method.getAnnotation(ConfigArguments.class); if (arg == null) { continue; // skip, not tagged }/*w w w . java 2 s . c o m*/ int mods = method.getModifiers(); if (!Modifier.isPublic(mods)) { continue; // skip, not public } if (Modifier.isStatic(mods)) { continue; // skip, dont support static } Class<?>[] params = method.getParameterTypes(); if (params == null) { continue; // skip, needs params } if (params.length != 1) { continue; // skip, needs 1 param } if (!(params[0].equals(String.class))) { continue; // skip, param must be String } if (this.rawArgAdder != null) { StringBuilder err = new StringBuilder(); err.append("Not allowed to have multiple @ConfigArguments defined: "); err.append("\n Duplicate found at ").append(clazz.getName()).append("#").append(method.getName()); err.append("\n Original found at ").append(rawArgAdder.getDeclaringClass().getName()).append("#") .append(rawArgAdder.getName()); throw new IllegalStateException(err.toString()); } this.rawArgAdder = method; } }
From source file:org.hswebframework.web.cache.spring.fix.FixUseSupperClassFallbackCacheOperationSource.java
private Collection<CacheOperation> computeCacheOperations(Method method, Class<?> targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; }/*from ww w .j a v a 2 s . co m*/ // The method may be on an interface, but we need attributes from the target class. // If the target class is null, the method will be unchanged. Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass); // If we are dealing with method with generic parameters, find the original method. specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); // First try is the method in the target class. // @CacheConfig? Collection<CacheOperation> opDef = findCacheOperations(targetClass, specificMethod); if (opDef != null) { return opDef; } // Second try is the caching operation on the target class. opDef = findCacheOperations(specificMethod.getDeclaringClass()); if (opDef != null && ClassUtils.isUserLevelMethod(method)) { return opDef; } if (specificMethod != method) { // Fallback is to look at the original method. opDef = findCacheOperations(targetClass, method); if (opDef != null) { return opDef; } // Last fallback is the class of the original method. opDef = findCacheOperations(method.getDeclaringClass()); if (opDef != null && ClassUtils.isUserLevelMethod(method)) { return opDef; } } return null; }
From source file:com.weibo.api.motan.config.AbstractConfig.java
private boolean isConfigMethod(Method method) { boolean checkMethod = (method.getName().startsWith("get") || method.getName().startsWith("is")) && !"isDefault".equals(method.getName()) && Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0 && isPrimitive(method.getReturnType()); if (checkMethod) { ConfigDesc configDesc = method.getAnnotation(ConfigDesc.class); if (configDesc != null && configDesc.excluded()) { return false; }//ww w. j av a2 s . c o m } return checkMethod; }
From source file:gobblin.runtime.cli.PublicMethodsGobblinCliFactory.java
private boolean canUseMethod(Method method) { if (!Modifier.isPublic(method.getModifiers())) { return false; }/* w w w. j a v a2 s . c o m*/ if (BLACKLISTED_FROM_CLI.contains(method.getName())) { return false; } if (method.isAnnotationPresent(NotOnCli.class)) { return false; } Class<?>[] parameters = method.getParameterTypes(); if (parameters.length > 2) { return false; } if (parameters.length == 1 && parameters[0] != String.class) { return false; } return true; }
From source file:com.opengamma.util.ReflectionUtils.java
/** * Checks if the class is closeable./* w w w .ja v a 2 s . c o m*/ * <p> * This invokes the close method if it is present. * * @param type the type, not null * @return true if closeable */ public static boolean isCloseable(final Class<?> type) { if (Closeable.class.isAssignableFrom(type)) { return true; } else if (Lifecycle.class.isAssignableFrom(type)) { return true; } else if (DisposableBean.class.isAssignableFrom(type)) { return true; } try { Method method = type.getMethod("close"); if (Modifier.isPublic(method.getModifiers()) && method.isSynthetic() == false) { return true; } } catch (Exception ex) { try { Method method = type.getMethod("stop"); if (Modifier.isPublic(method.getModifiers()) && method.isSynthetic() == false) { return true; } } catch (Exception ex2) { try { Method method = type.getMethod("shutdown"); if (Modifier.isPublic(method.getModifiers()) && method.isSynthetic() == false) { return true; } } catch (Exception ex3) { // ignored } } } return false; }
From source file:bboss.org.apache.velocity.util.introspection.ClassMap.java
private void populateMethodCacheWithInterface(MethodCache methodCache, Class iface) { if (Modifier.isPublic(iface.getModifiers())) { populateMethodCacheWith(methodCache, iface); }//w w w . j a va 2 s.c o m Class[] supers = iface.getInterfaces(); for (int i = 0; i < supers.length; i++) { populateMethodCacheWithInterface(methodCache, supers[i]); } }