congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
toothpick
Code IndexAdd Tabnine to your IDE (free)

How to use toothpick

Best Java code snippets using toothpick (Showing top 20 results out of 315)

origin: stephanenicolas/toothpick

@Override
public <T> Provider<T> getProvider(Class<T> clazz, String name) {
 crashIfClosed();
 return new ThreadSafeProviderImpl<>(this, clazz, name, false);
}
origin: stephanenicolas/toothpick

/**
 * Install bindings for scope.
 */
private void installBindingForScope() {
 //it's always possible to get access to the scope that contains an injected object.
 installBoundProvider(Scope.class, null, new InternalProviderImpl<>(this), false);
}
origin: stephanenicolas/toothpick

 private SecondEntryPoint() {
  Scope scope = Toothpick.openScope("SecondEntryPoint");
  Toothpick.inject(this, scope);
 }
}
origin: stephanenicolas/toothpick

 @Override
 public void doRun() {
  Toothpick.openScope(scopeName).getInstance(clazz);
  setIsSuccessful(true);
 }
}
origin: stephanenicolas/toothpick

@Override
public <T> T getInstance(Class<T> clazz, String name) {
 crashIfClosed();
 ConfigurationHolder.configuration.checkCyclesStart(clazz, name);
 T t;
 try {
  t = lookupProvider(clazz, name).get(this);
 } finally {
  ConfigurationHolder.configuration.checkCyclesEnd(clazz, name);
 }
 return t;
}
origin: stephanenicolas/toothpick

public void setScopeName(Object scopeName) {
 if (scope != null) {
  throw new IllegalStateException("scope is already initialized, use a constructor without a scope name for the rule.");
 }
 scope = Toothpick.openScope(scopeName);
 scope.installTestModules(testModule);
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void lazyGet_shouldFail_whenScopeIsClosed_andThereAreNoDependencies() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 Lazy<Bar> lazy = scope.getLazy(Bar.class);
 //WHEN
 scope.close();
 lazy.get();
 //THEN
}
origin: stephanenicolas/toothpick

/**
 * Opens a scope without any parent.
 * If a scope by this {@code name} already exists, it is returned.
 * Otherwise a new scope is created.
 */
public static Scope openScope(Object name) {
 return openScope(name, true);
}
origin: stephanenicolas/toothpick

/**
 * Resets the state of the scope.
 * Useful for automation testing when we want to reset the scope used to install test modules.
 */
@Override
protected void reset() {
 super.reset();
 mapClassesToNamedBoundProviders.clear();
 mapClassesToUnNamedBoundProviders.clear();
 hasTestModules = false;
 installBindingForScope();
}
origin: stephanenicolas/toothpick

@Override
public void installModules(Module... modules) {
 installModules(false, modules);
}
origin: stephanenicolas/toothpick

/**
 * Injects all dependencies (transitively) in {@code obj}, dependencies will be obtained in the
 * scope {@code scope}.
 *
 * @param obj the object to be injected.
 * @param scope the scope in which  all dependencies are obtained.
 */
public static void inject(Object obj, Scope scope) {
 injector.inject(obj, scope);
}
origin: stephanenicolas/toothpick

/**
 * Resets the state of a single scope. Useful for automation testing when we want to reset the scope used to install
 * test modules.
 * @param scope the scope we want to reset.
 */
public static void reset(Scope scope) {
 ScopeNode scopeNode = (ScopeNode) scope;
 scopeNode.reset();
}
origin: stephanenicolas/toothpick

/**
 * Obtains the provider of the class {@code clazz} and name {@code bindingName}, if any. The returned provider
 * will belong to the pool of unbound providers. It can be {@code null} if there is no such provider.
 *
 * @param clazz the class for which to obtain the unbound provider.
 * @param bindingName the name, possibly {@code null}, for which to obtain the unbound provider.
 * @param <T> the type of {@code clazz}.
 * @return the unbound provider for class {@code clazz} and {@code bindingName}. Returns {@code null} is there
 * is no such unbound provider.
 */
private <T> InternalProviderImpl<? extends T> getUnBoundProvider(Class<T> clazz, String bindingName) {
 return getInternalProvider(clazz, bindingName, false);
}
origin: stephanenicolas/toothpick

@Override
public <T> Provider<T> getProvider(Class<T> clazz) {
 return getProvider(clazz, null);
}
origin: stephanenicolas/toothpick

 public T get(Scope scope) {
  return super.get(this.scope);
 }
}
origin: stephanenicolas/toothpick

public ScopeImpl(Object name) {
 super(name);
 installBindingForScope();
}
origin: stephanenicolas/toothpick

 public static int getScopeNamesSize() {
  return Toothpick.getScopeNamesSize();
 }
}
origin: stephanenicolas/toothpick

public SimpleEntryPoint() {
 Scope scope = Toothpick.openScope("SimpleEntryPoint");
 Toothpick.inject(this, scope);
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void lazyGet_shouldFail_whenScopeIsClosed() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 Lazy<Foo> lazy = scope.getLazy(Foo.class);
 //WHEN
 scope.close();
 lazy.get();
 //THEN
}
origin: stephanenicolas/toothpick

@Override
public <T> Lazy<T> getLazy(Class<T> clazz, String name) {
 crashIfClosed();
 return new ThreadSafeProviderImpl<>(this, clazz, name, true);
}
toothpick

Most used classes

  • Binding
  • Scope
    A scope is one of the most important concept in ToothPick. It is actually important in Dependency I
  • Toothpick
    Main class to access toothpick features. It allows to create / retrieve scopes and perform injection
  • FactoryRegistryLocator
    Locates the FactoryRegistry instances. The registries form a tree, or a forest (collection of disjoi
  • MemberInjectorRegistryLocator
    Locates the MemberInjectorRegistry instances. Works in the same way as FactoryRegistry, except that
  • MemberInjectorRegistry,
  • ToothPickRule,
  • InternalProviderImpl,
  • ScopeImpl,
  • ScopeNode,
  • FactoryProcessor,
  • MemberInjectorProcessor,
  • Configuration,
  • SmoothieActivityModule,
  • FieldValueProvider,
  • Factory,
  • Injector,
  • MemberInjector,
  • ScopeImpl$ClassNameComparator
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now