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


Java Scope類代碼示例

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


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

示例1: annotationWithoutValueMethod

import javax.inject.Scope; //導入依賴的package包/類
@Test
public void annotationWithoutValueMethod() {
	Annotation annotation = Singleton.class.getAnnotation(Scope.class);
	cache.getQualifier(annotation);

	InOrder inOrder = inOrder(lock, cache);

	// initial call
	inOrder.verify(cache).getQualifier(annotation);

	// internal thread safe method lookup
	inOrder.verify(cache).getValueMethodThreadSafe(Scope.class);
	inOrder.verify(lock).lock();
	inOrder.verify(cache).getValueMethod(Scope.class);
	inOrder.verify(lock).unlock();
	// no value Method found, so no invocation needed

	inOrder.verifyNoMoreInteractions();
	verifyZeroInteractions(cache);
	assertThat(bindActionMap.size(), is(1));
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:22,代碼來源:QualifierCacheTests.java

示例2: getScopeName

import javax.inject.Scope; //導入依賴的package包/類
/**
 * Lookup {@link javax.inject.Scope} annotated annotations to provide the name of the scope the {@code typeElement} belongs to.
 * The method logs an error if the {@code typeElement} has multiple scope annotations.
 *
 * @param typeElement the element for which a scope is to be found.
 * @return the scope of this {@code typeElement} or {@code null} if it has no scope annotations.
 */
private String getScopeName(TypeElement typeElement) {
  String scopeName = null;
  for (AnnotationMirror annotationMirror : typeElement.getAnnotationMirrors()) {
    TypeElement annotationTypeElement = (TypeElement) annotationMirror.getAnnotationType().asElement();
    if (annotationTypeElement.getAnnotation(Scope.class) != null) {
      checkScopeAnnotationValidity(annotationTypeElement);
      if (scopeName != null) {
        error(typeElement, "Only one @Scope qualified annotation is allowed : %s", scopeName);
      }
      scopeName = annotationTypeElement.getQualifiedName().toString();
    }
  }

  return scopeName;
}
 
開發者ID:stephanenicolas,項目名稱:toothpick,代碼行數:23,代碼來源:FactoryProcessor.java

示例3: findScope

import javax.inject.Scope; //導入依賴的package包/類
/**
 * Finds the scope for a bean producing declaration, either a method or
 * a type.
 */
private <T> InjectScope<T> findScope(AnnotatedElement annElement)
{
  for (Annotation ann : annElement.getAnnotations()) {
    Class<? extends Annotation> annType = ann.annotationType();

    if (annType.isAnnotationPresent(Scope.class)) {
      Supplier<InjectScope<T>> scopeGen = (Supplier) _scopeMap.get(annType);

      if (scopeGen != null) {
        return scopeGen.get();
      }
      else {
        log.fine(L.l("@{0} is an unknown scope", annType.getSimpleName()));
      }
    }
  }

  return new InjectScopeFactory<>();
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:24,代碼來源:InjectorImpl.java

示例4: scope

import javax.inject.Scope; //導入依賴的package包/類
@Override
public BindingBuilderImpl<T> scope(Class<? extends Annotation> scopeType)
{
  Objects.requireNonNull(scopeType);

  if (! scopeType.isAnnotationPresent(Scope.class)) {
    throw error("'@{0}' is an invalid scope type because it is not annotated with @Scope",
                scopeType.getSimpleName());
  }

  if (_scopeMap.get(scopeType) == null) {
    throw error("'@{0}' is an unsupported scope. Only @Singleton and @Factory are supported.",
                scopeType.getSimpleName());

  }

  _scopeType = scopeType;

  return this;
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:21,代碼來源:InjectorBuilderImpl.java

示例5: getModuleScope

import javax.inject.Scope; //導入依賴的package包/類
/**
 * Returns the scope of this module, null for unscoped modules. Dagger requires that each module
 * can only contain no more than one scope type of scoped binding. Unscoped bindings are not
 * limited.
 * TODO(freeman): supported included modules.
 */
@Nullable
public static TypeElement getModuleScope(DeclaredType moduleType) {
  TypeElement moduleElement = (TypeElement) moduleType.asElement();
  Preconditions.checkArgument(
      moduleElement.getAnnotation(Module.class) != null,
      String.format("not module: %s.", moduleType));
  for (Element element : moduleElement.getEnclosedElements()) {
    if (element.getKind().equals(ElementKind.METHOD)
        && (element.getAnnotation(Provides.class) != null)) {
      for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        Annotation scope =
            annotationMirror.getAnnotationType().asElement().getAnnotation(Scope.class);
        if (scope != null) {
          return (TypeElement) annotationMirror.getAnnotationType().asElement();
        }
      }
    }
  }
  return null;
}
 
開發者ID:google,項目名稱:tiger,代碼行數:27,代碼來源:Utils.java

示例6: findScope

import javax.inject.Scope; //導入依賴的package包/類
/**
 * Find annotation that is itself annoted with @Scope
 * If there is one, it will be later applied on the generated component
 * Otherwise the component will be unscoped
 * Throw error if more than one scope annotation found
 */
private AnnotationMirror findScope() {
    AnnotationMirror annotationTypeMirror = null;

    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        Element annotationElement = annotationMirror.getAnnotationType().asElement();
        if (MoreElements.isAnnotationPresent(annotationElement, Scope.class)) {
            // already found one scope
            if (annotationTypeMirror != null) {
                errors.addInvalid("Several dagger scopes on same element are not allowed");
                continue;
            }

            annotationTypeMirror = annotationMirror;
        }
    }

    return annotationTypeMirror;
}
 
開發者ID:lukaspili,項目名稱:Mortar-architect,代碼行數:25,代碼來源:ScopeExtractor.java

示例7: DocumentedAnnotations

import javax.inject.Scope; //導入依賴的package包/類
public DocumentedAnnotations(Element element) {
    List<AnnotationMirror> allAnnotations = new ArrayList<AnnotationMirror>();
    allAnnotations.addAll(annotationsOf(element, Qualifier.class));
    allAnnotations.addAll(annotationsOf(element, Scope.class));

    if (allAnnotations.isEmpty()) {
        this.description = Optional.absent();
        return;
    }

    StringBuilder result = new StringBuilder();
    for (AnnotationMirror annotation : allAnnotations) {
        if (result.length() > 0) {
            result.append(" ");
        }
        result.append(annotation.toString());
    }

    this.description = Optional.of(result.toString());
}
 
開發者ID:Ladicek,項目名稱:ann-docu-gen,代碼行數:21,代碼來源:DocumentedAnnotations.java

示例8: methodCaching

import javax.inject.Scope; //導入依賴的package包/類
@Test
public void methodCaching() {
	Annotation annotation = Singleton.class.getAnnotation(Scope.class);
	// call twice - should cache once
	cache.getQualifier(annotation);
	cache.getQualifier(annotation);

	assertThat(bindActionMap.size(), is(1));
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:10,代碼來源:QualifierCacheTests.java

示例9: fieldScopeTest

import javax.inject.Scope; //導入依賴的package包/類
@Test
public void fieldScopeTest() throws NoSuchFieldException {
	Field field = Testable.class.getDeclaredField("scopedField");
	Annotation namedAnnotation = Annotations.findAnnotationAnnotatedWith(Scope.class, field);

	assertThat(namedAnnotation, allOf(notNullValue(), annotationOfType(Singleton.class)));
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:8,代碼來源:AnnotationsTests.java

示例10: methodScopeTest

import javax.inject.Scope; //導入依賴的package包/類
@Test
public void methodScopeTest() throws NoSuchMethodException {
	Method method = Testable.class.getDeclaredMethod("scopedMethod");
	Annotation namedAnnotation = Annotations.findAnnotationAnnotatedWith(Scope.class, method);

	assertThat(namedAnnotation, allOf(notNullValue(), annotationOfType(Singleton.class)));
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:8,代碼來源:AnnotationsTests.java

示例11: methodArgumentScopeTest

import javax.inject.Scope; //導入依賴的package包/類
@Test
public void methodArgumentScopeTest() throws NoSuchMethodException {
	Method method = Testable.class.getDeclaredMethod("scopedMethodArguments", Object.class);
	Annotation[] annotations = method.getParameterAnnotations()[0];
	Annotation namedAnnotation = Annotations.findAnnotationAnnotatedWith(Scope.class, annotations);

	assertThat(namedAnnotation, allOf(notNullValue(), annotationOfType(Singleton.class)));
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:9,代碼來源:AnnotationsTests.java

示例12: methodArgumentScopeMissingTest

import javax.inject.Scope; //導入依賴的package包/類
@Test
public void methodArgumentScopeMissingTest() throws NoSuchMethodException {
	Method method = Testable.class.getDeclaredMethod("scopedMethodArgumentsMissing", Object.class);
	Annotation[] annotations = method.getParameterAnnotations()[0];
	Annotation namedAnnotation = Annotations.findAnnotationAnnotatedWith(Scope.class, annotations);

	assertThat(namedAnnotation, is(nullValue()));
}
 
開發者ID:ByteWelder,項目名稱:Spork,代碼行數:9,代碼來源:AnnotationsTests.java

示例13: createFactoriesForClassesAnnotatedWithScopeAnnotations

import javax.inject.Scope; //導入依賴的package包/類
private void createFactoriesForClassesAnnotatedWithScopeAnnotations(RoundEnvironment roundEnv, Set<? extends TypeElement> annotations) {
  for (TypeElement annotation : annotations) {
    if (annotation.getAnnotation(Scope.class) != null) {
      checkScopeAnnotationValidity(annotation);
      createFactoriesForClassesAnnotatedWith(roundEnv, annotation);
    }
  }
}
 
開發者ID:stephanenicolas,項目名稱:toothpick,代碼行數:9,代碼來源:FactoryProcessor.java

示例14: checkScopeAnnotationValidity

import javax.inject.Scope; //導入依賴的package包/類
private void checkScopeAnnotationValidity(TypeElement annotation) {
  if (annotation.getAnnotation(Scope.class) == null) {
    error(annotation, "Scope Annotation %s does not contain Scope annotation.", annotation.getQualifiedName());
    return;
  }

  Retention retention = annotation.getAnnotation(Retention.class);
  if (retention == null || retention.value() != RetentionPolicy.RUNTIME) {
    error(annotation, "Scope Annotation %s does not have RUNTIME retention policy.", annotation.getQualifiedName());
  }
}
 
開發者ID:stephanenicolas,項目名稱:toothpick,代碼行數:12,代碼來源:FactoryProcessor.java

示例15: getScope

import javax.inject.Scope; //導入依賴的package包/類
@Override
public Class<? extends Annotation> getScope() {
	Class<? extends Annotation> scope = Arrays.stream(javaType.getAnnotations())
		.map(a -> a.getClass())
			.filter(a -> a.getAnnotation(Scope.class) != null)
				.findFirst().orElse(null);

	return scope == null ? Dependent.class : scope;
}
 
開發者ID:ljtfreitas,項目名稱:java-restify,代碼行數:10,代碼來源:RestifyProxyCdiBean.java


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