Make generator result caching framework api available publically.
Removes "Experimental" comment warnings.
Renames the class GeneratorExt to IncrementalGenerator.
Merges methods from GeneratorContextExt into GeneratorContext.
General refactoring and relocating of several support classes.
Added added support for versioning for incremental generators.
Review at http://gwt-code-reviews.appspot.com/1468804
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10492 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/CachedGeneratorResult.java b/dev/core/src/com/google/gwt/core/ext/CachedGeneratorResult.java
new file mode 100644
index 0000000..f2934c1
--- /dev/null
+++ b/dev/core/src/com/google/gwt/core/ext/CachedGeneratorResult.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+/**
+ * An interface to represent the cached results from a previous generator
+ * invocation. This is made available in the {@link GeneratorContext} to
+ * subsequent invocations of the same generator, when called under the same
+ * conditions (e.g. for the same rebind rule and requested type name).
+ *
+ * @see GeneratorContext#getCachedGeneratorResult
+ */
+public interface CachedGeneratorResult {
+ /**
+ * Retrieves cached client data by key.
+ */
+ Object getClientData(String key);
+
+ /**
+ * Returns the cached result rebind type name.
+ */
+ String getResultTypeName();
+
+ /**
+ * Returns the time this generator result was created.
+ */
+ long getTimeGenerated();
+
+ /**
+ * Check whether a given type is present in the cached result.
+ */
+ boolean isTypeCached(String typeName);
+}
\ No newline at end of file
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/CachedPropertyInformation.java b/dev/core/src/com/google/gwt/core/ext/CachedPropertyInformation.java
similarity index 91%
rename from dev/core/src/com/google/gwt/dev/javac/rebind/CachedPropertyInformation.java
rename to dev/core/src/com/google/gwt/core/ext/CachedPropertyInformation.java
index bddb4a7..85d7659 100644
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/CachedPropertyInformation.java
+++ b/dev/core/src/com/google/gwt/core/ext/CachedPropertyInformation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 Google Inc.
+ * Copyright 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -13,13 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.dev.javac.rebind;
-
-import com.google.gwt.core.ext.BadPropertyValueException;
-import com.google.gwt.core.ext.ConfigurationProperty;
-import com.google.gwt.core.ext.PropertyOracle;
-import com.google.gwt.core.ext.SelectionProperty;
-import com.google.gwt.core.ext.TreeLogger;
+package com.google.gwt.core.ext;
import java.io.Serializable;
import java.util.ArrayList;
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java b/dev/core/src/com/google/gwt/core/ext/DelegatingGeneratorContext.java
similarity index 69%
rename from dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java
rename to dev/core/src/com/google/gwt/core/ext/DelegatingGeneratorContext.java
index b429da3..fe68961 100644
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExtWrapper.java
+++ b/dev/core/src/com/google/gwt/core/ext/DelegatingGeneratorContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 Google Inc.
+ * Copyright 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -18,90 +18,92 @@
import com.google.gwt.core.ext.linker.Artifact;
import com.google.gwt.core.ext.linker.GeneratedResource;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
import com.google.gwt.dev.resource.ResourceOracle;
import java.io.OutputStream;
import java.io.PrintWriter;
/**
- * EXPERIMENTAL and subject to change. Do not use this in production code.
- * <p>
- * A wrapper to access a base {@link GeneratorContext} instance as a
- * {@link GeneratorContextExt} instance. Methods from the
- * {@link GeneratorContext} interface are passed through to the baseContext,
- * while methods from the {@link GeneratorContextExt} interface are given
- * default stub implementations.
+ * An abstract generator context class which delegates all methods to a provided
+ * baseContext. Implementing classes can selectively override individual
+ * methods.
*/
-public class GeneratorContextExtWrapper implements GeneratorContextExt {
+public abstract class DelegatingGeneratorContext implements GeneratorContext {
+
+ private final GeneratorContext baseContext;
/**
* Get a new instance wrapped from a base {@link GeneratorContext}
* implementation.
*/
- public static GeneratorContextExt newInstance(GeneratorContext baseContext) {
- return new GeneratorContextExtWrapper(baseContext);
- }
-
- private final GeneratorContext baseContext;
-
- private GeneratorContextExtWrapper(GeneratorContext baseContext) {
+ public DelegatingGeneratorContext(GeneratorContext baseContext) {
this.baseContext = baseContext;
}
+ @Override
public boolean checkRebindRuleAvailable(String sourceTypeName) {
return baseContext.checkRebindRuleAvailable(sourceTypeName);
}
+ @Override
public void commit(TreeLogger logger, PrintWriter pw) {
baseContext.commit(logger, pw);
}
+ @Override
public void commitArtifact(TreeLogger logger, Artifact<?> artifact)
throws UnableToCompleteException {
baseContext.commitArtifact(logger, artifact);
}
+ @Override
public GeneratedResource commitResource(TreeLogger logger, OutputStream os)
throws UnableToCompleteException {
return baseContext.commitResource(logger, os);
}
- public CachedRebindResult getCachedGeneratorResult() {
- return null;
+ @Override
+ public CachedGeneratorResult getCachedGeneratorResult() {
+ return baseContext.getCachedGeneratorResult();
}
+ @Override
public PropertyOracle getPropertyOracle() {
return baseContext.getPropertyOracle();
}
+ @Override
public ResourceOracle getResourcesOracle() {
return baseContext.getResourcesOracle();
}
+ @Override
public TypeOracle getTypeOracle() {
return baseContext.getTypeOracle();
}
+ @Override
public boolean isGeneratorResultCachingEnabled() {
- return false;
+ return baseContext.isGeneratorResultCachingEnabled();
}
+ @Override
public boolean isProdMode() {
- throw new UnsupportedOperationException(
- "isProdMode is only available from GeneratorContextExt.");
+ return baseContext.isProdMode();
}
-
- public boolean reuseTypeFromCacheIfAvailable(String typeName) {
- return false;
- }
-
+ @Override
public PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleName) {
return baseContext.tryCreate(logger, packageName, simpleName);
}
+ @Override
public OutputStream tryCreateResource(TreeLogger logger, String partialPath)
throws UnableToCompleteException {
return baseContext.tryCreateResource(logger, partialPath);
}
+
+ @Override
+ public boolean tryReuseTypeFromCache(String typeName) {
+ return baseContext.tryReuseTypeFromCache(typeName);
+ }
}
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorContext.java b/dev/core/src/com/google/gwt/core/ext/GeneratorContext.java
index 6e70447..fb1b905 100644
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorContext.java
+++ b/dev/core/src/com/google/gwt/core/ext/GeneratorContext.java
@@ -53,9 +53,8 @@
* {@link com.google.gwt.core.ext.linker.ArtifactSet#replace(Artifact)} if an
* equivalent Artifact had previously been committed.
*
- * @param logger a logger; normally the logger passed into
- * {@link Generator#generate(TreeLogger, GeneratorContext, String)}
- * or a branch thereof
+ * @param logger a logger; normally the logger passed into the currently
+ * invoked generator or a branch thereof
* @param artifact the Artifact to provide to the Linker chain.
*/
void commitArtifact(TreeLogger logger, Artifact<?> artifact) throws UnableToCompleteException;
@@ -74,6 +73,17 @@
throws UnableToCompleteException;
/**
+ * Get the cached rebind result that has been provided to the context, if
+ * available. The provided result will be the most recent previously generated
+ * result for the currently active rebind rule and requested type name.
+ *
+ * @return A {@link CachedGeneratorResult} object, if one has been provided to
+ * the context. Null is returned if there is no previous result
+ * available.
+ */
+ CachedGeneratorResult getCachedGeneratorResult();
+
+ /**
* Gets the property oracle for the current generator context. Generators can
* use the property oracle to query deferred binding properties.
*/
@@ -100,15 +110,26 @@
TypeOracle getTypeOracle();
/**
+ * Check whether generator result caching is currently enabled.
+ */
+ boolean isGeneratorResultCachingEnabled();
+
+ /**
+ * Returns true if generators are being run to produce code for a production
+ * compile. Returns false for dev mode. Generators can use this information to
+ * produce code optimized for the target.
+ */
+ boolean isProdMode();
+
+ /**
* Attempts to get a <code>PrintWriter</code> so that the caller can generate
* the source code for the named type. If the named types already exists,
* <code>null</code> is returned to indicate that no work needs to be done.
* The file is not committed until {@link #commit(TreeLogger, PrintWriter)} is
* called.
*
- * @param logger a logger; normally the logger passed into
- * {@link Generator#generate(TreeLogger, GeneratorContext, String)}
- * or a branch thereof
+ * @param logger a logger; normally the logger passed into the currently
+ * invoked generator, or a branch thereof
* @param packageName the name of the package to which the create type belongs
* @param simpleName the unqualified source name of the type being generated
* @return <code>null</code> if the package and class already exists,
@@ -122,9 +143,8 @@
* directory. The file is not committed until
* {@link #commitResource(TreeLogger, OutputStream)} is called.
*
- * @param logger a logger; normally the logger passed into
- * {@link Generator#generate(TreeLogger, GeneratorContext, String)}
- * or a branch thereof
+ * @param logger a logger; normally the logger passed into the currently
+ * invoked generator, or a branch thereof
* @param partialPath the name of the file whose contents are to be written;
* the name can include subdirectories separated by forward slashes
* ('/')
@@ -136,4 +156,18 @@
*/
OutputStream tryCreateResource(TreeLogger logger, String partialPath)
throws UnableToCompleteException;
+
+ /**
+ * Mark a type to be reused from the generator result cache, if available.
+ * Calling this method with a successful response indicates that the calling
+ * generator will not re-generate this type. A cached version of this type
+ * will be added to the context once the calling generator returns from
+ * {@link IncrementalGenerator#generateIncrementally}, with a result
+ * containing {@link RebindMode#USE_PARTIAL_CACHED}.
+ *
+ * @param typeName the fully qualified source name of a type.
+ * @return true if the requested type is available from the generator result
+ * cache, false otherwise.
+ */
+ boolean tryReuseTypeFromCache(String typeName);
}
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java b/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java
deleted file mode 100644
index 7153684..0000000
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorContextExt.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.core.ext;
-
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
-
-/**
- * EXPERIMENTAL and subject to change. Do not use this in production code.
- * <p>
- * An extension to GeneratorContext which includes access to previously cached
- * rebind results.
- * <p>
- * TODO(jbrosenberg): Merge this into {@link GeneratorContext} directly, once
- * the api has stabilized and we can remove the "experimental" moniker.
- */
-public interface GeneratorContextExt extends GeneratorContext {
-
- /**
- * Get cached result from a previous run of the current generator, if available.
- *
- * @return A {@link com.google.gwt.dev.javac.rebind.CachedRebindResult} object,
- * if one has been provided to the context. Null is returned if there
- * is no previous result, or if generator result caching is not enabled.
- */
- CachedRebindResult getCachedGeneratorResult();
-
- /**
- * Check whether generator result caching is currently enabled.
- */
- boolean isGeneratorResultCachingEnabled();
-
- /**
- * Returns true if generators are being run to produce code for a
- * production compile. Returns false for dev mode. Generators can use this
- * information to produce code optimized for the target.
- */
- boolean isProdMode();
-
- /**
- * Mark a type to be reused from the generator result cache. Calling this
- * method with a successful response indicates that the calling generator will
- * not re-generate this type. A cached version of this type will be added
- * to the context once the calling generator returns from
- * {@link GeneratorExt#generateIncrementally}, with a result containing
- * {@link com.google.gwt.dev.javac.rebind.RebindStatus#USE_PARTIAL_CACHED}.
- *
- * @param typeName the fully qualified name of a type.
- * @return true if the requested type is available from the generator result
- * cache, false otherwise.
- */
- boolean reuseTypeFromCacheIfAvailable(String typeName);
-}
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java b/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java
deleted file mode 100644
index 4e24aaf..0000000
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorExt.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.core.ext;
-
-import com.google.gwt.dev.javac.rebind.RebindResult;
-
-/**
- * EXPERIMENTAL and subject to change. Do not use this in production code.
- * <p>
- * Adds a new {@link #generateIncrementally} method.
- * <p>
- * TODO(jbrosenberg): Merge this into {@link Generator} directly, once the api
- * has stabilized and we can remove the "experimental" moniker.
- */
-public abstract class GeneratorExt extends Generator {
-
- /**
- * A default implementation of the abstract method defined in the base
- * {@link Generator} class. This will wrap a call to
- * {@link #generateIncrementally}, and attempt no caching. This supports
- * backwards compatibility for applications or other generators which call
- * this generator directly, as outside of the normal internal rebind process.
- * <p>
- * It is recommended that {@link #generateIncrementally} be used instead.
- *
- * @return the name of a subclass to substitute for the requested class, or
- * return <code>null</code> to cause the requested type itself to be
- * used
- */
- @Override
- public String generate(TreeLogger logger, GeneratorContext context,
- String typeName) throws UnableToCompleteException {
-
- // wrap the passed in context
- GeneratorContextExt contextExt = context instanceof GeneratorContextExt
- ? (GeneratorContextExt) context
- : GeneratorContextExtWrapper.newInstance(context);
-
- RebindResult result = generateIncrementally(logger, contextExt, typeName);
- return result.getReturnedTypeName();
- }
-
- /**
- * Incrementally generate a default constructible subclass of the requested
- * type. The generator can use information from the context to determine
- * whether it needs to regenerate everything, or whether it can selectively
- * regenerate a subset of its output, or whether it can return quickly to
- * allow reuse of all previously cached objects. It will return a
- * {@link RebindResult}, which contains a
- * {@link com.google.gwt.dev.javac.rebind.RebindStatus} field indicating
- * whether to use previously cached artifacts, newly generated ones, or a
- * partial mixture of both cached and newly generated objects.
- * <p>
- * The result also includes a field for the name of the subclass to
- * substitute for the requested class.
- * <p>
- * The generator throws an <code>UnableToCompleteException</code> if for
- * any reason it cannot complete successfully.
- *
- * @return a RebindResult
- */
- public abstract RebindResult generateIncrementally(TreeLogger logger,
- GeneratorContextExt context, String typeName)
- throws UnableToCompleteException;
-}
diff --git a/dev/core/src/com/google/gwt/core/ext/GeneratorExtWrapper.java b/dev/core/src/com/google/gwt/core/ext/GeneratorExtWrapper.java
deleted file mode 100644
index bc8a250..0000000
--- a/dev/core/src/com/google/gwt/core/ext/GeneratorExtWrapper.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.core.ext;
-
-import com.google.gwt.dev.javac.rebind.RebindResult;
-import com.google.gwt.dev.javac.rebind.RebindStatus;
-
-/**
- * EXPERIMENTAL and subject to change. Do not use this in production code.
- * <p>
- * A wrapper class for using base {@link Generator} implementations where
- * a {@link GeneratorExt} instance is needed.
- */
-public class GeneratorExtWrapper extends GeneratorExt {
-
- /**
- * Get a new instance wrapped from a base {@link Generator} implementation.
- */
- public static GeneratorExt newInstance(Generator baseGenerator) {
- return new GeneratorExtWrapper(baseGenerator);
- }
-
- private final Generator baseGenerator;
-
- public GeneratorExtWrapper(Generator baseGenerator) {
- this.baseGenerator = baseGenerator;
- }
-
- /**
- * Pass through to the base generator's generate method.
- */
- @Override
- public String generate(TreeLogger logger, GeneratorContext context,
- String typeName) throws UnableToCompleteException {
- return this.baseGenerator.generate(logger, context, typeName);
- }
-
- /**
- * Call base generator's generate method, and don't attempt any caching.
- */
- @Override
- public RebindResult generateIncrementally(TreeLogger logger,
- GeneratorContextExt context, String typeName)
- throws UnableToCompleteException {
-
- RebindStatus status;
- String resultTypeName = generate(logger, context, typeName);
- if (resultTypeName == null) {
- status = RebindStatus.USE_EXISTING;
- resultTypeName = typeName;
- } else {
- status = RebindStatus.USE_ALL_NEW_WITH_NO_CACHING;
- }
-
- return new RebindResult(status, resultTypeName);
- }
-}
\ No newline at end of file
diff --git a/dev/core/src/com/google/gwt/core/ext/IncrementalGenerator.java b/dev/core/src/com/google/gwt/core/ext/IncrementalGenerator.java
new file mode 100644
index 0000000..e42c678
--- /dev/null
+++ b/dev/core/src/com/google/gwt/core/ext/IncrementalGenerator.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+/**
+ * An extension to the {@link Generator} class which supports incremental
+ * generation. It adds a {@link #generateIncrementally} method.
+ */
+public abstract class IncrementalGenerator extends Generator {
+
+ /**
+ * A static helper method to wrap a non-incremental generator's result. It
+ * calls the generator's {@link Generator#generate} method, and synthesizes a
+ * {@link RebindResult} instance to be returned.
+ *
+ * @param logger A TreeLogger
+ * @param generator A non-incremental generator
+ * @param context The generator context
+ * @param typeName The type for which a subclass will be generated
+ * @return a RebindResult
+ * @throws UnableToCompleteException
+ */
+ public static RebindResult generateNonIncrementally(TreeLogger logger, Generator generator,
+ GeneratorContext context, String typeName) throws UnableToCompleteException {
+
+ RebindMode mode;
+ String resultTypeName = generator.generate(logger, context, typeName);
+ if (resultTypeName == null) {
+ mode = RebindMode.USE_EXISTING;
+ resultTypeName = typeName;
+ } else {
+ mode = RebindMode.USE_ALL_NEW_WITH_NO_CACHING;
+ }
+
+ return new RebindResult(mode, resultTypeName);
+ }
+
+ /**
+ * This method overrides {@link Generator#generate}, and is included only for
+ * backwards compatibility. It wraps a call to {@link #generateIncrementally}.
+ * This method won't normally be called by the gwt rebind process, and it is
+ * declared final and can't be overridden. It is provided in support of
+ * existing applications and other generators which call this method directly,
+ * outside of the gwt framework.
+ * <p>
+ * The passed in context is wrapped with an instance of
+ * {@link NonIncrementalGeneratorContext}, to ensure that no generator result
+ * caching is attempted, since the cached result will be ignored by callers of
+ * this method anyway.
+ *
+ * @see Generator#generate
+ *
+ * @param logger A TreeLogger
+ * @param context The generator context
+ * @param typeName The type for which a subclass will be generated
+ * @return the name of a subclass to substitute for the requested class, or
+ * return <code>null</code> to cause the requested type itself to be
+ * used
+ * @throws UnableToCompleteException
+ */
+ @Override
+ public final String generate(TreeLogger logger, GeneratorContext context, String typeName)
+ throws UnableToCompleteException {
+ /*
+ * Since no generator result caching should happen if this method is called,
+ * we wrap the context, to ensure that the check for {@link
+ * GeneratorContext.isGeneratorResultCachingEnabled()} will return false.
+ */
+ GeneratorContext wrappedContext = NonIncrementalGeneratorContext.newInstance(context);
+ RebindResult result = generateIncrementally(logger, wrappedContext, typeName);
+ return result.getResultTypeName();
+ }
+
+ /**
+ * Incrementally generate a default constructible subclass of the requested
+ * type. The generator can use information from the context to make decisions
+ * on whether to incrementally reuse cached output from previous invocations.
+ * <p>
+ * It returns a {@link RebindResult}, which contains a {@link RebindMode}
+ * field, which indicates whether to use previously cached output, newly
+ * generated output, or a partial mixture of both cached and newly generated
+ * output.
+ * <p>
+ * The result also includes a field for the name of the subclass to substitute
+ * for the requested class. It may also contain extra client data added by
+ * specific generator implementations.
+ * <p>
+ * This method throws an <code>UnableToCompleteException</code> if for any
+ * reason it cannot complete successfully.
+ *
+ * @see RebindResult
+ * @see RebindMode
+ *
+ * @param logger A TreeLogger
+ * @param context The generator context
+ * @param typeName The type for which a subclass will be generated
+ * @return a RebindResult
+ * @throws UnableToCompleteException
+ */
+ public abstract RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context,
+ String typeName) throws UnableToCompleteException;
+
+ /**
+ * Returns a version id for an IncrementalGenerator. It is used by the system
+ * to invalidate {@link CachedGeneratorResult}'s that were generated by a
+ * different version of this generator. This is useful when new versions of a
+ * generator are developed, which might alter the structure of generated
+ * output, or alter semantics for cache reusability checking.
+ * <p>
+ * It is the responsibility of the developer to maintain this version id
+ * consistently.
+ *
+ * @return a version id
+ */
+ public abstract long getVersionId();
+}
diff --git a/dev/core/src/com/google/gwt/core/ext/NonIncrementalGeneratorContext.java b/dev/core/src/com/google/gwt/core/ext/NonIncrementalGeneratorContext.java
new file mode 100644
index 0000000..8e70bf5
--- /dev/null
+++ b/dev/core/src/com/google/gwt/core/ext/NonIncrementalGeneratorContext.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+/**
+ * A wrapper to access a base {@link GeneratorContext} instance but with
+ * generator result caching disabled.
+ */
+public class NonIncrementalGeneratorContext extends DelegatingGeneratorContext {
+
+ /**
+ * Get a new instance wrapped from a base {@link GeneratorContext}
+ * implementation.
+ */
+ public static GeneratorContext newInstance(GeneratorContext baseContext) {
+ return new NonIncrementalGeneratorContext(baseContext);
+ }
+
+ private NonIncrementalGeneratorContext(GeneratorContext baseContext) {
+ super(baseContext);
+ }
+
+ @Override
+ public CachedGeneratorResult getCachedGeneratorResult() {
+ // disabled
+ return null;
+ }
+
+ @Override
+ public boolean isGeneratorResultCachingEnabled() {
+ // disabled
+ return false;
+ }
+
+ @Override
+ public boolean tryReuseTypeFromCache(String typeName) {
+ // disabled
+ return false;
+ }
+}
diff --git a/dev/core/src/com/google/gwt/core/ext/RebindMode.java b/dev/core/src/com/google/gwt/core/ext/RebindMode.java
new file mode 100644
index 0000000..4362d65
--- /dev/null
+++ b/dev/core/src/com/google/gwt/core/ext/RebindMode.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+/**
+ * A mode to indicate how incremental generator output should be integrated by
+ * the deferred binding implementation. The RebindMode is included as a member
+ * of the {@link RebindResult} returned by
+ * {@link IncrementalGenerator#generateIncrementally}. It is up to each
+ * generator implementation to determine the conditions for reuse of previously
+ * generated cached output.
+ *
+ * @see RebindResult
+ * @see IncrementalGenerator#generateIncrementally
+ */
+public enum RebindMode {
+
+ /**
+ * Indicates no generated code is needed to satisfy this rebind. This mode can
+ * be used in cases where the requested type can be used directly as a default
+ * instantiable class, or in cases where a generator determines it has already
+ * run for the requested type in the current context (e.g. via a failed call
+ * to {@link GeneratorContext#tryCreate}).
+ */
+ USE_EXISTING,
+
+ /**
+ * Indicates only newly generated output should be used. All generated output
+ * will be cached.
+ */
+ USE_ALL_NEW,
+
+ /**
+ * Indicates only newly generated output should be used, and no output should
+ * be cached. This mode should be used when no caching can be taken advantage
+ * of, such as for generators which don't implement
+ * {@link IncrementalGenerator#generateIncrementally}.
+ */
+ USE_ALL_NEW_WITH_NO_CACHING,
+
+ /**
+ * Indicates nothing new was generated, only cached output previously
+ * generated should be used.
+ */
+ USE_ALL_CACHED,
+
+ /**
+ * Indicates that a mixture of newly generated and previously cached output
+ * should be used. Types marked with a successful call to
+ * {@link GeneratorContext#tryReuseTypeFromCache} should be reused from cache,
+ * while everything else committed to the context should be treated as freshly
+ * generated output. A new composite cache entry will be created which
+ * combines the freshly generated output and the output reused from cache.
+ */
+ USE_PARTIAL_CACHED
+}
diff --git a/dev/core/src/com/google/gwt/core/ext/RebindResult.java b/dev/core/src/com/google/gwt/core/ext/RebindResult.java
new file mode 100644
index 0000000..f310ee6
--- /dev/null
+++ b/dev/core/src/com/google/gwt/core/ext/RebindResult.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A class for returning the result of a rebind operation.
+ */
+public class RebindResult {
+ private final RebindMode rebindMode;
+ private final String resultTypeName;
+ private Map<String, Serializable> clientData;
+
+ /**
+ * Constructs a result using the provided rebindMode and resultTypeName.
+ *
+ * @see RebindMode
+ *
+ * @param rebindMode
+ * @param resultType
+ */
+ public RebindResult(RebindMode rebindMode, String resultType) {
+ this.rebindMode = rebindMode;
+ this.resultTypeName = resultType;
+ }
+
+ /**
+ * Returns a map containing all client data added to this result.
+ *
+ * @return A map containing all client data added to this result. Returns
+ * <code>null</code> if no client data has been added.
+ */
+ public Map<String, Serializable> getClientDataMap() {
+ return clientData;
+ }
+
+ /**
+ * @return The rebind mode used to construct this result.
+ */
+ public RebindMode getRebindMode() {
+ return rebindMode;
+ }
+
+ /**
+ * @return The type name used to construct this result.
+ */
+ public String getResultTypeName() {
+ return resultTypeName;
+ }
+
+ /**
+ * Adds keyed, serializable data to a rebind result. This data will be made
+ * available, as part of a {@link CachedGeneratorResult}, to subsequent
+ * invocations of the same generator, when called under the same conditions
+ * (e.g. for the same rebind rule and requested type name). A generator
+ * implementation can use this to remember information needed for subsequent
+ * regeneration, such as for making cache reuse decisions.
+ *
+ * @see CachedGeneratorResult
+ * @see GeneratorContext#getCachedGeneratorResult
+ *
+ * @param key
+ * @param data
+ */
+ public void putClientData(String key, Serializable data) {
+ if (clientData == null) {
+ clientData = new HashMap<String, Serializable>();
+ }
+ clientData.put(key, data);
+ }
+}
\ No newline at end of file
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindRuleResolver.java b/dev/core/src/com/google/gwt/core/ext/RebindRuleResolver.java
similarity index 94%
rename from dev/core/src/com/google/gwt/dev/javac/rebind/RebindRuleResolver.java
rename to dev/core/src/com/google/gwt/core/ext/RebindRuleResolver.java
index 5cc5dcb..7dcc7cf 100644
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindRuleResolver.java
+++ b/dev/core/src/com/google/gwt/core/ext/RebindRuleResolver.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.dev.javac.rebind;
+package com.google.gwt.core.ext;
/**
* An interface for encapsulating rebind rule resolution.
diff --git a/dev/core/src/com/google/gwt/core/ext/StubGeneratorContext.java b/dev/core/src/com/google/gwt/core/ext/StubGeneratorContext.java
new file mode 100644
index 0000000..b3046da
--- /dev/null
+++ b/dev/core/src/com/google/gwt/core/ext/StubGeneratorContext.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+import com.google.gwt.core.ext.linker.Artifact;
+import com.google.gwt.core.ext.linker.GeneratedResource;
+import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.google.gwt.dev.resource.ResourceOracle;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+/**
+ * An abstract generator context class which by default throws
+ * UnsupportedOperationException for all methods. Implementing classes can
+ * selectively override individual methods. Useful for mocking and/or selective
+ * reuse of generator functionality.
+ */
+public abstract class StubGeneratorContext implements GeneratorContext {
+
+ @Override
+ public boolean checkRebindRuleAvailable(String sourceTypeName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void commit(TreeLogger logger, PrintWriter pw) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void commitArtifact(TreeLogger logger, Artifact<?> artifact) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public GeneratedResource commitResource(TreeLogger logger, OutputStream os) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CachedGeneratorResult getCachedGeneratorResult() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyOracle getPropertyOracle() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ResourceOracle getResourcesOracle() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TypeOracle getTypeOracle() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isGeneratorResultCachingEnabled() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isProdMode() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public OutputStream tryCreateResource(TreeLogger logger, String partialPath) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean tryReuseTypeFromCache(String typeName) {
+ throw new UnsupportedOperationException();
+ }
+}
\ No newline at end of file
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
index fdee5dc..d6cfd1f 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
@@ -19,10 +19,7 @@
* Type representing a Java class or interface type that a user would declare.
*/
public interface JRealClassType extends JClassType {
-
/**
- * EXPERIMENTAL and subject to change. Do not use this in production code.
- *
* Retrieve last modified time for this type.
*/
long getLastModifiedTime();
diff --git a/dev/core/src/com/google/gwt/dev/DevModeBase.java b/dev/core/src/com/google/gwt/dev/DevModeBase.java
index 69d575b..d4374c8 100644
--- a/dev/core/src/com/google/gwt/dev/DevModeBase.java
+++ b/dev/core/src/com/google/gwt/dev/DevModeBase.java
@@ -23,7 +23,6 @@
import com.google.gwt.dev.cfg.ModuleDefLoader;
import com.google.gwt.dev.javac.CompilationState;
import com.google.gwt.dev.javac.CompilationStateBuilder;
-import com.google.gwt.dev.javac.rebind.RebindCache;
import com.google.gwt.dev.jjs.JJSOptions;
import com.google.gwt.dev.shell.ArtifactAcceptor;
import com.google.gwt.dev.shell.BrowserChannelServer;
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindCache.java b/dev/core/src/com/google/gwt/dev/RebindCache.java
similarity index 62%
rename from dev/core/src/com/google/gwt/dev/javac/rebind/RebindCache.java
rename to dev/core/src/com/google/gwt/dev/RebindCache.java
index b1e7caa..cff8ea1 100644
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindCache.java
+++ b/dev/core/src/com/google/gwt/dev/RebindCache.java
@@ -13,8 +13,9 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.dev.javac.rebind;
+package com.google.gwt.dev;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.dev.cfg.Rule;
import java.io.Serializable;
@@ -22,19 +23,19 @@
import java.util.Map;
/**
- * A cache for storing {@link CachedRebindResult} entries. Entries are keyed
+ * A cache for storing {@link CachedGeneratorResult} entries. Entries are keyed
* by rebind Rule and queryTypeName.
*/
public class RebindCache implements Serializable {
- private final Map<String, Map<String, CachedRebindResult>> rebindResults;
+ private final Map<String, Map<String, CachedGeneratorResult>> rebindResults;
public RebindCache() {
- rebindResults = new HashMap<String, Map<String, CachedRebindResult>>();
+ rebindResults = new HashMap<String, Map<String, CachedGeneratorResult>>();
}
- public CachedRebindResult get(Rule rule, String queryTypeName) {
- Map<String, CachedRebindResult> ruleResults;
+ public CachedGeneratorResult get(Rule rule, String queryTypeName) {
+ Map<String, CachedGeneratorResult> ruleResults;
ruleResults = rebindResults.get(rule.toString());
if (ruleResults != null) {
return ruleResults.get(queryTypeName);
@@ -42,15 +43,11 @@
return null;
}
-
- public void invalidate() {
- rebindResults.clear();
- }
-
- public void put(Rule rule, String queryTypeName, CachedRebindResult results) {
- Map<String, CachedRebindResult> ruleResults = rebindResults.get(rule.toString());
+
+ public void put(Rule rule, String queryTypeName, CachedGeneratorResult results) {
+ Map<String, CachedGeneratorResult> ruleResults = rebindResults.get(rule.toString());
if (ruleResults == null) {
- ruleResults = new HashMap<String, CachedRebindResult>();
+ ruleResults = new HashMap<String, CachedGeneratorResult>();
rebindResults.put(rule.toString(), ruleResults);
}
ruleResults.put(queryTypeName, results);
diff --git a/dev/core/src/com/google/gwt/dev/cfg/Rule.java b/dev/core/src/com/google/gwt/dev/cfg/Rule.java
index 818bf3e..6b8a889 100644
--- a/dev/core/src/com/google/gwt/dev/cfg/Rule.java
+++ b/dev/core/src/com/google/gwt/dev/cfg/Rule.java
@@ -15,10 +15,10 @@
*/
package com.google.gwt.dev.cfg;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.javac.StandardGeneratorContext;
-import com.google.gwt.dev.javac.rebind.RebindResult;
/**
* Abstract base class for various kinds of deferred binding rules.
diff --git a/dev/core/src/com/google/gwt/dev/cfg/RuleFail.java b/dev/core/src/com/google/gwt/dev/cfg/RuleFail.java
index 89c0fd0..d1ef03b 100644
--- a/dev/core/src/com/google/gwt/dev/cfg/RuleFail.java
+++ b/dev/core/src/com/google/gwt/dev/cfg/RuleFail.java
@@ -15,10 +15,10 @@
*/
package com.google.gwt.dev.cfg;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.javac.StandardGeneratorContext;
-import com.google.gwt.dev.javac.rebind.RebindResult;
/**
* A rule to explicitly fail during a deferred binding request.
diff --git a/dev/core/src/com/google/gwt/dev/cfg/RuleGenerateWith.java b/dev/core/src/com/google/gwt/dev/cfg/RuleGenerateWith.java
index e41b51d..20e3482 100644
--- a/dev/core/src/com/google/gwt/dev/cfg/RuleGenerateWith.java
+++ b/dev/core/src/com/google/gwt/dev/cfg/RuleGenerateWith.java
@@ -16,10 +16,10 @@
package com.google.gwt.dev.cfg;
import com.google.gwt.core.ext.Generator;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.javac.StandardGeneratorContext;
-import com.google.gwt.dev.javac.rebind.RebindResult;
/**
* A rule to replace the type being rebound with a class whose name is
diff --git a/dev/core/src/com/google/gwt/dev/cfg/RuleReplaceWith.java b/dev/core/src/com/google/gwt/dev/cfg/RuleReplaceWith.java
index 4f4f273..e2fb681 100644
--- a/dev/core/src/com/google/gwt/dev/cfg/RuleReplaceWith.java
+++ b/dev/core/src/com/google/gwt/dev/cfg/RuleReplaceWith.java
@@ -15,11 +15,11 @@
*/
package com.google.gwt.dev.cfg;
+import com.google.gwt.core.ext.RebindMode;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.javac.StandardGeneratorContext;
-import com.google.gwt.dev.javac.rebind.RebindResult;
-import com.google.gwt.dev.javac.rebind.RebindStatus;
/**
* A rule to replace the type being rebound with an explicitly named class.
@@ -41,7 +41,7 @@
StandardGeneratorContext context, String typeName)
throws UnableToCompleteException {
return new RebindResult(
- RebindStatus.USE_EXISTING, replacementTypeName);
+ RebindMode.USE_EXISTING, replacementTypeName);
}
@Override
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/CachedRebindResult.java b/dev/core/src/com/google/gwt/dev/javac/CachedGeneratorResultImpl.java
similarity index 64%
rename from dev/core/src/com/google/gwt/dev/javac/rebind/CachedRebindResult.java
rename to dev/core/src/com/google/gwt/dev/javac/CachedGeneratorResultImpl.java
index dc74223..986f2c0 100644
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/CachedRebindResult.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CachedGeneratorResultImpl.java
@@ -1,22 +1,22 @@
/*
- * Copyright 2010 Google Inc.
- *
+ * Copyright 2011 Google Inc.
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.dev.javac.rebind;
+package com.google.gwt.dev.javac;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.core.ext.linker.ArtifactSet;
-import com.google.gwt.dev.javac.GeneratedUnit;
import java.io.Serializable;
import java.util.Collection;
@@ -24,36 +24,37 @@
import java.util.Map;
/**
- * A class to represent the results from a rebind operation. This can be
- * cached and presented to subsequent rebind operations, providing the generator
- * information needed to decide whether full or partial re-generation is required.
+ * An implementation class to represent the cached results from a previous
+ * generator invocation.
*/
-public class CachedRebindResult implements Serializable {
+public class CachedGeneratorResultImpl implements CachedGeneratorResult, Serializable {
private final ArtifactSet artifacts;
private final Map<String, GeneratedUnit> generatedUnitMap;
- private final String returnedTypeName;
+ private final String resultTypeName;
private final long timeGenerated;
- private final CachedClientDataMap clientDataMap;
+ private final Map<String, Serializable> clientDataMap;
- public CachedRebindResult(String resultTypeName, ArtifactSet artifacts,
- Map<String, GeneratedUnit> generatedUnitMap,
- long timeGenerated, CachedClientDataMap clientDataMap) {
- this.returnedTypeName = resultTypeName;
+ public CachedGeneratorResultImpl(String resultTypeName, ArtifactSet artifacts,
+ Map<String, GeneratedUnit> generatedUnitMap, long timeGenerated,
+ Map<String, Serializable> clientDataMap) {
+ this.resultTypeName = resultTypeName;
this.artifacts = new ArtifactSet(artifacts);
this.generatedUnitMap = new HashMap<String, GeneratedUnit>(generatedUnitMap);
this.timeGenerated = timeGenerated;
+ assert clientDataMap instanceof Serializable;
this.clientDataMap = clientDataMap;
}
-
- public CachedRebindResult(String resultTypeName, ArtifactSet artifacts,
+
+ public CachedGeneratorResultImpl(String resultTypeName, ArtifactSet artifacts,
Map<String, GeneratedUnit> generatedUnitMap, long timeGenerated) {
this(resultTypeName, artifacts, generatedUnitMap, timeGenerated, null);
}
-
+
public ArtifactSet getArtifacts() {
return artifacts;
}
-
+
+ @Override
public Object getClientData(String key) {
if (clientDataMap == null) {
return null;
@@ -61,27 +62,26 @@
return clientDataMap.get(key);
}
}
-
- public CachedClientDataMap getClientDataMap() {
- return clientDataMap;
- }
-
+
public GeneratedUnit getGeneratedUnit(String typeName) {
return generatedUnitMap.get(typeName);
}
-
+
public Collection<GeneratedUnit> getGeneratedUnits() {
return generatedUnitMap.values();
}
-
- public String getReturnedTypeName() {
- return returnedTypeName;
+
+ @Override
+ public String getResultTypeName() {
+ return resultTypeName;
}
-
+
+ @Override
public long getTimeGenerated() {
return timeGenerated;
}
-
+
+ @Override
public boolean isTypeCached(String typeName) {
return generatedUnitMap.containsKey(typeName);
}
diff --git a/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java b/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
index ae94764..b19eb9a 100644
--- a/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
+++ b/dev/core/src/com/google/gwt/dev/javac/StandardGeneratorContext.java
@@ -15,12 +15,13 @@
*/
package com.google.gwt.dev.javac;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.GeneratorContext;
-import com.google.gwt.core.ext.GeneratorContextExt;
-import com.google.gwt.core.ext.GeneratorExt;
-import com.google.gwt.core.ext.GeneratorExtWrapper;
+import com.google.gwt.core.ext.IncrementalGenerator;
import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.RebindResult;
+import com.google.gwt.core.ext.RebindRuleResolver;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.Artifact;
@@ -30,10 +31,6 @@
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.dev.cfg.ModuleDef;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
-import com.google.gwt.dev.javac.rebind.RebindResult;
-import com.google.gwt.dev.javac.rebind.RebindRuleResolver;
-import com.google.gwt.dev.javac.rebind.RebindStatus;
import com.google.gwt.dev.resource.ResourceOracle;
import com.google.gwt.dev.util.DiskCache;
import com.google.gwt.dev.util.Util;
@@ -63,7 +60,7 @@
/**
* Manages generators and generated units during a single compilation.
*/
-public class StandardGeneratorContext implements GeneratorContextExt {
+public class StandardGeneratorContext implements GeneratorContext {
/**
* Extras added to {@link GeneratedUnit}.
@@ -72,13 +69,6 @@
void abort();
void commit(TreeLogger logger);
-
- /**
- * Returns the strong hash of the source.
- */
- String getStrongHash();
-
- String getTypeName();
}
/**
@@ -107,6 +97,7 @@
this.sw = sw;
}
+ @Override
public void abort() {
sw = null;
}
@@ -114,6 +105,7 @@
/**
* Finalizes the source and adds this generated unit to the host.
*/
+ @Override
public void commit(TreeLogger logger) {
String source = sw.toString();
strongHash = Util.computeStrongName(Util.getBytes(source));
@@ -122,10 +114,12 @@
creationTime = System.currentTimeMillis();
}
+ @Override
public long creationTime() {
return creationTime;
}
+ @Override
public String getSource() {
if (sw != null) {
throw new IllegalStateException("source not committed");
@@ -133,6 +127,7 @@
return diskCache.readString(sourceToken);
}
+ @Override
public long getSourceToken() {
if (sw != null) {
throw new IllegalStateException("source not committed");
@@ -140,14 +135,17 @@
return sourceToken;
}
+ @Override
public String getStrongHash() {
return strongHash;
}
+ @Override
public String getTypeName() {
return typeName;
}
+ @Override
public String optionalFileLocation() {
return null;
}
@@ -239,6 +237,8 @@
}
}
+ private static final String GENERATOR_VERSION_ID_KEY = "generator-version-id";
+
private static DiskCache diskCache = DiskCache.INSTANCE;
private static final Map<String, CompilerEventType> eventsByGeneratorType =
@@ -295,7 +295,7 @@
private final Map<PrintWriter, Generated> uncommittedGeneratedCupsByPrintWriter =
new IdentityHashMap<PrintWriter, Generated>();
- private CachedRebindResult cachedRebindResult = null;
+ private CachedGeneratorResultImpl cachedRebindResult = null;
private boolean generatorResultCachingEnabled = false;
@@ -364,6 +364,7 @@
/**
* Checks whether a rebind rule is available for a given sourceTypeName.
*/
+ @Override
public boolean checkRebindRuleAvailable(String sourceTypeName) {
if (rebindRuleResolver != null) {
return rebindRuleResolver.checkRebindRuleResolvable(sourceTypeName);
@@ -383,6 +384,7 @@
/**
* Commits a pending generated type.
*/
+ @Override
public final void commit(TreeLogger logger, PrintWriter pw) {
Generated gcup = uncommittedGeneratedCupsByPrintWriter.get(pw);
if (gcup != null) {
@@ -401,6 +403,7 @@
* that only new entries will ever be inserted here for a given generator
* run).
*/
+ @Override
public void commitArtifact(TreeLogger logger, Artifact<?> artifact) {
allGeneratedArtifacts.replace(artifact);
newlyGeneratedArtifacts.add(artifact);
@@ -417,6 +420,7 @@
}
}
+ @Override
public GeneratedResource commitResource(TreeLogger logger, OutputStream os)
throws UnableToCompleteException {
@@ -493,7 +497,6 @@
committedGeneratedCups.clear();
newlyGeneratedTypeNames.clear();
newlyGeneratedArtifacts = new ArtifactSet();
- cachedRebindResult = null;
cachedTypeNamesToReuse = null;
}
}
@@ -512,7 +515,8 @@
/**
* Gets the previously cached rebind result for the current generator.
*/
- public CachedRebindResult getCachedGeneratorResult() {
+ @Override
+ public CachedGeneratorResult getCachedGeneratorResult() {
return cachedRebindResult;
}
@@ -531,49 +535,32 @@
return committedGeneratedCups;
}
+ @Override
public final PropertyOracle getPropertyOracle() {
return propOracle;
}
+ @Override
public ResourceOracle getResourcesOracle() {
return module.getResourcesOracle();
}
+ @Override
public final TypeOracle getTypeOracle() {
return compilationState.getTypeOracle();
}
+ @Override
public boolean isGeneratorResultCachingEnabled() {
return generatorResultCachingEnabled;
}
+ @Override
public boolean isProdMode() {
return isProdMode;
}
/**
- * Adds a type name to the list of types to be reused from cache, if
- * available.
- *
- * @param typeName The fully qualified name of a type.
- *
- * @return true, if the type is available in the cache and was successfully
- * added to the list for reuse, false otherwise.
- */
- public boolean reuseTypeFromCacheIfAvailable(String typeName) {
- if (!isGeneratorResultCachingEnabled() || cachedRebindResult == null
- || !cachedRebindResult.isTypeCached(typeName)) {
- return false;
- }
-
- if (cachedTypeNamesToReuse == null) {
- cachedTypeNamesToReuse = new ArrayList<String>();
- }
- cachedTypeNamesToReuse.add(typeName);
- return true;
- }
-
- /**
* This method is maintained for backwards compatibility.
* {@link #runGeneratorIncrementally} should be used instead.
*/
@@ -582,20 +569,21 @@
RebindResult result = runGeneratorIncrementally(logger, generatorClass, typeName);
- return result.getReturnedTypeName();
+ return result.getResultTypeName();
}
/**
* Runs a generator incrementally, with support for managing the returned
- * {@link RebindResult} object, which can contain status and cached results.
- * This is a replacement for the {@link #runGenerator} method.
+ * {@link RebindResult} object, which can contain cached results. This is a
+ * replacement for the {@link #runGenerator} method.
* <p>
- * If the passed in generatorClass is an instance of {@link GeneratorExt},
- * it's {@link GeneratorExt#generateIncrementally} method will be called.
+ * If the passed in generatorClass is an instance of
+ * {@link IncrementalGenerator}, it's
+ * {@link IncrementalGenerator#generateIncrementally} method will be called.
* <p>
* Otherwise, for backwards compatibility, the generatorClass will be wrapped
- * in a {@link GeneratorExt} instance, and it's {@link Generator#generate}
- * method will be called.
+ * in a {@link IncrementalGenerator} instance, and it's
+ * {@link Generator#generate} method will be called.
*
* @param logger
* @param generatorClass
@@ -625,6 +613,7 @@
// Avoid call to System.currentTimeMillis() if not logging DEBUG level
boolean loggable = logger.isLoggable(TreeLogger.DEBUG);
long before = loggable ? System.currentTimeMillis() : 0L;
+
String generatorClassName = generator.getClass().getName();
CompilerEventType type = eventsByGeneratorType.get(generatorClassName);
@@ -636,24 +625,38 @@
SpeedTracerLogger.start(type, "class", generatorClassName, "type", typeName);
try {
- GeneratorExt generatorExt;
- if (generator instanceof GeneratorExt) {
- generatorExt = (GeneratorExt) generator;
+ RebindResult result;
+ 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 {
- generatorExt = GeneratorExtWrapper.newInstance(generator);
+ // run a non-incremental generator
+ result = IncrementalGenerator.generateNonIncrementally(logger, generator, this, typeName);
}
- RebindResult result;
- result = generatorExt.generateIncrementally(logger, this, typeName);
-
if (loggable) {
- if (result.getResultStatus() == RebindStatus.USE_EXISTING) {
- msg = "Generator did not return a new class, type will be used as is";
- } else {
- msg = "Generator returned class '" + result.getReturnedTypeName() + "'";
- }
long after = System.currentTimeMillis();
- msg += "; in " + (after - before) + " ms";
+ msg =
+ "Generator returned type '" + result.getResultTypeName() + "; mode "
+ + result.getRebindMode() + "; in " + (after - before) + " ms";
logger.log(TreeLogger.DEBUG, msg, null);
}
return result;
@@ -674,8 +677,8 @@
/**
* Set previously cached rebind result for currently active generator.
*/
- public void setCachedGeneratorResult(CachedRebindResult cachedRebindResult) {
- this.cachedRebindResult = cachedRebindResult;
+ public void setCachedGeneratorResult(CachedGeneratorResult cachedRebindResult) {
+ this.cachedRebindResult = (CachedGeneratorResultImpl) cachedRebindResult;
}
public void setCurrentGenerator(Class<? extends Generator> currentGenerator) {
@@ -698,6 +701,7 @@
this.rebindRuleResolver = resolver;
}
+ @Override
public final PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleTypeName) {
String typeName;
if (packageName.length() == 0) {
@@ -752,6 +756,7 @@
return pw;
}
+ @Override
public OutputStream tryCreateResource(TreeLogger logger, String partialPath)
throws UnableToCompleteException {
@@ -810,6 +815,29 @@
return pendingResource;
}
+ /**
+ * Adds a type name to the list of types to be reused from cache, if
+ * available.
+ *
+ * @param typeName The fully qualified name of a type.
+ *
+ * @return true, if the type is available in the cache and was successfully
+ * added to the list for reuse, false otherwise.
+ */
+ @Override
+ public boolean tryReuseTypeFromCache(String typeName) {
+ if (!isGeneratorResultCachingEnabled() || cachedRebindResult == null
+ || !cachedRebindResult.isTypeCached(typeName)) {
+ return false;
+ }
+
+ if (cachedTypeNamesToReuse == null) {
+ cachedTypeNamesToReuse = new ArrayList<String>();
+ }
+ cachedTypeNamesToReuse.add(typeName);
+ return true;
+ }
+
private void abortUncommittedResources(TreeLogger logger) {
if (pendingResources.isEmpty()) {
// Nothing to do.
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/CachedClientDataMap.java b/dev/core/src/com/google/gwt/dev/javac/rebind/CachedClientDataMap.java
deleted file mode 100644
index c7b0d3d..0000000
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/CachedClientDataMap.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.dev.javac.rebind;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A simple map class for storing cached rebind client data. It ensures that
- * all stored data implement Serializable.
- */
-public class CachedClientDataMap implements Serializable {
-
- private final Map<String, Serializable> dataMap;
-
- public CachedClientDataMap() {
- dataMap = new HashMap<String, Serializable>();
- }
-
- public Object get(String key) {
- return dataMap.get(key);
- }
-
- public void put(String key, Object value) {
- dataMap.put(key, (Serializable) value);
- }
-}
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindResult.java b/dev/core/src/com/google/gwt/dev/javac/rebind/RebindResult.java
deleted file mode 100644
index 377c679..0000000
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindResult.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.dev.javac.rebind;
-
-/**
- * A class for returning the result of a rebind operation.
- */
-public class RebindResult {
- private final RebindStatus resultStatus;
- private final String returnedTypeName;
- private final CachedClientDataMap clientData;
-
- public RebindResult(RebindStatus resultStatus,
- String returnedType, CachedClientDataMap clientData) {
- this.resultStatus = resultStatus;
- this.returnedTypeName = returnedType;
- this.clientData = clientData;
- }
-
- public RebindResult(RebindStatus resultStatus, String returnedType) {
- this(resultStatus, returnedType, null);
- }
-
- public Object getClientData(String key) {
- if (clientData == null) {
- return null;
- } else {
- return clientData.get(key);
- }
- }
-
- public CachedClientDataMap getClientDataMap() {
- return clientData;
- }
-
- public RebindStatus getResultStatus() {
- return resultStatus;
- }
-
- public String getReturnedTypeName() {
- return returnedTypeName;
- }
-}
diff --git a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindStatus.java b/dev/core/src/com/google/gwt/dev/javac/rebind/RebindStatus.java
deleted file mode 100644
index 3506723..0000000
--- a/dev/core/src/com/google/gwt/dev/javac/rebind/RebindStatus.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.dev.javac.rebind;
-
-/**
- * The returned status for a rebind result. This status is used by the
- * {@link com.google.gwt.dev.shell.StandardRebindOracle} implementation to
- * determine how to integrate the result into the system. In the descriptions
- * below, the "products" of a rebind result can include updated type
- * information, newly generated artifacts, and newly generated compilation units.
- */
-public enum RebindStatus {
-
- /**
- * Indicates nothing new was created, use pre-existing type information.
- */
- USE_EXISTING,
-
- /**
- * Indicates only newly generated products should be used.
- */
- USE_ALL_NEW,
-
- /**
- * Indicates only newly generated products should be used, and no results
- * should be cached, such as in the case where no caching can be taken
- * advantage of.
- */
- USE_ALL_NEW_WITH_NO_CACHING,
-
- /**
- * Indicates only previously cached products should be used.
- */
- USE_ALL_CACHED,
-
- /**
- * Indicates that a mixture of newly generated and previously cached products
- * should be used.
- */
- USE_PARTIAL_CACHED
-}
diff --git a/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java b/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
index e5ac9b4..07e03ef 100644
--- a/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
+++ b/dev/core/src/com/google/gwt/dev/shell/ShellModuleSpaceHost.java
@@ -18,11 +18,11 @@
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.ArtifactSet;
+import com.google.gwt.dev.RebindCache;
import com.google.gwt.dev.cfg.ModuleDef;
import com.google.gwt.dev.cfg.Rules;
import com.google.gwt.dev.javac.CompilationState;
import com.google.gwt.dev.javac.StandardGeneratorContext;
-import com.google.gwt.dev.javac.rebind.RebindCache;
import com.google.gwt.dev.util.log.speedtracer.DevModeEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
diff --git a/dev/core/src/com/google/gwt/dev/shell/StandardRebindOracle.java b/dev/core/src/com/google/gwt/dev/shell/StandardRebindOracle.java
index 8449fee..e9cc7a8 100644
--- a/dev/core/src/com/google/gwt/dev/shell/StandardRebindOracle.java
+++ b/dev/core/src/com/google/gwt/dev/shell/StandardRebindOracle.java
@@ -15,18 +15,19 @@
*/
package com.google.gwt.dev.shell;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.RebindMode;
+import com.google.gwt.core.ext.RebindResult;
+import com.google.gwt.core.ext.RebindRuleResolver;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.ArtifactSet;
+import com.google.gwt.dev.RebindCache;
import com.google.gwt.dev.cfg.Rule;
import com.google.gwt.dev.cfg.Rules;
+import com.google.gwt.dev.javac.CachedGeneratorResultImpl;
import com.google.gwt.dev.javac.StandardGeneratorContext;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
-import com.google.gwt.dev.javac.rebind.RebindCache;
-import com.google.gwt.dev.javac.rebind.RebindResult;
-import com.google.gwt.dev.javac.rebind.RebindRuleResolver;
-import com.google.gwt.dev.javac.rebind.RebindStatus;
import com.google.gwt.dev.jdt.RebindOracle;
import com.google.gwt.dev.util.log.speedtracer.DevModeEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
@@ -69,7 +70,7 @@
return typeName;
}
- CachedRebindResult cachedResult = rebindCacheGet(rule, typeName);
+ CachedGeneratorResult cachedResult = rebindCacheGet(rule, typeName);
if (cachedResult != null) {
genCtx.setCachedGeneratorResult(cachedResult);
}
@@ -164,16 +165,16 @@
* to cache the new result for the future.
*/
private String processCacheableResult(TreeLogger logger, Rule rule, String typeName,
- CachedRebindResult cachedResult, RebindResult newResult) {
+ CachedGeneratorResult cachedResult, RebindResult newResult) {
- String resultTypeName = newResult.getReturnedTypeName();
+ String resultTypeName = newResult.getResultTypeName();
if (!genCtx.isGeneratorResultCachingEnabled()) {
return resultTypeName;
}
- RebindStatus status = newResult.getResultStatus();
- switch (status) {
+ RebindMode mode = newResult.getRebindMode();
+ switch (mode) {
case USE_EXISTING:
// in this case, no newly generated or cached types are needed
@@ -190,8 +191,9 @@
case USE_ALL_NEW:
// use all new results, add a new cache entry
cachedResult =
- new CachedRebindResult(newResult.getReturnedTypeName(), genCtx.getArtifacts(), genCtx
- .getGeneratedUnitMap(), System.currentTimeMillis(), newResult.getClientDataMap());
+ new CachedGeneratorResultImpl(newResult.getResultTypeName(), genCtx.getArtifacts(),
+ genCtx.getGeneratedUnitMap(), System.currentTimeMillis(), newResult
+ .getClientDataMap());
rebindCachePut(rule, typeName, cachedResult);
break;
@@ -203,7 +205,7 @@
genCtx.addGeneratedUnitsFromCache();
// use cached type name
- resultTypeName = cachedResult.getReturnedTypeName();
+ resultTypeName = cachedResult.getResultTypeName();
break;
case USE_PARTIAL_CACHED:
@@ -219,11 +221,16 @@
* cached results currently in genCtx.
*/
cachedResult =
- new CachedRebindResult(newResult.getReturnedTypeName(), genCtx.getArtifacts(), genCtx
- .getGeneratedUnitMap(), System.currentTimeMillis(), newResult.getClientDataMap());
+ new CachedGeneratorResultImpl(newResult.getResultTypeName(), genCtx.getArtifacts(),
+ genCtx.getGeneratedUnitMap(), System.currentTimeMillis(), newResult
+ .getClientDataMap());
rebindCachePut(rule, typeName, cachedResult);
break;
}
+
+ // clear the current cached result
+ genCtx.setCachedGeneratorResult(null);
+
return resultTypeName;
}
}
@@ -253,6 +260,7 @@
typeNameBindingMap.remove(sourceTypeName);
}
+ @Override
public String rebind(TreeLogger logger, String typeName) throws UnableToCompleteException {
return rebind(logger, typeName, null);
}
@@ -277,14 +285,14 @@
this.rebindCache = cache;
}
- private CachedRebindResult rebindCacheGet(Rule rule, String typeName) {
+ private CachedGeneratorResult rebindCacheGet(Rule rule, String typeName) {
if (rebindCache != null) {
return rebindCache.get(rule, typeName);
}
return null;
}
- private void rebindCachePut(Rule rule, String typeName, CachedRebindResult result) {
+ private void rebindCachePut(Rule rule, String typeName, CachedGeneratorResult result) {
if (rebindCache != null) {
rebindCache.put(rule, typeName, result);
}
diff --git a/user/src/com/google/gwt/i18n/rebind/CachedGeneratorContext.java b/user/src/com/google/gwt/i18n/rebind/CachedGeneratorContext.java
index e786bec..e972d43 100644
--- a/user/src/com/google/gwt/i18n/rebind/CachedGeneratorContext.java
+++ b/user/src/com/google/gwt/i18n/rebind/CachedGeneratorContext.java
@@ -15,14 +15,10 @@
*/
package com.google.gwt.i18n.rebind;
+import com.google.gwt.core.ext.DelegatingGeneratorContext;
import com.google.gwt.core.ext.GeneratorContext;
-import com.google.gwt.core.ext.PropertyOracle;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
-import com.google.gwt.core.ext.linker.Artifact;
-import com.google.gwt.core.ext.linker.GeneratedResource;
-import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.resource.ResourceOracle;
import java.io.OutputStream;
import java.io.PrintWriter;
@@ -35,45 +31,16 @@
* run. This is needed when one generator calls other generators multiple times
* (such as for runtime locale support).
*/
-class CachedGeneratorContext implements GeneratorContext {
+class CachedGeneratorContext extends DelegatingGeneratorContext {
private final GeneratorContext context;
private Set<String> generatedResources = new HashSet<String>();
private Set<String> generatedTypes = new HashSet<String>();
CachedGeneratorContext(GeneratorContext context) {
+ super(context);
this.context = context;
}
- public boolean checkRebindRuleAvailable(String sourceTypeName) {
- return context.checkRebindRuleAvailable(sourceTypeName);
- }
-
- public void commit(TreeLogger logger, PrintWriter pw) {
- context.commit(logger, pw);
- }
-
- public void commitArtifact(TreeLogger logger, Artifact<?> artifact)
- throws UnableToCompleteException {
- context.commitArtifact(logger, artifact);
- }
-
- public GeneratedResource commitResource(TreeLogger logger, OutputStream os)
- throws UnableToCompleteException {
- return context.commitResource(logger, os);
- }
-
- public PropertyOracle getPropertyOracle() {
- return context.getPropertyOracle();
- }
-
- public ResourceOracle getResourcesOracle() {
- return context.getResourcesOracle();
- }
-
- public TypeOracle getTypeOracle() {
- return context.getTypeOracle();
- }
-
/**
* Provide the canonical context represented by this context.
*
@@ -83,6 +50,7 @@
return context;
}
+ @Override
public PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleName) {
String typeName = packageName + '.' + simpleName;
if (generatedTypes.contains(typeName)) {
@@ -92,6 +60,7 @@
return context.tryCreate(logger, packageName, simpleName);
}
+ @Override
public OutputStream tryCreateResource(TreeLogger logger, String partialPath)
throws UnableToCompleteException {
if (generatedResources.contains(partialPath)) {
diff --git a/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java b/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java
index 489c3c5..69b78d6 100644
--- a/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java
+++ b/user/src/com/google/gwt/resources/rebind/context/AbstractClientBundleGenerator.java
@@ -17,10 +17,13 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.ext.BadPropertyValueException;
+import com.google.gwt.core.ext.CachedPropertyInformation;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.core.ext.GeneratorContext;
-import com.google.gwt.core.ext.GeneratorContextExt;
-import com.google.gwt.core.ext.GeneratorExt;
+import com.google.gwt.core.ext.IncrementalGenerator;
import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.RebindMode;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.SelectionProperty;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
@@ -32,11 +35,6 @@
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.dev.generator.NameFactory;
-import com.google.gwt.dev.javac.rebind.CachedClientDataMap;
-import com.google.gwt.dev.javac.rebind.CachedPropertyInformation;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
-import com.google.gwt.dev.javac.rebind.RebindResult;
-import com.google.gwt.dev.javac.rebind.RebindStatus;
import com.google.gwt.dev.util.Util;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ClientBundleWithLookup;
@@ -53,6 +51,7 @@
import com.google.gwt.user.rebind.SourceWriter;
import java.io.PrintWriter;
+import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@@ -114,12 +113,21 @@
* of an instance of the ClientBundle type so that resources can refer to one
* another by simply emitting a call to <code>resource()</code>.
*/
-public abstract class AbstractClientBundleGenerator extends GeneratorExt {
+public abstract class AbstractClientBundleGenerator extends IncrementalGenerator {
private static final String CACHED_PROPERTY_INFORMATION = "cached-property-info";
private static final String CACHED_RESOURCE_INFORMATION = "cached-resource-info";
private static final String CACHED_TYPE_INFORMATION = "cached-type-info";
private static final String INSTANCE_NAME = "_instance0";
+ /*
+ * A version id. Increment this as needed, when structural changes are made to
+ * the generated output, specifically with respect to it's effect on the
+ * caching and reuse of previous generator results. Previously cached
+ * generator results will be invalidated automatically if they were generated
+ * by a version of this generator with a different version id.
+ */
+ private static final long GENERATOR_VERSION_ID = 1L;
+
/**
* An implementation of ClientBundleFields.
*/
@@ -324,18 +332,17 @@
}
@Override
- public RebindResult generateIncrementally(TreeLogger logger,
- GeneratorContextExt generatorContext, String typeName)
- throws UnableToCompleteException {
+ public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext generatorContext,
+ String typeName) throws UnableToCompleteException {
/*
* Do a series of checks to see if we can use a previously cached result,
* and if so, we can skip further execution and return immediately.
*/
boolean useCache = false;
- if (checkPropertyCacheability(logger, generatorContext)
- && checkSourceTypeCacheability(logger, generatorContext)
- && checkDependentResourceCacheability(logger, generatorContext)) {
+ if (checkCachedPropertyInformation(logger, generatorContext)
+ && checkCachedSourceTypes(logger, generatorContext)
+ && checkCachedDependentResources(logger, generatorContext)) {
useCache = true;
}
@@ -352,7 +359,7 @@
}
if (useCache) {
- return new RebindResult(RebindStatus.USE_ALL_CACHED, typeName);
+ return new RebindResult(RebindMode.USE_ALL_CACHED, typeName);
}
// The TypeOracle knows about all types in the type system
@@ -488,21 +495,27 @@
// remember the required resources
Map<String, URL> cri = requirements.getResolvedResources();
- // create data map to be returned the next time the generator is run
- CachedClientDataMap data = new CachedClientDataMap();
- data.put(CACHED_PROPERTY_INFORMATION, cpi);
- data.put(CACHED_RESOURCE_INFORMATION, cri);
- data.put(CACHED_TYPE_INFORMATION, cti);
+ // create a new cacheable result
+ RebindResult result = new RebindResult(RebindMode.USE_ALL_NEW, createdClassName);
- // Return a new cacheable result
- return new RebindResult(RebindStatus.USE_ALL_NEW, createdClassName, data);
+ // 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(RebindStatus.USE_ALL_NEW_WITH_NO_CACHING,
+ return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING,
createdClassName);
}
}
+ @Override
+ public long getVersionId() {
+ return GENERATOR_VERSION_ID;
+ }
+
/**
* Create the ResourceContext object that will be used by
* {@link ResourceGenerator} subclasses. This is the primary way to implement
@@ -555,40 +568,12 @@
}
/**
- * Check that the cached last modified times match those from the current
- * typeOracle.
+ * Check cached dependent resources.
*/
- private boolean checkCachedTypeLastModifiedTimes(TreeLogger logger,
- GeneratorContextExt generatorContext, Map<String, Long> typeLastModifiedTimes) {
-
- TypeOracle oracle = generatorContext.getTypeOracle();
-
- for (String sourceTypeName : typeLastModifiedTimes.keySet()) {
- JClassType sourceType = oracle.findType(sourceTypeName);
- if (sourceType == null) {
- logger.log(TreeLogger.TRACE,
- "Found previously dependent type that's no longer present: " + sourceTypeName);
- return false;
- }
- assert sourceType instanceof JRealClassType;
- JRealClassType sourceRealType = (JRealClassType) sourceType;
-
- if (sourceRealType.getLastModifiedTime() != typeLastModifiedTimes.get(sourceTypeName)) {
- logger.log(TreeLogger.TRACE, "Found dependent type that has changed: " + sourceTypeName);
- return false;
- }
- }
-
- return true;
- }
+ private boolean checkCachedDependentResources(TreeLogger logger,
+ GeneratorContext genContext) {
- /**
- * Check dependent resources for cacheability.
- */
- private boolean checkDependentResourceCacheability(TreeLogger logger,
- GeneratorContextExt genContext) {
-
- CachedRebindResult lastRebindResult = genContext.getCachedGeneratorResult();
+ CachedGeneratorResult lastRebindResult = genContext.getCachedGeneratorResult();
if (lastRebindResult == null
|| !genContext.isGeneratorResultCachingEnabled()) {
@@ -636,13 +621,12 @@
return true;
}
- /*
- * Check properties for cacheability
+ /**
+ * Check cached properties.
*/
- private boolean checkPropertyCacheability(TreeLogger logger,
- GeneratorContextExt genContext) {
+ private boolean checkCachedPropertyInformation(TreeLogger logger, GeneratorContext genContext) {
- CachedRebindResult lastRebindResult = genContext.getCachedGeneratorResult();
+ CachedGeneratorResult lastRebindResult = genContext.getCachedGeneratorResult();
if (lastRebindResult == null
|| !genContext.isGeneratorResultCachingEnabled()) {
@@ -659,36 +643,13 @@
return cpi != null && cpi.checkPropertiesWithPropertyOracle(logger,
genContext.getPropertyOracle());
}
-
+
/**
- * Check cacheability for resource generators in taskList.
+ * Check cached source types.
*/
- private boolean checkResourceGeneratorCacheability(
- GeneratorContextExt genContext,
- Map<Class<? extends ResourceGenerator>, List<JMethod>> taskList) {
-
- if (!genContext.isGeneratorResultCachingEnabled()) {
- return false;
- }
+ private boolean checkCachedSourceTypes(TreeLogger logger, GeneratorContext genContext) {
- /*
- * Loop through each of our ResouceGenerator classes, and check those that
- * implement the SupportsGeneratorResultCaching interface.
- */
- for (Class<? extends ResourceGenerator> rgClass : taskList.keySet()) {
- if (!SupportsGeneratorResultCaching.class.isAssignableFrom(rgClass)) {
- return false;
- }
- }
- return true;
- }
-
- /*
- * Check source types for cacheability
- */
- private boolean checkSourceTypeCacheability(TreeLogger logger, GeneratorContextExt genContext) {
-
- CachedRebindResult lastRebindResult = genContext.getCachedGeneratorResult();
+ CachedGeneratorResult lastRebindResult = genContext.getCachedGeneratorResult();
if (lastRebindResult == null
|| !genContext.isGeneratorResultCachingEnabled()) {
@@ -709,6 +670,56 @@
}
/**
+ * Check that the cached last modified times match those from the current
+ * typeOracle.
+ */
+ private boolean checkCachedTypeLastModifiedTimes(TreeLogger logger,
+ GeneratorContext generatorContext, Map<String, Long> typeLastModifiedTimes) {
+
+ TypeOracle oracle = generatorContext.getTypeOracle();
+
+ for (String sourceTypeName : typeLastModifiedTimes.keySet()) {
+ JClassType sourceType = oracle.findType(sourceTypeName);
+ if (sourceType == null) {
+ logger.log(TreeLogger.TRACE,
+ "Found previously dependent type that's no longer present: " + sourceTypeName);
+ return false;
+ }
+ assert sourceType instanceof JRealClassType;
+ JRealClassType sourceRealType = (JRealClassType) sourceType;
+
+ if (sourceRealType.getLastModifiedTime() != typeLastModifiedTimes.get(sourceTypeName)) {
+ logger.log(TreeLogger.TRACE, "Found dependent type that has changed: " + sourceTypeName);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Check cacheability for resource generators in taskList.
+ */
+ private boolean checkResourceGeneratorCacheability(GeneratorContext genContext,
+ Map<Class<? extends ResourceGenerator>, List<JMethod>> taskList) {
+
+ if (!genContext.isGeneratorResultCachingEnabled()) {
+ return false;
+ }
+
+ /*
+ * Loop through each of our ResouceGenerator classes, and check those that
+ * implement the SupportsGeneratorResultCaching interface.
+ */
+ for (Class<? extends ResourceGenerator> rgClass : taskList.keySet()) {
+ if (!SupportsGeneratorResultCaching.class.isAssignableFrom(rgClass)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Create fields and assignments for a single ResourceGenerator.
*/
private boolean createFieldsAndAssignments(TreeLogger logger,
diff --git a/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java b/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java
index 7ea1bac..167a216 100644
--- a/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java
+++ b/user/src/com/google/gwt/rpc/rebind/RpcProxyCreator.java
@@ -19,7 +19,7 @@
import com.google.gwt.core.client.impl.ArtificialRescue;
import com.google.gwt.core.client.impl.Impl;
import com.google.gwt.core.client.impl.ArtificialRescue.Rescue;
-import com.google.gwt.core.ext.GeneratorContextExt;
+import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JArrayType;
@@ -118,7 +118,7 @@
}
@Override
- protected void generateTypeHandlers(TreeLogger logger, GeneratorContextExt ctx,
+ protected void generateTypeHandlers(TreeLogger logger, GeneratorContext ctx,
SerializableTypeOracle serializationSto,
SerializableTypeOracle deserializationSto)
throws UnableToCompleteException {
@@ -271,7 +271,7 @@
@Override
protected String writeSerializationPolicyFile(TreeLogger logger,
- GeneratorContextExt ctx, SerializableTypeOracle serializationSto,
+ GeneratorContext ctx, SerializableTypeOracle serializationSto,
SerializableTypeOracle deserializationSto)
throws UnableToCompleteException {
diff --git a/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java b/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java
index 8429c8c..6ec516c 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java
@@ -151,7 +151,7 @@
}
/*
- * Finds a last modified time for a type, for testing cacheability.
+ * Finds a last modified time for a type, for testing cache reusability.
*/
private long getLastModifiedTime(JType type) {
if (type instanceof JArrayType) {
diff --git a/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java b/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java
index 2834667..07d3414 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java
@@ -18,7 +18,6 @@
import com.google.gwt.core.client.UnsafeNativeLong;
import com.google.gwt.core.client.impl.WeakMapping;
import com.google.gwt.core.ext.GeneratorContext;
-import com.google.gwt.core.ext.GeneratorContextExt;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.typeinfo.JArrayType;
import com.google.gwt.core.ext.typeinfo.JClassType;
@@ -63,7 +62,7 @@
private static final String WEAK_MAPPING_CLASS_NAME = WeakMapping.class.getName();
- private final GeneratorContextExt context;
+ private final GeneratorContext context;
private final JClassType customFieldSerializer;
@@ -94,7 +93,7 @@
/**
* Constructs a field serializer for the class.
*/
- public FieldSerializerCreator(GeneratorContextExt context,
+ public FieldSerializerCreator(GeneratorContext context,
SerializableTypeOracle typesSentFromBrowser, SerializableTypeOracle typesSentToBrowser,
JClassType requestedClass, JClassType customFieldSerializer) {
this.context = context;
diff --git a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
index 0596841..8b037da 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
@@ -18,9 +18,13 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.impl.Impl;
import com.google.gwt.core.ext.BadPropertyValueException;
+import com.google.gwt.core.ext.CachedPropertyInformation;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.core.ext.ConfigurationProperty;
-import com.google.gwt.core.ext.GeneratorContextExt;
+import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.RebindMode;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.EmittedArtifact.Visibility;
@@ -36,11 +40,6 @@
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.dev.generator.NameFactory;
-import com.google.gwt.dev.javac.rebind.CachedClientDataMap;
-import com.google.gwt.dev.javac.rebind.CachedPropertyInformation;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
-import com.google.gwt.dev.javac.rebind.RebindResult;
-import com.google.gwt.dev.javac.rebind.RebindStatus;
import com.google.gwt.dev.util.Util;
import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
@@ -101,7 +100,7 @@
public static final String MANIFEST_ARTIFACT_DIR = "rpcPolicyManifest/manifests";
/**
- * Properties which need to be checked to determine cacheability.
+ * Properties which need to be checked to determine cache reusability.
*/
private static final Collection<String> configPropsToCheck = Arrays.asList(
TypeSerializerCreator.GWT_ELIDE_TYPE_NAMES_FROM_RPC, Shared.RPC_ENHANCED_CLASSES);
@@ -254,7 +253,7 @@
*
* @throws UnableToCompleteException
*/
- public RebindResult create(TreeLogger logger, GeneratorContextExt context)
+ public RebindResult create(TreeLogger logger, GeneratorContext context)
throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
@@ -268,7 +267,7 @@
}
if (checkAlreadyGenerated(typeOracle, serviceIntf)) {
- return new RebindResult(RebindStatus.USE_EXISTING, getProxyQualifiedName());
+ return new RebindResult(RebindMode.USE_EXISTING, getProxyQualifiedName());
}
// Make sure that the async and synchronous versions of the RemoteService
@@ -328,7 +327,7 @@
// 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(RebindStatus.USE_ALL_CACHED, getProxyQualifiedName());
+ return new RebindResult(RebindMode.USE_ALL_CACHED, getProxyQualifiedName());
}
try {
@@ -347,7 +346,7 @@
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(RebindStatus.USE_EXISTING, getProxyQualifiedName());
+ return new RebindResult(RebindMode.USE_EXISTING, getProxyQualifiedName());
}
generateTypeHandlers(logger, context, typesSentFromBrowser, typesSentToBrowser);
@@ -379,25 +378,28 @@
}
if (checkGeneratorResultCacheability(context)) {
- // Remember the type info that we care about for cacheability testing.
- CachedClientDataMap clientData = new CachedClientDataMap();
+ /*
+ * 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);
- clientData.put(CACHED_TYPE_INFO_KEY, cti);
CachedPropertyInformation cpi =
new CachedPropertyInformation(logger, context.getPropertyOracle(), selectionPropsToCheck,
configPropsToCheck);
- clientData.put(CACHED_PROPERTY_INFO_KEY, cpi);
+ result.putClientData(CACHED_TYPE_INFO_KEY, cti);
+ result.putClientData(CACHED_PROPERTY_INFO_KEY, cpi);
- /*
- * Return with RebindStatus.USE_PARTIAL_CACHED, since we are allowing
- * reuse of cached results for field serializers, when available, but
- * all other types have been newly generated.
- */
- return new RebindResult(RebindStatus.USE_PARTIAL_CACHED, getProxyQualifiedName(), clientData);
+ return result;
} else {
- return new RebindResult(RebindStatus.USE_ALL_NEW_WITH_NO_CACHING, getProxyQualifiedName());
+ return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, getProxyQualifiedName());
}
}
@@ -689,7 +691,7 @@
srcWriter.println("}");
}
- protected void generateTypeHandlers(TreeLogger logger, GeneratorContextExt context,
+ protected void generateTypeHandlers(TreeLogger logger, GeneratorContext context,
SerializableTypeOracle typesSentFromBrowser, SerializableTypeOracle typesSentToBrowser)
throws UnableToCompleteException {
Event event = SpeedTracerLogger.start(CompilerEventType.GENERATOR_RPC_TYPE_SERIALIZER);
@@ -730,7 +732,7 @@
return ClientSerializationStreamWriter.class;
}
- protected String writeSerializationPolicyFile(TreeLogger logger, GeneratorContextExt ctx,
+ protected String writeSerializationPolicyFile(TreeLogger logger, GeneratorContext ctx,
SerializableTypeOracle serializationSto, SerializableTypeOracle deserializationSto)
throws UnableToCompleteException {
try {
@@ -832,10 +834,10 @@
return typeOracle.findType(packageName, getProxySimpleName()) != null;
}
- private boolean checkCachedGeneratorResultValid(TreeLogger logger, GeneratorContextExt ctx,
+ private boolean checkCachedGeneratorResultValid(TreeLogger logger, GeneratorContext ctx,
SerializableTypeOracle typesSentFromBrowser, SerializableTypeOracle typesSentToBrowser) {
- CachedRebindResult lastResult = ctx.getCachedGeneratorResult();
+ CachedGeneratorResult lastResult = ctx.getCachedGeneratorResult();
if (lastResult == null || !ctx.isGeneratorResultCachingEnabled()) {
return false;
}
@@ -864,7 +866,7 @@
return true;
}
- private boolean checkGeneratorResultCacheability(GeneratorContextExt context) {
+ private boolean checkGeneratorResultCacheability(GeneratorContext context) {
/*
* Currently not supporting caching for implementations which sub-class this
* class, such as {@link RpcProxyCreator}, which implements deRPC.
@@ -876,7 +878,7 @@
return context.isGeneratorResultCachingEnabled();
}
- private void emitPolicyFileArtifact(TreeLogger logger, GeneratorContextExt context,
+ private void emitPolicyFileArtifact(TreeLogger logger, GeneratorContext context,
String partialPath) throws UnableToCompleteException {
try {
String qualifiedSourceName = serviceIntf.getQualifiedSourceName();
@@ -924,7 +926,7 @@
return ResponseReader.OBJECT;
}
- private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContextExt ctx,
+ private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx,
JClassType serviceAsync) {
JPackage serviceIntfPkg = serviceAsync.getPackage();
String packageName = serviceIntfPkg == null ? "" : serviceIntfPkg.getName();
diff --git a/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java b/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java
index 22437ff..5463c55 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilder.java
@@ -15,7 +15,7 @@
*/
package com.google.gwt.user.rebind.rpc;
-import com.google.gwt.core.ext.GeneratorContextExt;
+import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.PropertyOracle;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
@@ -307,6 +307,7 @@
* Compares {@link JType}s according to their qualified source names.
*/
static final Comparator<JType> JTYPE_COMPARATOR = new Comparator<JType>() {
+ @Override
public int compare(JType t1, JType t2) {
return t1.getQualifiedSourceName().compareTo(t2.getQualifiedSourceName());
}
@@ -316,10 +317,12 @@
* No type filtering by default..
*/
private static final TypeFilter DEFAULT_TYPE_FILTER = new TypeFilter() {
+ @Override
public String getName() {
return "Default";
}
+ @Override
public boolean isAllowed(JClassType type) {
return true;
}
@@ -726,7 +729,7 @@
*/
private final JGenericType collectionClass;
- private final GeneratorContextExt context;
+ private final GeneratorContext context;
private Set<String> enhancedClasses = null;
@@ -772,13 +775,13 @@
*
* @param logger
* @param propertyOracle
- * @param typeOracle
+ * @param context
*
* @throws UnableToCompleteException if we fail to find one of our special
* types
*/
public SerializableTypeOracleBuilder(TreeLogger logger, PropertyOracle propertyOracle,
- GeneratorContextExt context) throws UnableToCompleteException {
+ GeneratorContext context) throws UnableToCompleteException {
this.context = context;
this.typeOracle = context.getTypeOracle();
typeConstrainer = new TypeConstrainer(typeOracle);
@@ -1329,7 +1332,7 @@
* Check the argument to a parameterized type to see if it will make the type
* it is applied to be serializable. As a side effect, populates
* {@link #typeToTypeInfoComputed} in the same way as
- * {@link #checkTypeInstantiable(TreeLogger, JType, boolean)}.
+ * {@link #computeTypeInstantiability}.
*
* @param logger
* @param baseType - The generic type the parameter is on
diff --git a/user/src/com/google/gwt/user/rebind/rpc/ServiceInterfaceProxyGenerator.java b/user/src/com/google/gwt/user/rebind/rpc/ServiceInterfaceProxyGenerator.java
index 60435de..2e9026a 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/ServiceInterfaceProxyGenerator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/ServiceInterfaceProxyGenerator.java
@@ -15,22 +15,31 @@
*/
package com.google.gwt.user.rebind.rpc;
-import com.google.gwt.core.ext.GeneratorContextExt;
-import com.google.gwt.core.ext.GeneratorExt;
+import com.google.gwt.core.ext.GeneratorContext;
+import com.google.gwt.core.ext.IncrementalGenerator;
+import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.rebind.RebindResult;
/**
* Generator for producing the asynchronous version of a
* {@link com.google.gwt.user.client.rpc.RemoteService RemoteService} interface.
*/
-public class ServiceInterfaceProxyGenerator extends GeneratorExt {
+public class ServiceInterfaceProxyGenerator extends IncrementalGenerator {
+
+ /*
+ * A version id. Increment this as needed, when structural changes are made to
+ * the generated output, specifically with respect to it's effect on the
+ * caching and reuse of previous generator results. Previously cached
+ * generator results will be invalidated automatically if they were generated
+ * by a version of this generator with a different version id.
+ */
+ private static final long GENERATOR_VERSION_ID = 1L;
@Override
- public RebindResult generateIncrementally(TreeLogger logger, GeneratorContextExt ctx,
+ public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext ctx,
String requestedClass) throws UnableToCompleteException {
TypeOracle typeOracle = ctx.getTypeOracle();
@@ -58,6 +67,11 @@
return proxyCreator.create(proxyLogger, ctx);
}
+ @Override
+ public long getVersionId() {
+ return GENERATOR_VERSION_ID;
+ }
+
protected ProxyCreator createProxyCreator(JClassType remoteService) {
return new ProxyCreator(remoteService);
}
diff --git a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
index 7489b7b..753d5f0 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
@@ -20,8 +20,9 @@
import com.google.gwt.core.client.GwtScriptOnly;
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.core.ext.BadPropertyValueException;
+import com.google.gwt.core.ext.CachedGeneratorResult;
import com.google.gwt.core.ext.ConfigurationProperty;
-import com.google.gwt.core.ext.GeneratorContextExt;
+import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
@@ -29,7 +30,6 @@
import com.google.gwt.core.ext.typeinfo.JParameterizedType;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
@@ -99,7 +99,7 @@
}
}
- private final GeneratorContextExt context;
+ private final GeneratorContext context;
private final SerializableTypeOracle deserializationOracle;
@@ -124,7 +124,7 @@
private final Set<JType> customFieldSerializersUsed;
public TypeSerializerCreator(TreeLogger logger, SerializableTypeOracle serializationOracle,
- SerializableTypeOracle deserializationOracle, GeneratorContextExt context,
+ SerializableTypeOracle deserializationOracle, GeneratorContext context,
String typeSerializerClassName, String typeSerializerSimpleName)
throws UnableToCompleteException {
this.context = context;
@@ -223,7 +223,7 @@
* Create a field serializer for a type if it does not have a custom
* serializer.
*/
- private void createFieldSerializer(TreeLogger logger, GeneratorContextExt ctx, JType type) {
+ private void createFieldSerializer(TreeLogger logger, GeneratorContext ctx, JType type) {
Event event = SpeedTracerLogger.start(CompilerEventType.GENERATOR_RPC_FIELD_SERIALIZER);
try {
assert (type != null);
@@ -249,7 +249,7 @@
SerializableTypeOracleBuilder.findCustomFieldSerializer(typeOracle, type);
if (ctx.isGeneratorResultCachingEnabled()) {
- // update cacheable info for next iteration
+ // update cached info for next iteration
if (customFieldSerializer != null) {
customFieldSerializersUsed.add(customFieldSerializer);
} else {
@@ -257,7 +257,7 @@
}
// check the cache for a valid field serializer for the current type
- if (findCacheableFieldSerializerAndMarkForReuseIfAvailable(logger, ctx, type,
+ if (findReusableCachedFieldSerializerIfAvailable(logger, ctx, type,
customFieldSerializer)) {
// we can skip re-generation of the field serializer for the current
// type
@@ -278,7 +278,7 @@
/*
* Create all of the necessary field serializers.
*/
- private void createFieldSerializers(TreeLogger logger, GeneratorContextExt ctx) {
+ private void createFieldSerializers(TreeLogger logger, GeneratorContext ctx) {
JType[] types = getSerializableTypes();
int typeCount = types.length;
for (int typeIndex = 0; typeIndex < typeCount; ++typeIndex) {
@@ -294,10 +294,10 @@
* FieldSerializer. If so, mark it for reuse, and return true. Otherwise
* return false.
*/
- private boolean findCacheableFieldSerializerAndMarkForReuseIfAvailable(TreeLogger logger,
- GeneratorContextExt ctx, JType type, JType customFieldSerializer) {
+ private boolean findReusableCachedFieldSerializerIfAvailable(TreeLogger logger,
+ GeneratorContext ctx, JType type, JType customFieldSerializer) {
- CachedRebindResult lastResult = ctx.getCachedGeneratorResult();
+ CachedGeneratorResult lastResult = ctx.getCachedGeneratorResult();
if (lastResult == null || !ctx.isGeneratorResultCachingEnabled()) {
return false;
}
@@ -330,7 +330,7 @@
.checkLastModifiedTime(customFieldSerializer)) || (customFieldSerializer == null && cachedTypeInfo
.checkTypeNotUsingCustomSerializer(type)))) {
// use cached version, if available
- foundMatch = ctx.reuseTypeFromCacheIfAvailable(fieldSerializerName);
+ foundMatch = ctx.tryReuseTypeFromCache(fieldSerializerName);
}
if (logger.isLoggable(TreeLogger.TRACE)) {
@@ -361,7 +361,7 @@
return serializableTypes;
}
- private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContextExt ctx) {
+ private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx) {
String name[] = getPackageAndClassName(typeSerializerClassName);
String packageName = name[0];
String className = name[1];
diff --git a/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java b/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
index f7dcf56..04a1618 100644
--- a/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
+++ b/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
@@ -15,12 +15,9 @@
*/
package com.google.gwt.user.rebind.rpc;
-import com.google.gwt.core.ext.GeneratorContextExt;
-import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.StubGeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
-import com.google.gwt.core.ext.linker.Artifact;
-import com.google.gwt.core.ext.linker.GeneratedResource;
import com.google.gwt.core.ext.typeinfo.JArrayType;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.JGenericType;
@@ -38,12 +35,10 @@
import com.google.gwt.dev.cfg.ModuleDefLoader;
import com.google.gwt.dev.cfg.StaticPropertyOracle;
import com.google.gwt.dev.javac.TypeOracleTestingUtils;
-import com.google.gwt.dev.javac.rebind.CachedRebindResult;
import com.google.gwt.dev.javac.testing.impl.JavaResourceBase;
import com.google.gwt.dev.javac.testing.impl.MockJavaResource;
import com.google.gwt.dev.javac.testing.impl.StaticJavaResource;
import com.google.gwt.dev.resource.Resource;
-import com.google.gwt.dev.resource.ResourceOracle;
import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
import com.google.gwt.user.rebind.rpc.testcases.client.AbstractSerializableTypes;
import com.google.gwt.user.rebind.rpc.testcases.client.ClassWithTypeParameterThatErasesToObject;
@@ -53,7 +48,7 @@
import junit.framework.TestCase;
-import java.io.OutputStream;
+// import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
@@ -69,68 +64,25 @@
*/
public class SerializableTypeOracleBuilderTest extends TestCase {
/**
- * Just enough of a {@code GeneratorContextExt} to satisfy
+ * Just enough of a {@code GeneratorContext} to satisfy
* {@code SerializableTypeOracleBuilder}.
*/
- static class MockContext implements GeneratorContextExt {
+ static class MockContext extends StubGeneratorContext {
private TypeOracle typeOracle;
MockContext(TypeOracle typeOracle) {
this.typeOracle = typeOracle;
}
- public boolean checkRebindRuleAvailable(String sourceTypeName) {
- return true;
- }
-
- public void commit(TreeLogger logger, PrintWriter pw) {
- }
-
- public void commitArtifact(TreeLogger logger, Artifact<?> artifact)
- throws UnableToCompleteException {
- }
-
- public GeneratedResource commitResource(TreeLogger logger, OutputStream os)
- throws UnableToCompleteException {
- return null;
- }
-
- public CachedRebindResult getCachedGeneratorResult() {
- return null;
- }
-
- public PropertyOracle getPropertyOracle() {
- return null;
- }
-
- public ResourceOracle getResourcesOracle() {
- return null;
- }
-
+ @Override
public TypeOracle getTypeOracle() {
return typeOracle;
}
- public boolean isGeneratorResultCachingEnabled() {
- return false;
- }
-
+ @Override
public boolean isProdMode() {
return true;
}
-
- public boolean reuseTypeFromCacheIfAvailable(String typeName) {
- return false;
- }
-
- public PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleName) {
- return null;
- }
-
- public OutputStream tryCreateResource(TreeLogger logger, String partialPath)
- throws UnableToCompleteException {
- return null;
- }
}
/**
@@ -282,6 +234,7 @@
private static void sort(TypeInfo[] typeInfos) {
Arrays.sort(typeInfos, new Comparator<TypeInfo>() {
+ @Override
public int compare(TypeInfo ti1, TypeInfo ti2) {
if (ti1 == ti2) {
return 0;
@@ -2172,7 +2125,6 @@
/**
* Miscellaneous direct tests of {@link TypeConstrainer}.
*
- * @throws UnableToCompleteException
* @throws NotFoundException
*/
public void testTypeConstrainer() throws NotFoundException {