@Override boolean isVisible(int modifiers) { return !Modifier.isPrivate(modifiers); } },
/** Return true if the method includes the {@code private} modifier. */ public boolean isPrivate () { return Modifier.isPrivate(method.getModifiers()); }
/** Return true if the method includes the {@code private} modifier. */ public boolean isPrivate () { return Modifier.isPrivate(method.getModifiers()); }
/** Return true if the field includes the {@code private} modifier. */ public boolean isPrivate () { return Modifier.isPrivate(field.getModifiers()); }
/** Return true if the field includes the {@code private} modifier. */ public boolean isPrivate () { return Modifier.isPrivate(field.getModifiers()); }
private static boolean isStaticNonPrivateAndNonFinal(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); int modifiers = clazz.getModifiers(); return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)); }
private static boolean typeIsPrivateAbstractInnerClass(Class<?> type, int modifiers) { return Modifier.isPrivate(modifiers) && Modifier.isAbstract(modifiers) && type.getEnclosingClass() != null; }
public LifecycleElement(Method method) { if (method.getParameterCount() != 0) { throw new IllegalStateException("Lifecycle method annotation requires a no-arg method: " + method); } this.method = method; this.identifier = (Modifier.isPrivate(method.getModifiers()) ? ClassUtils.getQualifiedMethodName(method) : method.getName()); }
/** Returns true if the element is private. */ public final boolean isPrivate() { return Modifier.isPrivate(getModifiers()); }
private static String modifier(int mod) { StringBuilder modifier = new StringBuilder(); if (Modifier.isPublic(mod)) { modifier.append("public"); } if (Modifier.isProtected(mod)) { modifier.append("protected"); } if (Modifier.isPrivate(mod)) { modifier.append("private"); } if (Modifier.isStatic(mod)) { modifier.append(" static"); } if (Modifier.isVolatile(mod)) { modifier.append(" volatile"); } return modifier.toString(); }
private static String modifier(int mod) { StringBuilder modifier = new StringBuilder(); if (Modifier.isPublic(mod)) { modifier.append("public"); } if (Modifier.isProtected(mod)) { modifier.append("protected"); } if (Modifier.isPrivate(mod)) { modifier.append("private"); } if (Modifier.isStatic(mod)) { modifier.append(" static"); } if (Modifier.isVolatile(mod)) { modifier.append(" volatile"); } return modifier.toString(); }
private static boolean shouldProxy(java.lang.reflect.Method method) { int modifiers = method.getModifiers(); return !Modifier.isAbstract(modifiers) && !Modifier.isFinal(modifiers) && !Modifier.isPrivate( modifiers) && !Modifier.isNative(modifiers); }
/** * Determine whether the given method is overridable in the given target class. * @param method the method to check * @param targetClass the target class to check against */ private static boolean isOverridable(Method method, @Nullable Class<?> targetClass) { if (Modifier.isPrivate(method.getModifiers())) { return false; } if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) { return true; } return (targetClass == null || getPackageName(method.getDeclaringClass()).equals(getPackageName(targetClass))); }
/** Returns true if the element is private. */ public final boolean isPrivate() { return Modifier.isPrivate(getModifiers()); }
private static boolean canInclude(boolean isSamePackage, Method method, Map<String, Set<Method>> collected) { int methodModifiers = method.getModifiers(); boolean visible = (Modifier.isPublic(methodModifiers) || Modifier.isProtected(methodModifiers)) || (isSamePackage && !Modifier.isPrivate(methodModifiers)); boolean hasNoInheritanceTraits = !isOverridden(method, collected) && !Modifier.isAbstract(methodModifiers); return visible && hasNoInheritanceTraits; }
/** * Select an invocable method on the target type: either the given method itself * if actually exposed on the target type, or otherwise a corresponding method * on one of the target type's interfaces or on the target type itself. * @param method the method to check * @param targetType the target type to search methods on (typically an AOP proxy) * @return a corresponding invocable method on the target type * @throws IllegalStateException if the given method is not invocable on the given * target type (typically due to a proxy mismatch) * @since 4.3 * @see MethodIntrospector#selectInvocableMethod(Method, Class) */ public static Method selectInvocableMethod(Method method, @Nullable Class<?> targetType) { if (targetType == null) { return method; } Method methodToUse = MethodIntrospector.selectInvocableMethod(method, targetType); if (Modifier.isPrivate(methodToUse.getModifiers()) && !Modifier.isStatic(methodToUse.getModifiers()) && SpringProxy.class.isAssignableFrom(targetType)) { throw new IllegalStateException(String.format( "Need to invoke method '%s' found on proxy for target class '%s' but cannot " + "be delegated to target bean. Switch its visibility to package or protected.", method.getName(), method.getDeclaringClass().getSimpleName())); } return methodToUse; }
@Override public boolean isOverridable() { return (!isStatic() && !isFinal() && !Modifier.isPrivate(this.introspectedMethod.getModifiers())); }
/** Returns true if the element is private. */ public final boolean isPrivate() { return Modifier.isPrivate(getModifiers()); }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory); } ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory; this.scopedTargetSource.setBeanFactory(beanFactory); ProxyFactory pf = new ProxyFactory(); pf.copyFrom(this); pf.setTargetSource(this.scopedTargetSource); Assert.notNull(this.targetBeanName, "Property 'targetBeanName' is required"); Class<?> beanType = beanFactory.getType(this.targetBeanName); if (beanType == null) { throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName + "': Target type could not be determined at the time of proxy creation."); } if (!isProxyTargetClass() || beanType.isInterface() || Modifier.isPrivate(beanType.getModifiers())) { pf.setInterfaces(ClassUtils.getAllInterfacesForClass(beanType, cbf.getBeanClassLoader())); } // Add an introduction that implements only the methods on ScopedObject. ScopedObject scopedObject = new DefaultScopedObject(cbf, this.scopedTargetSource.getTargetBeanName()); pf.addAdvice(new DelegatingIntroductionInterceptor(scopedObject)); // Add the AopInfrastructureBean marker to indicate that the scoped proxy // itself is not subject to auto-proxying! Only its target bean is. pf.addInterface(AopInfrastructureBean.class); this.proxy = pf.getProxy(cbf.getBeanClassLoader()); }
@Test public void findField() { Field field = ReflectionUtils.findField(TestObjectSubclassWithPublicField.class, "publicField", String.class); assertNotNull(field); assertEquals("publicField", field.getName()); assertEquals(String.class, field.getType()); assertTrue("Field should be public.", Modifier.isPublic(field.getModifiers())); field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "prot", String.class); assertNotNull(field); assertEquals("prot", field.getName()); assertEquals(String.class, field.getType()); assertTrue("Field should be protected.", Modifier.isProtected(field.getModifiers())); field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class); assertNotNull(field); assertEquals("name", field.getName()); assertEquals(String.class, field.getType()); assertTrue("Field should be private.", Modifier.isPrivate(field.getModifiers())); }