@Override public Indexer.IndexedBinding visit(LinkedKeyBinding<? extends Object> binding) { return new Indexer.IndexedBinding( binding, BindingType.LINKED_KEY, scope(binding), binding.getLinkedKey()); }
/** * Visitor for {@link LinkedKeyBinding}. This is the standard {@link Binding} you get from * binding an interface class to an implementation class. We draw a {@link BindingEdge} from the * interface node to the node of the implementing class. */ @Override public Collection<Edge> visit(LinkedKeyBinding<?> binding) { return ImmutableList.<Edge>of( new BindingEdge( NodeId.newTypeId(binding.getKey()), NodeId.newTypeId(binding.getLinkedKey()), BindingEdge.Type.NORMAL)); }
.onLinkedBinding(linkedKeyBinding -> linkedKeyBinding.getLinkedKey().getTypeLiteral().getRawType()) .onProviderKeyBinding(providerKeyBinding -> providerKeyBinding.getProviderKey().getTypeLiteral().getRawType()) .visit() bind(linkedKeyBinding.getKey()) .toProvider(() -> Components.newInstance(linkedKeyBinding.getLinkedKey().getTypeLiteral().getRawType())) .in(relatedScope); })
@Override public Boolean visit(LinkedKeyBinding<? extends T> binding) { prepareBinding(); Key<? extends T> linkedKey = binding.getLinkedKey(); if (key.equals(linkedKey)) { errors.recursiveBinding(); } FactoryProxy<T> factory = new FactoryProxy<>(injector, key, linkedKey, source); bindingData.addCreationListener(factory); InternalFactory<? extends T> scopedFactory = Scoping.scope(key, injector, factory, source, scoping); putBinding( new LinkedBindingImpl<T>(injector, key, source, scopedFactory, scoping, linkedKey)); return true; }
final Key linkedKey = binding.getLinkedKey(); final Key sourceKey = Key.get(typeLiteral); .consumeLinkedBinding(linkedKeyBinding -> { if (Objects.equals(typeLiteral.getRawType(), linkedKeyBinding.getLinkedKey().getTypeLiteral().getRawType())) { elementsToWrite.remove(linkedKeyBinding); bindNonAbstractType(linkedKeyBinding.getKey(), GuiceSpi.resolveScope(linkedKeyBinding));
@Override public Collection<Key<?>> visit(LinkedKeyBinding<?> binding) { return ImmutableSet.<Key<?>>of(binding.getLinkedKey()); }
@Override public Void visit(LinkedKeyBinding<? extends T> binding) { builder.to(binding.getLinkedKey()).in(Scopes.SINGLETON); return null; }
@Override public Class<?> visit( final LinkedKeyBinding<?> binding ) { // this assumes only one level of indirection: api-->impl return binding.getLinkedKey().getTypeLiteral().getRawType(); }
@Override public Void visit(LinkedKeyBinding<? extends T> linkedKeyBinding) { return addBindingKey(linkedKeyBinding, linkedKeyBinding.getLinkedKey()); }
@Override public Void visit(LinkedKeyBinding<? extends T> linkedKeyBinding) { return addBindingKey(linkedKeyBinding, linkedKeyBinding.getLinkedKey()); }
@Override public Indexer.IndexedBinding visit(LinkedKeyBinding<? extends Object> binding) { return new Indexer.IndexedBinding( binding, BindingType.LINKED_KEY, scope(binding), binding.getLinkedKey()); }
@Override public Indexer.IndexedBinding visit(LinkedKeyBinding<? extends Object> binding) { return new Indexer.IndexedBinding( binding, BindingType.LINKED_KEY, scope(binding), binding.getLinkedKey()); }
@Override public IndexedBinding visit(LinkedKeyBinding<? extends Object> binding) { return new IndexedBinding(binding, BindingType.LINKED_KEY, scope(binding), binding.getLinkedKey()); }
public static void printInjector(com.google.inject.Injector injector, Logger log) { Level level = Level.INFO ; log.log(level,"=== printInjector start ===") ; for (Map.Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) { if ( entry.getKey().toString().contains("type=org.matsim") ) { Annotation annotation = entry.getKey().getAnnotation(); log.log( level, entry.getKey().getTypeLiteral() + " " + (annotation != null ? annotation.toString() : "")); log.log(level, " --> provider: " + entry.getValue().getProvider()); log.log(level, " --> source: " + entry.getValue().getSource() ); if ( entry.getValue() instanceof BindingImpl ) { log.log( level, " --> scope: " + ((BindingImpl<?>)entry.getValue()).getScoping() ) ; } if ( entry.getValue() instanceof LinkedKeyBinding) { log.log( level, " --> target: " + ((LinkedKeyBinding) entry.getValue()).getLinkedKey() ) ; } log.log(level, " ==full==> " + entry.getValue() ); // yy could probably format the above in a better way. kai, may'16 log.log(level, "" ); } } log.log(level,"=== printInjector end ===") ; }
public Void visit(LinkedKeyBinding<? extends T> linkedKeyBinding) { Context context = Context.forElement(linkedKeyBinding); bindingsCollection.addBinding(targetKey, bindingFactory.getBindClassBinding(linkedKeyBinding.getLinkedKey(), targetKey, context)); return null; }
@Override public Boolean visit( final LinkedKeyBinding<?> binding ) { final Key<?> linkedKey = binding.getLinkedKey(); if ( linkedKey.getAnnotationType() == null ) { return analyzeImplementation( linkedKey.getTypeLiteral(), true ); } return Boolean.TRUE; // indirect binding, don't scan }
@Override public Boolean visit( final LinkedKeyBinding<?> binding ) { final Key<?> linkedKey = binding.getLinkedKey(); if ( linkedKey.getAnnotationType() == null ) { return verifyImplementation( linkedKey.getTypeLiteral() ); } return Boolean.TRUE; // indirect binding, don't scan }
@Override @SuppressWarnings("unchecked") protected void configure() { final List<Element> elements = Elements.getElements(sourceModule); final List<Element> elementsToWrite = new ArrayList<>(elements); GuiceSpi.getBindings(elements).forEach(binding -> { final Scoping scoping = GuiceSpi.resolveScope(binding); if (scoping == null) { return; } final Class<? extends Annotation> scopeAnnotation = scoping.getScopeAnnotation(); if (isSingletonScopeAnnotation(scopeAnnotation)) { boolean isEagerSingleton = isEagerSingletonAnnotation(scopeAnnotation); final UiContextAnnotation uiContextAnnotation = UiAnnotations.cast(binding.getKey().getAnnotation()); final Class<? extends Annotation> relatedScopeAnnotation = uiContextAnnotation.getRelatedScopeAnnotation(isEagerSingleton); if (!Objects.equals(relatedScopeAnnotation, scopeAnnotation)) { elementsToWrite.remove(binding); final Key key = binding.getKey(); GuiceSpi.<ScopedBindingBuilder>inspect(binding) .onLinkedBinding(linkedKeyBinding -> bind(key).to(linkedKeyBinding.getLinkedKey())) .onProviderKeyBinding(providerBinding -> bind(key).toProvider(providerBinding.getProviderKey())) .visit() .ifPresent(scopedBindingBuilder -> scopedBindingBuilder.in(relatedScopeAnnotation)); } } }); elementsToWrite.forEach(element -> element.applyTo(binder())); }
public Boolean visit(LinkedKeyBinding<? extends T> binding) { prepareBinding(); Key<? extends T> linkedKey = binding.getLinkedKey(); if (key.equals(linkedKey)) { errors.recursiveBinding(); } FactoryProxy<T> factory = new FactoryProxy<T>(injector, key, linkedKey, source); bindingData.addCreationListener(factory); InternalFactory<? extends T> scopedFactory = Scoping.scope(key, injector, factory, source, scoping); putBinding( new LinkedBindingImpl<T>(injector, key, source, scopedFactory, scoping, linkedKey)); return true; }
public Boolean visit(LinkedKeyBinding<? extends T> binding) { prepareBinding(); Key<? extends T> linkedKey = binding.getLinkedKey(); if (key.equals(linkedKey)) { errors.recursiveBinding(); } FactoryProxy<T> factory = new FactoryProxy<T>(injector, key, linkedKey, source); bindingData.addCreationListener(factory); InternalFactory<? extends T> scopedFactory = Scoping.scope(key, injector, factory, source, scoping); putBinding( new LinkedBindingImpl<T>(injector, key, source, scopedFactory, scoping, linkedKey)); return true; }