Java Code Examples for com.google.inject.util.Types#newParameterizedType()

The following examples show how to use com.google.inject.util.Types#newParameterizedType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonConfigProvider.java    From druid-api with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> void bindInstance(
    Binder binder,
    Key<T> bindKey,
    T instance
)
{
  binder.bind(bindKey).toInstance(instance);

  final ParameterizedType supType = Types.newParameterizedType(Supplier.class, bindKey.getTypeLiteral().getType());
  final Key supplierKey;

  if (bindKey.getAnnotationType() != null) {
    supplierKey = Key.get(supType, bindKey.getAnnotationType());
  }
  else if (bindKey.getAnnotation() != null) {
    supplierKey = Key.get(supType, bindKey.getAnnotation());
  }
  else {
    supplierKey = Key.get(supType);
  }

  binder.bind(supplierKey).toInstance(Suppliers.<T>ofInstance(instance));
}
 
Example 2
Source File: AlgorithmsParametersMarshallingProviderImpl.java    From xades4j with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<Node> marshalParameters(Algorithm alg, Document doc) throws UnsupportedAlgorithmException
{
    AlgorithmParametersMarshaller marshaller;
    try
    {
        ParameterizedType pt = Types.newParameterizedType(AlgorithmParametersMarshaller.class, alg.getClass());
        marshaller = (AlgorithmParametersMarshaller) injector.getInstance(Key.get(TypeLiteral.get(pt)));
    } catch (RuntimeException ex)
    {
        throw new UnsupportedAlgorithmException("AlgorithmParametersMarshaller not available", alg.getUri(), ex);
    }

    List<Node> params = marshaller.marshalParameters(alg, doc);
    if (params != null && params.isEmpty())
    {
        throw new IllegalArgumentException(String.format("Parameter marshaller returned empty parameter list for algorithm %s", alg.getUri()));
    }
    return params;
}
 
Example 3
Source File: DefaultVerificationBindingsModule.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
private <TData extends PropertyDataObject> void bindBuiltInVerifier(
        Class<TData> dataObjectClass,
        Class<? extends QualifyingPropertyVerifier<TData>> verifierClass)
{
    ParameterizedType pt = Types.newParameterizedType(QualifyingPropertyVerifier.class, dataObjectClass);
    TypeLiteral<QualifyingPropertyVerifier<TData>> tl = (TypeLiteral<QualifyingPropertyVerifier<TData>>)TypeLiteral.get(pt);
    
    bind(tl).to(verifierClass);
    bind(tl).annotatedWith(BuiltIn.class).to(verifierClass);
}
 
Example 4
Source File: FormProcessorCreator.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void initRepeatedConverter(Type genericParamType) {
  if (genericParamType instanceof JavaType) {
    genericParamType = Types.newParameterizedType(((JavaType) genericParamType).getRawClass(),
        ((JavaType) genericParamType).getContentType());
  }
  converter = partsToTargetConverters.get(genericParamType);
}
 
Example 5
Source File: JobStatusUtil.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public TypeReference<JobStatus<?, ?>> load(final JobType<?, ?> jobType)
        throws Exception {
    return new TypeReference<JobStatus<?, ?>>() {
        private Type _type = Types.newParameterizedType(
                JobStatus.class, jobType.getRequestType(), jobType.getResultType());

        @Override
        public Type getType() {
            return _type;
        }
    };
}
 
Example 6
Source File: Spoofax.java    From spoofax with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiate the MetaBorg API with a Spoofax implementation.
 * 
 * @param loader
 *            Module plugin loader to use.
 * @param module
 *            Spoofax module to use.
 * @param additionalModules
 *            Additional modules to use.
 * 
 * @throws MetaborgException
 *             When loading plugins or dependency injection fails.
 */
public Spoofax(IModulePluginLoader loader, SpoofaxModule module, Module... additionalModules)
    throws MetaborgException {
    super(ISpoofaxInputUnit.class, ISpoofaxParseUnit.class, ISpoofaxAnalyzeUnit.class,
        ISpoofaxAnalyzeUnitUpdate.class,
        Types.newParameterizedType(ISpoofaxTransformUnit.class, Types.subtypeOf(Object.class)),
        Types.newParameterizedType(ISpoofaxTransformUnit.class, ISpoofaxParseUnit.class),
        Types.newParameterizedType(ISpoofaxTransformUnit.class, ISpoofaxAnalyzeUnit.class), IStrategoTerm.class,
        loader, module, additionalModules);
    
    this.unitService = injector.getInstance(ISpoofaxUnitService.class);
    
    this.syntaxService = injector.getInstance(ISpoofaxSyntaxService.class);
    this.analysisService = injector.getInstance(ISpoofaxAnalysisService.class);
    this.transformService = injector.getInstance(ISpoofaxTransformService.class);
    
    this.builder = injector.getInstance(ISpoofaxBuilder.class);
    this.processorRunner = injector.getInstance(ISpoofaxProcessorRunner.class);

    this.parseResultProcessor = injector.getInstance(ISpoofaxParseResultProcessor.class);
    this.analysisResultProcessor = injector.getInstance(ISpoofaxAnalysisResultProcessor.class);
    
    this.tracingService = injector.getInstance(ISpoofaxTracingService.class);
    
    this.categorizerService = injector.getInstance(ISpoofaxCategorizerService.class);
    this.stylerService = injector.getInstance(ISpoofaxStylerService.class);
    this.hoverService = injector.getInstance(ISpoofaxHoverService.class);
    this.resolverService = injector.getInstance(ISpoofaxResolverService.class);
    this.outlineService = injector.getInstance(ISpoofaxOutlineService.class);
    this.completionService = injector.getInstance(ISpoofaxCompletionService.class);
    
    this.termFactory = injector.getInstance(ITermFactory.class);
    this.strategoRuntimeService = injector.getInstance(IStrategoRuntimeService.class);
    this.strategoCommon = injector.getInstance(IStrategoCommon.class);
}
 
Example 7
Source File: PropertyDataGeneratorsMapperImpl.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public <TProp extends QualifyingProperty> PropertyDataObjectGenerator<TProp> getGenerator(
        TProp p) throws PropertyDataGeneratorNotAvailableException
{
    try
    {
        ParameterizedType pt = Types.newParameterizedType(PropertyDataObjectGenerator.class, p.getClass());
        return (PropertyDataObjectGenerator)injector.getInstance(Key.get(TypeLiteral.get(pt)));
    } catch (RuntimeException ex)
    {
        throw new PropertyDataGeneratorNotAvailableException(p, ex);
    }
}
 
Example 8
Source File: PartListProcessor.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public Type getProcessType() {
  return Types.newParameterizedType(List.class, Part.class);
}
 
Example 9
Source File: DomainRegistryImpl.java    From business with Mozilla Public License 2.0 4 votes vote down vote up
private Type getType(Type rawType, Type... typeArguments) {
    if (typeArguments.length == 0) {
        return rawType;
    }
    return Types.newParameterizedType(rawType, typeArguments);
}
 
Example 10
Source File: AssemblerRegistryImpl.java    From business with Mozilla Public License 2.0 4 votes vote down vote up
private Type classesToTupleType(Class<? extends AggregateRoot<?>>[] aggregateRootClasses) {
    return Types.newParameterizedType(Tuples.classOfTuple(aggregateRootClasses.length), aggregateRootClasses);
}
 
Example 11
Source File: ResourceTest.java    From alchemy with MIT License 4 votes vote down vote up
protected static <K, V> GenericType<Map<K, V>> map(Class<K> keyType, Class<V> valueType) {
    return new GenericType<>(Types.newParameterizedType(Map.class, keyType, valueType));
}
 
Example 12
Source File: ResourceTest.java    From alchemy with MIT License 4 votes vote down vote up
protected static <T> GenericType<Set<T>> set(Class<T> elementType) {
    return new GenericType<>(Types.newParameterizedType(Set.class, elementType));
}
 
Example 13
Source File: ResourceTest.java    From alchemy with MIT License 4 votes vote down vote up
protected static <T> GenericType<Iterable<T>> iterable(Class<T> elementType) {
    return new GenericType<>(Types.newParameterizedType(List.class, elementType));
}
 
Example 14
Source File: MetaBorgGeneric.java    From spoofax with Apache License 2.0 4 votes vote down vote up
private <K> K instance(TypeLiteral<K> typeLiteral, Type... typeArgs) {
    final Class<? super K> rawType = typeLiteral.getRawType();
    final ParameterizedType type = Types.newParameterizedType(rawType, typeArgs);
    @SuppressWarnings("unchecked") final Key<K> key = (Key<K>) Key.get(type);
    return injector.getInstance(key);
}
 
Example 15
Source File: PartListToMultipartListConverter.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public Type getTargetType() {
  return Types.newParameterizedType(List.class, MultipartFile.class);
}
 
Example 16
Source File: PartListToMultipartListConverter.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public Type getSrcType() {
  return Types.newParameterizedType(List.class, Part.class);
}
 
Example 17
Source File: PartListToPartArrayConverter.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public Type getSrcType() {
  return Types.newParameterizedType(List.class, Part.class);
}
 
Example 18
Source File: PartListToPartListConverter.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public Type getTargetType() {
  return Types.newParameterizedType(List.class, Part.class);
}
 
Example 19
Source File: PartListToPartListConverter.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public Type getSrcType() {
  return Types.newParameterizedType(List.class, Part.class);
}
 
Example 20
Source File: Tuples.java    From business with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Returns the {@link ParameterizedType} of the Tuple class corresponding to the specified
 * classes. <p> For instance, for a list with Customer.class and Order.class the method will
 * return Pair&lt;Customer, Order&gt;. </p>
 *
 * @param classes the tuple classes.
 * @return the tuple type.
 */
public static ParameterizedType typeOfTuple(final Class<?>... classes) {
    return Types.newParameterizedType(classOfTuple(classes.length), (Type[]) classes);
}