当前位置: 首页>>代码示例>>Java>>正文


Java TypeToken.getRawType方法代码示例

本文整理汇总了Java中com.google.common.reflect.TypeToken.getRawType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeToken.getRawType方法的具体用法?Java TypeToken.getRawType怎么用?Java TypeToken.getRawType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.reflect.TypeToken的用法示例。


在下文中一共展示了TypeToken.getRawType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@SuppressWarnings ("unchecked")
private D init (final URL url, final Capabilities capability) {
	log.trace ("Initializing driver...");
	final TypeToken <D> token = new TypeToken <D> (getClass ()) {
		private static final long serialVersionUID = 1562415938665085306L;
	};
	final Class <D> cls = (Class <D>) token.getRawType ();
	final Class <?> [] argTypes = new Class <?> [] { URL.class, Capabilities.class };
	try {
		final Constructor <D> ctor = cls.getDeclaredConstructor (argTypes);
		return ctor.newInstance (url, capability);
	}
	catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
			| IllegalArgumentException | InvocationTargetException e) {
		fail (DeviceDriverInitializationFailedError.class, "Error occured while initializing device driver.", e);
	}
	return null;
}
 
开发者ID:WasiqB,项目名称:coteafs-appium,代码行数:19,代码来源:Device.java

示例2: getDummyValue

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private <T> T getDummyValue(TypeToken<T> type) {
  Class<? super T> rawType = type.getRawType();
  @SuppressWarnings("unchecked") // Assume all default values are generics safe.
  T defaultValue = (T) defaultValues.getInstance(rawType);
  if (defaultValue != null) {
    return defaultValue;
  }
  @SuppressWarnings("unchecked") // ArbitraryInstances always returns generics-safe dummies.
  T value = (T) ArbitraryInstances.get(rawType);
  if (value != null) {
    return value;
  }
  if (rawType.isInterface()) {
    return new SerializableDummyProxy(this).newProxy(type);
  }
  return null;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:ClassSanityTester.java

示例3: invocationFailureReason

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private static @Nullable String invocationFailureReason(Invokable<?, ?> to, Invokable<?, ?> from) {
    final String reason = invocationFailureReason(methodType(to), methodType(from));
    if(reason != null) return reason;

    thrownLoop: for(TypeToken<? extends Throwable> thrown : from.getExceptionTypes()) {
        final Class<?> thrownRaw = thrown.getRawType();
        if(Error.class.isAssignableFrom(thrownRaw)) continue;
        if(RuntimeException.class.isAssignableFrom(thrownRaw)) continue ;
        for(TypeToken<? extends Throwable> caught : to.getExceptionTypes()) {
            if(caught.getRawType().isAssignableFrom(thrownRaw)) continue thrownLoop;
        }
        return "unhandled exception " + thrown.getRawType().getName();
    }

    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:Methods.java

示例4: isConvertibleForInvocation

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
 * Test if an invocation conversion can be applied to the given types.
 *
 * https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.3
 */
public static boolean isConvertibleForInvocation(TypeToken<?> to, TypeToken<?> from) {
    if(to.isPrimitive()) {
        // Assigning to a primitive allows for both unboxing and primitive widening
        Class<?> fromRaw = from.getRawType();
        if(!fromRaw.isPrimitive()) {
            fromRaw = BOXINGS.inverse().get(fromRaw);
            if(fromRaw == null) return false;
        }
        return isPromotable(to.getRawType(), fromRaw);
    } else if(from.isPrimitive()) {
        // Assigning to an object from a primitive allows boxing and reference widening
        return to.isAssignableFrom(box(from.getRawType()));
    } else {
        return to.isAssignableFrom(from);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:Types.java

示例5: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
 * Convert for a target of Optional
 */
@Override
public Object convert(FixtureTemplate fixtureTemplate, TypeToken typeToken) {
    if (typeToken.getRawType() != Optional.class) {
        return fixtureConverter.convert(fixtureTemplate, typeToken);
    }
    List<TypeToken<?>> types = TypeTokenUtils.extractGenericTypeTokens(typeToken);
    if (types.isEmpty()) {
        if (fixtureTemplate instanceof FixtureValue) {
            Object value = ((FixtureValue) fixtureTemplate).getValue();
            return Optional.of(value);
        }
        return null;
    } else {
        return Optional.of(fixtureConverter.convert(fixtureTemplate, types.get(0)));
    }
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:20,代码来源:OptionalTypeFixtureConverter.java

示例6: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
 * Convert for a target of Optional

 */
@Override
public Object convert(FixtureTemplate fixtureTemplate, TypeToken typeToken) {
    if (typeToken.getRawType() != Optional.class) {
        return fixtureConverter.convert(fixtureTemplate, typeToken);
    }
    List<TypeToken<?>> types = TypeTokenUtils.extractGenericTypeTokens(typeToken);
    if (types.isEmpty()) {
        if (fixtureTemplate instanceof FixtureValue) {
            Object value = ((FixtureValue) fixtureTemplate).getValue();
            return Optional.of(value);
        }
        return null;
    } else {
        return Optional.of(fixtureConverter.convert(fixtureTemplate, types.get(0)));
    }
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:21,代码来源:OptionalTypeFixtureConverter.java

示例7: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object convert(Object source, TypeToken<?> targetTypeToken) {
    if (!canHandle(source, targetTypeToken)) throw new ConverterException(source, targetTypeToken.getRawType());

    Class enumClass = targetTypeToken.getRawType();
    for (Object enumConstant : enumClass.getEnumConstants()) {
        String enumStr = enumConstant.toString().replaceAll("\\_", "");
        String sourceStr = ((String) source).replaceAll("\\-", "").replaceAll("\\_", "").replaceAll("\\s", "");
        if (enumStr.equalsIgnoreCase(sourceStr)) {
            return Enum.valueOf(enumClass, enumConstant.toString());
        }
    }

    throw new ConverterException(source, targetTypeToken.getRawType(), "can not find enum constants");
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:17,代码来源:StringToEnumConverter.java

示例8: NotificationInvoker

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private NotificationInvoker(final NotificationListener listener) {
    delegate = listener;
    final Map<Class<? extends Notification>, InvokerContext> builder = new HashMap<>();
    for(final TypeToken<?> ifaceToken : TypeToken.of(listener.getClass()).getTypes().interfaces()) {
        final Class<?> iface = ifaceToken.getRawType();
        if(NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
            @SuppressWarnings("unchecked")
            final Class<? extends NotificationListener> listenerType = (Class<? extends NotificationListener>) iface;
            final NotificationListenerInvoker invoker = NotificationListenerInvoker.from(listenerType);
            for(final Class<? extends Notification> type : getNotificationTypes(listenerType)) {
                builder.put(type, new InvokerContext(BindingReflections.findQName(type) , invoker));
            }
        }
    }
    invokers = ImmutableMap.copyOf(builder);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:NotificationInvoker.java

示例9: getDefaultValue

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private <T> T getDefaultValue(TypeToken<T> type) {
  // We assume that all defaults are generics-safe, even if they aren't,
  // we take the risk.
  @SuppressWarnings("unchecked")
  T defaultValue = (T) defaults.getInstance(type.getRawType());
  if (defaultValue != null) {
    return defaultValue;
  }
  @SuppressWarnings("unchecked") // All arbitrary instances are generics-safe
  T arbitrary = (T) ArbitraryInstances.get(type.getRawType());
  if (arbitrary != null) {
    return arbitrary;
  }
  if (type.getRawType() == Class.class) {
    // If parameter is Class<? extends Foo>, we return Foo.class
    @SuppressWarnings("unchecked")
    T defaultClass = (T) getFirstTypeParameter(type.getType()).getRawType();
    return defaultClass;
  }
  if (type.getRawType() == TypeToken.class) {
    // If parameter is TypeToken<? extends Foo>, we return TypeToken<Foo>.
    @SuppressWarnings("unchecked")
    T defaultType = (T) getFirstTypeParameter(type.getType());
    return defaultType;
  }
  if (type.getRawType() == Converter.class) {
    TypeToken<?> convertFromType = type.resolveType(
        Converter.class.getTypeParameters()[0]);
    TypeToken<?> convertToType = type.resolveType(
        Converter.class.getTypeParameters()[1]);
    @SuppressWarnings("unchecked") // returns default for both F and T
    T defaultConverter = (T) defaultConverter(convertFromType, convertToType);
    return defaultConverter;
  }
  if (type.getRawType().isInterface()) {
    return newDefaultReturningProxy(type);
  }
  return null;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:40,代码来源:NullPointerTester.java

示例10: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object convert(Object input, ParameterContext context) throws ArgumentConversionException {
  TypeToken<?> parameterType = TypeToken.of(context.getParameter().getParameterizedType());
  if (parameterType.getRawType() != Class.class) {
    throw new ArgumentConversionException(
        String.format("Could not convert: %s. Invalid parameter type.", input));
  }

  return convert(input.toString(), (TypeToken<? extends Class<?>>) parameterType);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:12,代码来源:ClassArgumentConverter.java

示例11: deserialize

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Trail deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {

    Class<?> clazz = type.getRawType();
    return Sponge.getDataManager()
        .deserialize(Trail.class, DataTranslators.CONFIGURATION_NODE.translate(value))
        .orElseThrow(() -> new ObjectMappingException("Could not translate DataSerializable of type: " + clazz.getName()));
}
 
开发者ID:gabizou,项目名称:HappyTrails,代码行数:9,代码来源:Trail.java

示例12: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Object convert(Object source, TypeToken<?> targetTypeToken) {
    if (!canHandle(source, targetTypeToken)) {
        throw new ConverterException(source, targetTypeToken.getRawType());
    }

    Integer period = null;
    if (source instanceof Number) {
        period = (Integer) numberToNumberConverter.convert(source, TypeToken.of(Integer.class));
    } else if (source instanceof String) {
        period = (Integer) stringToNumberConverter.convert(source, TypeToken.of(Integer.class));
    }

    Type targetType = targetTypeToken.getType();

    if (targetType.equals(Seconds.class)) {
        return Seconds.seconds(period);
    } else if (targetType.equals(Minutes.class)) {
        return Minutes.minutes(period);
    } else if (targetType.equals(Hours.class)) {
        return Hours.hours(period);
    } else if (targetType.equals(Days.class)) {
        return Days.days(period);
    } else if (targetType.equals(Weeks.class)) {
        return Weeks.weeks(period);
    } else if (targetType.equals(Months.class)) {
        return Months.months(period);
    } else if (targetType.equals(Years.class)) {
        return Years.years(period);
    }

    throw new ConverterException(source, targetTypeToken.getRawType());
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:34,代码来源:JodaTimeSingleFieldPeriodConverter.java

示例13: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Object convert(Object source, TypeToken<?> targetTypeToken) {
    if (!canHandle(source, targetTypeToken)) {
        throw new ConverterException(source, targetTypeToken.getRawType());
    }

    Date date = stringToDateConverter.convert(String.valueOf(source));
    return dateToJodaTimeBaseLocalConverter.convert(date, targetTypeToken);
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:10,代码来源:StringToJodaTimeBaseLocalConverter.java

示例14: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object convert(Object source, TypeToken<?> targetTypeToken) {
    if (!canHandle(source, targetTypeToken)) throw new ConverterException(source, targetTypeToken.getRawType());
    if (targetTypeToken.isPrimitive()) {
        targetTypeToken = PrimitiveTypeUtils.toWrapperTypeToken(targetTypeToken);
    }
    return NumberUtils.convertNumberToTargetClass((Number) source, (Class) targetTypeToken.getType());
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:10,代码来源:NumberToNumberConverter.java

示例15: convert

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Object convert(Object source, TypeToken<?> targetTypeToken) {
    if (targetTypeToken.isPrimitive()) {
        targetTypeToken = PrimitiveTypeUtils.toWrapperTypeToken(targetTypeToken);
    }

    if (canHandle(source, targetTypeToken)) {
        return NumberUtils.parseNumber((String) source, (Class) targetTypeToken.getType());
    } else {
        throw new ConverterException("can not convert '" + source + "' to " + targetTypeToken.getRawType());
    }
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:13,代码来源:StringToNumberConverter.java


注:本文中的com.google.common.reflect.TypeToken.getRawType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。