com.google.inject.matcher.AbstractMatcher Java Examples

The following examples show how to use com.google.inject.matcher.AbstractMatcher. 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: BackupServiceModule.java    From EDDI with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    registerConfigFiles(this.configFiles);
    bind(IRestExportService.class).to(RestExportService.class).in(Scopes.SINGLETON);
    bind(IRestImportService.class).to(RestImportService.class).in(Scopes.SINGLETON);
    bind(IRestGitBackupService.class).to(RestGitBackupService.class).in(Scopes.SINGLETON);

    // AutoGit Injection - all methods that are annotated with @ConfigurationUpdate and start with
    // update or delete trigger a new commit/push
    bindInterceptor(Matchers.any(), new AbstractMatcher<>() {
        @Override
        public boolean matches(Method method) {
            return method.isAnnotationPresent(IResourceStore.ConfigurationUpdate.class) && !method.isSynthetic();
        }

    }, new GitConfigurationUpdateService(getProvider(IRestGitBackupService.class),
                                         getProvider(IBotStore.class),
                                         getProvider(IDeploymentStore.class),
                                         getProvider(IPackageStore.class),
                                         getProvider(IJsonSerialization.class)));
    bind(IZipArchive.class).to(ZipArchive.class).in(Scopes.SINGLETON);
}
 
Example #2
Source File: ConstantModule.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
protected void configure() {
    convertToTypes(new AbstractMatcher<TypeLiteral<?>>() {
        @Override
        public boolean matches(TypeLiteral<?> typeLiteral) {
            return typeLiteral.getType().equals(Sample.class);
        }
    }, new TypeConverter() {
        @Override
        public Object convert(String value, TypeLiteral<?> toType) {
            return new Sample();
        }
    });
    bindConstant().annotatedWith(Names.named("smth")).to(12);
    bindConstant().annotatedWith(Names.named("string")).to("12");
}
 
Example #3
Source File: CasesModule.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
protected void configure() {
    bindListener(new AbstractMatcher<TypeLiteral<?>>() {
        @Override
        public boolean matches(TypeLiteral<?> typeLiteral) {
            return false;
        }
    }, new CustomTypeListener());

    bindListener(new AbstractMatcher<Object>() {
        @Override
        public boolean matches(Object o) {
            return false;
        }
    }, new CustomProvisionListener());

    bindInterceptor(Matchers.subclassesOf(AopedService.class), Matchers.any(),
            new CustomAop());

    bind(AopedService.class);
    bind(BindService.class).to(OverriddenService.class);
    bind(BindService2.class).toInstance(new BindService2() {});
}
 
Example #4
Source File: RepositoryModule.java    From guice-persist-orient with MIT License 6 votes vote down vote up
/**
 * Configures repository annotations interceptor.
 */
protected void configureAop() {
    final RepositoryMethodInterceptor proxy = new RepositoryMethodInterceptor();
    requestInjection(proxy);
    // repository specific method annotations (query, function, delegate, etc.)
    bindInterceptor(Matchers.any(), new AbstractMatcher<Method>() {
        @Override
        public boolean matches(final Method method) {
            // this will throw error if two or more annotations specified (fail fast)
            try {
                return ExtUtils.findMethodAnnotation(method) != null;
            } catch (Exception ex) {
                throw new MethodDefinitionException(String.format("Error declaration on method %s",
                        RepositoryUtils.methodToString(method)), ex);
            }
        }
    }, proxy);
}
 
Example #5
Source File: GuiceUtils.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
    }
  };
}
 
Example #6
Source File: AbstractAspect.java    From act-platform with ISC License 5 votes vote down vote up
/**
 * 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);
    }
  };
}
 
Example #7
Source File: FunctionalMatcher.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
        }
    };
}
 
Example #8
Source File: FunctionalMatcher.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
        }
    };
}
 
Example #9
Source File: Fabric8WsMasterModule.java    From rh-che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  bind(GitHubOAuthAuthenticator.class)
      .to(OpenShiftGitHubOAuthAuthenticator.class)
      .asEagerSingleton();
  bind(OAuthAPIProvider.class).to(Fabric8OAuthAPIProvider.class);
  bind(KeycloakServiceClient.class).to(Fabric8AuthServiceClient.class).asEagerSingleton();
  final DisableAuthenticationInterceptor disableAuthenticationInterceptor =
      new DisableAuthenticationInterceptor();
  requestInjection(disableAuthenticationInterceptor);
  bindInterceptor(
      Matchers.subclassesOf(MultiUserEnvironmentInitializationFilter.class),
      new AbstractMatcher<Method>() {
        @Override
        public boolean matches(Method m) {
          return "doFilter".equals(m.getName());
        }
      },
      disableAuthenticationInterceptor);

  final Multibinder<MachineAuthenticatedResource> machineAuthenticatedResources =
      Multibinder.newSetBinder(binder(), MachineAuthenticatedResource.class);
  machineAuthenticatedResources
      .addBinding()
      .toInstance(
          new MachineAuthenticatedResource(
              "/fabric8-che-analytics", "segmentWriteKey", "woopraDomain", "warning", "error"));

  machineAuthenticatedResources
      .addBinding()
      .toInstance(new MachineAuthenticatedResource("/bayesian", "getBayesianToken"));
}
 
Example #10
Source File: AdapterInjectionSupport.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Binds an {@link AdaptableTypeListener} (via
 * {@link #bindListener(Matcher, TypeListener)}) and ensures it gets
 * properly injected ({@link #requestInjection(Object)}).
 */
@Override
protected void configure() {
	AdaptableTypeListener adaptableTypeListener = new AdaptableTypeListener(
			loggingMode);
	requestInjection(adaptableTypeListener);
	bindListener(new AbstractMatcher<TypeLiteral<?>>() {
		@Override
		public boolean matches(TypeLiteral<?> t) {
			return IAdaptable.class.isAssignableFrom(t.getRawType());
		}
	}, adaptableTypeListener);
}
 
Example #11
Source File: OrientModule.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@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);
}
 
Example #12
Source File: ValidationModule.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
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;
        }
    };
}
 
Example #13
Source File: ValidationModule.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private Matcher<Method> dynamicValidationMatcher() {
    return new AbstractMatcher<Method>() {
        @Override
        public boolean matches(Method method) {
            return shouldValidateParameters(method) || shouldValidateReturnType(method);
        }
    };
}
 
Example #14
Source File: CoreModule.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private <T> Matcher<T> createMatcherFromPredicate(Predicate<T> predicate) {
    return new AbstractMatcher<T>() {
        @Override
        public boolean matches(T t) {
            return predicate.test(t);
        }
    };
}