private ImmutableList<Method> getVisibleMethods(Class<?> cls) { // Don't use cls.getPackage() because it does nasty things like reading // a file. String visiblePackage = Reflection.getPackageName(cls); ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Class<?> type : TypeToken.of(cls).getTypes().rawTypes()) { if (!Reflection.getPackageName(type).equals(visiblePackage)) { break; } for (Method method : type.getDeclaredMethods()) { if (!method.isSynthetic() && isVisible(method)) { builder.add(method); } } } return builder.build(); } }
ImmutableList<Method> getInstanceMethodsToTest(Class<?> c, Visibility minimalVisibility) { ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Method method : minimalVisibility.getInstanceMethods(c)) { if (!isIgnored(method)) { builder.add(method); } } return builder.build(); }
final Iterable<Method> getStaticMethods(Class<?> cls) { ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Method method : getVisibleMethods(cls)) { if (Invokable.from(method).isStatic()) { builder.add(method); } } return builder.build(); }
private ImmutableList<Method> getVisibleMethods(Class<?> cls) { // Don't use cls.getPackage() because it does nasty things like reading // a file. String visiblePackage = Reflection.getPackageName(cls); ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Class<?> type : TypeToken.of(cls).getTypes().classes().rawTypes()) { if (!Reflection.getPackageName(type).equals(visiblePackage)) { break; } for (Method method : type.getDeclaredMethods()) { if (!method.isSynthetic() && isVisible(method)) { builder.add(method); } } } return builder.build(); } }
private ImmutableList<Method> getVisibleMethods(Class<?> cls) { // Don't use cls.getPackage() because it does nasty things like reading // a file. String visiblePackage = Reflection.getPackageName(cls); ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Class<?> type : TypeToken.of(cls).getTypes().rawTypes()) { if (!Reflection.getPackageName(type).equals(visiblePackage)) { break; } for (Method method : type.getDeclaredMethods()) { if (!method.isSynthetic() && isVisible(method)) { builder.add(method); } } } return builder.build(); } }
@Override public boolean apply(Class<?> cls) { return visibility.isVisible(cls.getModifiers()); } };
/** Returns {@code true} if {@code member} is visible under {@code this} visibility. */ final boolean isVisible(Member member) { return isVisible(member.getModifiers()); }
public void testVisibility_public() throws Exception { assertFalse(Visibility.PUBLIC.isVisible( VisibilityMethods.class.getDeclaredMethod("privateMethod"))); assertFalse(Visibility.PUBLIC.isVisible( VisibilityMethods.class.getDeclaredMethod("packagePrivateMethod"))); assertFalse(Visibility.PUBLIC.isVisible( VisibilityMethods.class.getDeclaredMethod("protectedMethod"))); assertTrue(Visibility.PUBLIC.isVisible( VisibilityMethods.class.getDeclaredMethod("publicMethod"))); }
final Iterable<Method> getInstanceMethods(Class<?> cls) { ConcurrentMap<Signature, Method> map = Maps.newConcurrentMap(); for (Method method : getVisibleMethods(cls)) { if (!Invokable.from(method).isStatic()) { map.putIfAbsent(new Signature(method), method); } } return map.values(); }
/** * Returns {@code true} if {@code member} is visible under {@code this} * visibility. */ final boolean isVisible(Member member) { return isVisible(member.getModifiers()); }
/** * Runs {@link #testConstructor} on every constructor in class {@code c} that * has at least {@code minimalVisibility}. */ public void testConstructors(Class<?> c, Visibility minimalVisibility) { for (Constructor<?> constructor : c.getDeclaredConstructors()) { if (minimalVisibility.isVisible(constructor) && !isIgnored(constructor)) { testConstructor(constructor); } } }
public void testVisibility_package() throws Exception { assertFalse(Visibility.PACKAGE.isVisible( VisibilityMethods.class.getDeclaredMethod("privateMethod"))); assertTrue(Visibility.PACKAGE.isVisible( VisibilityMethods.class.getDeclaredMethod("packagePrivateMethod"))); assertTrue(Visibility.PACKAGE.isVisible( VisibilityMethods.class.getDeclaredMethod("protectedMethod"))); assertTrue(Visibility.PACKAGE.isVisible( VisibilityMethods.class.getDeclaredMethod("publicMethod"))); }
ImmutableList<Method> getInstanceMethodsToTest(Class<?> c, Visibility minimalVisibility) { ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Method method : minimalVisibility.getInstanceMethods(c)) { if (!isIgnored(method)) { builder.add(method); } } return builder.build(); }
private VisibilityLocal convert( final Visibility visibility) { return VisibilityLocal.valueOf(visibility.name()); }
/** * Runs {@link #testConstructor} on every constructor in class {@code c} that has at least {@code * minimalVisibility}. */ public void testConstructors(Class<?> c, Visibility minimalVisibility) { for (Constructor<?> constructor : c.getDeclaredConstructors()) { if (minimalVisibility.isVisible(constructor) && !isIgnored(constructor)) { testConstructor(constructor); } } }
public void testVisibility_package() throws Exception { assertFalse( Visibility.PACKAGE.isVisible(VisibilityMethods.class.getDeclaredMethod("privateMethod"))); assertTrue( Visibility.PACKAGE.isVisible( VisibilityMethods.class.getDeclaredMethod("packagePrivateMethod"))); assertTrue( Visibility.PACKAGE.isVisible(VisibilityMethods.class.getDeclaredMethod("protectedMethod"))); assertTrue( Visibility.PACKAGE.isVisible(VisibilityMethods.class.getDeclaredMethod("publicMethod"))); }
ImmutableList<Method> getInstanceMethodsToTest(Class<?> c, Visibility minimalVisibility) { ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Method method : minimalVisibility.getInstanceMethods(c)) { if (!isIgnored(method)) { builder.add(method); } } return builder.build(); }
final Iterable<Method> getInstanceMethods(Class<?> cls) { ConcurrentMap<Signature, Method> map = Maps.newConcurrentMap(); for (Method method : getVisibleMethods(cls)) { if (!Invokable.from(method).isStatic()) { map.putIfAbsent(new Signature(method), method); } } return map.values(); }
/** * Runs {@link #testMethod} on every static method of class {@code c} that has at least {@code * minimalVisibility}, including those "inherited" from superclasses of the same package. */ public void testStaticMethods(Class<?> c, Visibility minimalVisibility) { for (Method method : minimalVisibility.getStaticMethods(c)) { if (!isIgnored(method)) { testMethod(null, method); } } }
public void testVisibility_public() throws Exception { assertFalse( Visibility.PUBLIC.isVisible(VisibilityMethods.class.getDeclaredMethod("privateMethod"))); assertFalse( Visibility.PUBLIC.isVisible( VisibilityMethods.class.getDeclaredMethod("packagePrivateMethod"))); assertFalse( Visibility.PUBLIC.isVisible(VisibilityMethods.class.getDeclaredMethod("protectedMethod"))); assertTrue( Visibility.PUBLIC.isVisible(VisibilityMethods.class.getDeclaredMethod("publicMethod"))); }