當前位置: 首頁>>代碼示例>>Java>>正文


Java Scope類代碼示例

本文整理匯總了Java中com.google.inject.Scope的典型用法代碼示例。如果您正苦於以下問題:Java Scope類的具體用法?Java Scope怎麽用?Java Scope使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Scope類屬於com.google.inject包,在下文中一共展示了Scope類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyScoping

import com.google.inject.Scope; //導入依賴的package包/類
protected void applyScoping(Binding<?> binding, final ScopedBindingBuilder scopedBindingBuilder) {
  binding.acceptScopingVisitor(new BindingScopingVisitor<Void>() {
    public Void visitEagerSingleton() {
      if (scopedBindingBuilder != null) {
        scopedBindingBuilder.asEagerSingleton();
      }
      return null;
    }

    public Void visitScope(Scope scope) {
      scopedBindingBuilder.in(scope);
      return null;
    }

    public Void visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
      scopedBindingBuilder.in(scopeAnnotation);
      return null;
    }

    public Void visitNoScoping() {
      // do nothing
      return null;
    }
  });
}
 
開發者ID:zorzella,項目名稱:guiceberry,代碼行數:26,代碼來源:ModuleWriter.java

示例2: scoped

import com.google.inject.Scope; //導入依賴的package包/類
private static String scoped(final Binding<?> binding, final String statement) {
  return binding.acceptScopingVisitor(new BindingScopingVisitor<String>() {
    @Override
    public String visitEagerSingleton() {
      if (binding instanceof InstanceBinding<?>) {
        return statement;
      }
      throw new DeguicifierException();
    }

    @Override
    public String visitScope(Scope scope) {
      return scopeFieldName(scope) + ".scope(null, " + guicify(statement) + ")";
    }

    @Override
    public String visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
      throw new DeguicifierException();
    }

    @Override
    public String visitNoScoping() {
      return statement;
    }
  });
}
 
開發者ID:mikosik,項目名稱:deguicifier,代碼行數:27,代碼來源:Generators.java

示例3: visit

import com.google.inject.Scope; //導入依賴的package包/類
@Override public Boolean visit(ScopeBinding command) {
  Scope scope = command.getScope();
  Class<? extends Annotation> annotationType = command.getAnnotationType();

  if (!Annotations.isScopeAnnotation(annotationType)) {
    errors.missingScopeAnnotation(annotationType);
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  if (!Annotations.isRetainedAtRuntime(annotationType)) {
    errors.missingRuntimeRetention(annotationType);
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  ScopeBinding existing = injector.state.getScopeBinding(checkNotNull(annotationType, "annotation type"));
  if (existing != null) {
    errors.duplicateScopes(existing, annotationType, scope);
  } else {
    checkNotNull(scope, "scope");
    injector.state.putScopeBinding(annotationType, command);
  }

  return true;
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:25,代碼來源:ScopeBindingProcessor.java

示例4: forInstance

import com.google.inject.Scope; //導入依賴的package包/類
public static Scoping forInstance(final Scope scope) {
  if (scope == Scopes.SINGLETON) {
    return SINGLETON_INSTANCE;
  }

  return new Scoping() {
    @Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScope(scope);
    }

    @Override public Scope getScopeInstance() {
      return scope;
    }

    @Override public String toString() {
      return scope.toString();
    }

    @Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scope);
    }
  };
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:24,代碼來源:Scoping.java

示例5: testOverrideScopeAnnotation

import com.google.inject.Scope; //導入依賴的package包/類
public void testOverrideScopeAnnotation() {
  final Scope scope = new Scope() {
    public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
      throw new AssertionError("Should not be called");
    }
  };

  final SingleUseScope replacementScope = new SingleUseScope();

  Module original = new AbstractModule() {
    @Override protected void configure() {
      bindScope(TestScopeAnnotation.class, scope);
      bind(Date.class).in(TestScopeAnnotation.class);
    }
  };

  Module replacements = new AbstractModule() {
    @Override protected void configure() {
      bindScope(TestScopeAnnotation.class, replacementScope);
    }
  };

  Injector injector = createInjector(Modules.override(original).with(replacements));
  injector.getInstance(Date.class);
  assertTrue(replacementScope.used);
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:27,代碼來源:OverrideModuleTest.java

示例6: visit

import com.google.inject.Scope; //導入依賴的package包/類
@Override public Boolean visit(ScopeBinding command) {
  Scope scope = command.getScope();
  Class<? extends Annotation> annotationType = command.getAnnotationType();

  if (!Annotations.isScopeAnnotation(annotationType)) {
    errors.withSource(annotationType).missingScopeAnnotation();
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  if (!Annotations.isRetainedAtRuntime(annotationType)) {
    errors.withSource(annotationType)
        .missingRuntimeRetention(command.getSource());
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type"));
  if (existing != null) {
    errors.duplicateScopes(existing, annotationType, scope);
  } else {
    injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope"));
  }

  return true;
}
 
開發者ID:utopiazh,項目名稱:google-guice,代碼行數:25,代碼來源:ScopeBindingProcessor.java

示例7: forInstance

import com.google.inject.Scope; //導入依賴的package包/類
public static Scoping forInstance(final Scope scope) {
  if (scope == Scopes.SINGLETON) {
    return SINGLETON_INSTANCE;
  }

  return new Scoping() {
    public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScope(scope);
    }

    @Override public Scope getScopeInstance() {
      return scope;
    }

    @Override public String toString() {
      return scope.toString();
    }

    public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scope);
    }
  };
}
 
開發者ID:utopiazh,項目名稱:google-guice,代碼行數:24,代碼來源:Scoping.java

示例8: OutOfScopeException

import com.google.inject.Scope; //導入依賴的package包/類
public OutOfScopeException(Scope scope, Key<?> key, Throwable cause) 
{
    super(String.format(
        "Not in scope %s for key %s: caused by %s",
        scope, key, cause
    ), cause);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:8,代碼來源:OutOfScopeException.java

示例9: OutOfScopeException

import com.google.inject.Scope; //導入依賴的package包/類
public OutOfScopeException(Scope scope, Key<?> key, Throwable cause)
{
    super(String.format(
        "Not in scope %s for key %s: caused by %s",
        scope, key, cause
    ), cause);
}
 
開發者ID:directwebremoting,項目名稱:dwr,代碼行數:8,代碼來源:OutOfScopeException.java

示例10: bindScopeInstance

import com.google.inject.Scope; //導入依賴的package包/類
@SuppressWarnings({"unchecked"})
public static void bindScopeInstance(Binder binder, Scope scope, Class<? extends Annotation> annotationType)
{
    requireNonNull(scope);
    binder.bindScope(annotationType, scope);
    binder.bind((Class) scope.getClass()).toInstance(scope);
}
 
開發者ID:wrmsr,項目名稱:wava,代碼行數:8,代碼來源:Scopes.java

示例11: getScopeAnnotation

import com.google.inject.Scope; //導入依賴的package包/類
/**
 * Returns the scope annotation for the given binding or null if there is no
 * scope
 */
public static Class<? extends Annotation> getScopeAnnotation(
        Binding<?> binding) {
    Class<? extends Annotation> scopeAnnotation = null;
    if (binding instanceof BindingImpl) {
        BindingImpl bindingImpl = (BindingImpl) binding;
        Scoping scoping = bindingImpl.getScoping();
        if (scoping != null) {
            scopeAnnotation = scoping.getScopeAnnotation();

            // TODO not sure why we need this hack???
            if (scopeAnnotation == null) {
                Scope scope = scoping.getScopeInstance();
                if (scope instanceof HasScopeAnnotation) {
                    HasScopeAnnotation hasScopeAnnotation = (HasScopeAnnotation) scope;
                    scopeAnnotation = hasScopeAnnotation
                            .getScopeAnnotation();
                }

                if (scopeAnnotation == null
                        && (scoping == Scoping.EAGER_SINGLETON
                                || scoping == Scoping.SINGLETON_ANNOTATION || scoping == Scoping.SINGLETON_INSTANCE)) {
                    scopeAnnotation = Singleton.class;
                }
            }
        }
    }
    return scopeAnnotation;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:33,代碼來源:Injectors.java

示例12: RequestScopePropagator

import com.google.inject.Scope; //導入依賴的package包/類
protected RequestScopePropagator(
    Scope scope,
    ThreadLocalRequestContext local,
    Provider<RequestScopedReviewDbProvider> dbProviderProvider) {
  this.scope = scope;
  this.local = local;
  this.dbProviderProvider = dbProviderProvider;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:9,代碼來源:RequestScopePropagator.java

示例13: ThreadLocalRequestScopePropagator

import com.google.inject.Scope; //導入依賴的package包/類
protected ThreadLocalRequestScopePropagator(
    Scope scope,
    ThreadLocal<C> threadLocal,
    ThreadLocalRequestContext local,
    Provider<RequestScopedReviewDbProvider> dbProviderProvider) {
  super(scope, local, dbProviderProvider);
  this.threadLocal = threadLocal;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:9,代碼來源:ThreadLocalRequestScopePropagator.java

示例14: createScopeMap

import com.google.inject.Scope; //導入依賴的package包/類
@Override
public Map<Scope, ComponentScope> createScopeMap() {
    Map<Scope, ComponentScope> m = super.createScopeMap();

    m.put(ServletScopes.REQUEST, ComponentScope.PerRequest);
    return m;
}
 
開發者ID:jclawson,項目名稱:dropwizardry,代碼行數:8,代碼來源:GuiceContainer.java

示例15: scopeInstance

import com.google.inject.Scope; //導入依賴的package包/類
private static String scopeInstance(Scope scope) {
  if (scope == Scopes.SINGLETON) {
    return Scopes.class.getCanonicalName() + ".SINGLETON";
  } else {
    return "new " + scope.getClass().getCanonicalName() + "()";
  }
}
 
開發者ID:mikosik,項目名稱:deguicifier,代碼行數:8,代碼來源:Generators.java


注:本文中的com.google.inject.Scope類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。