Package com.google.gwt.core.ext.typeinfo

Examples of com.google.gwt.core.ext.typeinfo.JMethod


              annotationMethod.defaultValue);
        }
        method = new JAnnotationMethod(enclosingType, name, defaultValue,
            declaredAnnotations);
      } else {
        method = new JMethod(enclosingType, name, declaredAnnotations,
            jtypeParameters);
      }

      // Do a second pass to resolve the bounds on each JTypeParameter.
      // The type parameters must be resolved at this point, because they may
View Full Code Here


          throw new UnableToCompleteException();
        }
        desc.eventFullName = eventType.getQualifiedSourceName();

        // Make sure the eventType has a static getType method
        JMethod getTypeMethod = eventType.findMethod("getType", new JType[0]);
        if (getTypeMethod == null || !getTypeMethod.isStatic()
            || getTypeMethod.getParameters().length != 0) {
          logger.log(TreeLogger.ERROR, "In presenter " + presenterClassName
              + ", method " + desc.functionName + " annotated with @"
              + ProxyEvent.class.getSimpleName() + ". The event class "
              + eventType.getName()
              + " does not have a static getType method with no parameters.");
          throw new UnableToCompleteException();
        }
        JClassType getTypeReturnType = getTypeMethod.getReturnType().isClassOrInterface();
        if (getTypeReturnType == null
            || !getTypeReturnType.isAssignableTo(gwtEventTypeClass)) {
          logger.log(TreeLogger.ERROR, "In presenter " + presenterClassName
              + ", method " + desc.functionName + " annotated with @"
              + ProxyEvent.class.getSimpleName() + ". The event class "
              + eventType.getName()
              + " getType() method  not return a GwtEvent.Type object.");
          throw new UnableToCompleteException();
        }

        // Find the handler class via the dispatch method
        JClassType handlerType = null;
        for (JMethod eventMethod : eventType.getMethods()) {
          if (eventMethod.getName().equals("dispatch")
              && eventMethod.getParameters().length == 1) {
            JClassType maybeHandlerType = eventMethod.getParameters()[0].getType().isClassOrInterface();
            if (maybeHandlerType != null
                && maybeHandlerType.isAssignableTo(eventHandlerClass)) {
              if (handlerType != null) {
                logger.log(TreeLogger.ERROR, "In presenter "
                    + presenterClassName + ", method " + desc.functionName
                    + " annotated with @" + ProxyEvent.class.getSimpleName()
                    + ". The event class " + eventType.getName()
                    + " has more than one potential 'dispatch' method.");
                throw new UnableToCompleteException();
              }
              handlerType = maybeHandlerType;
            }
          }
        }

        if (handlerType == null) {
          logger.log(TreeLogger.ERROR, "In presenter " + presenterClassName
              + ", method " + desc.functionName + " annotated with @"
              + ProxyEvent.class.getSimpleName() + ". The event class "
              + eventType.getName() + " has no valid 'dispatch' method.");
          throw new UnableToCompleteException();
        }
        desc.handlerFullName = handlerType.getQualifiedSourceName();

        // Find the handler method
        if (handlerType.getMethods().length != 1) {
          logger.log(TreeLogger.ERROR, "In presenter " + presenterClassName
              + ", method " + desc.functionName + " annotated with @"
              + ProxyEvent.class.getSimpleName() + ". The handler class "
              + handlerType.getName() + " has more than one method.");
          throw new UnableToCompleteException();
        }

        JMethod handlerMethod = handlerType.getMethods()[0];

        JClassType handlerMethodReturnType = handlerMethod.getReturnType().isClassOrInterface();
        if (handlerMethodReturnType != null
            || handlerMethod.getReturnType().isPrimitive() != JPrimitiveType.VOID) {
          logger.log(
              TreeLogger.WARN,
              "In presenter "
                  + presenterClassName
                  + ", method "
                  + desc.functionName
                  + " annotated with @"
                  + ProxyEvent.class.getSimpleName()
                  + ". The handler class "
                  + handlerType.getName()
                  + " method "
                  + handlerMethod.getName()
                  + " returns something else than void. Return value will be ignored.");
        }

        desc.handlerMethodName = handlerMethod.getName();

        // Warn if handlerMethodName is different
        if (!desc.handlerMethodName.equals(desc.functionName)) {
          logger.log(
              TreeLogger.WARN,
              "In presenter "
                  + presenterClassName
                  + ", method "
                  + desc.functionName
                  + " annotated with @"
                  + ProxyEvent.class.getSimpleName()
                  + ". The handler class "
                  + handlerType.getName()
                  + " method "
                  + handlerMethod.getName()
                  + " differs from the annotated method. You should use the same method name for easier reference.");
        }

        // Make sure that handler method name is not already used
        for (ProxyEventDescription prevDesc : result) {
          if (prevDesc.handlerMethodName.equals(desc.handlerMethodName)
              && prevDesc.eventFullName.equals(desc.eventFullName)) {
            logger.log(TreeLogger.ERROR, "In presenter " + presenterClassName
                + ", method " + desc.functionName + " annotated with @"
                + ProxyEvent.class.getSimpleName() + ". The handler method "
                + handlerMethod.getName() + " is already used by method "
                + prevDesc.functionName + ".");
            throw new UnableToCompleteException();
          }
        }
View Full Code Here

          method.getSimpleSourceName(),
          AbstractRequestFactory.class.getCanonicalName());

      // Write each Request method
      for (RequestMethod request : method.getRequestMethods()) {
        JMethod jmethod = request.getDeclarationMethod();
        String operation = jmethod.getEnclosingType().getQualifiedBinaryName()
            + "::" + jmethod.getName();

        // foo, bar, baz
        StringBuilder parameterArray = new StringBuilder();
        // final Foo foo, final Bar bar, final Baz baz
        StringBuilder parameterDeclaration = new StringBuilder();
        // <P extends Blah>
        StringBuilder typeParameterDeclaration = new StringBuilder();

        if (request.isInstance()) {
          // Leave a spot for the using() method to fill in later
          parameterArray.append(",null");
        }
        for (JTypeParameter param : jmethod.getTypeParameters()) {
          typeParameterDeclaration.append(",").append(
              param.getQualifiedSourceName());
        }
        for (JParameter param : jmethod.getParameters()) {
          parameterArray.append(",").append(param.getName());
          parameterDeclaration.append(",final ").append(
              param.getType().getParameterizedQualifiedSourceName()).append(" ").append(
              param.getName());
        }
        if (parameterArray.length() > 0) {
          parameterArray.deleteCharAt(0);
        }
        if (parameterDeclaration.length() > 0) {
          parameterDeclaration.deleteCharAt(0);
        }
        if (typeParameterDeclaration.length() > 0) {
          typeParameterDeclaration.deleteCharAt(0).insert(0, "<").append(">");
        }

        // public Request<Foo> doFoo(final Foo foo) {
        sw.println("public %s %s %s(%s) {", typeParameterDeclaration,
            jmethod.getReturnType().getParameterizedQualifiedSourceName(),
            jmethod.getName(), parameterDeclaration);
        sw.indent();
        // The implements clause covers InstanceRequest
        // class X extends AbstractRequest<Return> implements Request<Return> {
        sw.println("class X extends %s<%s> implements %s {",
            AbstractRequest.class.getCanonicalName(),
            request.getDataType().getParameterizedQualifiedSourceName(),
            jmethod.getReturnType().getParameterizedQualifiedSourceName());
        sw.indent();

        // public X() { super(FooRequestContext.this); }
        sw.println("public X() { super(%s.this);}",
            method.getSimpleSourceName());
View Full Code Here

    sw.indent();
    // return new FooIntf() {
    sw.println("return new %s() {", type.getPeerType().getQualifiedSourceName());
    sw.indent();
    for (AutoBeanMethod method : type.getMethods()) {
      JMethod jmethod = method.getMethod();
      sw.println("public %s {", getBaseMethodDeclaration(jmethod));
      sw.indent();
      switch (method.getAction()) {
        case GET: {
          // Must handle de-boxing primitive types
          JPrimitiveType primitive = jmethod.getReturnType().isPrimitive();
          if (primitive != null) {
            // Object toReturn = values.get("foo");
            sw.println("Object toReturn = values.get(\"%s\");",
                method.getPropertyName());
            sw.println("if (toReturn == null) {");
            // return 0;
            sw.indentln("return %s;",
                primitive.getUninitializedFieldExpression());
            sw.println("} else {");
            // return (BoxedType) toReturn;
            sw.indentln("return (%s) toReturn;",
                primitive.getQualifiedBoxedSourceName());
            sw.println("}");
          } else {
            // return (ReturnType) values.get(\"foo\");
            sw.println("return (%s) values.get(\"%s\");",
                ModelUtils.getQualifiedBaseSourceName(jmethod.getReturnType()),
                method.getPropertyName());
          }
        }
          break;
        case SET:
          // values.put("foo", parameter);
          sw.println("values.put(\"%s\", %s);", method.getPropertyName(),
              jmethod.getParameters()[0].getName());
          break;
        case CALL:
          // return com.example.Owner.staticMethod(Outer.this, param,
          // param);
          JMethod staticImpl = method.getStaticImpl();
          if (!jmethod.getReturnType().equals(JPrimitiveType.VOID)) {
            sw.print("return ");
          }
          sw.print("%s.%s(%s.this",
              staticImpl.getEnclosingType().getQualifiedSourceName(),
              staticImpl.getName(), type.getSimpleSourceName());
          for (JParameter param : jmethod.getParameters()) {
            sw.print(", %s", param.getName());
          }
          sw.println(");");
          break;
View Full Code Here

  }

  private void writeReturnWrapper(SourceWriter sw, AutoBeanType type,
      AutoBeanMethod method) throws UnableToCompleteException {
    if (!method.isValueType() && !method.isNoWrap()) {
      JMethod jmethod = method.getMethod();
      JClassType returnClass = jmethod.getReturnType().isClassOrInterface();
      AutoBeanType peer = model.getPeer(returnClass);

      sw.println("if (toReturn != null) {");
      sw.indent();
      sw.println("if (%s.this.isWrapped(toReturn)) {",
          type.getSimpleSourceName());
      sw.indentln("toReturn = %s.this.getFromWrapper(toReturn);",
          type.getSimpleSourceName());
      sw.println("} else {");
      sw.indent();
      if (peer != null) {
        // toReturn = new FooAutoBean(getFactory(), toReturn).as();
        sw.println("toReturn = new %s(getFactory(), toReturn).as();",
            peer.getQualifiedSourceName());
      }
      sw.outdent();
      sw.println("}");

      sw.outdent();
      sw.println("}");
    }
    // Allow return values to be intercepted
    JMethod interceptor = type.getInterceptor();
    if (interceptor != null) {
      // toReturn = FooCategory.__intercept(FooAutoBean.this, toReturn);
      sw.println("toReturn = %s.%s(%s.this, toReturn);",
          interceptor.getEnclosingType().getQualifiedSourceName(),
          interceptor.getName(), type.getSimpleSourceName());
    }
  }
View Full Code Here

    // private final FooImpl shim = new FooImpl() {
    sw.println("private final %1$s shim = new %1$s() {",
        type.getPeerType().getQualifiedSourceName());
    sw.indent();
    for (AutoBeanMethod method : type.getMethods()) {
      JMethod jmethod = method.getMethod();
      String methodName = jmethod.getName();
      JParameter[] parameters = jmethod.getParameters();
      if (isObjectMethodImplementedByShim(jmethod)) {
        // Skip any methods declared on Object, since we have special handling
        continue;
      }

      // foo, bar, baz
      StringBuilder arguments = new StringBuilder();
      {
        for (JParameter param : parameters) {
          arguments.append(",").append(param.getName());
        }
        if (arguments.length() > 0) {
          arguments = arguments.deleteCharAt(0);
        }
      }

      sw.println("public %s {", getBaseMethodDeclaration(jmethod));
      sw.indent();

      // Use explicit enclosing this reference to avoid method conflicts
      sw.println("%s.this.checkWrapped();", type.getSimpleSourceName());

      switch (method.getAction()) {
        case GET:
          /*
           * The getter call will ensure that any non-value return type is
           * definitely wrapped by an AutoBean instance.
           */
          // Foo toReturn=FooAutoBean.this.get("getFoo", getWrapped().getFoo());
          sw.println(
              "%s toReturn = %3$s.this.get(\"%2$s\", getWrapped().%2$s());",
              ModelUtils.getQualifiedBaseSourceName(jmethod.getReturnType()),
              methodName, type.getSimpleSourceName());

          // Non-value types might need to be wrapped
          writeReturnWrapper(sw, type, method);
          sw.println("return toReturn;");
          break;
        case SET:
          sw.println("%s.this.checkFrozen();", type.getSimpleSourceName());
          // getWrapped().setFoo(foo);
          sw.println("%s.this.getWrapped().%s(%s);",
              type.getSimpleSourceName(), methodName, parameters[0].getName());
          // FooAutoBean.this.set("setFoo", foo);
          sw.println("%s.this.set(\"%s\", %s);", type.getSimpleSourceName(),
              methodName, parameters[0].getName());
          break;
        case CALL:
          // XXX How should freezing and calls work together?
          // sw.println("checkFrozen();");
          if (JPrimitiveType.VOID.equals(jmethod.getReturnType())) {
            // getWrapped().doFoo(params);
            sw.println("%s.this.getWrapped().%s(%s);",
                type.getSimpleSourceName(), methodName, arguments);
            // call("doFoo", null, params);
            sw.println("%s.this.call(\"%s\", null%s %s);",
                type.getSimpleSourceName(), methodName, arguments.length() > 0
                    ? "," : "", arguments);
          } else {
            // Type toReturn = getWrapped().doFoo(params);
            sw.println(
                "%s toReturn = %s.this.getWrapped().%s(%s);",
                ModelUtils.ensureBaseType(jmethod.getReturnType()).getQualifiedSourceName(),
                type.getSimpleSourceName(), methodName, arguments);
            // Non-value types might need to be wrapped
            writeReturnWrapper(sw, type, method);
            // call("doFoo", toReturn, params);
            sw.println("%s.this.call(\"%s\", toReturn%s %s);",
View Full Code Here

      }
    }

    /* Nope. Maybe a @UiFactory will make it */

    JMethod factoryMethod = writer.getOwnerClass().getUiFactoryMethod(
        resourceType);
    if (factoryMethod != null) {
      String initializer;
      if (writer.getDesignTime().isDesignTime()) {
        String typeName = factoryMethod.getReturnType().getQualifiedSourceName();
        initializer = writer.getDesignTime().getProvidedFactory(typeName,
            factoryMethod.getName(), "");
      } else {
        initializer = String.format("owner.%s()", factoryMethod.getName());
      }
      fieldWriter.setInitializer(initializer);
    }

    /*
 
View Full Code Here

              break;
            }
          }
        }

        JMethod getter = search.findMethod(getterName, new JType[0]);
        if (getter != null) {
          JType returnType = getter.getReturnType();
          lookingAt = returnType.isClassOrInterface();
          if (lookingAt == null) {
            poison(foundPrimitiveMessage(returnType,
                interstitialGetters.toString(), path));
            return;
View Full Code Here

      // GET, SET, or CALL
      Action action = Action.which(method);
      builder.setAction(action);
      if (Action.CALL.equals(action)) {
        JMethod staticImpl = findStaticImpl(beanType, method);
        if (staticImpl == null && objectMethods.contains(method)) {
          // Don't complain about lack of implementation for Object methods
          continue;
        }
        builder.setStaticImp(staticImpl);
View Full Code Here

          + benchmarkClass, e);
    }

    // Add all of the benchmark methods
    for (int i = 0; i < testMethods.size(); ++i) {
      JMethod method = (JMethod) testMethods.get(i);
      String methodName = method.getName();
      String methodCategoryType = getSimpleMetaData(method,
          GWT_BENCHMARK_CATEGORY);
      if (methodCategoryType == null) {
        methodCategoryType = categoryType;
      }
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.typeinfo.JMethod

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.