Package com.google.gwt.core.ext

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


                logger.log(TreeLogger.ERROR, "", e);
                throw new UnableToCompleteException();
            }
        }

        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + '.' + className);
    }
View Full Code Here


  @Override
  public RebindResult create(TreeLogger logger, GeneratorContext context)
      throws UnableToCompleteException
  {
    this.logger = logger;
    RebindResult result = super.create(logger, context);
   
    String asyncServiceTypeName = result.getResultTypeName();
   
    return createAsyncWrapper(context, asyncServiceTypeName);
  }
View Full Code Here

    JClassType serviceAsync = context.getTypeOracle().findType(serviceIntf.getQualifiedSourceName() + "Async");
    String asyncWrapperName = getProxyWrapperQualifiedName();

    if (checkAlreadyGenerated(context, asyncWrapperName))
    {
      return new RebindResult(RebindMode.USE_EXISTING, asyncWrapperName);
    }

    SourceWriter srcWriter = getSourceWriter(logger, context, asyncServiceTypeName, asyncWrapperName);
      if (srcWriter == null)
    {
      return new RebindResult(RebindMode.USE_EXISTING, asyncWrapperName);
    }

    generateWrapperProxyFields(srcWriter, asyncServiceTypeName);

    generateWrapperProxyContructor(srcWriter);

    generateProxyWrapperMethods(srcWriter, serviceAsync);
   
    if (this.hasSyncTokenMethod)
    {
      generateProxyWrapperStartMethod(srcWriter);

      generateProxyWrapperEndMethod(srcWriter);
     
      generateProxyWrapperUpdateTokenMethod(srcWriter);
     
      generateSetServiceEntryPointMethod(srcWriter);
    }
   
      srcWriter.commit(logger);
     
      return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, asyncWrapperName);
  }
View Full Code Here

   
    AbstractProxyCreator proxy = createProxy(logger, context, baseIntf);
    String returnType = proxy.create();
    if (returnType == null)
    {
        return new RebindResult(RebindMode.USE_EXISTING, typeName);
    }
    else if (proxy.isCacheable())
    {
        return new RebindResult(RebindMode.USE_PARTIAL_CACHED, returnType);
    }
    else
    {
        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, returnType);
    }
  }
View Full Code Here

        logger.log(TreeLogger.TRACE, msg);
      }
    }

    if (useCache) {
      return new RebindResult(RebindMode.USE_ALL_CACHED, typeName);
    }

    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = generatorContext.getTypeOracle();

    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);

    // Ensure that the requested type exists
    if (sourceType == null) {
      logger.log(TreeLogger.ERROR, "Could not find requested typeName");
      throw new UnableToCompleteException();
    } else if (sourceType.isInterface() == null) {
      // The incoming type wasn't a plain interface, we don't support
      // abstract base classes
      logger.log(TreeLogger.ERROR, sourceType.getQualifiedSourceName()
          + " is not an interface.", null);
      throw new UnableToCompleteException();
    }

    /*
     * This associates the methods to implement with the ResourceGenerator class
     * that will generate the implementations of those methods.
     */
    Map<Class<? extends ResourceGenerator>, List<JMethod>> taskList = createTaskList(
        logger, typeOracle, sourceType);

    /*
     * Check the resource generators associated with our taskList, and see if
     * they all support generator result caching.
     */
    boolean canBeCacheable = checkResourceGeneratorCacheability(
        generatorContext, taskList);

    /*
     * Additional objects that hold state during the generation process.
     */
    AbstractResourceContext resourceContext = createResourceContext(logger,
        generatorContext, sourceType);
    FieldsImpl fields = new FieldsImpl();
    RequirementsImpl requirements = new RequirementsImpl(
        generatorContext.getPropertyOracle(), canBeCacheable);
    resourceContext.setRequirements(requirements);
    doAddFieldsAndRequirements(logger, generatorContext, fields, requirements);

    /*
     * Add our source type (and it's supertypes) as a requirement.  Note further
     * types may be added during the processing of the taskList.
     */
    requirements.addTypeHierarchy(sourceType);

    /*
     * Initialize the ResourceGenerators and prepare them for subsequent code
     * generation.
     */
    Map<ResourceGenerator, List<JMethod>> generators = initAndPrepare(logger,
        taskList, resourceContext, requirements);

    /*
     * Now that the ResourceGenerators have been initialized and prepared, we
     * can compute the actual name of the implementation class in order to
     * ensure that we use a distinct name between permutations.
     */
    String generatedSimpleSourceName = generateSimpleSourceName(logger,
        resourceContext, requirements);
    String packageName = sourceType.getPackage().getName();
    String createdClassName = packageName + "." + generatedSimpleSourceName;

    PrintWriter out = generatorContext.tryCreate(logger, packageName,
        generatedSimpleSourceName);

    // If an implementation already exists, we don't need to do any work
    if (out != null) {
      // There is actual work to do
      doCreateBundleForPermutation(logger, generatorContext, fields,
          generatedSimpleSourceName);
      // Begin writing the generated source.
      ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
          packageName, generatedSimpleSourceName);

      // The generated class needs to be able to determine the module base URL
      f.addImport(GWT.class.getName());

      // Used by the map methods
      f.addImport(ResourcePrototype.class.getName());

      // The whole point of this exercise
      f.addImplementedInterface(sourceType.getQualifiedSourceName());

      // All source gets written through this Writer
      SourceWriter sw = f.createSourceWriter(generatorContext, out);

      // Set the now-calculated simple source name
      resourceContext.setSimpleSourceName(generatedSimpleSourceName);

      JParameterizedType hashMapStringResource = getHashMapStringResource(typeOracle);
      String resourceMapField = fields.define(hashMapStringResource, "resourceMap");

      // Write a static instance for use by the static initializers.
      sw.print("private static " + generatedSimpleSourceName + " ");
      sw.println(INSTANCE_NAME + " = new " + generatedSimpleSourceName + "();");

      // Write the generated code to disk
      createFieldsAndAssignments(logger, sw, generators, resourceContext,
          fields);

      // Print the accumulated field definitions
      sw.println(fields.getCode());

      /*
       * The map-accessor methods use JSNI and need a fully-qualified class
       * name, but should not include any sub-bundles.
       */
      taskList.remove(BundleResourceGenerator.class);
      writeMapMethods(sw, taskList, hashMapStringResource, resourceMapField);

      sw.commit(logger);
    }

    finish(logger, resourceContext, generators.keySet());
    doFinish(logger);

    if (canBeCacheable) {
      // remember the current set of required properties, and their values
      CachedPropertyInformation cpi = new CachedPropertyInformation(logger,
          generatorContext.getPropertyOracle(),
          requirements.getPermutationAxes(),
          requirements.getConfigurationPropertyNames());

      // remember the last modified times for required source types
      Map<String, Long> cti = requirements.getTypeLastModifiedTimes();

      // remember the required resources
      Map<String, URL> cri = requirements.getResolvedResources();

      // create a new cacheable result
      RebindResult result = new RebindResult(RebindMode.USE_ALL_NEW, createdClassName);

      // add data to be returned the next time the generator is run
      result.putClientData(CACHED_PROPERTY_INFORMATION, cpi);
      result.putClientData(CACHED_RESOURCE_INFORMATION, (Serializable) cri);
      result.putClientData(CACHED_TYPE_INFORMATION, (Serializable) cti);

      return result;
    } else {
      // If we can't be cacheable, don't return a cacheable result
      return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING,
          createdClassName);
    }
  }
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, context);
      typesSentFromBrowserBuilder.setTypeFilter(blacklistTypeFilter);
      SerializableTypeOracleBuilder typesSentToBrowserBuilder =
          new SerializableTypeOracleBuilder(logger, 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

   * {@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

        if (cachedResult != null) {
          genCtx.setCachedGeneratorResult(cachedResult);
        }

        // realize the rule (call a generator, or do type replacement, etc.)
        RebindResult result = rule.realize(logger, genCtx, typeName);

        // handle rebind result caching (if enabled)
        String resultTypeName =
            processCacheableResult(logger, rule, typeName, cachedResult, result);
View Full Code Here

  @Override
  public RebindResult realize(TreeLogger logger,
      StandardGeneratorContext context, String typeName)
      throws UnableToCompleteException {
    return new RebindResult(
        RebindMode.USE_EXISTING, replacementTypeName);
  }
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.