本文整理汇总了Java中com.google.inject.internal.MoreTypes类的典型用法代码示例。如果您正苦于以下问题:Java MoreTypes类的具体用法?Java MoreTypes怎么用?Java MoreTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MoreTypes类属于com.google.inject.internal包,在下文中一共展示了MoreTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exposeInternal
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
private <T> AnnotatedElementBuilder exposeInternal(Key<T> key) {
if (privateElements == null) {
addError(
"Cannot expose %s on a standard binder. "
+ "Exposed bindings are only applicable to private binders.",
key);
return new AnnotatedElementBuilder() {
@Override
public void annotatedWith(Class<? extends Annotation> annotationType) {}
@Override
public void annotatedWith(Annotation annotation) {}
};
}
ExposureBuilder<T> builder =
new ExposureBuilder<T>(this, getElementSource(), MoreTypes.canonicalizeKey(key));
privateElements.addExposureBuilder(builder);
return builder;
}
示例2: justInTimeResolution
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
@Override
public boolean justInTimeResolution(Injectee injectee) {
Type type = injectee.getRequiredType();
Class<?> clazz = MoreTypes.getRawType(type);
if (clazz != null) {
Binding<?> binding = findBinding(injectee);
if (binding != null) {
Key<?> key = binding.getKey();
Set<Annotation> qualifiers = BindingUtils.getQualifiers(key);
GuiceBindingDescriptor<?> descriptor = new GuiceBindingDescriptor<>(
type, clazz, qualifiers, binding);
ServiceLocatorUtilities.addOneDescriptor(locator, descriptor);
return true;
}
}
return false;
}
示例3: define
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* Register a Java type and produces an equivalent RAML type. It returns an existing RAML type if
* the Java type was registered already.
*
* @param type Java type.
* @return RAML type.
*/
public RamlType define(Type type) {
if (types == null) {
types = new LinkedHashMap<>();
}
Type componentType = componentType(type);
String typeName = MoreTypes.getRawType(componentType).getSimpleName();
RamlType ramlType = RamlType.valueOf(typeName);
if (ramlType.isObject()) {
RamlType existing = types.get(typeName);
if (existing == null) {
ModelConverters converter = ModelConverters.getInstance();
Property property = converter.readAsProperty(componentType);
Map<PropertyBuilder.PropertyId, Object> args = new EnumMap<>(
PropertyBuilder.PropertyId.class);
for (Map.Entry<String, Model> entry : converter.readAll(componentType).entrySet()) {
define(entry.getKey(), entry.getValue());
}
ramlType = define(typeName, PropertyBuilder.toModel(PropertyBuilder.merge(property, args)));
} else {
ramlType = existing;
}
}
return type != componentType ? ramlType.toArray() : ramlType;
}
示例4: extractBuilderType
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
private Type extractBuilderType()
{
Class<?> builderClass = extractBuilderClass();
if (builderClass == null) {
return null;
}
if (builderClass.getTypeParameters().length == 0) {
return builderClass;
}
if (!(structType instanceof ParameterizedType)) {
metadataErrors.addError("Builder class '%s' may only be generic if the type it builds ('%s') is also generic", builderClass.getName(), getStructClass().getName());
return builderClass;
}
if (builderClass.getTypeParameters().length != getStructClass().getTypeParameters().length) {
metadataErrors.addError(
"Generic builder class '%s' must have the same number of type parameters as the type it builds ('%s')",
builderClass.getName(),
getStructClass().getName());
return builderClass;
}
ParameterizedType parameterizedStructType = (ParameterizedType) structType;
return new MoreTypes.ParameterizedTypeImpl(builderClass.getEnclosingClass(), builderClass, parameterizedStructType.getActualTypeArguments());
}
示例5: Key
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* Unsafe. Constructs a key from a manually specified type.
*/
@SuppressWarnings("unchecked")
private Key(Type type, AnnotationStrategy annotationStrategy) {
this.annotationStrategy = annotationStrategy;
this.typeLiteral = MoreTypes
.canonicalizeForKey((TypeLiteral<T>) TypeLiteral.get(type));
this.hashCode = computeHashCode();
this.toStringSupplier = createToStringSupplier();
}
示例6: testToString
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
public void testToString() {
Assert.assertEquals("java.lang.String",
MoreTypes.typeToString(String.class));
assertEquals("java.util.Set<java.lang.String>[][]",
MoreTypes.typeToString(setStringArray));
assertEquals("java.util.Map<java.lang.String, java.lang.Integer>",
MoreTypes.typeToString(mapStringInteger));
assertEquals("java.util.List<java.util.Set<java.lang.String>[][]>",
MoreTypes.typeToString(listSetStringArray));
assertEquals(innerFloatDouble.toString(),
MoreTypes.typeToString(innerFloatDouble));
}
示例7: toString
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* Returns the method's declaring type and name in the format used in
* javadoc, e.g. {@code com.bar.Foo#baz(com.bar.Foo, com.bar.Bar)}, with
* resolved type parameters.
*
* @return string representation for this method including the declaring type
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName()).append("(");
List<String> parameters = new ArrayList<String>();
for (Type parameterType : getRawParameterTypes()) {
// TODO(schmitt): We are not respecting varargs here.
parameters.add(MoreTypes.typeToString(parameterType));
}
sb.append(join(", ", parameters)).append(")");
return String.format("%s#%s", getDeclaringType(), sb.toString());
}
示例8: TypeLiteral
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* Constructs a new type literal. Derives represented class from type parameter.
*
* <p>Clients create an empty anonymous subclass. Doing so embeds the type parameter in the
* anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
*/
@SuppressWarnings("unchecked")
protected TypeLiteral() {
this.type = getSuperclassTypeParameter(getClass());
this.rawType = (Class<? super T>) MoreTypes.getRawType(type);
this.hashCode = type.hashCode();
}
示例9: Key
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/** Unsafe. Constructs a key from a manually specified type. */
@SuppressWarnings("unchecked")
private Key(Type type, AnnotationStrategy annotationStrategy) {
this.annotationStrategy = annotationStrategy;
this.typeLiteral = MoreTypes.canonicalizeForKey((TypeLiteral<T>) TypeLiteral.get(type));
this.hashCode = computeHashCode();
}
示例10: getMembersInjector
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
@Override
public <T> MembersInjector<T> getMembersInjector(final TypeLiteral<T> typeLiteral) {
final MembersInjectorLookup<T> element =
new MembersInjectorLookup<T>(
getElementSource(), MoreTypes.canonicalizeForKey(typeLiteral));
elements.add(element);
return element.getMembersInjector();
}
示例11: testToString
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
public void testToString() {
Assert.assertEquals("java.lang.String", MoreTypes.typeToString(String.class));
assertEquals("java.util.Set<java.lang.String>[][]", MoreTypes.typeToString(setStringArray));
assertEquals(
"java.util.Map<java.lang.String, java.lang.Integer>",
MoreTypes.typeToString(mapStringInteger));
assertEquals(
"java.util.List<java.util.Set<java.lang.String>[][]>",
MoreTypes.typeToString(listSetStringArray));
assertEquals(innerFloatDouble.toString(), MoreTypes.typeToString(innerFloatDouble));
}
示例12: TypeLiteral
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* Unsafe. Constructs a type literal manually.
*/
@SuppressWarnings("unchecked")
TypeLiteral(Type type) {
this.type = canonicalize(checkNotNull(type, "type"));
this.rawType = (Class<? super T>) MoreTypes.getRawType(this.type);
this.hashCode = this.type.hashCode();
}
示例13: Key
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* Unsafe. Constructs a key from a manually specified type.
*/
@SuppressWarnings("unchecked")
private Key(Type type, AnnotationStrategy annotationStrategy) {
this.annotationStrategy = annotationStrategy;
this.typeLiteral = MoreTypes.canonicalizeForKey((TypeLiteral<T>) TypeLiteral.get(type));
this.hashCode = computeHashCode();
this.toStringSupplier = createToStringSupplier();
}
示例14: testToString
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
public void testToString() {
Assert.assertEquals("java.lang.String", MoreTypes.typeToString(String.class));
assertEquals("java.util.Set<java.lang.String>[][]", MoreTypes.typeToString(setStringArray));
assertEquals("java.util.Map<java.lang.String, java.lang.Integer>",
MoreTypes.typeToString(mapStringInteger));
assertEquals("java.util.List<java.util.Set<java.lang.String>[][]>",
MoreTypes.typeToString(listSetStringArray));
assertEquals(innerFloatDouble.toString(),
MoreTypes.typeToString(innerFloatDouble));
}
示例15: enums
import com.google.inject.internal.MoreTypes; //导入依赖的package包/类
/**
* List of enum values when the {@link #type()} represents an enum.
*
* @return Enum values.
*/
public List<String> enums() {
return Optional.ofNullable(MoreTypes.getRawType(type))
.map(Class::getEnumConstants)
.filter(Objects::nonNull)
.map(values -> Arrays.asList(values).stream()
.map(value -> ((Enum) value).name())
.collect(Collectors.toList())
).orElse(Collections.emptyList());
}