Example usage for com.google.gwt.core.ext.typeinfo JParameter getType

List of usage examples for com.google.gwt.core.ext.typeinfo JParameter getType

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JParameter getType.

Prototype

JType getType();

Source Link

Usage

From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private void printMethods(JClassType c, String varName, String methodType, JAbstractMethod[] methodTypes) {
    if (methodTypes != null) {
        pb(varName + "." + methodType.toLowerCase() + "s = new " + methodType + "[] {");
        for (JAbstractMethod m : methodTypes) {
            MethodStub stub = new MethodStub();
            stub.isPublic = m.isPublic();
            stub.enclosingType = getType(c);
            if (m.isMethod() != null) {
                stub.isMethod = true;/* w w w . ja v a  2 s .c  o  m*/
                stub.returnType = getType(m.isMethod().getReturnType());
                stub.isStatic = m.isMethod().isStatic();
                stub.isAbstract = m.isMethod().isAbstract();
                stub.isNative = m.isMethod().isAbstract();
                stub.isFinal = m.isMethod().isFinal();

            } else {
                if (m.isPrivate() || m.isDefaultAccess()) {
                    logger.log(Type.INFO, "Skipping non-visible constructor for class " + c.getName());
                    continue;
                }
                if (m.getEnclosingType().isFinal() && !m.isPublic()) {
                    logger.log(Type.INFO, "Skipping non-public constructor for final class" + c.getName());
                    continue;
                }
                stub.isConstructor = true;
                stub.returnType = stub.enclosingType;
            }

            stub.jnsi = "";
            stub.methodId = nextId();
            stub.name = m.getName();
            methodStubs.add(stub);

            String methodAnnotations = getAnnotations(m.getDeclaredAnnotations());

            pb("new " + methodType + "(\"" + m.getName() + "\", ");
            pb(stub.enclosingType + ", ");
            pb(stub.returnType + ", ");

            pb("new Parameter[] {");
            if (m.getParameters() != null) {
                for (JParameter p : m.getParameters()) {
                    stub.parameterTypes.add(getType(p.getType()));
                    stub.jnsi += p.getType().getErasedType().getJNISignature();
                    pb("new Parameter(\"" + p.getName() + "\", " + getType(p.getType()) + ", \""
                            + p.getType().getJNISignature() + "\"), ");
                }
            }
            pb("}, ");

            pb(stub.isAbstract + ", " + stub.isFinal + ", " + stub.isStatic + ", " + m.isDefaultAccess() + ", "
                    + m.isPrivate() + ", " + m.isProtected() + ", " + m.isPublic() + ", " + stub.isNative + ", "
                    + m.isVarArgs() + ", " + stub.isMethod + ", " + stub.isConstructor + ", " + stub.methodId
                    + ", " + methodAnnotations + "),");
        }
        pb("};");
    }
}

From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private void createTypeInvokables(JClassType c, String varName, String methodType,
        JAbstractMethod[] methodTypes) {
    if (methodTypes != null && methodTypes.length > 0) {
        pb(varName + "." + methodType.toLowerCase() + "s = new " + methodType + "[] {");
        for (JAbstractMethod m : methodTypes) {
            MethodStub stub = new MethodStub();
            stub.isPublic = m.isPublic();
            stub.enclosingType = getType(c);
            if (m.isMethod() != null) {
                stub.isMethod = true;// w w w.  j  a  va  2s  .c o m
                stub.returnType = getType(m.isMethod().getReturnType());
                stub.isStatic = m.isMethod().isStatic();
                stub.isAbstract = m.isMethod().isAbstract();
                stub.isNative = m.isMethod().isAbstract();
                stub.isFinal = m.isMethod().isFinal();
            } else {
                if (m.isPrivate() || m.isDefaultAccess()) {
                    logger.log(Type.INFO, "Skipping non-visible constructor for class " + c.getName());
                    continue;
                }
                if (m.getEnclosingType().isFinal() && !m.isPublic()) {
                    logger.log(Type.INFO, "Skipping non-public constructor for final class" + c.getName());
                    continue;
                }
                stub.isConstructor = true;
                stub.returnType = stub.enclosingType;
            }
            stub.jnsi = "";
            stub.methodId = nextInvokableId++;
            stub.name = m.getName();
            methodStubs.add(stub);

            pbn("    new " + methodType + "(\"" + m.getName() + "\", ");
            pbn(stub.enclosingType + ", ");
            pbn(stub.returnType + ", ");

            if (m.getParameters() != null && m.getParameters().length > 0) {
                pbn("new Parameter[] {");
                for (JParameter p : m.getParameters()) {
                    stub.parameterTypes.add(getType(p.getType()));
                    stub.jnsi += p.getType().getErasedType().getJNISignature();
                    String paramName = (p.getName() + "__" + p.getType().getErasedType().getJNISignature())
                            .replaceAll("[/;\\[\\]]", "_");
                    String paramInstantiation = "new Parameter(\"" + p.getName() + "\", " + getType(p.getType())
                            + ", \"" + p.getType().getJNISignature() + "\")";
                    parameterName2ParameterInstantiation.put(paramName, paramInstantiation);
                    pbn(paramName + "(), ");
                }
                pbn("}, ");
            } else {
                pbn("EMPTY_PARAMETERS,");
            }

            pb(stub.isAbstract + ", " + stub.isFinal + ", " + stub.isStatic + ", " + m.isDefaultAccess() + ", "
                    + m.isPrivate() + ", " + m.isProtected() + ", " + m.isPublic() + ", " + stub.isNative + ", "
                    + m.isVarArgs() + ", " + stub.isMethod + ", " + stub.isConstructor + ", " + stub.methodId
                    + "," + getAnnotations(m.getDeclaredAnnotations()) + "),");
        }
        pb("};");
    }
}

From source file:com.cgxlib.xq.rebind.LazyGenerator.java

License:Apache License

public void generateMethod(SourceWriter sw, JMethod method, String nonLazyClass, String genClass,
        TreeLogger logger) throws UnableToCompleteException {

    JParameter[] params = method.getParameters();
    JTypeParameter gType = method.getReturnType().isTypeParameter();

    String retType = method.getReturnType().getParameterizedQualifiedSourceName();
    if (gType != null) {
        retType = "<" + gType.getParameterizedQualifiedSourceName() + " extends "
                + gType.getFirstBound().getQualifiedSourceName() + "> " + retType;
    }/*from  w w w . j  av  a 2  s .com*/
    sw.print("public final native " + retType + " " + method.getName());
    sw.print("(");
    int argNum = 0;
    for (JParameter param : params) {
        sw.print((argNum == 0 ? "" : ", ") + param.getType().getParameterizedQualifiedSourceName() + " arg"
                + argNum);
        argNum++;
    }
    sw.println(") /*-{");

    sw.indent();
    sw.println("var self=this;");
    sw.println("this.@" + genClass + "::closures.push(");
    sw.indent();
    sw.println("function() {");
    sw.indent();
    sw.print("self.@" + genClass + "::ctx=self.@" + genClass + "::ctx.@" + nonLazyClass + "::"
            + method.getName());
    sw.print(getJSNIParams(method));
    sw.print("(");
    for (int i = 0; i < argNum; i++) {
        sw.print("arg" + i + (i < argNum - 1 ? "," : ""));
    }

    sw.print(")");
    // special case, as() needs to invoke createLazy()
    if ("as".equals(method.getName())) {
        sw.print(".createLazy()");
    }
    sw.println(";");
    sw.outdent();
    sw.println("}");
    sw.outdent();
    sw.println(");");
    sw.println("return this;");
    sw.outdent();
    sw.println("}-*/;");
}

From source file:com.colinalworth.gwt.websockets.rebind.ServerCreator.java

License:Apache License

/**
 * Helper method to build up the list of types that can go over the wire
 * @param logger//from  w  w w  .  j  a va2  s.co m
 * @param serviceInterface
 * @param serviceSuperClass
 * @param serializerBuilder
 */
private void appendMethodParameters(TreeLogger logger, JClassType serviceInterface, Class<?> serviceSuperClass,
        SerializableTypeOracleBuilder serializerBuilder) {
    TreeLogger l = logger.branch(Type.DEBUG, "Adding params types to " + serviceInterface.getName());
    for (JMethod m : serviceInterface.getMethods()) {
        if (isRemoteMethod(m, serviceSuperClass)) {
            JParameter[] parameters = m.getParameters();
            for (int i = 0; i < parameters.length; i++) {
                JParameter param = parameters[i];
                if (i + 1 != m.getParameters().length || param.getType().isInterface() == null || !param
                        .getType().isInterface().getQualifiedSourceName().equals(Callback.class.getName())) {
                    serializerBuilder.addRootType(l, param.getType());
                }
            }
        }
    }
}

From source file:com.colinalworth.gwt.websockets.rebind.ServerCreator.java

License:Apache License

/**
 * Writes out the method to use to invoke a server call. Mostly derived from RPC's way of building proxy methods
 *
 * @param logger//  www .  j  a  v a 2s. co  m
 * @param context
 * @param sw
 * @param m
 */
private void printServerMethodBody(TreeLogger logger, GeneratorContext context, SourceWriter sw, JMethod m) {
    sw.println("%1$s {", m.getReadableDeclaration(false, true, true, true, true));
    sw.indent();

    sw.print("__sendMessage(\"%1$s\"", m.getName());
    StringBuilder sb = new StringBuilder();
    String callback = "null";
    JParameter[] parameters = m.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        JParameter param = parameters[i];
        if (i + 1 == parameters.length && param.getType().isInterface() != null
                && param.getType().isInterface().getQualifiedSourceName().equals(Callback.class.getName())) {
            callback = param.getName();
        } else {
            sb.append(",\n").append(param.getName());
        }
    }
    sw.print(",");
    sw.println(callback);
    sw.print(sb.toString());
    sw.println(");");

    sw.outdent();
    sw.println("}");
}

From source file:com.didactilab.gwt.phprpc.rebind.PhpServiceModelFileArtifact.java

License:Apache License

@Override
protected void getContents(TreeLogger logger, StringBuffer buffer) throws UnableToCompleteException {
    buffer.append("<?php\n\n");
    buffer.append("/** @gwtname ").append(type.getQualifiedSourceName()).append(" */\n");
    if (type.getEnclosingType() != null) {
        buffer.append("/** @enclosing ").append(type.getEnclosingType().getQualifiedSourceName())
                .append(" */\n");
    }//from w  ww  . j a  v a  2s  .c o m
    buffer.append("class ").append(type.getName()).append(" implements RemoteService {\n\n");

    for (JMethod method : type.getMethods()) {
        JType returnType = method.getReturnType();
        String returnTypeString = PhpTools.typeToString(returnType, false);
        if (method.getParameters().length != 0) {
            buffer.append("\t/**\n");
            for (JParameter param : method.getParameters()) {
                buffer.append("\t * @param ").append(PhpTools.typeToString(param.getType(), false));
                buffer.append(" $").append(param.getName()).append("\n");
            }
            buffer.append("\t * @return ").append(returnTypeString).append("\n");
            buffer.append("\t */\n");
        } else {
            buffer.append("\t/** @return ").append(returnTypeString).append(" */\n");
        }
        buffer.append("\t").append(PhpTools.getPhpVisibility(method)).append(" function ")
                .append(method.getName()).append("(");
        JParameter[] params = method.getParameters();
        for (int i = 0, c = params.length; i < c; i++) {
            buffer.append("$").append(params[i].getName());
            if (i < c - 1)
                buffer.append(", ");
        }
        buffer.append(") {\n\n");
        buffer.append("\t}\n\n");
    }
    buffer.append("}\n");
}

From source file:com.github.nmorel.gwtjackson.rebind.RebindConfiguration.java

License:Apache License

private MapperType[] getParameters(JType mappedType, JAbstractMethod method, boolean isSerializers) {
    if (!isSerializers && typeOracle.isEnumSupertype(mappedType)) {
        // For enums, the constructor requires the enum class. We just return an empty array and will handle it later
        if (method.getParameters().length == 1
                && Class.class.getName().equals(method.getParameters()[0].getType().getQualifiedSourceName())) {
            return new MapperType[0];
        } else {/*from  w  w  w  . j a va  2  s. com*/
            // Not a valid method to create enum deserializer
            return null;
        }
    }

    MapperType[] parameters = new MapperType[method.getParameters().length];
    for (int i = 0; i < method.getParameters().length; i++) {
        JParameter parameter = method.getParameters()[i];
        if (isSerializers) {
            if (typeOracle.isKeySerializer(parameter.getType())) {
                parameters[i] = MapperType.KEY_SERIALIZER;
            } else if (typeOracle.isJsonSerializer(parameter.getType())) {
                parameters[i] = MapperType.JSON_SERIALIZER;
            } else {
                // the parameter is unknown, we ignore this method
                return null;
            }
        } else {
            if (typeOracle.isKeyDeserializer(parameter.getType())) {
                parameters[i] = MapperType.KEY_DESERIALIZER;
            } else if (typeOracle.isJsonDeserializer(parameter.getType())) {
                parameters[i] = MapperType.JSON_DESERIALIZER;
            } else {
                // the parameter is unknown, we ignore this method
                return null;
            }
        }
    }
    return parameters;
}

From source file:com.google.appinventor.rebind.ExtendedServiceProxyGenerator.java

License:Open Source License

/**
 * Generate the implementation of a single method.
 *
 * @param out where to print the method to
 * @param method the method/*  w ww  .j a  va 2  s  .  c o m*/
 * @param typeName type name of the containing proxy class
 */
private void printMethod(PrintWriter out, JMethod method, String typeName) {
    // Build parameter lists
    int i = 0;
    StringBuilder actualParamsBuilder = new StringBuilder();
    StringBuilder formalParamsBuilder = new StringBuilder();
    for (JParameter param : method.getParameters()) {
        if (i != 0) {
            actualParamsBuilder.append(", ");
            formalParamsBuilder.append(", ");
        }

        String paramType = param.getType().getParameterizedQualifiedSourceName();
        String paramName = "p" + i++;
        actualParamsBuilder.append(paramName);
        formalParamsBuilder.append(paramType + " " + paramName);
    }
    String actualParams = actualParamsBuilder.toString();
    String formalParams = formalParamsBuilder.toString();

    // Information about the return type
    JType returnType = method.getReturnType();
    boolean hasReturnValue = !returnType.getSimpleSourceName().equals("void");

    JPrimitiveType primitiveReturnType = returnType.isPrimitive();
    String resultType = primitiveReturnType != null ? primitiveReturnType.getQualifiedBoxedSourceName()
            : returnType.getParameterizedQualifiedSourceName();

    String callbackType = AsyncCallback.class.getName() + "<" + resultType + ">";

    // Print method
    out.println("  public void " + method.getName() + "(" + formalParams + (formalParams.isEmpty() ? "" : ", ")
            + "final " + callbackType + " callback" + ") {");
    out.println("    fireStart(\"" + method.getName() + "\"" + (actualParams.isEmpty() ? "" : ", ")
            + actualParams + ");");
    out.println("    proxy." + method.getName() + "(" + actualParams + (actualParams.isEmpty() ? "" : ", ")
            + "new " + callbackType + "() {");
    out.println("      public void onSuccess(" + resultType + " result) {");
    out.println("        " + outcome(method, "Success", "result"));
    out.println("      }");
    out.println("      public void onFailure(Throwable caught) {");
    out.println("        " + outcome(method, "Failure", "caught"));
    out.println("      }");
    out.println("    });");
    out.println("  }");
}

From source file:com.google.code.gwt.database.rebind.GeneratorUtils.java

License:Apache License

/**
 * Returns the Type of the parameter with the specified name, or
 * <code>null</code> if not found.
 *//*  w w w .  j ava  2  s . c o  m*/
public static JType findType(String name, JParameter[] parameters) {
    for (JParameter param : parameters) {
        if (param.getName().equals(name)) {
            return param.getType();
        }
    }
    return null;
}

From source file:com.google.code.gwt.database.rebind.SqlProxyCreator.java

License:Apache License

/**
 * Generates the proxy method implementing the specified service.
 *//*from   ww w .  j a  v a 2  s .c o m*/
private void generateProxyServiceMethod(JMethod service) throws UnableToCompleteException {
    Select select = service.getAnnotation(Select.class);
    Update update = service.getAnnotation(Update.class);

    // Assertions:
    if (select == null && update == null) {
        logger.log(TreeLogger.ERROR, service.getName() + " has no @Select nor @Update annotation");
        throw new UnableToCompleteException();
    }
    if ((select == null || StringUtils.isEmpty(getSql(select)))
            && (update == null || StringUtils.isEmpty(getSql(update)))) {
        logger.log(TreeLogger.ERROR,
                service.getName() + ": @Select or @Update annotation has no SQL statement");
        throw new UnableToCompleteException();
    }
    JParameter[] params = service.getParameters();
    if (params.length == 0) {
        logger.log(TreeLogger.ERROR,
                "Method " + service.getName() + " must have at least one (callback) parameter");
        throw new UnableToCompleteException();
    }
    JParameter callback = params[params.length - 1];
    if (!genUtils.isAssignableToType(callback.getType(), Callback.class)) {
        logger.log(TreeLogger.ERROR, "The last parameter of method " + service.getName()
                + " is no valid Callback! Must be subtype of " + genUtils.getClassName(Callback.class));
        throw new UnableToCompleteException();
    }

    generateProxyServiceMethodJavadoc(service);

    sw.print("public final void " + service.getName() + "(");
    for (int i = 0; i < params.length; i++) {
        if (i > 0) {
            sw.print(", ");
        }
        sw.print("final " + genUtils.getClassName(params[i].getType()) + " " + params[i].getName());
    }
    sw.println(") {");
    sw.indent();

    // Depending on the callback type, create a service method body:
    ServiceMethodCreator creator = update != null
            ? createExecuteSqlCreator(service, getSql(update), update.foreach(), update)
            : createExecuteSqlCreator(service, getSql(select), null, select);

    creator.generateServiceMethodBody();

    // ends service method
    sw.outdent();
    sw.println("}");
}