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(); }
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 an object responsible for performing sanity tests against the return values of all * public static methods declared by {@code cls}, excluding superclasses. */ public FactoryMethodReturnValueTester forAllPublicStaticMethods(Class<?> cls) { ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder(); for (Method method : cls.getDeclaredMethods()) { Invokable<?, ?> invokable = Invokable.from(method); invokable.setAccessible(true); if (invokable.isPublic() && invokable.isStatic() && !invokable.isSynthetic()) { builder.add(invokable); } } return new FactoryMethodReturnValueTester(cls, builder.build(), "public static methods"); }
if (!invokable.isPrivate() && !invokable.isSynthetic() && invokable.isStatic() && type.isSupertypeOf(invokable.getReturnType())) { @SuppressWarnings("unchecked") // guarded by isAssignableFrom()
public void testStaticMethod_isOverridable() throws Exception { Invokable<?, ?> delegate = Prepender.method("staticMethod"); assertTrue(delegate.isStatic()); assertFalse(delegate.isOverridable()); assertFalse(delegate.isVarArgs()); }
public void testStaticFinalMethod_isFinal() throws Exception { Invokable<?, ?> delegate = Prepender.method("staticFinalMethod"); assertTrue(delegate.isStatic()); assertTrue(delegate.isFinal()); assertFalse(delegate.isOverridable()); assertFalse(delegate.isVarArgs()); }
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(); }
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(); }
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(); }
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 an object responsible for performing sanity tests against the return values of all * public static methods declared by {@code cls}, excluding superclasses. */ public FactoryMethodReturnValueTester forAllPublicStaticMethods(Class<?> cls) { ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder(); for (Method method : cls.getDeclaredMethods()) { Invokable<?, ?> invokable = Invokable.from(method); invokable.setAccessible(true); if (invokable.isPublic() && invokable.isStatic() && !invokable.isSynthetic()) { builder.add(invokable); } } return new FactoryMethodReturnValueTester(cls, builder.build(), "public static methods"); }
/** * Returns an object responsible for performing sanity tests against the return values * of all public static methods declared by {@code cls}, excluding superclasses. */ public FactoryMethodReturnValueTester forAllPublicStaticMethods(Class<?> cls) { ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder(); for (Method method : cls.getDeclaredMethods()) { Invokable<?, ?> invokable = Invokable.from(method); invokable.setAccessible(true); if (invokable.isPublic() && invokable.isStatic() && !invokable.isSynthetic()) { builder.add(invokable); } } return new FactoryMethodReturnValueTester(cls, builder.build(), "public static methods"); }
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { com.google.common.reflect.TypeToken<T> token = typeToken(type.getType()); Invokable<T, T> deserializationTarget = constructorFieldNamingPolicy.getDeserializer(token); if (deserializationTarget == null) { return null; // allow GSON to choose the correct Adapter (can't simply return delegateFactory.create()) } // @AutoValue is SOURCE retention, which means it cannot be looked up at runtime. // Assume abstract types built by static methods are AutoValue. if (Modifier.isAbstract(type.getRawType().getModifiers()) && deserializationTarget.isStatic()) { // Lookup the generated AutoValue class, whose fields must be read for serialization. String packageName = type.getRawType().getPackage().getName(); String autoClassName = type.getRawType().getName().replace('$', '_') .replace(packageName + ".", packageName + ".AutoValue_"); try { type = (TypeToken<T>) TypeToken.get(type.getRawType().getClassLoader().loadClass(autoClassName)); } catch (ClassNotFoundException ignored) { } } return new DeserializeIntoParameterizedConstructor<T>(delegateFactory.create(gson, type), deserializationTarget, getParameterReaders(gson, deserializationTarget)); }
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { com.google.common.reflect.TypeToken<T> token = typeToken(type.getType()); Invokable<T, T> deserializationTarget = constructorFieldNamingPolicy.getDeserializer(token); if (deserializationTarget == null) { return null; // allow GSON to choose the correct Adapter (can't simply return delegateFactory.create()) } // @AutoValue is SOURCE retention, which means it cannot be looked up at runtime. // Assume abstract types built by static methods are AutoValue. if (Modifier.isAbstract(type.getRawType().getModifiers()) && deserializationTarget.isStatic()) { // Lookup the generated AutoValue class, whose fields must be read for serialization. String packageName = type.getRawType().getPackage().getName(); String autoClassName = type.getRawType().getName().replace('$', '_') .replace(packageName + ".", packageName + ".AutoValue_"); try { type = (TypeToken<T>) TypeToken.get(type.getRawType().getClassLoader().loadClass(autoClassName)); } catch (ClassNotFoundException ignored) { } } return new DeserializeIntoParameterizedConstructor<T>(delegateFactory.create(gson, type), deserializationTarget, getParameterReaders(gson, deserializationTarget)); }
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { com.google.common.reflect.TypeToken<T> token = typeToken(type.getType()); Invokable<T, T> deserializationTarget = constructorFieldNamingPolicy.getDeserializer(token); if (deserializationTarget == null) { return null; // allow GSON to choose the correct Adapter (can't simply return delegateFactory.create()) } // @AutoValue is SOURCE retention, which means it cannot be looked up at runtime. // Assume abstract types built by static methods are AutoValue. if (Modifier.isAbstract(type.getRawType().getModifiers()) && deserializationTarget.isStatic()) { // Lookup the generated AutoValue class, whose fields must be read for serialization. String packageName = type.getRawType().getPackage().getName(); String autoClassName = type.getRawType().getName().replace('$', '_') .replace(packageName + ".", packageName + ".AutoValue_"); try { type = (TypeToken<T>) TypeToken.get(type.getRawType().getClassLoader().loadClass(autoClassName)); } catch (ClassNotFoundException ignored) { } } return new DeserializeIntoParameterizedConstructor<T>(delegateFactory.create(gson, type), deserializationTarget, getParameterReaders(gson, deserializationTarget)); }
final Iterable<Method> getStaticMethods(final Class<?> cls) { ImmutableList.Builder<Method> builder = ImmutableList.builder(); for (Method method : getVisibleMethods(cls)) { if (Invokable.from(method).isStatic()) { builder.add(method); } } return builder.build(); }
final Iterable<Method> getInstanceMethods(final 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(); }
private void verifyMethodAccessibility(Errors methodErrors, Invokable<T, ?> method, Object source) { if (method.isStatic() || method.isPrivate() || method.isAbstract() || method.isSynthetic()) { methodErrors.addMessage( "Method @%s %s must not be private, static or abstract", EventuallyProvides.class.getSimpleName(), source); } else if (!method.isPublic()) { method.setAccessible(true); } }
public void testStaticMethod_isOverridable() throws Exception { Invokable<?, ?> delegate = Prepender.method("staticMethod"); assertTrue(delegate.isStatic()); assertFalse(delegate.isOverridable()); assertFalse(delegate.isVarArgs()); }
public void testStaticFinalMethod_isFinal() throws Exception { Invokable<?, ?> delegate = Prepender.method("staticFinalMethod"); assertTrue(delegate.isStatic()); assertTrue(delegate.isFinal()); assertFalse(delegate.isOverridable()); assertFalse(delegate.isVarArgs()); }