You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/07/03 02:22:40 UTC
groovy git commit: GROOVY-8675:
GenericsUtils.PARAMETERIZED_TYPE_CACHE is static and private(closes #765)
Repository: groovy
Updated Branches:
refs/heads/master cbb5e0345 -> 3143944c3
GROOVY-8675: GenericsUtils.PARAMETERIZED_TYPE_CACHE is static and private(closes #765)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3143944c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3143944c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3143944c
Branch: refs/heads/master
Commit: 3143944c30f340208be40e9452e2e5be2e4a33be
Parents: cbb5e03
Author: sunlan <su...@apache.org>
Authored: Tue Jul 3 10:20:53 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Jul 3 10:22:21 2018 +0800
----------------------------------------------------------------------
.../groovy/ast/tools/GenericsUtils.java | 25 ++++++++++++++++++++
1 file changed, 25 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/3143944c/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 933807f..05e96ab 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -665,11 +665,28 @@ public class GenericsUtils {
return newTypes;
}
+ private static final boolean PARAMETERIZED_TYPE_CACHE_ENABLED;
+ private static final String TRUE_STR = "true";
+ static {
+ boolean tmp;
+ try {
+ tmp = TRUE_STR.equals(System.getProperty("groovy.enable.parameterized.type.cache", TRUE_STR));
+ } catch (Exception e) {
+ tmp = true;
+ }
+
+ PARAMETERIZED_TYPE_CACHE_ENABLED = tmp;
+ }
+
/**
* Try to get the parameterized type from the cache.
* If no cached item found, cache and return the result of {@link #findParameterizedType(ClassNode, ClassNode)}
*/
public static ClassNode findParameterizedTypeFromCache(final ClassNode genericsClass, final ClassNode actualType) {
+ if (!PARAMETERIZED_TYPE_CACHE_ENABLED) {
+ return findParameterizedType(genericsClass, actualType);
+ }
+
SoftReference<ClassNode> sr = PARAMETERIZED_TYPE_CACHE.getAndPut(new ParameterizedTypeCacheKey(genericsClass, actualType), key -> new SoftReference<>(findParameterizedType(key.getGenericsClass(), key.getActualType())));
return null == sr ? null : sr.get();
@@ -743,6 +760,14 @@ public class GenericsUtils {
private static final EvictableCache<ParameterizedTypeCacheKey, SoftReference<ClassNode>> PARAMETERIZED_TYPE_CACHE = new ConcurrentSoftCache<>(64);
/**
+ * Clear the parameterized type cache
+ * It is useful to IDE as the type being compiled are continuously being edited/altered, see GROOVY-8675
+ */
+ public static void clearParameterizedTypeCache() {
+ PARAMETERIZED_TYPE_CACHE.clearAll();
+ }
+
+ /**
* map declaring generics type to actual generics type, e.g. GROOVY-7204:
* declaring generics types: T, S extends Serializable
* actual generics types : String, Long