From commits-return-7006-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Tue Jul 3 04:35:47 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 2D248180626 for ; Tue, 3 Jul 2018 04:35:47 +0200 (CEST) Received: (qmail 79188 invoked by uid 500); 3 Jul 2018 02:35:46 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 79179 invoked by uid 99); 3 Jul 2018 02:35:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2018 02:35:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 04437E049E; Tue, 3 Jul 2018 02:35:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: <0628bd9b520c4c92beedf396453ed65a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: GROOVY-8675: GenericsUtils.PARAMETERIZED_TYPE_CACHE is static and private(closes #765) Date: Tue, 3 Jul 2018 02:35:45 +0000 (UTC) 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 Authored: Tue Jul 3 10:20:53 2018 +0800 Committer: sunlan 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 sr = PARAMETERIZED_TYPE_CACHE.getAndPut(new ParameterizedTypeCacheKey(genericsClass, actualType), new EvictableCache.ValueProvider>() { @Override public SoftReference provide(ParameterizedTypeCacheKey key) { @@ -748,6 +765,14 @@ public class GenericsUtils { private static final EvictableCache> 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