Package com.google.gwt.core.ext

Examples of com.google.gwt.core.ext.RebindResult


   * {@link #runGeneratorIncrementally} should be used instead.
   */
  public String runGenerator(TreeLogger logger, Class<? extends Generator> generatorClass,
      String typeName) throws UnableToCompleteException {

    RebindResult result = runGeneratorIncrementally(logger, generatorClass, typeName);

    return result.getResultTypeName();
  }
View Full Code Here


    Event generatorEvent =
        SpeedTracerLogger.start(type, "class", generatorClassName, "type", typeName);

    PropertyOracle originalPropertyOracle = propertyOracle;
    try {
      RebindResult result;
      // TODO(stalcup): refactor the Generator/PropertyOracle system (in a potentially backwards
      // incompatible way) so that all Generators are forced to accurately declare the names of
      // properties they care about.
      propertyOracle = new SubsetFilteringPropertyOracle(
          RuleGenerateWith.getAccessedPropertyNames(generator.getClass()), originalPropertyOracle,
          generatorClassName + "'s RunsLocal annotation may need to be updated.");
      if (generator instanceof IncrementalGenerator) {
        IncrementalGenerator incGenerator = (IncrementalGenerator) generator;

        // check version id for any previously cached rebind result
        if (cachedRebindResult != null) {
          Long cachedVersionId = (Long) cachedRebindResult.getClientData(GENERATOR_VERSION_ID_KEY);
          if (cachedVersionId != null && cachedVersionId != incGenerator.getVersionId()) {
            // remove from context
            if (logger.isLoggable(TreeLogger.TRACE)) {
              logger.log(TreeLogger.TRACE, "Got version mismatch with cached generator result for "
                  + typeName + ", invalidating cached result");
            }
            cachedRebindResult = null;
          }
        }

        // run the generator
        result = incGenerator.generateIncrementally(logger, this, typeName);

        // add version id to the returned result
        result.putClientData(GENERATOR_VERSION_ID_KEY, incGenerator.getVersionId());
      } else {
        // run a non-incremental generator
        result = IncrementalGenerator.generateNonIncrementally(logger, generator, this, typeName);
      }

      if (loggable) {
        long after = System.currentTimeMillis();
        msg =
            "Generator returned type '" + result.getResultTypeName() + "; mode "
                + result.getRebindMode() + "; in " + (after - before) + " ms";
        logger.log(TreeLogger.DEBUG, msg, null);
      }
      return result;
    } catch (AssertionError e) {
      // Catch and log the assertion as a convenience to the developer
View Full Code Here

      RemoteServiceAsyncValidator.logValidAsyncInterfaceDeclaration(logger, serviceIntf);
      throw new UnableToCompleteException();
    }

    if (checkAlreadyGenerated(typeOracle, serviceIntf)) {
      return new RebindResult(RebindMode.USE_EXISTING, getProxyQualifiedName());
    }

    // Make sure that the async and synchronous versions of the RemoteService
    // agree with one another
    //
    RemoteServiceAsyncValidator rsav = new RemoteServiceAsyncValidator(logger, typeOracle);
    Map<JMethod, JMethod> syncMethToAsyncMethMap = rsav.validate(logger, serviceIntf, serviceAsync);

    final PropertyOracle propertyOracle = context.getPropertyOracle();

    // Load the blacklist/whitelist
    TypeFilter blacklistTypeFilter = new BlacklistTypeFilter(logger, propertyOracle);

    // Determine the set of serializable types
    Event event = SpeedTracerLogger.start(CompilerEventType.GENERATOR_RPC_STOB);
    SerializableTypeOracle typesSentFromBrowser;
    SerializableTypeOracle typesSentToBrowser;
    String rpcLog = null;
    try {
      SerializableTypeOracleBuilder typesSentFromBrowserBuilder =
          new SerializableTypeOracleBuilder(logger, propertyOracle, context);
      typesSentFromBrowserBuilder.setTypeFilter(blacklistTypeFilter);
      SerializableTypeOracleBuilder typesSentToBrowserBuilder =
          new SerializableTypeOracleBuilder(logger, propertyOracle, context);
      typesSentToBrowserBuilder.setTypeFilter(blacklistTypeFilter);

      addRoots(logger, typeOracle, typesSentFromBrowserBuilder, typesSentToBrowserBuilder);

      // Decide what types to send in each direction.
      {
        if (logger.isLoggable(TreeLogger.Type.DEBUG)) {
          // Log the decisions to a string that will be written later in this method
          StringWriter stringWriter = new StringWriter();
          PrintWriter writer = new PrintWriter(stringWriter);

          typesSentFromBrowserBuilder.setLogOutputWriter(writer);
          typesSentToBrowserBuilder.setLogOutputWriter(writer);

          writer.write("====================================\n");
          writer.write("Types potentially sent from browser:\n");
          writer.write("====================================\n\n");
          writer.flush();
          typesSentFromBrowser = typesSentFromBrowserBuilder.build(logger);

          writer.write("===================================\n");
          writer.write("Types potentially sent from server:\n");
          writer.write("===================================\n\n");
          writer.flush();
          typesSentToBrowser = typesSentToBrowserBuilder.build(logger);

          writer.close();
          rpcLog = stringWriter.toString();
        } else {
          typesSentFromBrowser = typesSentFromBrowserBuilder.build(logger);
          typesSentToBrowser = typesSentToBrowserBuilder.build(logger);
        }
      }
    } finally {
      event.end();
    }

    // Check previous cached result, to see if we can return now
    if (checkCachedGeneratorResultValid(logger, context, typesSentFromBrowser, typesSentToBrowser)) {
      logger.log(TreeLogger.TRACE, "Reusing all cached artifacts for " + getProxyQualifiedName());
      return new RebindResult(RebindMode.USE_ALL_CACHED, getProxyQualifiedName());
    }

    try {
      ConfigurationProperty prop =
          context.getPropertyOracle().getConfigurationProperty(
              TypeSerializerCreator.GWT_ELIDE_TYPE_NAMES_FROM_RPC);
      elideTypeNames = Boolean.parseBoolean(prop.getValues().get(0));
    } catch (BadPropertyValueException e) {
      logger.log(TreeLogger.ERROR, "Configuration property "
          + TypeSerializerCreator.GWT_ELIDE_TYPE_NAMES_FROM_RPC
          + " is not defined. Is RemoteService.gwt.xml inherited?");
      throw new UnableToCompleteException();
    }

    SourceWriter srcWriter = getSourceWriter(logger, context, serviceAsync);
    if (srcWriter == null) {
      // don't expect this to occur, but could happen if an instance was
      // recently generated but not yet committed
      return new RebindResult(RebindMode.USE_EXISTING, getProxyQualifiedName());
    }

    generateTypeHandlers(logger, context, typesSentFromBrowser, typesSentToBrowser);

    String serializationPolicyStrongName =
        writeSerializationPolicyFile(logger, context, typesSentFromBrowser, typesSentToBrowser);

    String remoteServiceInterfaceName =
        elideTypeNames ? TypeNameObfuscator.SERVICE_INTERFACE_ID : SerializationUtils
            .getRpcTypeName(serviceIntf);
    generateProxyFields(srcWriter, typesSentFromBrowser, serializationPolicyStrongName,
        remoteServiceInterfaceName);

    generateProxyContructor(srcWriter);

    generateProxyMethods(srcWriter, typesSentFromBrowser, typeOracle, syncMethToAsyncMethMap);

    generateStreamWriterOverride(srcWriter);

    generateCheckRpcTokenTypeOverride(srcWriter, typeOracle, typesSentFromBrowser);

    srcWriter.commit(logger);

    if (rpcLog != null) {
      // Create an artifact explaining STOB's decisions. It will be emitted by
      // RpcLogLinker
      context.commitArtifact(logger, new RpcLogArtifact(serviceIntf.getQualifiedSourceName(),
          serializationPolicyStrongName, rpcLog));
    }

    if (checkGeneratorResultCacheability(context)) {
      /*
       * Create a new cacheable result. The mode is set to
       * RebindMode.USE_PARTIAL_CACHED, since we are allowing reuse of cached
       * results for field serializers, when available, but all other types have
       * been newly generated.
       */
      RebindResult result =
          new RebindResult(RebindMode.USE_PARTIAL_CACHED, getProxyQualifiedName());

      // Remember the type info that we care about for cache reuse testing.
      CachedRpcTypeInformation cti =
          new CachedRpcTypeInformation(typesSentFromBrowser, typesSentToBrowser,
              customSerializersUsed, typesNotUsingCustomSerializers);
      CachedPropertyInformation cpi =
          new CachedPropertyInformation(logger, context.getPropertyOracle(), selectionPropsToCheck,
              configPropsToCheck);
      result.putClientData(CACHED_TYPE_INFO_KEY, cti);
      result.putClientData(CACHED_PROPERTY_INFO_KEY, cpi);

      return result;
    } else {
      return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, getProxyQualifiedName());
    }
  }
View Full Code Here

    final MetaClass cachedType = cachedPortableTypes.get(fullyQualifiedTypeName);
   
    if (cachedType != null && cachedType.hashContent() == type.hashContent()
            && context.isGeneratorResultCachingEnabled()) {
      log.debug("Reusing cached marshaller for "  + fullyQualifiedTypeName);
      return new RebindResult(RebindMode.USE_ALL_CACHED, marshallerTypeName);
    }
    else {
      final PrintWriter printWriter = context.tryCreate(logger, packageName, className);
      if (printWriter == null) {
        return new RebindResult(RebindMode.USE_EXISTING, marshallerTypeName);
      }
      log.debug("Generating marshaller for " + fullyQualifiedTypeName);
      generateMarshaller(context, type, className, marshallerTypeName, logger, printWriter);
      cachedPortableTypes.put(fullyQualifiedTypeName, type);
      return new RebindResult(RebindMode.USE_ALL_NEW, marshallerTypeName);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.RebindResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.