Example usage for com.google.gwt.dev.asm Type getType

List of usage examples for com.google.gwt.dev.asm Type getType

Introduction

In this page you can find the example usage for com.google.gwt.dev.asm Type getType.

Prototype

public static Type getType(final Class c) 

Source Link

Document

Returns the Java type corresponding to the given class.

Usage

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java

License:Apache License

/**
 * This method checks a RequestFactory interface.
 * <p>//from  w w  w. jav a  2s. c o  m
 * This method may be called repeatedly on a single instance of the validator.
 * Doing so will amortize type calculation costs. It does not perform any
 * checks as to whether or not the RequestContext could actually be generated
 * by the Generator.
 * <p>
 * Checks implemented:
 * <ul>
 * <li> <code>binaryName</code> implements RequestFactory</li>
 * <li>All referenced RequestContext types are valid</li>
 * </ul>
 * 
 * @param binaryName the binary name (e.g. {@link Class#getName()}) of the
 *          RequestContext subtype
 * @see #validateRequestContext(String)
 */
public void validateRequestFactory(String binaryName) {
    if (fastFail(binaryName)) {
        return;
    }

    Type requestFactoryType = Type.getObjectType(BinaryName.toInternalName(binaryName));
    ErrorContext logger = parentLogger.setType(requestFactoryType);

    // Quick sanity check for calling code
    if (!isAssignable(logger, Type.getType(RequestFactory.class), requestFactoryType)) {
        logger.poison("%s is not a %s", print(requestFactoryType), RequestFactory.class.getSimpleName());
        return;
    }

    // Validate each RequestContext method in the RF
    for (Method contextMethod : getMethodsInHierarchy(logger, requestFactoryType)) {
        Type returnType = contextMethod.getReturnType();
        if (isAssignable(logger, requestContextIntf, returnType)) {
            validateRequestContext(returnType.getClassName());
        }
    }

    maybeCheckExtraTypes(logger, requestFactoryType);
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java

License:Apache License

/**
 * This looks like it should be a utility method somewhere else, but I can't
 * find it./*ww w . j av a2 s. co m*/
 */
private Type getBoxedType(Type primitive) {
    switch (primitive.getSort()) {
    case Type.BOOLEAN:
        return Type.getType(Boolean.class);
    case Type.BYTE:
        return Type.getType(Byte.class);
    case Type.CHAR:
        return Type.getType(Character.class);
    case Type.DOUBLE:
        return Type.getType(Double.class);
    case Type.FLOAT:
        return Type.getType(Float.class);
    case Type.INT:
        return Type.getType(Integer.class);
    case Type.LONG:
        return Type.getType(Long.class);
    case Type.SHORT:
        return Type.getType(Short.class);
    case Type.VOID:
        return Type.getType(Void.class);
    }
    throw new RuntimeException(primitive.getDescriptor() + " is not a primitive type");
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryJarExtractor.java

License:Apache License

/**
 * Blocks until all work has been finished.
 *///from   w ww  . java2s  .  com
public void run() throws IOException {
    for (Class<?> seed : seeds) {
        processType("seeds", Type.getType(seed));
    }
    for (Map.Entry<String, byte[]> entry : resources.entrySet()) {
        writerService.submit(new EmitOneResource(entry.getKey(), entry.getValue()));
    }
    // Wait for all tasks to be completed
    while (!inProcess.isEmpty()) {
        try {
            Future<?> task = inProcess.take();
            task.get();
        } catch (InterruptedException retry) {
        } catch (ExecutionException e) {
            e.getCause().printStackTrace();
            executionFailed = true;
        }
    }
    emitter.close();
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryJarExtractor.java

License:Apache License

/**
 * Process the type represented by the descriptor, possibly returning a
 * rebased descriptor./*w  w  w .  j  ava 2s.  co  m*/
 */
private String processDescriptor(String sourceType, String desc) {
    if (desc == null) {
        return null;
    }
    return processType(sourceType, Type.getType(desc)).getDescriptor();
}

From source file:com.google.web.bindery.requestfactory.server.RequestFactoryJarExtractor.java

License:Apache License

/**
 * Process a type, possibly returning a rebased type.
 * //w w w.  ja v  a2  s .  c  o m
 * @param sourceType TODO
 */
private Type processType(String sourceType, Type type) {
    Type toReturn;
    synchronized (seen) {
        toReturn = seen.get(type);
        if (toReturn != null) {
            return toReturn;
        }
        toReturn = Type.getType(type.getDescriptor());
        seen.put(type, toReturn);
    }
    int sort = type.getSort();
    if (sort != Type.OBJECT && sort != Type.ARRAY) {
        return toReturn;
    }
    if (sort == Type.ARRAY) {
        processType(sourceType, type.getElementType());
        return toReturn;
    }
    assert type.getInternalName().charAt(0) != 'L';
    if (type.getInternalName().startsWith("java/") || type.getInternalName().startsWith("javax/")) {
        return toReturn;
    }
    if (VERBOSE) {
        System.out.println(sourceType + " -> " + type.getClassName());
    }
    Future<State> future = ex.submit(new ProcessOneType(type));
    inProcess.add(future);
    return toReturn;
}