下面列出了怎么用com.google.inject.ScopeAnnotation的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Checks scope annotation presence directly on bean. Base classes are not checked as scope is not
* inheritable.
*
* @param type bean type
* @param hkManaged true if bean is going to be managed by hk, false for guice management
* @return true if scope annotation found, false otherwise
*/
private boolean hasScopeAnnotation(final Class<?> type, final boolean hkManaged) {
boolean found = false;
for (Annotation ann : type.getAnnotations()) {
final Class<? extends Annotation> annType = ann.annotationType();
if (annType.isAnnotationPresent(Scope.class)) {
found = true;
break;
}
// guice has special marker annotation
if (!hkManaged && annType.isAnnotationPresent(ScopeAnnotation.class)) {
found = true;
break;
}
}
return found;
}
/**
* Tells if the given annotation is a Google Guice "scope annotation", i.e. if the annotation class is itself
* annotated with <code>@ScopeAnnotation</code>.
*/
public static final boolean isScopeAnnotation(Class<? extends Annotation> annotationClass) {
return annotationClass.isAnnotationPresent(ScopeAnnotation.class);
}