private String findName(Annotation[] annotations) { for (Annotation annotation : annotations) { if (annotation instanceof Named) { return ((Named) annotation).value(); } } return null; }
private String extractName(Named annotation) { if (annotation != null) { return annotation.value(); } else { return null; } }
/** * If the annotation is an instance of {@code javax.inject.Named}, canonicalizes to * com.google.guice.name.Named. Returns the given annotation otherwise. */ public static Annotation canonicalizeIfNamed(Annotation annotation) { if (annotation instanceof javax.inject.Named) { return Names.named(((javax.inject.Named) annotation).value()); } else { return annotation; } }
/** * Adds service's qualifier. * * @return current instance. */ public D qualifiedBy(Annotation annotation) { if (Named.class.equals(annotation.annotationType())) { this.name = ((Named) annotation).value(); } this.qualifiers.add(annotation); return (D) this; }
/** * Adds service's qualifier. * * @return current instance. */ public D qualifiedBy(Annotation annotation) { if (Named.class.equals(annotation.annotationType())) { this.name = ((Named) annotation).value(); } this.qualifiers.add(annotation); return (D) this; }
@Override public void introspectField(Class clazz, Field f) { if (f.isAnnotationPresent(Named.class)) { String name = f.getAnnotation(Named.class).value(); if (name.isEmpty()) { name = f.getName(); } nameLocal.set(name); } } }
private static Set<Annotation> getFieldAdjustedQualifierAnnotations(Field field, Set<Annotation> qualifiers) { Named n = field.getAnnotation(Named.class); if (n == null || !"".equals(n.value())) { return qualifiers; } HashSet<Annotation> retVal = new HashSet<>(); for (Annotation qualifier : qualifiers) { if (qualifier.annotationType().equals(Named.class)) { retVal.add(new NamedImpl(field.getName())); } else { retVal.add(qualifier); } } return retVal; }
private static String findName(final AnnotatedElement elem) { Named named = elem.getAnnotation(Named.class); if (named == null) { com.google.inject.name.Named gnamed = elem .getAnnotation(com.google.inject.name.Named.class); if (gnamed == null) { Header header = elem.getAnnotation(Header.class); if (header == null) { return null; } return Strings.emptyToNull(header.value()); } return gnamed.value(); } return Strings.emptyToNull(named.value()); }
Named named = getNamedAnnotation(constructor.getParameterAnnotations()[i]); if (named != null) { args[i] = get(constructor.getParameterTypes()[i], named.value()); } else { args[i] = get(constructor.getParameterTypes()[i]);
Class<? extends Annotation> annotationType = annotations[i].annotationType(); if (annotationType == Named.class) { return ((Named) annotations[i]).value();
@Override public void run(IHookCallBack callBack, ITestResult testResult) { Method method = testResult.getMethod().getConstructorOrMethod().getMethod(); for (int i = 0; i < callBack.getParameters().length; i++) { Annotation[] annotations = method.getParameterAnnotations()[i]; for (Annotation annotation : annotations) { if (annotation instanceof Named) { Named named = (Named) annotation; callBack.getParameters()[0] = callBack.getParameters()[0] + named.value(); } } } callBack.runTestMethod(testResult); }
public boolean equals(Object o) { if (!(o instanceof Named)) { return false; } Named other = (Named) o; return value.equals(other.value()); }
public boolean equals(Object o) { if (!(o instanceof Named)) { return false; } Named other = (Named) o; return value.equals(other.value()); }
public boolean equals(Object o) { if (!(o instanceof Named)) { return false; } Named other = (Named) o; return value.equals(other.value()); }
public boolean equals(Object o) { if (!(o instanceof Named)) { return false; } Named other = (Named) o; return value.equals(other.value()); }
private String findInjectionName(Field field) { for (Annotation annotation : field.getAnnotations()) { //works for both easy mock and mockito if (annotation.annotationType() == Named.class) { return ((Named) annotation).value(); } //works for both easy mock and mockito if (annotation.annotationType() != Inject.class && !annotation.annotationType().getName().contains("Mock")) { return annotation.annotationType().getName(); } } return null; }
@Override public Collection<Either<Class<?>, String>> getInjectedDependencies() { return getAnnotatedFields(configuration.getValue().getClass(), Inject.class).stream() .map(field -> { Named name = field.getAnnotation(Named.class); return name != null ? Either.<Class<?>, String>right(name.value()) : Either.<Class<?>, String>left(field.getType()); }).collect(toList()); }
private List<Object> calculateAugmentedArgs(Object target, Method method, Object[] args, Method injectable) { final List<Object> augmentedArgs = args == null ? new ArrayList<>() : new ArrayList<>(asList(args)); for (int i = method.getParameters().length; i < injectable.getParameters().length; ++i) { final Parameter parameter = injectable.getParameters()[i]; Object arg; Named named = parameter.getAnnotation(Named.class); if (named != null) { arg = registry.lookupByName(named.value()) .orElseThrow(() -> new IllegalDependencyInjectionException(format(NO_OBJECT_FOUND_FOR_PARAM, parameter.getName(), injectable.getName(), target.toString()))); } else { final Collection<?> lookupObjects = registry.lookupAllByType(parameter.getType()); arg = new PreferredObjectSelector().select(lookupObjects.iterator()); } augmentedArgs.add(arg); } return augmentedArgs; }