com.google.inject.spi.ConstructorBinding Java Examples

The following examples show how to use com.google.inject.spi.ConstructorBinding. 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: Bindings.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static <T> Optional<TypeLiteral<? extends T>> targetType(Injector injector, Binding<T> binding) {
    if(binding instanceof UntargettedBinding) {
        return Optional.of(binding.getKey().getTypeLiteral());
    } else if(binding instanceof ConstructorBinding) {
        return Optional.of((TypeLiteral<? extends T>) ((ConstructorBinding) binding).getConstructor().getDeclaringType());
    } else if(binding instanceof InstanceBinding) {
        return Optional.of(TypeLiteral.get((Class<T>) ((InstanceBinding) binding).getInstance().getClass()));
    } else if(binding instanceof LinkedKeyBinding) {
        return targetType(injector, injector.getBinding(((LinkedKeyBinding) binding).getLinkedKey()));
    } else if(binding instanceof ExposedBinding) {
        return targetType(((ExposedBinding) binding).getPrivateElements().getInjector(), binding.getKey());
    }
    return Optional.empty();
}
 
Example #2
Source File: GuiceAopMapRenderer.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
public String renderReport(final GuiceAopConfig config) {
    final StringBuilder res = new StringBuilder();

    // AOP declarations
    final List<Element> declared = Elements.getElements(Stage.TOOL, modules).stream()
            .filter(it -> it instanceof InterceptorBinding)
            .collect(Collectors.toList());

    if (!config.isHideDeclarationsBlock()) {
        final List<ModuleDeclaration> declarationModules = GuiceModelParser.parse(injector, declared);
        res.append(Reporter.NEWLINE).append(Reporter.NEWLINE);
        renderDeclared(declarationModules, res);
    }

    if (!declared.isEmpty()) {
        // AOP appliance map
        final List<Binding> guiceManagedObjects = injector.getAllBindings().values().stream()
                .filter(it -> it instanceof ConstructorBinding)
                .collect(Collectors.toList());
        final List<AopDeclaration> tree = filter(GuiceModelParser.parse(injector, guiceManagedObjects), config);
        if (!tree.isEmpty()) {
            res.append(Reporter.NEWLINE).append(Reporter.NEWLINE);
            renderMap(tree, res);
        }
    }
    return res.toString();
}
 
Example #3
Source File: GuiceAopMapRenderer.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private List<AopDeclaration> filter(final List<ModuleDeclaration> modules, final GuiceAopConfig config) {
    final List<AopDeclaration> res = new ArrayList<>();
    GuiceModelUtils.visitBindings(modules, it -> {
        final Class<?> type = it.getKey().getTypeLiteral().getRawType();
        // filter by class
        if (config.getTypeMatcher() != null && !config.getTypeMatcher().matches(type)) {
            return;
        }
        final AopDeclaration dec = new AopDeclaration(it.getKey());
        final Map<Method, List<MethodInterceptor>> interceptors =
                ((ConstructorBinding) it.getElement()).getMethodInterceptors();
        for (Map.Entry<Method, List<MethodInterceptor>> entry : interceptors.entrySet()) {
            final Method method = entry.getKey();
            // filter by method
            if (config.getMethodMatcher() != null && !config.getMethodMatcher().matches(method)) {
                continue;
            }
            final List<Class<? extends MethodInterceptor>> handlers = entry.getValue()
                    .stream().map(MethodInterceptor::getClass).collect(Collectors.toList());
            // filter by required interceptors
            if (config.getShowOnly().isEmpty() || !Collections.disjoint(config.getShowOnly(), handlers)) {
                dec.getInterceptors().put(method, handlers);
            }
        }
        if (!dec.getInterceptors().isEmpty()) {
            res.add(dec);
        }
    });
    // for predictable order in report
    res.sort(Comparator.comparing(it -> it.getKey().getTypeLiteral().getRawType().getSimpleName()));
    return res;
}
 
Example #4
Source File: BindingTargetTypeResolver.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Optional<TypeLiteral<?>> visit(ConstructorBinding<?> binding) {
    // Return the owning type of the constructor
    return of(binding.getConstructor().getDeclaringType());
}
 
Example #5
Source File: DependencyCollector.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Object visit(ConstructorBinding<? extends T> constructorBinding) {
    processInjectionPoint(constructorBinding.getConstructor());
    processInjectionPoints(constructorBinding.getInjectableMembers());
    return super.visit(constructorBinding);
}
 
Example #6
Source File: Scoper.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Void visit(ConstructorBinding<? extends T> binding) {
    final InjectionPoint point = binding.getConstructor();
    scope(binding, rebind(binding).toConstructor((Constructor) point.getMember(), point.getDeclaringType()));
    return null;
}
 
Example #7
Source File: AdapterInjector.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public TypeToken<?> visit(
		ConstructorBinding<? extends Object> binding) {
	return TypeToken.of(binding.getKey().getTypeLiteral().getType());
}
 
Example #8
Source File: AdapterInjector.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public MapBinderBinding<?> visit(
		ConstructorBinding<? extends Object> binding) {
	return null;
}