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

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

Introduction

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

Prototype

JMethod isMethod();

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  ww  w .j  a  va2  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;//from ww w .j  a  va  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("};");
    }
}