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

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

Introduction

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

Prototype

String getName();

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;//from  w w  w.j a v  a  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 = 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;/*from w  w w  .  j  a  v  a  2  s .c om*/
                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.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//from  www  .  j a v a  2  s .  c  o 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   www .  j ava2  s. com*/
    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.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.
 *//*from  w w w .  j  ava 2  s.c  om*/
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.GeneratorUtils.java

License:Apache License

/**
 * Fabricates the name of a variable for use in a method body.
 * // w  w w  .  j  av  a  2  s  .  c om
 * <p>
 * This method ensures that the returned name is not used as parameter name.
 * </p>
 */
public static String getVariableName(String name, JParameter[] params) {
    for (JParameter param : params) {
        if (name.equals(param.getName())) {
            return getVariableName("_" + name, params);
        }
    }
    return name;
}

From source file:com.google.gwt.testing.easygwtmock.rebind.MocksGenerator.java

License:Apache License

private void printMatchingParameters(SourceWriter out, JConstructor constructorToCall) {
    JParameter[] params = constructorToCall.getParameters();
    for (int i = 0; i < params.length; i++) {
        if (i > 0) {
            out.print(", ");
        }// w  w w . ja va 2s .co  m
        JParameter param = params[i];
        out.print(param.getType().getParameterizedQualifiedSourceName());
        out.print(" ");
        out.print(param.getName());
    }
}

From source file:com.google.gwt.testing.easygwtmock.rebind.MocksGenerator.java

License:Apache License

/**
 * Returns a variable name that doesn't collide with any of the argument names.
 * The returned variable name starts with the provided prefix.
 *///from  w  w w . j  a v a  2s.co m
private String freeVariableName(String prefix, JParameter[] args) {
    String nextVar = prefix;

    Set<String> usedNames = new HashSet<String>();
    for (JParameter arg : args) {
        usedNames.add(arg.getName());
    }

    int varCount = 0;
    while (usedNames.contains(nextVar)) {
        nextVar = prefix + varCount++;
    }
    return nextVar;
}

From source file:com.google.web.bindery.autobean.gwt.rebind.AutoBeanFactoryGenerator.java

License:Apache License

private String getBaseMethodDeclaration(JMethod jmethod) {
    // Foo foo, Bar bar, Baz baz
    StringBuilder parameters = new StringBuilder();
    for (JParameter param : jmethod.getParameters()) {
        parameters.append(",").append(ModelUtils.getQualifiedBaseSourceName(param.getType())).append(" ")
                .append(param.getName());
    }//from   w ww .  j  a  v  a  2  s  .  co m
    if (parameters.length() > 0) {
        parameters = parameters.deleteCharAt(0);
    }

    StringBuilder throwsDeclaration = new StringBuilder();
    if (jmethod.getThrows().length > 0) {
        for (JType thrown : jmethod.getThrows()) {
            throwsDeclaration.append(". ").append(ModelUtils.getQualifiedBaseSourceName(thrown));
        }
        throwsDeclaration.deleteCharAt(0);
        throwsDeclaration.insert(0, "throws ");
    }
    String returnName = ModelUtils.getQualifiedBaseSourceName(jmethod.getReturnType());
    assert !returnName.contains("extends");
    return String.format("%s %s(%s) %s", returnName, jmethod.getName(), parameters, throwsDeclaration);
}

From source file:com.google.web.bindery.autobean.gwt.rebind.AutoBeanFactoryGenerator.java

License:Apache License

/**
 * For interfaces that consist of nothing more than getters and setters,
 * create a map-based implementation that will allow the AutoBean's internal
 * state to be easily consumed./*w  ww .j av  a 2 s  . c  om*/
 */
private void writeCreateSimpleBean(SourceWriter sw, AutoBeanType type) {
    sw.println("@Override protected %s createSimplePeer() {", type.getPeerType().getQualifiedSourceName());
    sw.indent();
    // return new FooIntf() {
    sw.println("return new %s() {", type.getPeerType().getQualifiedSourceName());
    sw.indent();
    sw.println("private final %s data = %s.this.data;", Splittable.class.getCanonicalName(),
            type.getQualifiedSourceName());
    for (AutoBeanMethod method : type.getMethods()) {
        JMethod jmethod = method.getMethod();
        JType returnType = jmethod.getReturnType();
        sw.println("public %s {", getBaseMethodDeclaration(jmethod));
        sw.indent();
        switch (method.getAction()) {
        case GET: {
            String castType;
            if (returnType.isPrimitive() != null) {
                castType = returnType.isPrimitive().getQualifiedBoxedSourceName();
                // Boolean toReturn = Other.this.getOrReify("foo");
                sw.println("%s toReturn = %s.this.getOrReify(\"%s\");", castType, type.getSimpleSourceName(),
                        method.getPropertyName());
                // return toReturn == null ? false : toReturn;
                sw.println("return toReturn == null ? %s : toReturn;",
                        returnType.isPrimitive().getUninitializedFieldExpression());
            } else if (returnType
                    .equals(context.getTypeOracle().findType(Splittable.class.getCanonicalName()))) {
                sw.println("return data.isNull(\"%1$s\") ? null : data.get(\"%1$s\");",
                        method.getPropertyName());
            } else {
                // return (ReturnType) Outer.this.getOrReify(\"foo\");
                castType = ModelUtils.getQualifiedBaseSourceName(returnType);
                sw.println("return (%s) %s.this.getOrReify(\"%s\");", castType, type.getSimpleSourceName(),
                        method.getPropertyName());
            }
        }
            break;
        case SET:
        case SET_BUILDER: {
            JParameter param = jmethod.getParameters()[0];
            // Other.this.setProperty("foo", parameter);
            sw.println("%s.this.setProperty(\"%s\", %s);", type.getSimpleSourceName(), method.getPropertyName(),
                    param.getName());
            if (JBeanMethod.SET_BUILDER.equals(method.getAction())) {
                sw.println("return this;");
            }
            break;
        }
        case CALL:
            // return com.example.Owner.staticMethod(Outer.this, param,
            // param);
            JMethod staticImpl = method.getStaticImpl();
            if (!returnType.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;
        default:
            throw new RuntimeException();
        }
        sw.outdent();
        sw.println("}");
    }
    sw.outdent();
    sw.println("};");
    sw.outdent();
    sw.println("}");
}