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

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

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JAbstractMethod 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 www  .ja v  a 2s .  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 = 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  ww w.  j  av a2s .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.github.nmorel.gwtjackson.rebind.BeanJsonDeserializerCreator.java

License:Apache License

private MethodSpec buildInstanceBuilderCreateMethod() {
    JAbstractMethod method = beanInfo.getCreatorMethod().get();

    MethodSpec.Builder builder = MethodSpec.methodBuilder("create").addModifiers(Modifier.PRIVATE)
            .returns(typeName(beanInfo.getType()));

    StringBuilder parametersNameBuilder = new StringBuilder();
    int index = 0;
    for (Map.Entry<String, JParameter> parameterEntry : beanInfo.getCreatorParameters().entrySet()) {
        if (index > 0) {
            parametersNameBuilder.append(", ");
        }//  w  w  w.  ja va  2  s .  c o  m
        PropertyInfo property = properties.get(parameterEntry.getKey());

        String variableName = String.format(INSTANCE_BUILDER_VARIABLE_FORMAT, index++);
        builder.addParameter(typeName(property.getType()), variableName);
        parametersNameBuilder.append(variableName);
    }
    String parametersName = parametersNameBuilder.toString();

    if (method.isPrivate() || (!method.isPublic() && !mapperInfo.isSamePackage())) {
        // private method, we use jsni
        builder.addModifiers(Modifier.NATIVE);
        builder.addCode(JsniCodeBlockBuilder.builder()
                .addStatement("return $L($L)", method.getJsniSignature(), parametersName).build());
    } else {
        if (null != method.isConstructor()) {
            builder.addStatement("return new $T($L)", typeName(beanInfo.getType()), parametersName);
        } else {
            builder.addStatement("return $T.$L($L)", typeName(beanInfo.getType()), method.getName(),
                    parametersName);
        }
    }

    return builder.build();
}

From source file:com.gwtplatform.dispatch.rest.rebind.parameter.HttpParameterFactory.java

License:Apache License

private void error(JParameter parameter, String message) {
    JAbstractMethod method = parameter.getEnclosingMethod();
    String typeName = method.getEnclosingType().getQualifiedSourceName();
    String methodName = method.getName();
    String parameterName = parameter.getName();

    logger.error(String.format(message, typeName, methodName, parameterName));
}

From source file:fr.onevu.gwt.uibinder.rebind.JClassTypeAdapter.java

License:Apache License

/**
 * Adds expectations common to all method types (methods and constructors).
 *
 * @param realMember the java method/*www. j  a v  a  2 s  .  com*/
 * @param member the mock GWT method
 * @param enclosingType the type to which the method belongs
 */
private void addCommonAbstractMethodBehaviour(Member realMember, JAbstractMethod member,
        JClassType enclosingType) {
    // Attributes
    int modifiers = realMember.getModifiers();
    expect(member.isPublic()).andStubReturn(Modifier.isPublic(modifiers));
    expect(member.isProtected()).andStubReturn(Modifier.isProtected(modifiers));
    expect(member.isPrivate()).andStubReturn(Modifier.isPrivate(modifiers));
    expect(member.getName()).andStubReturn(realMember.getName());
    expect(member.getEnclosingType()).andStubReturn(enclosingType);
}

From source file:org.jboss.errai.ioc.rebind.ioc.codegen.meta.impl.gwt.GWTParameter.java

License:Apache License

GWTParameter(JParameter parameter, MetaMethod declaredBy) {
    this.parameter = parameter;
    this.declaredBy = declaredBy;

    try {/*from w  w w.ja  v a  2  s.  c  o m*/
        Class<?> cls = Class.forName(parameter.getEnclosingMethod().getEnclosingType().getQualifiedSourceName(),
                false, Thread.currentThread().getContextClassLoader());

        JAbstractMethod jMethod = parameter.getEnclosingMethod();

        int index = -1;
        for (int i = 0; i < jMethod.getParameters().length; i++) {
            if (jMethod.getParameters()[i].getName().equals(parameter.getName())) {
                index = i;
            }
        }

        Method method = null;
        try {
            method = cls.getDeclaredMethod(jMethod.getName(), InjectUtil.jParmToClass(jMethod.getParameters()));
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        annotations = method.getParameterAnnotations()[index];

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}