public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) { Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType()); for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { list.add(new Runnable() { public void run() { invokeOnInjectee(method, injectee); } }, sameThreadExecutor()); } }); } for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { closer.addToClose(new Closeable() { public void close() throws IOException { invokeOnInjectee(method, injectee); } }); } }); } }
public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) { Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType()); for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { list.add(new Runnable() { public void run() { invokeOnInjectee(method, injectee); } }, sameThreadExecutor()); } }); } for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { closer.addToClose(new Closeable() { public void close() throws IOException { invokeOnInjectee(method, injectee); } }); } }); } }
public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) { Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType()); for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { list.add(new Runnable() { public void run() { invokeOnInjectee(method, injectee); } }, sameThreadExecutor()); } }); } for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { closer.addToClose(new Closeable() { public void close() throws IOException { invokeOnInjectee(method, injectee); } }); } }); } }
public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) { Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType()); for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { list.add(new Runnable() { public void run() { invokeOnInjectee(method, injectee); } }, sameThreadExecutor()); } }); } for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { closer.addToClose(new Closeable() { public void close() throws IOException { invokeOnInjectee(method, injectee); } }); } }); } }
public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) { Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType()); for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { list.add(new Runnable() { public void run() { invokeOnInjectee(method, injectee); } }, sameThreadExecutor()); } }); } for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { closer.addToClose(new Closeable() { public void close() throws IOException { invokeOnInjectee(method, injectee); } }); } }); } }
public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) { Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType()); for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { list.add(new Runnable() { public void run() { invokeOnInjectee(method, injectee); } }, newDirectExecutorService()); } }); } for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) { encounter.register(new InjectionListener<I>() { public void afterInjection(final I injectee) { closer.addToClose(new Closeable() { public void close() throws IOException { invokeOnInjectee(method, injectee); } }); } }); } }
public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) { for (Invokable<?, ?> invoked : methods(sync)) { Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } }
public void testMethods() { Set<String> methodNames = FluentIterable.from(methods(Set.class)).transform(invokableToName) .transform(toStringFunction()).toSet(); assertEquals(methodNames, setMethods); }
public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) { for (Invokable<?, ?> invoked : methods(sync)) { Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } }
public void testMethodsSubClass() { Set<String> methodNames = FluentIterable.from(methods(SortedSet.class)).transform(invokableToName) .transform(toStringFunction()).toSet(); assertEquals(methodNames, ImmutableSet.builder().add("comparator", "last", "first", "subSet", "headSet", "tailSet") .addAll(setMethods).build()); }
public static void putInvokables(Class<?> sync, Class<?> async, Cache<Invokable<?, ?>, Invokable<?, ?>> cache) { for (Invokable<?, ?> invoked : methods(sync)) { Invokable<?, ?> delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } }
public void testMethodsSubClass() { Set<String> methodNames = FluentIterable.from(methods(SortedSet.class)).transform(invokableToName) .transform(toStringFunction()) .filter(Predicates.not(Predicates.<String>in(SORTED_SET_METHODS))) .toSet(); assertEquals(methodNames, ImmutableSet.<String>of()); }
public void testMethods() { Set<String> methodNames = FluentIterable.from(methods(Set.class)).transform(invokableToName) .transform(toStringFunction()) .filter(Predicates.not(Predicates.<String>in(SET_METHODS))) .toSet(); assertEquals(methodNames, ImmutableSet.<String>of()); }
public void testCoreJavaMethodsNotMadeAccessible(final Method testMethod) { // a nice mock is required because plenty of other checks will be made SecurityManager mockSecurityManager = createNiceMock(SecurityManager.class); // clunky way of failing if the following method is ever called mockSecurityManager.checkPermission(new ReflectPermission("suppressAccessChecks")); expectLastCall().andStubAnswer(new IAnswer<Void>() { @Override public Void answer() throws Throwable { try { // generate a stacktrace throw new Exception(); } catch(Exception exception) { // fail *only* if being called from this test for (StackTraceElement element : exception.getStackTrace()) { if (element.getMethodName().equals(testMethod.getName())) { throw new AssertionError("checkPermission(new ReflectPermission(\"suppressAccessChecks\")) should not be called"); } } } return null; } }); replay(mockSecurityManager); System.setSecurityManager(mockSecurityManager); securityManagerOverridden = true; methods(Enum.class); }
public void testCoreJavaMethodsNotMadeAccessible(final Method testMethod) { // a nice mock is required because plenty of other checks will be made SecurityManager mockSecurityManager = createNiceMock(SecurityManager.class); // clunky way of failing if the following method is ever called mockSecurityManager.checkPermission(new ReflectPermission("suppressAccessChecks")); expectLastCall().andStubAnswer(new IAnswer<Void>() { @Override public Void answer() throws Throwable { try { // generate a stacktrace throw new Exception(); } catch (Exception exception) { // fail *only* if being called from this test for (StackTraceElement element : exception.getStackTrace()) { if (element.getMethodName().equals(testMethod.getName())) { throw new AssertionError("checkPermission(new ReflectPermission(\"suppressAccessChecks\")) should not be called"); } } } return null; } }); replay(mockSecurityManager); System.setSecurityManager(mockSecurityManager); securityManagerOverridden = true; methods(Enum.class); }