Example usage for com.google.gwt.dev.jjs.ast JDeclaredType getJavahSignatureName

List of usage examples for com.google.gwt.dev.jjs.ast JDeclaredType getJavahSignatureName

Introduction

In this page you can find the example usage for com.google.gwt.dev.jjs.ast JDeclaredType getJavahSignatureName.

Prototype

@Override
    public String getJavahSignatureName() 

Source Link

Usage

From source file:xapi.dev.generators.AsyncProxyGenerator.java

License:Open Source License

/**
 * @throws ClassNotFoundException/*from  www  .  j a  v  a  2  s.c  om*/
 */
public static InjectionCallbackArtifact setupAsyncCallback(TreeLogger logger, GeneratorContext context,
        JClassType singletonType, JDeclaredType callbackType)
        throws ClassNotFoundException, UnableToCompleteException {
    PlatformSet platforms = CurrentGwtPlatform.getPlatforms(context);

    logger = logger.branch(Type.TRACE,
            "Binding callback " + callbackType.getName() + " to " + singletonType.getQualifiedSourceName());

    JClassType winningCallback = null;
    SingletonOverride winningCallbackOverride = null;
    logger.log(Type.WARN, "Checking " + callbackType.getName() + " : " + callbackType.getJavahSignatureName());
    JClassType providerType = context.getTypeOracle().findType(SourceUtil.toSourceName(callbackType.getName()));
    for (JClassType subtype : providerType.getSubtypes()) {
        if (winningCallback == null) {
            SingletonDefault singletonDefault = subtype.getAnnotation(SingletonDefault.class);
            // make sure this default is not for a different platform.
            if (singletonDefault != null && platforms.isAllowedType(subtype)) {
                winningCallback = subtype;
                continue;
            }
        }
        SingletonOverride override = subtype.getAnnotation(SingletonOverride.class);
        if (override != null) {
            logger.log(Type.DEBUG, "Got subtype " + subtype + " : " + " - prodMode: " + context.isProdMode());
            if (platforms.isAllowedType(subtype)) {
                if (winningCallbackOverride != null) {
                    if (winningCallbackOverride.priority() > override.priority())
                        continue;
                }
                winningCallbackOverride = override;
                winningCallback = subtype;
            }
        }
    }
    if (winningCallback == null) {
        logger.log(Type.WARN, "No callback type override found, using " + providerType.getQualifiedSourceName()
                + " : " + providerType.getJNISignature());
        winningCallback = providerType;// no matches, resort to instantiate the class sent.
        // TODO sanity check here
    }

    JClassType targetType = singletonType;
    SingletonOverride winningOverride = null;
    JClassType winningType = null;
    for (JClassType subtype : singletonType.getSubtypes()) {
        if (winningType == null) {
            SingletonDefault singletonDefault = subtype.getAnnotation(SingletonDefault.class);
            if (singletonDefault != null && platforms.isAllowedType(subtype)) {
                winningType = subtype;
                continue;
            }
        }
        SingletonOverride override = subtype.getAnnotation(SingletonOverride.class);
        if (override != null) {
            logger.log(Type.DEBUG, "Got subtype " + subtype + " - prodMode: " + context.isProdMode());
            if (platforms.isAllowedType(subtype)) {
                if (winningOverride != null) {
                    if (winningOverride.priority() > override.priority())
                        continue;
                }
                winningOverride = override;
                winningType = subtype;
            }
        }
    }
    if (winningType == null) {
        winningType = targetType;// no matches, resort to instantiate the class sent.
        // TODO sanity check here
    }

    InjectionCallbackArtifact artifact = AbstractInjectionGenerator.ensureAsyncInjected(logger,
            singletonType.getPackage().getName(), singletonType.getName(), winningType.getQualifiedSourceName(),
            context);
    // TODO: switch between service-centric splits, or callback-centric splits.
    artifact.addCallback(winningCallback.getQualifiedSourceName());
    context.commitArtifact(logger, artifact);

    return artifact;
}