groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [1/4] groovy git commit: Trivial refactoring: avoid redundant creation of `GenericsTypeName`
Date Sat, 25 Aug 2018 17:02:01 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 4c337fe96 -> 6c615579f


Trivial refactoring: avoid redundant creation of `GenericsTypeName`

(cherry picked from commit bf7c42ea511d110170837b854c31e66778158dd1)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: ca75954dff3388426e4447aee3a9a0753943b19f
Parents: 4c337fe
Author: Daniel Sun <sunlan@apache.org>
Authored: Sat Aug 25 23:42:56 2018 +0800
Committer: Daniel Sun <sunlan@apache.org>
Committed: Sun Aug 26 00:46:49 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/ast/GenericsType.java    | 19 +++++++++++--------
 .../groovy/ast/tools/WideningCategories.java     |  5 +++--
 .../codehaus/groovy/control/ResolveVisitor.java  |  9 +++++----
 .../transform/stc/StaticTypeCheckingSupport.java |  2 +-
 4 files changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ca75954d/src/main/java/org/codehaus/groovy/ast/GenericsType.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 6e8dcc0..28216e1 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -372,8 +372,8 @@ public class GenericsType extends ASTNode {
                 return true;
             }
             GenericsType[] redirectBoundGenericTypes = bound.redirect().getGenericsTypes();
-            Map<GenericsType.GenericsTypeName, GenericsType> classNodePlaceholders
= GenericsUtils.extractPlaceholders(classNode);
-            Map<GenericsType.GenericsTypeName, GenericsType> boundPlaceHolders = GenericsUtils.extractPlaceholders(bound);
+            Map<GenericsTypeName, GenericsType> classNodePlaceholders = GenericsUtils.extractPlaceholders(classNode);
+            Map<GenericsTypeName, GenericsType> boundPlaceHolders = GenericsUtils.extractPlaceholders(bound);
             boolean match = true;
             for (int i = 0; redirectBoundGenericTypes!=null && i < redirectBoundGenericTypes.length
&& match; i++) {
                 GenericsType redirectBoundType = redirectBoundGenericTypes[i];
@@ -381,9 +381,10 @@ public class GenericsType extends ASTNode {
                 if (classNodeType.isPlaceholder()) {
                     GenericsTypeName name = new GenericsTypeName(classNodeType.getName());
                     if (redirectBoundType.isPlaceholder()) {
-                        match = name.equals(new GenericsTypeName(redirectBoundType.getName()));
+                        GenericsTypeName gtn = new GenericsTypeName(redirectBoundType.getName());
+                        match = name.equals(gtn);
                         if (!match) {
-                            GenericsType genericsType = boundPlaceHolders.get(new GenericsTypeName(redirectBoundType.getName()));
+                            GenericsType genericsType = boundPlaceHolders.get(gtn);
                             match = false;
                             if (genericsType!=null) {
                                 if (genericsType.isPlaceholder()) {
@@ -424,8 +425,9 @@ public class GenericsType extends ASTNode {
                                             if (gt.isPlaceholder()) {
                                                 // check for recursive generic typedef, like
in
                                                 // <T extends Comparable<? super T>>
-                                                if (classNodePlaceholders.containsKey(new
GenericsTypeName(gt.getName()))) {
-                                                    gt = classNodePlaceholders.get(new GenericsTypeName(gt.getName()));
+                                                GenericsTypeName gtn = new GenericsTypeName(gt.getName());
+                                                if (classNodePlaceholders.containsKey(gtn))
{
+                                                    gt = classNodePlaceholders.get(gtn);
                                                 }
                                             }
                                             match = implementsInterfaceOrIsSubclassOf(gt.getType(),
classNodeType.getType());
@@ -436,8 +438,9 @@ public class GenericsType extends ASTNode {
                                                 if (gt.isPlaceholder()) {
                                                     // check for recursive generic typedef,
like in
                                                     // <T extends Comparable<? super
T>>
-                                                    if (classNodePlaceholders.containsKey(new
GenericsTypeName(gt.getName()))) {
-                                                        gt = classNodePlaceholders.get(new
GenericsTypeName(gt.getName()));
+                                                    GenericsTypeName gtn = new GenericsTypeName(gt.getName());
+                                                    if (classNodePlaceholders.containsKey(gtn))
{
+                                                        gt = classNodePlaceholders.get(gtn);
                                                     }
                                                 }
                                                 match = implementsInterfaceOrIsSubclassOf(classNodeType.getType(),
gt.getType())

http://git-wip-us.apache.org/repos/asf/groovy/blob/ca75954d/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index 68b67b3..fb1cc72 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -309,8 +309,9 @@ public class WideningCategories {
                 GenericsType[] copyTypes = new GenericsType[genericsTypes.length];
                 for (int i = 0; i < genericsTypes.length; i++) {
                     GenericsType genericsType = genericsTypes[i];
-                    if (genericsType.isPlaceholder() && genericsTypeMap.containsKey(new
GenericsTypeName(genericsType.getName()))) {
-                        copyTypes[i] = genericsTypeMap.get(new GenericsTypeName(genericsType.getName()));
+                    GenericsTypeName gtn = new GenericsTypeName(genericsType.getName());
+                    if (genericsType.isPlaceholder() && genericsTypeMap.containsKey(gtn))
{
+                        copyTypes[i] = genericsTypeMap.get(gtn);
                     } else {
                         copyTypes[i] = genericsType;
                     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/ca75954d/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 9a90cb0..34728bd 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -1490,9 +1490,10 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer
{
 
             ClassNode classNode = type.getType();
             String name = type.getName();
+            GenericsTypeName gtn = new GenericsTypeName(name);
             ClassNode[] bounds = type.getUpperBounds();
             boolean isWild = QUESTION_MARK.equals(name);
-            boolean toDealWithGenerics = 0 == level || (level > 0 && null != genericParameterNames.get(new
GenericsTypeName(name)));
+            boolean toDealWithGenerics = 0 == level || (level > 0 && null != genericParameterNames.get(gtn));
 
             if (bounds != null) {
                 boolean nameAdded = false;
@@ -1500,7 +1501,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
                     if (!isWild) {
                         if (!nameAdded && upperBound != null || !resolve(classNode))
{
                             if (toDealWithGenerics) {
-                                genericParameterNames.put(new GenericsTypeName(name), type);
+                                genericParameterNames.put(gtn, type);
                                 type.setPlaceholder(true);
                                 classNode.setRedirect(upperBound);
                                 nameAdded = true;
@@ -1517,8 +1518,8 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             } else {
                 if (!isWild) {
                     if (toDealWithGenerics) {
-                        GenericsType originalGt = genericParameterNames.get(new GenericsTypeName(name));
-                        genericParameterNames.put(new GenericsTypeName(name), type);
+                        GenericsType originalGt = genericParameterNames.get(gtn);
+                        genericParameterNames.put(gtn, type);
                         type.setPlaceholder(true);
 
                         if (null == originalGt) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/ca75954d/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 5a6cfa8..04b8888 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1682,7 +1682,7 @@ public abstract class StaticTypeCheckingSupport {
                 }
                 boolean placeholderReplacement = replacement.isPlaceholder();
                 if (placeholderReplacement) {
-                    GenericsType connectedType = resolvedPlaceholders.get(new GenericsTypeName(replacement.getName()));
+                    GenericsType connectedType = resolvedPlaceholders.get(name);
                     if (replacement == connectedType) continue;
                 }
                 // GROOVY-6787: Don't override the original if the replacement placeholder
doesn't respect the bounds,


Mime
View raw message