类com.google.inject.matcher.Matcher源码实例Demo

下面列出了怎么用com.google.inject.matcher.Matcher的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: seed   文件: ValidationModule.java
private Matcher<? super Binding<?>> staticValidationMatcher() {
    return new AbstractMatcher<Binding<?>>() {
        @Override
        public boolean matches(Binding<?> binding) {
            Class<?> candidate = binding.getKey().getTypeLiteral().getRawType();
            for (Field field : candidate.getDeclaredFields()) {
                for (Annotation annotation : field.getAnnotations()) {
                    if (hasConstraintOrValidAnnotation(annotation)) {
                        return true;
                    }
                }
            }
            return false;
        }
    };
}
 
源代码2 项目: attic-aurora   文件: GuiceUtils.java
/**
 * Creates a matcher that will match methods of an interface, optionally excluding inherited
 * methods.
 *
 * @param matchInterface The interface to match.
 * @param declaredMethodsOnly if {@code true} only methods directly declared in the interface
 *                            will be matched, otherwise all methods on the interface are matched.
 * @return A new matcher instance.
 */
public static Matcher<Method> interfaceMatcher(
    Class<?> matchInterface,
    boolean declaredMethodsOnly) {

  Method[] methods =
      declaredMethodsOnly ? matchInterface.getDeclaredMethods() : matchInterface.getMethods();
  final Set<Pair<String, Class<?>[]>> interfaceMethods =
      ImmutableSet.copyOf(Iterables.transform(ImmutableList.copyOf(methods), CANONICALIZE));
  final LoadingCache<Method, Pair<String, Class<?>[]>> cache = CacheBuilder.newBuilder()
      .build(CacheLoader.from(CANONICALIZE));

  return new AbstractMatcher<Method>() {
    @Override
    public boolean matches(Method method) {
      return interfaceMethods.contains(cache.getUnchecked(method));
    }
  };
}
 
源代码3 项目: attic-aurora   文件: GuiceUtils.java
/**
 * Binds an exception trap on all interface methods of all classes bound against an interface.
 * Individual methods may opt out of trapping by annotating with {@link AllowUnchecked}.
 * Only void methods are allowed, any non-void interface methods must explicitly opt out.
 *
 * @param binder The binder to register an interceptor with.
 * @param wrapInterface Interface whose methods should be wrapped.
 * @throws IllegalArgumentException If any of the non-whitelisted interface methods are non-void.
 */
public static void bindExceptionTrap(Binder binder, Class<?> wrapInterface)
    throws IllegalArgumentException {

  Set<Method> disallowed = ImmutableSet.copyOf(Iterables.filter(
      ImmutableList.copyOf(wrapInterface.getMethods()),
      Predicates.and(Predicates.not(IS_WHITELISTED), Predicates.not(VOID_METHOD))));
  Preconditions.checkArgument(disallowed.isEmpty(),
      "Non-void methods must be explicitly whitelisted with @AllowUnchecked: %s", disallowed);

  Matcher<Method> matcher =
      Matchers.not(WHITELIST_MATCHER).and(interfaceMatcher(wrapInterface, false));
  binder.bindInterceptor(Matchers.subclassesOf(wrapInterface), matcher,
      new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
          try {
            return invocation.proceed();
          } catch (RuntimeException e) {
            LOG.warn("Trapped uncaught exception: " + e, e);
            return null;
          }
        }
      });
}
 
源代码4 项目: act-platform   文件: AbstractAspect.java
/**
 * Create a Matcher which matches against a service method.
 *
 * @return Matcher matching a service method
 */
Matcher<Method> matchServiceMethod() {
  return new AbstractMatcher<Method>() {
    @Override
    public boolean matches(Method method) {
      return isServiceMethod(method);
    }
  };
}
 
源代码5 项目: ProjectAres   文件: FunctionalMatcher.java
@Override
default Matcher<T> and(com.google.inject.matcher.Matcher<? super T> other) {
    return new AbstractMatcher<T>() {
        @Override public boolean matches(T t) {
            return FunctionalMatcher.this.matches(t) && other.matches(t);
        }
    };
}
 
源代码6 项目: ProjectAres   文件: FunctionalMatcher.java
@Override
default Matcher<T> or(com.google.inject.matcher.Matcher<? super T> other) {
    return new AbstractMatcher<T>() {
        @Override public boolean matches(T t) {
            return FunctionalMatcher.this.matches(t) || other.matches(t);
        }
    };
}
 
源代码7 项目: nexus-public   文件: AbstractInterceptorModule.java
@Override
protected void bindInterceptor(final Matcher<? super Class<?>> classMatcher,
                               final Matcher<? super Method> methodMatcher,
                               final MethodInterceptor... interceptors)
{
  if (!bound) {
    // Explicitly bind module instance under a specific sub-type (not Module as Guice forbids that)
    bind(Key.get(AbstractInterceptorModule.class, Names.named(getClass().getName()))).toInstance(this);
    bound = true;
  }
  super.bindInterceptor(classMatcher, methodMatcher, interceptors);
}
 
源代码8 项目: nano-framework   文件: JdbcModule.java
@Override
protected void configure() {
    JdbcAdapter.newInstance(configs.values(), poolType, this.getClass());

    JdbcTransactionalMethodInterceptor interceptor = new JdbcTransactionalMethodInterceptor();
    requestInjection(interceptor);
    Matcher<AnnotatedElement> annotatedElement = annotatedWith(JdbcTransactional.class);
    bindInterceptor(any(), annotatedElement, interceptor);
    bindInterceptor(annotatedElement, not(annotatedElement), interceptor);

}
 
源代码9 项目: nano-framework   文件: MultiTransactionalModule.java
@Override
protected void configure() {
    final MultiTransactionalMethodInterceptor interceptor = new MultiTransactionalMethodInterceptor();
    requestInjection(interceptor);

    final Matcher<AnnotatedElement> annotatedElement = annotatedWith(MultiTransactional.class);
    bindInterceptor(any(), annotatedElement, interceptor);
    bindInterceptor(annotatedElement, not(annotatedElement), interceptor);
}
 
源代码10 项目: guice-persist-orient   文件: OrientModule.java
@Override
protected void bindInterceptor(final Matcher<? super Class<?>> classMatcher,
                               final Matcher<? super Method> methodMatcher,
                               final MethodInterceptor... interceptors) {
    // hack to correctly bind @Transactional annotation for java8:
    // aop tries to intercept synthetic methods which cause a lot of warnings
    // (and generally not correct)
    super.bindInterceptor(classMatcher, new AbstractMatcher<Method>() {
        @Override
        public boolean matches(final Method method) {
            return !method.isSynthetic() && !method.isBridge() && methodMatcher.matches(method);
        }
    }, interceptors);
}
 
protected AbstractObjectInitializer(final Provider<ODatabaseObject> dbProvider,
                                    final ObjectSchemeInitializer schemeInitializer,
                                    final Matcher<? super Class<?>> classMatcher,
                                    final String... packages) {
    this.schemeInitializer = schemeInitializer;
    this.dbProvider = dbProvider;
    this.classMatcher = classMatcher;
    this.packages = packages.length == 0 ? new String[]{""} : packages;
}
 
源代码12 项目: seed   文件: ValidationModule.java
private Matcher<Method> dynamicValidationMatcher() {
    return new AbstractMatcher<Method>() {
        @Override
        public boolean matches(Method method) {
            return shouldValidateParameters(method) || shouldValidateReturnType(method);
        }
    };
}
 
源代码13 项目: seed   文件: TransactionModule.java
private static Matcher<Method> buildMethodMatcher() {
    MethodMatcherBuilder methodMatcherBuilder = new MethodMatcherBuilder(TransactionalResolver.INSTANCE);
    if (TransactionPlugin.JTA_12_OPTIONAL.isPresent()) {
        methodMatcherBuilder.or(JtaTransactionalResolver.INSTANCE);
    }
    return methodMatcherBuilder.build();
}
 
源代码14 项目: seed   文件: CoreModule.java
private <T> Matcher<T> createMatcherFromPredicate(Predicate<T> predicate) {
    return new AbstractMatcher<T>() {
        @Override
        public boolean matches(T t) {
            return predicate.test(t);
        }
    };
}
 
源代码15 项目: guice-validator   文件: ValidationModule.java
@SuppressWarnings("unchecked")
protected Matcher<? super Class<?>> getClassMatcher(final Class<? extends Annotation> annotation) {
    final Matcher<AnnotatedElement> res = Matchers.annotatedWith(annotation);
    return classMatcher == Matchers.any()
            // combine custom filter with annotation
            ? res : res.and((Matcher<? super AnnotatedElement>) classMatcher);
}
 
源代码16 项目: guice-validator   文件: ValidationModule.java
@SuppressWarnings({"unchecked", "PMD.CompareObjectsWithEquals"})
protected Matcher<? super Method> getMethodMatcher(final Class<? extends Annotation> annotation) {
    final Matcher<AnnotatedElement> res = Matchers.annotatedWith(annotation);
    return methodMatcher == DECLARED_METHOD_MATCHER
            // combine custom filter with annotation
            ? res : res.and((Matcher<? super AnnotatedElement>) methodMatcher);
}
 
源代码17 项目: attic-aurora   文件: AopModule.java
public static void bindThriftDecorator(
    Binder binder,
    Matcher<? super Class<?>> classMatcher,
    MethodInterceptor interceptor) {

  binder.bindInterceptor(
      classMatcher,
      Matchers.returns(Matchers.subclassesOf(Response.class)),
      interceptor);
  binder.requestInjection(interceptor);
}
 
源代码18 项目: ProjectAres   文件: Matchers.java
public static Matcher<? extends TypeLiteral<?>> subtypesOf(TypeLiteral<?> type) {
    return (FunctionalMatcher<? extends TypeLiteral<?>>) t -> Types.isAssignable(type, t);
}
 
源代码19 项目: ProjectAres   文件: Matchers.java
public static Matcher<? extends Binding<?>> bindingsForKeys(Matcher<? super Key<?>> keys) {
    return (FunctionalMatcher<? extends Binding<?>>) binding -> keys.matches(binding.getKey());
}
 
源代码20 项目: ProjectAres   文件: Matchers.java
public static Matcher<? extends Binding<?>> bindingsForTypeLiterals(Matcher<? super TypeLiteral<?>> types) {
    return (FunctionalMatcher<? extends Binding<?>>) binding -> types.matches(binding.getKey().getTypeLiteral());
}
 
源代码21 项目: ProjectAres   文件: Matchers.java
public static Matcher<? extends Binding<?>> bindingsForClasses(Matcher<? super Class<?>> types) {
    return (FunctionalMatcher<? extends Binding<?>>) binding -> types.matches(binding.getKey().getTypeLiteral().getRawType());
}
 
源代码22 项目: ProjectAres   文件: Matchers.java
public static Matcher<? extends Binding<?>> bindingsForSubtypesOf(TypeLiteral<?> type) {
    return bindingsForTypeLiterals((Matcher<TypeLiteral<?>>) subtypesOf(type));
}
 
源代码23 项目: ProjectAres   文件: Matchers.java
public static Matcher<? extends Binding<?>> bindingsForSubtypesOf(Class<?> type) {
    return bindingsForSubtypesOf(TypeLiteral.get(type));
}
 
源代码24 项目: bobcat   文件: FrameModule.java
@Override
protected void bindInterceptor(Matcher<? super Class<?>> classMatcher,
    Matcher<? super Method> methodMatcher, MethodInterceptor... interceptors) {
  super.bindInterceptor(classMatcher, NoSyntheticMethodMatcher.INSTANCE.and(methodMatcher),
      interceptors);
}
 
源代码25 项目: che   文件: Matchers.java
/** Returns a matcher which matches methods with matching name. */
public static Matcher<Method> names(String methodName) {
  return new Names(methodName);
}
 
源代码26 项目: herald   文件: LogModule.java
public LogModule(final Matcher<Object> typeMatcher) {
    this.typeMatcher = typeMatcher;
}
 
源代码27 项目: james-project   文件: LifeCycleStageModule.java
@Override
public void matching(Matcher<? super TypeLiteral<?>> typeMatcher) {
    this.typeMatcher = checkNotNull(typeMatcher, "Argument 'typeMatcher' must be not null");
}
 
源代码28 项目: dropwizard-guicey   文件: GuiceAopConfig.java
/**
 * @return configured type matcher or null
 */
public Matcher<? super Class<?>> getTypeMatcher() {
    return typeMatcher;
}
 
源代码29 项目: dropwizard-guicey   文件: GuiceAopConfig.java
/**
 * @return configured method matcher or null
 */
public Matcher<? super Method> getMethodMatcher() {
    return methodMatcher;
}
 
源代码30 项目: business   文件: DomainModule.java
private Matcher<Method> factoryMethods() {
    return new MethodMatcherBuilder(ExecutablePredicates.<Method>executableBelongsToClassAssignableTo(Factory.class)
            .and(m -> !m.getName().equals(GET_PRODUCED_CLASS))
            .and(CreateResolver.INSTANCE)
    ).build();
}
 
 类所在包
 类方法
 同包方法