You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/12/20 12:39:36 UTC

[2/3] groovy git commit: Simplify some expressions

Simplify some expressions


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

Branch: refs/heads/master
Commit: 70f639683b732f66dc7ed80b3f47357c98b5f813
Parents: fae2911
Author: Frank Pavageau <fp...@ekino.com>
Authored: Wed Dec 16 13:47:26 2015 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Dec 20 12:37:30 2015 +0100

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingSupport.java          |  7 +++----
 .../stc/StaticTypeCheckingVisitor.java          | 22 ++++++++++----------
 2 files changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/70f63968/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 69359e9..cfc2fb7 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1577,7 +1577,7 @@ public abstract class StaticTypeCheckingSupport {
         if (!orig.equals(copy)) return false;
         GenericsType[] gt1 = orig.getGenericsTypes();
         GenericsType[] gt2 = copy.getGenericsTypes();
-        if ((gt1==null || gt2==null) && gt1!=gt2) return false;
+        if ((gt1==null) ^ (gt2==null)) return false;
         if (gt1==gt2) return true;
         if (gt1.length!=gt2.length) return false;
         for (int i=0; i<gt1.length; i++) {
@@ -1864,11 +1864,10 @@ public abstract class StaticTypeCheckingSupport {
     private static Map<String, GenericsType> mergeGenerics(Map<String, GenericsType> current, GenericsType[] newGenerics) {
         if (newGenerics == null || newGenerics.length == 0) return current;
         if (current==null) current = new HashMap<String, GenericsType>();
-        for (int i = 0; i < newGenerics.length; i++) {
-            GenericsType gt = newGenerics[i];
+        for (GenericsType gt : newGenerics) {
             if (!gt.isPlaceholder()) continue;
             String name = gt.getName();
-            if (!current.containsKey(name)) current.put(name, newGenerics[i]);
+            if (!current.containsKey(name)) current.put(name, gt);
         }
         return current;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/70f63968/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 604aea4..9835c75 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -882,7 +882,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
     private boolean addedReadOnlyPropertyError(Expression expr) {
         // if expr is of READONLY_PROPERTY_RETURN type, then it means we are on a missing property
         if (expr.getNodeMetaData(StaticTypesMarker.READONLY_PROPERTY) == null) return false;
-        String name = null;
+        String name;
         if (expr instanceof VariableExpression) {
             name = ((VariableExpression) expr).getName();
         } else {
@@ -1411,7 +1411,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
     private <T> T allowStaticAccessToMember(T member, boolean staticOnly) {
         if (member == null) return null;
         if (!staticOnly) return member;
-        boolean isStatic = false;
+        boolean isStatic;
         if (member instanceof Variable) {
             Variable v = (Variable) member;
             isStatic = Modifier.isStatic(v.getModifiers());
@@ -1860,7 +1860,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         }
 
 
-        MethodNode node = null;
+        MethodNode node;
         if (args.length == 1
                 && implementsInterfaceOrIsSubclassOf(args[0], MAP_TYPE)
                 && findMethod(receiver, "<init>", ClassNode.EMPTY_ARRAY).size() == 1
@@ -2391,7 +2391,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
     private List<ClassNode[]> getSignaturesFromHint(final ClosureExpression expression, final MethodNode selectedMethod, final Expression hintClass, final Expression options) {
         // initialize hints
-        List<ClassNode[]> closureSignatures = null;
+        List<ClassNode[]> closureSignatures;
         try {
             ClassLoader transformLoader = getTransformLoader();
             @SuppressWarnings("unchecked")
@@ -2864,7 +2864,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                         storeType(call, data);
                     }
                 }
-                int nbOfArgs = 0;
+                int nbOfArgs;
                 if (callArguments instanceof ArgumentListExpression) {
                     ArgumentListExpression list = (ArgumentListExpression) callArguments;
                     nbOfArgs = list.getExpressions().size();
@@ -3737,14 +3737,14 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 Parameter[] newParams = new Parameter[parameters.length - j];
                 int index = 0;
                 int k = 1;
-                for (int i = 0; i < parameters.length; i++) {
-                    if (k > counter - j && parameters[i] != null && parameters[i].hasInitialExpression()) {
+                for (Parameter parameter : parameters) {
+                    if (k > counter - j && parameter != null && parameter.hasInitialExpression()) {
                         k++;
-                    } else if (parameters[i] != null && parameters[i].hasInitialExpression()) {
-                        newParams[index++] = parameters[i];
+                    } else if (parameter != null && parameter.hasInitialExpression()) {
+                        newParams[index++] = parameter;
                         k++;
                     } else {
-                        newParams[index++] = parameters[i];
+                        newParams[index++] = parameter;
                     }
                 }
                 MethodNode stubbed;
@@ -4050,7 +4050,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
      */
     private ClassNode getGenericsResolvedTypeOfFieldOrProperty(AnnotatedNode an, ClassNode type) {
         if (!type.isUsingGenerics()) return type;
-        Map<String, GenericsType> connections = new HashMap();
+        Map<String, GenericsType> connections = new HashMap<String, GenericsType>();
         //TODO: inner classes mean a different this-type. This is ignored here!
         extractGenericsConnections(connections, typeCheckingContext.getEnclosingClassNode(), an.getDeclaringClass());
         type= applyGenericsContext(connections, type);