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

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

Introduction

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

Prototype

JClassType getEnclosingType();

Source Link

Document

Gets the type in which this method or constructor was declared.

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  va 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   w  ww  . j av 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.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/*from  w  w w .j  a va 2 s  . c o  m*/
 * @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);
}