groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: GROOVY-8675: GenericsUtils.PARAMETERIZED_TYPE_CACHE is static and private(closes #765)
Date Tue, 03 Jul 2018 02:35:45 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 5152c3a93 -> 371d8eb1e


GROOVY-8675: GenericsUtils.PARAMETERIZED_TYPE_CACHE is static and private(closes #765)

(cherry picked from commit 3143944)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/371d8eb1
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/371d8eb1
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/371d8eb1

Branch: refs/heads/GROOVY_2_5_X
Commit: 371d8eb1eafbb4be8db21b2597044471d2886426
Parents: 5152c3a
Author: sunlan <sunlan@apache.org>
Authored: Tue Jul 3 10:20:53 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Jul 3 10:30:42 2018 +0800

----------------------------------------------------------------------
 .../groovy/ast/tools/GenericsUtils.java         | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/371d8eb1/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 967db62..bac79fd 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), new EvictableCache.ValueProvider<ParameterizedTypeCacheKey, SoftReference<ClassNode>>()
{
             @Override
             public SoftReference<ClassNode> provide(ParameterizedTypeCacheKey key)
{
@@ -748,6 +765,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


Mime
View raw message