private void introspect() {
    List<AnnotatedParameter<X>> parameters = _method.getParameters();

    /*
    if (parameters.size() == 1) {
      if (parameters.get(0).isAnnotationPresent(IfExists.class)) {
        _isIfExists = true;
      }

      return;
    }
    */

    _args = new BeanArg[parameters.size()];

    for (int i = 0; i < _args.length; i++) {
      AnnotatedParameter<?> param = parameters.get(i);

      Observes observes = param.getAnnotation(Observes.class);

      if (observes != null) {
        _isIfExists = observes.notifyObserver() == Reception.IF_EXISTS;
      } else {
        _args[i] =
            new BeanArg(param.getBaseType(), _beanManager.getQualifiers(param.getAnnotations()));
      }
    }
  }
예제 #2
0
  private void introspectInjectMethod(
      AnnotatedType<X> type, ArrayList<ConfigProgram> injectProgramList) {

    for (AnnotatedMethod method : type.getMethods()) {
      if (method.getAnnotations().size() == 0) continue;

      if (method.isAnnotationPresent(Inject.class)) {
        // boolean isOptional = isQualifierOptional(field);

        List<AnnotatedParameter<?>> params = method.getParameters();

        InjectionPoint[] args = new InjectionPoint[params.size()];

        for (int i = 0; i < args.length; i++) {
          InjectionPoint ij = new InjectionPointImpl(getBeanManager(), this, params.get(i));

          _injectionPointSet.add(ij);

          args[i] = ij;
        }

        injectProgramList.add(new MethodInjectProgram(method.getJavaMember(), args));
      } else {
        InjectionPointHandler handler = getBeanManager().getInjectionPointHandler(method);

        if (handler != null) {
          ConfigProgram program = new MethodHandlerProgram(method, handler);

          injectProgramList.add(program);
        }
      }
    }
  }
  private void introspectInjectionPoints() {
    for (AnnotatedParameter<?> param : _producesMethod.getParameters()) {
      InjectionPointImpl ip = new InjectionPointImpl(getBeanManager(), this, param);

      _injectionPointSet.add(ip);
    }
  }
  private ProducesMethodBean(
      InjectManager manager,
      Bean<X> producerBean,
      AnnotatedMethod<? super X> producesMethod,
      Arg<?>[] producesArgs,
      AnnotatedMethod<? super X> disposesMethod,
      Arg<?>[] disposesArgs) {
    super(manager, producesMethod.getBaseType(), producesMethod);

    _producerBean = producerBean;
    _producesMethod = producesMethod;
    _producesArgs = producesArgs;

    if (producesMethod == null) throw new NullPointerException();

    if (producesArgs == null) throw new NullPointerException();

    producesMethod.getJavaMember().setAccessible(true);

    if (disposesMethod != null) {
      _disposesProducer =
          new DisposesProducer<T, X>(
              manager, producerBean,
              disposesMethod, disposesArgs);

      for (AnnotatedParameter<? super X> param : disposesMethod.getParameters()) {
        if (param.isAnnotationPresent(Disposes.class)) _disposedParam = param;
      }
    }

    introspectInjectionPoints();

    _methodProducer = new MethodProducer();
    _producer = _methodProducer;

    Method javaMethod = producesMethod.getJavaMember();
    int modifiers = javaMethod.getModifiers();

    if (producesMethod.isAnnotationPresent(Specializes.class)) {
      if (Modifier.isStatic(modifiers)) {
        throw new ConfigException(
            L.l(
                "{0}.{1} is an invalid @Specializes @Producer because the method is static.",
                javaMethod.getDeclaringClass().getName(), javaMethod.getName()));
      }

      Method parentMethod = getSpecializedMethod(javaMethod);

      if (parentMethod == null) {
        throw new ConfigException(
            L.l(
                "{0}.{1} is an invalid @Specializes @Producer because it does not directly specialize a parent method",
                javaMethod.getDeclaringClass().getName(), javaMethod.getName()));
      }

      if (producesMethod.getJavaMember().isAnnotationPresent(Named.class)
          && parentMethod.isAnnotationPresent(Named.class)) {
        throw new ConfigException(
            L.l(
                "{0}.{1} is an invalid @Specializes @Producer because both it and its parent defines @Named",
                javaMethod.getDeclaringClass().getName(), javaMethod.getName()));
      }

      for (Annotation ann : parentMethod.getAnnotations()) {
        if (ann.annotationType().isAnnotationPresent(Qualifier.class)) {
          // ioc/07a5
          if (producesMethod instanceof AnnotatedElementImpl) {
            ((AnnotatedElementImpl) producesMethod).addAnnotation(ann);
          }
        }
      }
    }
  }