List of usage examples for com.google.common.reflect TypeToken TypeToken
private TypeToken(Type type)
From source file:org.mayocat.configuration.internal.ConfigurationMerger.java
public <T> Class getConfigurationClass(Object object) { TypeToken<T> type = new TypeToken<T>(object.getClass()) { }; return type.getRawType(); }
From source file:net.navatwo.jfxproperties.MoreReflection.java
/** * Unwraps a {@link Property} subtype and gets the underlying value type. * * @param propertyType Type of the property, used to extract the generic * @return Underlying type or null if not found *//* w w w.j a v a 2 s. com*/ @CheckReturnValue public static TypeToken<?> unwrapPropertyType(TypeToken<?> propertyType) { checkNotNull(propertyType, "propertyType == null"); Class<?> rawType = propertyType.getRawType(); checkNotNull(rawType, "rawType == null"); // used to clean up the if statements TypeToken<?> readOnlyPrim = new TypeToken<ReadOnlyProperty<Number>>(rawType) { }; if (propertyType.isSubtypeOf(readOnlyPrim)) { if (propertyType.isSubtypeOf(ReadOnlyIntegerProperty.class)) { return TypeToken.of(int.class); } else if (propertyType.isSubtypeOf(ReadOnlyLongProperty.class)) { return TypeToken.of(long.class); } else if (propertyType.isSubtypeOf(ReadOnlyDoubleProperty.class)) { return TypeToken.of(double.class); } else { throw new IllegalArgumentException("Unknown primitive property: " + propertyType); } } else if (propertyType.isSubtypeOf(ReadOnlyStringProperty.class)) { return TypeToken.of(String.class); } else if (isReadOnlyProperty(propertyType)) { // This checks for ReadOnlyProperty, both of which we can handle by // Pulling out the first generic argument (thanks to Guava's TypeToken) TypeToken<?> param = propertyType.resolveType(ReadOnlyProperty.class.getTypeParameters()[0]); return param; } else if (isOptional(propertyType)) { TypeToken<?> param = propertyType.resolveType(Optional.class.getTypeParameters()[0]); return param; } else { return propertyType; } }
From source file:org.gradle.model.internal.inspect.AbstractAnnotationDrivenMethodRuleDefinitionHandler.java
protected AbstractAnnotationDrivenMethodRuleDefinitionHandler() { @SuppressWarnings("unchecked") Class<T> annotationType = (Class<T>) new TypeToken<T>(getClass()) { }.getRawType();//from w ww . j ava 2s .co m this.annotationType = annotationType; }
From source file:com.github.rinde.rinsim.core.model.AbstractModel.java
/** * Create a new model.//from w w w .ja v a 2s. com */ @SuppressWarnings({ "serial", "unchecked" }) protected AbstractModel() { this.clazz = (Class<T>) new TypeToken<T>(getClass()) { }.getRawType(); }
From source file:org.gradle.model.internal.inspect.AbstractAnnotationDrivenModelRuleExtractor.java
protected AbstractAnnotationDrivenModelRuleExtractor() { @SuppressWarnings("unchecked") Class<T> annotationType = (Class<T>) new TypeToken<T>(getClass()) { }.getRawType();//from w w w.ja va2 s . c o m this.annotationType = annotationType; }
From source file:qa.qcri.nadeef.core.pipeline.Operator.java
/** * Constructor.//from w w w . j av a 2s .c o m */ public Operator(ExecutionContext context) { this.typeToken = new TypeToken<TInput>(getClass()) { }; this.context = context; }
From source file:net.derquinse.common.reflect.This.java
/** * Constructor.//from w ww .j av a2s . c o m * @throws IllegalArgumentException if the type argument is not the same (raw type) as the actual * class. */ protected This() { final Class<?> thisClass = getClass(); @SuppressWarnings("serial") final TypeToken<T> token = new TypeToken<T>(thisClass) { }; Type raw = token.getRawType(); checkArgument(thisClass.equals(raw)); }
From source file:ratpack.render.Renderer.java
/** * Creates a type token for a <i>compatible</i> renderer of the given type of object. * * @param toRender the type that the renderer renders * @param <T> the type that the renderer renders * @return a type token for a <i>compatible</i> renderer of the given type of object *//*from ww w . java 2 s . c o m*/ static <T> TypeToken<Renderer<? super T>> typeCompatibleOf(T toRender) { Class<T> clazz = Types.cast(toRender.getClass()); return new TypeToken<Renderer<? super T>>(clazz) { }.where(new TypeParameter<T>() { }, clazz); }
From source file:edu.washington.cs.cupid.standard.Flatten.java
@Override public TypeToken<Collection<Collection<V>>> getInputType() { return new TypeToken<Collection<Collection<V>>>(getClass()) { private static final long serialVersionUID = 1L; };// w ww . ja va 2s .com }
From source file:edu.washington.cs.cupid.standard.NonEmpty.java
@Override public TypeToken<Collection<V>> getInputType() { return new TypeToken<Collection<V>>(getClass()) { private static final long serialVersionUID = 1L; };//ww w.j a va 2 s. com }