com.google.inject.TypeLiteral#getRawType ( )源码实例Demo

下面列出了com.google.inject.TypeLiteral#getRawType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: seed   文件: LoggingTypeListener.java
@Override
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) {
    Set<Field> fields = new HashSet<>();
    for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c = c.getSuperclass()) {
        for (Field field : c.getDeclaredFields()) {
            if (field.isAnnotationPresent(Logging.class)) {
                if (field.getType() == Logger.class) {
                    fields.add(field);
                } else {
                    throw SeedException.createNew(CoreErrorCode.BAD_LOGGER_TYPE)
                            .put("field", format("%s.%s", field.getDeclaringClass().getName(), field.getName()))
                            .put("expectedType", Logger.class.getName())
                            .put("givenType", field.getType().getName());
                }
            }
        }
    }

    if (!fields.isEmpty()) {
        typeEncounter.register(new LoggingMembersInjector<>(fields));
    }
}
 
源代码2 项目: seed   文件: ConfigurationTypeListener.java
@Override
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) {
    Set<ConfigurationMembersInjector.ConfigurableField> fields = new HashSet<>();
    for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c = c.getSuperclass()) {
        for (Field field : c.getDeclaredFields()) {
            Configuration annotation = field.getAnnotation(Configuration.class);
            if (annotation != null) {
                fields.add(new ConfigurationMembersInjector.ConfigurableField(field, annotation));
            }
        }
    }

    if (!fields.isEmpty()) {
        typeEncounter.register(new ConfigurationMembersInjector<>(configuration, fields));
    }
}
 
源代码3 项目: seed   文件: CliTypeListener.java
@Override
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) {
    Set<Field> fields = new HashSet<>();
    CliCommand cliCommand = null;
    for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c = c.getSuperclass()) {
        if (cliCommand == null) {
            cliCommand = c.getAnnotation(CliCommand.class);
        } else if (c.isAnnotationPresent(CliCommand.class)) {
            throw SeedException.createNew(CliErrorCode.CONFLICTING_COMMAND_ANNOTATIONS)
                    .put("class", c.getCanonicalName());
        }
        Arrays.stream(c.getDeclaredFields()).filter(this::isCandidate).forEach(fields::add);
    }

    if (!fields.isEmpty()) {
        typeEncounter.register(new CliMembersInjector<>(
                cliContext,
                cliCommand == null ? typeLiteral.getType().getTypeName() : cliCommand.value(),
                fields)
        );
    }
}
 
源代码4 项目: yql-plus   文件: ReflectiveJavaTypeWidget.java
public ReflectiveJavaTypeWidget(ProgramValueTypeAdapter adapter, TypeLiteral<?> typeLiteral) {
    super(Type.getType(typeLiteral.getRawType()));
    this.clazz = typeLiteral.getRawType();
    Preconditions.checkArgument(!clazz.isPrimitive(), "ReflectiveTypeWidget used on primitive: %s", clazz.getName());
    Preconditions.checkArgument(!clazz.isArray(), "ReflectiveTypeWidget used on array: %s", clazz.getName());
    Preconditions.checkArgument(TypeUtilities.getPrimitiveType(clazz) == null, "ReflectiveTypeWidget used on boxed primitive: %s", clazz.getName());
    this.adapter = adapter;
    this.type = Type.getType(typeLiteral.getRawType());
    this.typeLiteral = typeLiteral;
    this.dispatcher = new MethodDispatcher(typeLiteral);
}
 
源代码5 项目: emodb   文件: ParameterizedTimedListener.java
@Override
public <I> void hear(TypeLiteral<I> literal, TypeEncounter<I> encounter) {
    Class<? super I> type = literal.getRawType();
    for (Method method : type.getMethods()) {
        ParameterizedTimed annotation = method.getAnnotation(ParameterizedTimed.class);
        if (annotation == null) {
            continue;
        }

        String metricType = annotation.type();
        if(metricType == null || metricType.isEmpty()) {
            metricType = type.getSimpleName().replaceAll("\\$$", "");
        }
        String metricName = annotation.name();
        if(metricName == null || metricName.isEmpty()) {
            metricName = method.getName();
        }
        String metric = MetricRegistry.name(_group, metricType, metricName);
        final Timer timer = _metricRegistry.timer(metric);

        encounter.bindInterceptor(Matchers.only(method), new MethodInterceptor() {
            @Override
            public Object invoke(MethodInvocation invocation) throws Throwable {
                Timer.Context time = timer.time();
                try {
                    return invocation.proceed();
                } finally {
                    time.stop();
                }
            }
        });
    }
}
 
源代码6 项目: biomedicus   文件: SettingsBinder.java
private <T> void bindSetting(Key<T> key, Object value) {
  if (value instanceof Key) {
    @SuppressWarnings("unchecked")
    Key<T> valueKey = (Key<T>) value;
    binder.bind(key).to(valueKey);
  } else {
    TypeLiteral<T> typeLiteral = key.getTypeLiteral();
    Class<? super T> rawType = typeLiteral.getRawType();
    @SuppressWarnings("unchecked")
    T cast = (T) rawType.cast(value);
    binder.bind(key).toInstance(cast);
  }
}
 
源代码7 项目: attic-apex-core   文件: InjectConfigTest.java
@Override
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter)
{
  for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c = c.getSuperclass()) {
    LOG.debug("Inspecting fields for " + c);
    for (Field field : c.getDeclaredFields()) {
      if (field.isAnnotationPresent(InjectConfig.class)) {
        typeEncounter.register(new ConfigurationInjector<T>(field, field.getAnnotation(InjectConfig.class)));
      }
    }
  }
}
 
源代码8 项目: che   文件: SeleniumClassModule.java
@Override
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
  Class<?> clazz = type.getRawType();
  for (Field field : clazz.getDeclaredFields()) {
    if (field.getType() == TestOrganization.class
        && field.isAnnotationPresent(InjectTestOrganization.class)) {
      encounter.register(
          new TestOrganizationInjector<>(
              field, field.getAnnotation(InjectTestOrganization.class), injectorProvider));
    }
  }
}
 
源代码9 项目: termsuite-core   文件: IndexedCorpusModule.java
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) {
     Class<?> clazz = typeLiteral.getRawType();
     while (clazz != null) {
       for (Field field : clazz.getDeclaredFields()) {
         boolean injectAnnoPresent = 
         		field.isAnnotationPresent(fr.univnantes.termsuite.framework.InjectLogger.class);
if (field.getType() == Logger.class &&
           injectAnnoPresent) {
           typeEncounter.register(new Slf4JMembersInjector<T>(field));
         }
       }
       clazz = clazz.getSuperclass();
     }
   }
 
源代码10 项目: seed   文件: ResourceTypeListener.java
@Override
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) {
    for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c = c.getSuperclass()) {
        for (Field field : typeLiteral.getRawType().getDeclaredFields()) {
            Resource resourceAnnotation = field.getAnnotation(Resource.class);
            if (resourceAnnotation != null) {
                String resourceName = resourceAnnotation.name();
                Context contextToLookup = defaultContext;
                String contextName = "default";

                // Check if this injection is from an additional context
                JndiContext jndiContextAnnotation = field.getAnnotation(JndiContext.class);
                if (jndiContextAnnotation != null) {
                    contextName = jndiContextAnnotation.value();
                    contextToLookup = jndiContexts.get(contextName);
                    if (contextToLookup == null) {
                        throw SeedException.createNew(JndiErrorCode.UNKNOWN_JNDI_CONTEXT)
                                .put("field", field)
                                .put("context", contextName);
                    }
                }

                // Register the members injector
                if (!resourceName.isEmpty()) {
                    typeEncounter.register(new ResourceMembersInjector<>(field,
                            contextToLookup,
                            contextName,
                            resourceName));
                }
            }
        }
    }
}
 
源代码11 项目: ProjectAres   文件: MockProvider.java
public static <T> MockProvider<T> of(TypeLiteral<T> type) {
    return new MockProvider<>((Class<T>) type.getRawType());
}
 
源代码12 项目: ProjectAres   文件: LenientEnumSetTypeAdapter.java
@Inject public LenientEnumSetTypeAdapter(TypeLiteral<T> type) {
    this.type = (Class<T>) type.getRawType();
}
 
源代码13 项目: spoofax   文件: MetaBorgGeneric.java
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);
}
 
 同类方法