Package org.jboss.errai.codegen.meta

Examples of org.jboss.errai.codegen.meta.MetaMethod


  public Statement valueAccessorFor(final MetaClassMember member) {
    if (member instanceof MetaField) {
      final MetaField field = (MetaField) member;
      if (!field.isPublic()) {
        final MetaMethod getterMethod = GenUtil.findCaseInsensitiveMatch(field.getType(),
                field.getDeclaringClass(), "get" + field.getName());

        if (getterMethod != null) {
          return loadVariable("a0").invoke(getterMethod);
        }
        else {
          if (!context.isExposed(field)) {
            PrivateAccessUtil.addPrivateAccessStubs(gwtTarget ? "jsni" : "reflection", context.getClassStructureBuilder(), field);
            context.markExposed(field);
          }

          return Stmt.invokeStatic(context.getGeneratedBootstrapClass(), PrivateAccessUtil
              .getPrivateFieldInjectorName(field),
                  loadVariable("a0"));
        }
      }
      else {
        return loadVariable("a0").loadField(field.getName());
      }
    }
    else {
      final MetaMethod method = (MetaMethod) member;
      return loadVariable("a0").invoke(method);
    }
  }
View Full Code Here


  }

  public Statement callOrBind(Statement... values) {
    final Injector targetInjector = injector;

    MetaMethod meth = method;
    switch (taskType) {
      case PrivateField:
        Statement[] args = new Statement[values.length + 1];
        args[0] = Refs.get(targetInjector.getVarName());
        System.arraycopy(values, 0, args, 1, values.length);

        return Stmt.invokeStatic(injectionContext.getProcessingContext().getBootstrapClass(),
                getPrivateFieldInjectorName(field), args);

      case Field:
        return Stmt.loadVariable(targetInjector.getVarName()).loadField(field.getName()).assignValue(values[0]);

      case Parameter:
        if (parm.getDeclaringMember() instanceof MetaMethod) {
          meth = (MetaMethod) parm.getDeclaringMember();
        }
        else {
          throw new RuntimeException("cannot call task on element: " + parm.getDeclaringMember());
        }

      case Method:
      case PrivateMethod:
        args = new Statement[values.length + 1];
        args[0] = Refs.get(targetInjector.getVarName());
        System.arraycopy(values, 0, args, 1, values.length);

        if (!meth.isPublic()) {
          return Stmt.invokeStatic(injectionContext.getProcessingContext().getBootstrapClass(),
                  getPrivateMethodName(meth), args);
        }
        else {
          return Stmt.loadVariable(targetInjector.getVarName()).invoke(meth, values);
View Full Code Here

  public void ensureMemberExposed(PrivateAccessType accessType) {
    switch (taskType) {
      case Parameter:
        if (parm.getDeclaringMember() instanceof MetaMethod) {
          MetaMethod declMeth = (MetaMethod) parm.getDeclaringMember();
          injectionContext.addExposedMethod(declMeth);
        }
      case PrivateMethod:
        injectionContext.addExposedMethod(method);
        break;
View Full Code Here

    if (javaMember instanceof Field) {
      MetaField field = MetaClassFactory.get((Field) javaMember);
      return field.isAnnotationPresent(GeneratedValue.class);
    }
    else if (javaMember instanceof Method) {
      MetaMethod method = MetaClassFactory.get((Method) javaMember);
      return method.isAnnotationPresent(GeneratedValue.class);
    }
    throw new IllegalArgumentException("Given member is a "
        + javaMember.getClass().getName()
        + " but JPA attributes can only be a Field or a Method.");
  }
View Full Code Here

  }

  private Statement generatePropertiesMap() {
    BlockStatement block = new BlockStatement();
    for (String property : bindable.getBeanDescriptor().getProperties()) {
      MetaMethod readMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property);
      if (!readMethod.isFinal()) {
        block.addStatement(Stmt.loadVariable("propertyTypes").invoke("put", property,
            readMethod.getReturnType().asBoxed().asClass()));
      }
    }
    return block;
  }
View Full Code Here

  }

  private void generateGetter(ClassStructureBuilder<?> classBuilder, String property,
      BlockBuilder<?> getMethod) {

    MetaMethod getterMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property);
    if (getterMethod != null && !getterMethod.isFinal()) {
      getMethod.append(
          If.objEquals(Stmt.loadVariable("property"), property)
              .append(Stmt.loadVariable("this").invoke(getterMethod.getName()).returnValue())
              .finish()
          );

      classBuilder.publicMethod(getterMethod.getReturnType(), getterMethod.getName())
          .append(Stmt.loadClassMember("target").invoke(getterMethod.getName()).returnValue())
          .finish();
    }
  }
View Full Code Here

          .finish();
    }
  }

  private void generateSetter(ClassStructureBuilder<?> classBuilder, String property, BlockBuilder<?> setMethod) {
    MetaMethod getterMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property);
    MetaMethod setterMethod = bindable.getBeanDescriptor().getWriteMethodForProperty(property);
    if (setterMethod != null && !setterMethod.isFinal()) {
      setMethod.append(
          If.cond(Stmt.loadVariable("property").invoke("equals", property))
              .append(
                  Stmt.declareVariable("oldValue", setterMethod.getParameters()[0].getType().asBoxed(),
                      Stmt.loadVariable("this").invoke(getterMethod)))
              .append(
                  Stmt.loadVariable("target").invoke(
                      setterMethod.getName(),
                      Cast.to(setterMethod.getParameters()[0].getType().asBoxed(),
                          Stmt.invokeStatic(Convert.class, "toModelValue",
                              setterMethod.getParameters()[0].getType().asBoxed().asClass(),
                              Stmt.loadVariable("bindings").invoke("get", Variable.get("property")),
                              Stmt.loadVariable("value"),
                              Stmt.loadVariable("converters").invoke("get", Variable.get("property"))))))
              .append(
                  Stmt.loadVariable("propertyChangeHandlerSupport").invoke("notifyHandlers",
                      Stmt.newObject(PropertyChangeEvent.class, Stmt.loadVariable("this"),
                          Stmt.loadVariable("property"), Stmt .loadVariable("oldValue"),
                          Stmt.loadVariable("value"))))
              .append(Stmt.returnVoid())
              .finish()
          );

      MetaClass paramType = setterMethod.getParameters()[0].getType();

      Statement callSetterOnTarget = Stmt.loadClassMember("target").invoke(setterMethod.getName(),
                Cast.to(paramType, Stmt.loadVariable(property)));

      // If the set method we are proxying returns a value, capture that value into a local variable
      Statement returnValueOfSetter = EmptyStatement.INSTANCE;
      if (!setterMethod.getReturnType().equals(MetaClassFactory.get(void.class))) {
        callSetterOnTarget =
            Stmt.declareFinalVariable("returnValueOfSetter", setterMethod.getReturnType(), callSetterOnTarget);
        returnValueOfSetter = Stmt.nestedCall(Refs.get("returnValueOfSetter")).returnValue();
      }

      classBuilder.publicMethod(setterMethod.getReturnType(), setterMethod.getName(),
          Parameter.of(paramType, property))
          .append(
              Stmt.declareVariable("oldValue", Object.class, Stmt.loadClassMember("target").invoke(
                  getterMethod.getName())))
          .append(callSetterOnTarget)
View Full Code Here


  public Statement callOrBind(final Statement... values) {
    final Injector targetInjector = injector;

    MetaMethod meth = method;
    switch (taskType) {
      case PrivateField:
      case Field:
        return InjectUtil.setPublicOrPrivateFieldValue(
            injectionContext,
View Full Code Here

  }

  @Override
  public List<? extends Statement> generateDecorator(final InjectableInstance<Observes> instance) {
    final Context ctx = instance.getInjectionContext().getProcessingContext().getContext();
    final MetaMethod method = instance.getMethod();
    final MetaParameter parm = instance.getParm();

    if (!method.isPublic()) {
      instance.ensureMemberExposed(PrivateAccessType.Write);
    }

    final String parmClassName = parm.getType().getFullyQualifiedName();
    final List<Annotation> annotations = InjectUtil.extractQualifiers(instance);
View Full Code Here

    do {
      for (MetaField field : visit.getDeclaredFields()) {
        if (isInjectionPoint(ctx, field)) {
          if (!field.isPublic()) {
            MetaMethod meth = visit.getMethod(ReflectionUtil.getSetter(field.getName()),
                    field.getType());

            if (meth == null) {
              InjectionTask task = new InjectionTask(injector, field);
              accumulator.add(task);
            }
            else {
              InjectionTask task = new InjectionTask(injector, meth);
              accumulator.add(task);
            }

          }
          else {
            accumulator.add(new InjectionTask(injector, field));
          }
        }

        ElementType[] elTypes;
        for (Class<? extends Annotation> a : decorators) {
          elTypes = a.isAnnotationPresent(Target.class) ? a.getAnnotation(Target.class).value()
                  : new ElementType[]{ElementType.FIELD};

          for (ElementType elType : elTypes) {
            switch (elType) {
              case FIELD:
                if (field.isAnnotationPresent(a)) {
                  accumulator.add(new DecoratorTask(injector, field, ctx.getDecorator(a)));
                }
                break;
            }
          }
        }
      }

      for (MetaMethod meth : visit.getDeclaredMethods()) {
        if (isInjectionPoint(ctx, meth)) {
          accumulator.add(new InjectionTask(injector, meth));
        }

        ElementType[] elTypes;
        for (Class<? extends Annotation> a : decorators) {
          elTypes = a.isAnnotationPresent(Target.class) ? a.getAnnotation(Target.class).value()
                  : new ElementType[]{ElementType.FIELD};

          for (ElementType elType : elTypes) {
            switch (elType) {
              case METHOD:
                if (meth.isAnnotationPresent(a)) {
                  accumulator.add(new DecoratorTask(injector, meth, ctx.getDecorator(a)));
                }
                break;
              case PARAMETER:
                for (MetaParameter parameter : meth.getParameters()) {
                  if (parameter.isAnnotationPresent(a)) {
                    DecoratorTask task = new DecoratorTask(injector, parameter, ctx.getDecorator(a));
                    accumulator.add(task);
                  }
                }
View Full Code Here

TOP

Related Classes of org.jboss.errai.codegen.meta.MetaMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.