当前位置: 首页>>代码示例>>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;未经允许,请勿转载。