groovy git commit: trivial refactor: typos in comments
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 799b853dd -> 4faac01a4 trivial refactor: typos in comments Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4faac01a Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4faac01a Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4faac01a Branch: refs/heads/GROOVY_2_5_X Commit: 4faac01a4b24262b2ba5186a57bcd27c7efc9cfc Parents: 799b853 Author: paulkAuthored: Sun Sep 17 11:18:41 2017 +1000 Committer: paulk Committed: Sun Sep 17 12:46:00 2017 +1000 -- .../groovy/transform/stc/StaticTypeCheckingVisitor.java | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/4faac01a/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 3c6f24e..885ecc3 100644 --- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -1142,7 +1142,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { /** * A helper method which determines which receiver class should be used in error messages when a field or attribute - * is not found. The returned type class depends on whether we have temporary type information availble (due to + * is not found. The returned type class depends on whether we have temporary type information available (due to * instanceof checks) and whether there is a single candidate in that case. * * @param expr the expression for which an unknown field has been found @@ -2075,8 +2075,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { protected void saveVariableExpressionMetadata(final Set closureSharedExpressions, final Map typesBeforeVisit) { for (VariableExpression ve : closureSharedExpressions) { -// GROOVY-6921: We must force a call to getType in order to update closure shared variable which types are -// inferred thanks to closure parameter type inference +// GROOVY-6921: We must force a call to getType in order to update closure shared variable whose +// types are inferred thanks to closure parameter type inference getType(ve); ListHashMap metadata = new ListHashMap (); for (StaticTypesMarker marker : StaticTypesMarker.values()) { @@ -2137,7 +2137,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { // for example, in a mixed mode where only some methods are statically checked // we must not visit a method which used dynamic dispatch. // We do not check for an annotation because some other AST transformations -// may use this visitor without the annotation being explicitely set +// may use this visitor without the annotation being explicitly set if (!typeCheckingContext.methodsToBeVisited.isEmpty() && !typeCheckingContext.methodsToBeVisited.contains(node)) return; // alreadyVisitedMethods prevents from visiting the same method multiple times @@ -3479,7 +3479,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { if (!typeCheckingContext.temporaryIfBranchTypeInformation.empty()) { List temporaryTypesForExpression = getTemporaryTypesForExpression(exp); if (temporaryTypesForExpression != null && !temporaryTypesForExpression.isEmpty()) { -// a type inference has been made on a variable which type was defined in an instanceof block +// a type inference has been made on a variable whose type was defined in an instanceof block // we erase available information with the new type temporaryTypesForExpression.clear(); }
groovy git commit: trivial refactor: typos in comments
Repository: groovy Updated Branches: refs/heads/master e6db31177 -> 01c3539b3 trivial refactor: typos in comments Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/01c3539b Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/01c3539b Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/01c3539b Branch: refs/heads/master Commit: 01c3539b32fd3a3c0c3afc9699304373fb3ed306 Parents: e6db311 Author: paulkAuthored: Sun Sep 17 11:18:41 2017 +1000 Committer: paulk Committed: Sun Sep 17 11:18:41 2017 +1000 -- .../groovy/transform/stc/StaticTypeCheckingVisitor.java | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/01c3539b/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 b8be25d..12ea2b5 100644 --- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -1140,7 +1140,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { /** * A helper method which determines which receiver class should be used in error messages when a field or attribute - * is not found. The returned type class depends on whether we have temporary type information availble (due to + * is not found. The returned type class depends on whether we have temporary type information available (due to * instanceof checks) and whether there is a single candidate in that case. * * @param expr the expression for which an unknown field has been found @@ -2073,8 +2073,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { protected void saveVariableExpressionMetadata(final Set closureSharedExpressions, final Map typesBeforeVisit) { for (VariableExpression ve : closureSharedExpressions) { -// GROOVY-6921: We must force a call to getType in order to update closure shared variable which types are -// inferred thanks to closure parameter type inference +// GROOVY-6921: We must force a call to getType in order to update closure shared variable whose +// types are inferred thanks to closure parameter type inference getType(ve); ListHashMap metadata = new ListHashMap (); for (StaticTypesMarker marker : StaticTypesMarker.values()) { @@ -2135,7 +2135,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { // for example, in a mixed mode where only some methods are statically checked // we must not visit a method which used dynamic dispatch. // We do not check for an annotation because some other AST transformations -// may use this visitor without the annotation being explicitely set +// may use this visitor without the annotation being explicitly set if (!typeCheckingContext.methodsToBeVisited.isEmpty() && !typeCheckingContext.methodsToBeVisited.contains(node)) return; // alreadyVisitedMethods prevents from visiting the same method multiple times @@ -3477,7 +3477,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { if (!typeCheckingContext.temporaryIfBranchTypeInformation.empty()) { List temporaryTypesForExpression = getTemporaryTypesForExpression(exp); if (temporaryTypesForExpression != null && !temporaryTypesForExpression.isEmpty()) { -// a type inference has been made on a variable which type was defined in an instanceof block +// a type inference has been made on a variable whose type was defined in an instanceof block // we erase available information with the new type temporaryTypesForExpression.clear(); }
groovy git commit: Minor refactoring
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 46f0416f6 -> 799b853dd Minor refactoring (cherry picked from commit e6db31177e1d34a3f472d4922bd1ee582e00ac1a) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/799b853d Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/799b853d Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/799b853d Branch: refs/heads/GROOVY_2_5_X Commit: 799b853dd80d341d85ff11eb8da155613957447e Parents: 46f0416 Author: sunlanAuthored: Sun Sep 17 04:51:45 2017 +0800 Committer: sunlan Committed: Sun Sep 17 04:51:45 2017 +0800 -- .../org/codehaus/groovy/control/SourceUnit.java | 21 ++-- 1 file changed, 2 insertions(+), 19 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/799b853d/src/main/org/codehaus/groovy/control/SourceUnit.java -- diff --git a/src/main/org/codehaus/groovy/control/SourceUnit.java b/src/main/org/codehaus/groovy/control/SourceUnit.java index b2c8a32..9a1727d 100644 --- a/src/main/org/codehaus/groovy/control/SourceUnit.java +++ b/src/main/org/codehaus/groovy/control/SourceUnit.java @@ -223,31 +223,14 @@ public class SourceUnit extends ProcessingUnit { // // Create a reader on the source and run the parser. -Reader reader = null; -try { -reader = source.getReader(); - +try (Reader reader = source.getReader()) { // let's recreate the parser each time as it tends to keep around state parserPlugin = getConfiguration().getPluginFactory().createParserPlugin(); cst = parserPlugin.parseCST(this, reader); - -reader.close(); - -} -catch (IOException e) { +} catch (IOException e) { getErrorCollector().addFatalError(new SimpleMessage(e.getMessage(), this)); } -finally { -if (reader != null) { -try { -reader.close(); -} -catch (IOException e) { -// Ignore -} -} -} } /**
groovy git commit: Minor refactoring
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 995479cd5 -> 7ba35700e Minor refactoring (cherry picked from commit e6db311) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7ba35700 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7ba35700 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7ba35700 Branch: refs/heads/GROOVY_2_6_X Commit: 7ba35700e618611d017cc4ea7bec7e6c4fb7d345 Parents: 995479c Author: sunlanAuthored: Sun Sep 17 04:47:53 2017 +0800 Committer: sunlan Committed: Sun Sep 17 04:48:35 2017 +0800 -- .../org/codehaus/groovy/control/SourceUnit.java | 21 ++-- 1 file changed, 2 insertions(+), 19 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/7ba35700/src/main/org/codehaus/groovy/control/SourceUnit.java -- diff --git a/src/main/org/codehaus/groovy/control/SourceUnit.java b/src/main/org/codehaus/groovy/control/SourceUnit.java index 2dcb82a..8f3ce5e 100644 --- a/src/main/org/codehaus/groovy/control/SourceUnit.java +++ b/src/main/org/codehaus/groovy/control/SourceUnit.java @@ -223,31 +223,14 @@ public class SourceUnit extends ProcessingUnit { // // Create a reader on the source and run the parser. -Reader reader = null; -try { -reader = source.getReader(); - +try (Reader reader = source.getReader()) { // let's recreate the parser each time as it tends to keep around state parserPlugin = getConfiguration().getPluginFactory().createParserPlugin(); cst = parserPlugin.parseCST(this, reader); - -reader.close(); - -} -catch (IOException e) { +} catch (IOException e) { getErrorCollector().addFatalError(new SimpleMessage(e.getMessage(), this)); } -finally { -if (reader != null) { -try { -reader.close(); -} -catch (IOException e) { -// Ignore -} -} -} } /**
groovy git commit: Minor refactoring
Repository: groovy Updated Branches: refs/heads/master 6a8518dbf -> e6db31177 Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e6db3117 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e6db3117 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e6db3117 Branch: refs/heads/master Commit: e6db31177e1d34a3f472d4922bd1ee582e00ac1a Parents: 6a8518d Author: sunlanAuthored: Sun Sep 17 04:47:53 2017 +0800 Committer: sunlan Committed: Sun Sep 17 04:47:53 2017 +0800 -- .../org/codehaus/groovy/control/SourceUnit.java | 21 ++-- 1 file changed, 2 insertions(+), 19 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/e6db3117/src/main/org/codehaus/groovy/control/SourceUnit.java -- diff --git a/src/main/org/codehaus/groovy/control/SourceUnit.java b/src/main/org/codehaus/groovy/control/SourceUnit.java index 2dcb82a..8f3ce5e 100644 --- a/src/main/org/codehaus/groovy/control/SourceUnit.java +++ b/src/main/org/codehaus/groovy/control/SourceUnit.java @@ -223,31 +223,14 @@ public class SourceUnit extends ProcessingUnit { // // Create a reader on the source and run the parser. -Reader reader = null; -try { -reader = source.getReader(); - +try (Reader reader = source.getReader()) { // let's recreate the parser each time as it tends to keep around state parserPlugin = getConfiguration().getPluginFactory().createParserPlugin(); cst = parserPlugin.parseCST(this, reader); - -reader.close(); - -} -catch (IOException e) { +} catch (IOException e) { getErrorCollector().addFatalError(new SimpleMessage(e.getMessage(), this)); } -finally { -if (reader != null) { -try { -reader.close(); -} -catch (IOException e) { -// Ignore -} -} -} } /**
groovy git commit: Simplify hashCode of Tuple
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 6d3060d45 -> 46f0416f6 Simplify hashCode of Tuple (cherry picked from commit 6a8518d) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/46f0416f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/46f0416f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/46f0416f Branch: refs/heads/GROOVY_2_5_X Commit: 46f0416f6027c67c6c324a0dd366e14371eb7d4b Parents: 6d3060d Author: sunlanAuthored: Sun Sep 17 04:06:00 2017 +0800 Committer: sunlan Committed: Sun Sep 17 04:14:57 2017 +0800 -- src/main/groovy/lang/Tuple.java | 20 ++-- 1 file changed, 6 insertions(+), 14 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/46f0416f/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 06d501a..aef53f6 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -22,6 +22,7 @@ import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; import java.util.AbstractList; import java.util.List; +import java.util.Objects; /** * Represents a list of Objects. @@ -30,7 +31,6 @@ import java.util.List; */ public class Tuple extends AbstractList { private final E[] contents; -private int hashCode; public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); @@ -47,6 +47,7 @@ public class Tuple extends AbstractList { return contents.length; } +@SuppressWarnings("unchecked") @Override public List subList(int fromIndex, int toIndex) { int size = toIndex - fromIndex; @@ -65,8 +66,9 @@ public class Tuple extends AbstractList { if (o == null || !(o instanceof Tuple)) return false; Tuple that = (Tuple) o; -if (size() != that.size()) return false; -for (int i = 0; i < size(); i++) { +int size = size(); +if (size != that.size()) return false; +for (int i = 0; i < size; i++) { if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { return false; } @@ -76,16 +78,6 @@ public class Tuple extends AbstractList { @Override public int hashCode() { -if (hashCode == 0) { -for (int i = 0; i < size(); i++) { -Object value = get(i); -int hash = (value != null) ? value.hashCode() : 0xbabe; -hashCode ^= hash; -} -if (hashCode == 0) { -hashCode = 0xbabe; -} -} -return hashCode; +return Objects.hash(contents); } }
groovy git commit: Simplify hashCode of Tuple
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X bcf47ad3a -> 995479cd5 Simplify hashCode of Tuple (cherry picked from commit 6a8518dbf78575adc5e9602614b9a739e0e3d086) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/995479cd Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/995479cd Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/995479cd Branch: refs/heads/GROOVY_2_6_X Commit: 995479cd575f8186e8855c1a6c6c324949afafd1 Parents: bcf47ad Author: sunlanAuthored: Sun Sep 17 04:10:08 2017 +0800 Committer: sunlan Committed: Sun Sep 17 04:10:08 2017 +0800 -- src/main/groovy/lang/Tuple.java | 20 ++-- 1 file changed, 6 insertions(+), 14 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/995479cd/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 06d501a..aef53f6 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -22,6 +22,7 @@ import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; import java.util.AbstractList; import java.util.List; +import java.util.Objects; /** * Represents a list of Objects. @@ -30,7 +31,6 @@ import java.util.List; */ public class Tuple extends AbstractList { private final E[] contents; -private int hashCode; public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); @@ -47,6 +47,7 @@ public class Tuple extends AbstractList { return contents.length; } +@SuppressWarnings("unchecked") @Override public List subList(int fromIndex, int toIndex) { int size = toIndex - fromIndex; @@ -65,8 +66,9 @@ public class Tuple extends AbstractList { if (o == null || !(o instanceof Tuple)) return false; Tuple that = (Tuple) o; -if (size() != that.size()) return false; -for (int i = 0; i < size(); i++) { +int size = size(); +if (size != that.size()) return false; +for (int i = 0; i < size; i++) { if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { return false; } @@ -76,16 +78,6 @@ public class Tuple extends AbstractList { @Override public int hashCode() { -if (hashCode == 0) { -for (int i = 0; i < size(); i++) { -Object value = get(i); -int hash = (value != null) ? value.hashCode() : 0xbabe; -hashCode ^= hash; -} -if (hashCode == 0) { -hashCode = 0xbabe; -} -} -return hashCode; +return Objects.hash(contents); } }
groovy git commit: Replace Pair with Tuple2 further
Repository: groovy Updated Branches: refs/heads/master 7dc7cb52b -> de56fe3c7 Replace Pair with Tuple2 further Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/de56fe3c Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/de56fe3c Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/de56fe3c Branch: refs/heads/master Commit: de56fe3c7f371cbf96e1b0299fa4b6198dc8ca00 Parents: 7dc7cb5 Author: sunlanAuthored: Sun Sep 17 02:58:18 2017 +0800 Committer: sunlan Committed: Sun Sep 17 02:58:18 2017 +0800 -- .../parser/antlr4/util/PositionConfigureUtils.java| 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/de56fe3c/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java -- diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java index bbe83eb..aba0244 100644 --- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java +++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java @@ -18,10 +18,10 @@ */ package org.apache.groovy.parser.antlr4.util; +import groovy.lang.Tuple2; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.TerminalNode; import org.apache.groovy.parser.antlr4.GroovyParser; -import org.apache.groovy.parser.antlr4.Pair; import org.codehaus.groovy.ast.ASTNode; import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean; @@ -50,7 +50,7 @@ public class PositionConfigureUtils { return astNode; } -public static Pair endPosition(Token token) { +public static Tuple2 endPosition(Token token) { String stopText = token.getText(); int stopTextLength = 0; int newLineCnt = 0; @@ -60,9 +60,9 @@ public class PositionConfigureUtils { } if (0 == newLineCnt) { -return new Pair<>(token.getLine(), token.getCharPositionInLine() + 1 + token.getText().length()); +return new Tuple2<>(token.getLine(), token.getCharPositionInLine() + 1 + token.getText().length()); } else { // e.g. GStringEnd contains newlines, we should fix the location info -return new Pair<>(token.getLine() + newLineCnt, stopTextLength - stopText.lastIndexOf('\n')); +return new Tuple2<>(token.getLine() + newLineCnt, stopTextLength - stopText.lastIndexOf('\n')); } } @@ -105,9 +105,9 @@ public class PositionConfigureUtils { } public static void configureEndPosition(T astNode, Token token) { -Pair endPosition = endPosition(token); -astNode.setLastLineNumber(endPosition.getKey()); -astNode.setLastColumnNumber(endPosition.getValue()); +Tuple2 endPosition = endPosition(token); +astNode.setLastLineNumber(endPosition.getFirst()); +astNode.setLastColumnNumber(endPosition.getSecond()); } public static T configureAST(T astNode, ASTNode start, ASTNode stop) {
groovy git commit: Replace Pair with Tuple2
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X cd5e5b773 -> bcf47ad3a Replace Pair with Tuple2 Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/bcf47ad3 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/bcf47ad3 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/bcf47ad3 Branch: refs/heads/GROOVY_2_6_X Commit: bcf47ad3a9a3825f0fdacab5214544a074817ca6 Parents: cd5e5b7 Author: sunlanAuthored: Sun Sep 17 02:56:46 2017 +0800 Committer: sunlan Committed: Sun Sep 17 02:56:46 2017 +0800 -- .../apache/groovy/parser/antlr4/AstBuilder.java | 75 ++-- .../groovy/parser/antlr4/GroovydocManager.java | 2 +- .../groovy/parser/antlr4/ModifierManager.java | 3 - .../groovy/parser/antlr4/ModifierNode.java | 2 - .../org/apache/groovy/parser/antlr4/Pair.java | 68 -- .../antlr4/util/PositionConfigureUtils.java | 14 ++-- 6 files changed, 46 insertions(+), 118 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/bcf47ad3/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java -- diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java index 4239300..c766283 100644 --- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -19,6 +19,7 @@ package org.apache.groovy.parser.antlr4; import groovy.lang.IntRange; +import groovy.lang.Tuple2; import org.antlr.v4.runtime.ANTLRErrorListener; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; @@ -271,7 +272,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov this.configureScriptClassNode(); if (null != this.numberFormatError) { -throw createParsingFailedException(this.numberFormatError.getValue().getMessage(), this.numberFormatError.getKey()); +throw createParsingFailedException(this.numberFormatError.getSecond().getMessage(), this.numberFormatError.getFirst()); } return moduleNode; @@ -417,17 +418,17 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov @Override public ForStatement visitForStmtAlt(ForStmtAltContext ctx) { -Pair controlPair = this.visitForControl(ctx.forControl()); +Tuple2 controlPair = this.visitForControl(ctx.forControl()); Statement loopBlock = this.unpackStatement((Statement) this.visit(ctx.statement())); return configureAST( -new ForStatement(controlPair.getKey(), controlPair.getValue(), asBoolean(loopBlock) ? loopBlock : EmptyStatement.INSTANCE), +new ForStatement(controlPair.getFirst(), controlPair.getSecond(), asBoolean(loopBlock) ? loopBlock : EmptyStatement.INSTANCE), ctx); } @Override -public Pair visitForControl(ForControlContext ctx) { +public Tuple2 visitForControl(ForControlContext ctx) { if (asBoolean(ctx.enhancedForControl())) { // e.g. for(int i in 0..<10) {} return this.visitEnhancedForControl(ctx.enhancedForControl()); } @@ -483,7 +484,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov } @Override -public Pair visitEnhancedForControl(EnhancedForControlContext ctx) { +public Tuple2 visitEnhancedForControl(EnhancedForControlContext ctx) { Parameter parameter = configureAST( new Parameter(this.visitType(ctx.type()), this.visitVariableDeclaratorId(ctx.variableDeclaratorId()).getName()), ctx.variableDeclaratorId()); @@ -491,18 +492,18 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov // FIXME Groovy will ignore variableModifier of parameter in the for control // In order to make the new parser behave same with the old one, we do not process variableModifier* -return new Pair<>(parameter, (Expression) this.visit(ctx.expression())); +return new Tuple2<>(parameter, (Expression) this.visit(ctx.expression())); } @Override -public Pair visitClassicalForControl(ClassicalForControlContext ctx) { +public Tuple2 visitClassicalForControl(ClassicalForControlContext ctx) {
groovy git commit: Replace Pair with Tuple2
Repository: groovy Updated Branches: refs/heads/master 56b0d4a7d -> 7dc7cb52b Replace Pair with Tuple2 Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7dc7cb52 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7dc7cb52 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7dc7cb52 Branch: refs/heads/master Commit: 7dc7cb52b7d5692df085c5ba737eee4dce59cb23 Parents: 56b0d4a Author: sunlanAuthored: Sun Sep 17 02:43:26 2017 +0800 Committer: sunlan Committed: Sun Sep 17 02:43:26 2017 +0800 -- .../apache/groovy/parser/antlr4/AstBuilder.java | 69 ++-- .../groovy/parser/antlr4/GroovydocManager.java | 2 +- .../groovy/parser/antlr4/ModifierManager.java | 1 - .../groovy/parser/antlr4/ModifierNode.java | 2 - .../org/apache/groovy/parser/antlr4/Pair.java | 68 --- 5 files changed, 36 insertions(+), 106 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/7dc7cb52/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java -- diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java index 01f4213..e228a4d 100644 --- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -19,6 +19,7 @@ package org.apache.groovy.parser.antlr4; import groovy.lang.IntRange; +import groovy.lang.Tuple2; import org.antlr.v4.runtime.ANTLRErrorListener; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; @@ -274,7 +275,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov this.configureScriptClassNode(); if (null != this.numberFormatError) { -throw createParsingFailedException(this.numberFormatError.getValue().getMessage(), this.numberFormatError.getKey()); +throw createParsingFailedException(this.numberFormatError.getSecond().getMessage(), this.numberFormatError.getFirst()); } return moduleNode; @@ -413,17 +414,17 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov @Override public ForStatement visitForStmtAlt(ForStmtAltContext ctx) { -Pair controlPair = this.visitForControl(ctx.forControl()); +Tuple2 controlTuple = this.visitForControl(ctx.forControl()); Statement loopBlock = this.unpackStatement((Statement) this.visit(ctx.statement())); return configureAST( -new ForStatement(controlPair.getKey(), controlPair.getValue(), asBoolean(loopBlock) ? loopBlock : EmptyStatement.INSTANCE), +new ForStatement(controlTuple.getFirst(), controlTuple.getSecond(), asBoolean(loopBlock) ? loopBlock : EmptyStatement.INSTANCE), ctx); } @Override -public Pair visitForControl(ForControlContext ctx) { +public Tuple2 visitForControl(ForControlContext ctx) { if (asBoolean(ctx.enhancedForControl())) { // e.g. for(int i in 0..<10) {} return this.visitEnhancedForControl(ctx.enhancedForControl()); } @@ -479,7 +480,7 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov } @Override -public Pair visitEnhancedForControl(EnhancedForControlContext ctx) { +public Tuple2 visitEnhancedForControl(EnhancedForControlContext ctx) { Parameter parameter = configureAST( new Parameter(this.visitType(ctx.type()), this.visitVariableDeclaratorId(ctx.variableDeclaratorId()).getName()), ctx.variableDeclaratorId()); @@ -487,18 +488,18 @@ public class AstBuilder extends GroovyParserBaseVisitor implements Groov // FIXME Groovy will ignore variableModifier of parameter in the for control // In order to make the new parser behave same with the old one, we do not process variableModifier* -return new Pair<>(parameter, (Expression) this.visit(ctx.expression())); +return new Tuple2<>(parameter, (Expression) this.visit(ctx.expression())); } @Override -public Pair visitClassicalForControl(ClassicalForControlContext ctx) { +public Tuple2 visitClassicalForControl(ClassicalForControlContext ctx) { ClosureListExpression closureListExpression = new ClosureListExpression();
groovy git commit: Remove AbstractTuple
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 9f9c6625b -> 6d3060d45 Remove AbstractTuple (cherry picked from commit 56b0d4a) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6d3060d4 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6d3060d4 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6d3060d4 Branch: refs/heads/GROOVY_2_5_X Commit: 6d3060d45a82766e7f12f1f04d50d0f896a04d80 Parents: 9f9c662 Author: sunlanAuthored: Sat Sep 16 20:04:25 2017 +0800 Committer: sunlan Committed: Sat Sep 16 20:05:53 2017 +0800 -- src/main/groovy/lang/AbstractTuple.java | 61 src/main/groovy/lang/Tuple.java | 36 +++- 2 files changed, 35 insertions(+), 62 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/6d3060d4/src/main/groovy/lang/AbstractTuple.java -- diff --git a/src/main/groovy/lang/AbstractTuple.java b/src/main/groovy/lang/AbstractTuple.java deleted file mode 100644 index c0e0845..000 --- a/src/main/groovy/lang/AbstractTuple.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - *http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package groovy.lang; - -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; - -import java.util.AbstractList; - -/** - * @since 2.5.0 - */ -public abstract class AbstractTuple extends AbstractList { -private int hashCode; - -@Override -public boolean equals(Object o) { -if (this == o) return true; -if (o == null || !(o instanceof AbstractTuple)) return false; - -AbstractTuple that = (AbstractTuple) o; -if (size() != that.size()) return false; -for (int i = 0; i < size(); i++) { -if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { -return false; -} -} -return true; -} - -@Override -public int hashCode() { -if (hashCode == 0) { -for (int i = 0; i < size(); i++) { -Object value = get(i); -int hash = (value != null) ? value.hashCode() : 0xbabe; -hashCode ^= hash; -} -if (hashCode == 0) { -hashCode = 0xbabe; -} -} -return hashCode; -} -} http://git-wip-us.apache.org/repos/asf/groovy/blob/6d3060d4/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 38d835d..06d501a 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -18,6 +18,9 @@ */ package groovy.lang; +import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; + +import java.util.AbstractList; import java.util.List; /** @@ -25,8 +28,9 @@ import java.util.List; * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractTuple { +public class Tuple extends AbstractList { private final E[] contents; +private int hashCode; public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); @@ -54,4 +58,34 @@ public class Tuple extends AbstractTuple { public Tuple subTuple(int fromIndex, int toIndex) { return (Tuple) subList(fromIndex, toIndex); } + +@Override +public boolean equals(Object o) { +if (this == o) return true; +if (o == null || !(o instanceof Tuple)) return false; + +Tuple that = (Tuple) o; +if (size() != that.size()) return false; +for (int i = 0; i < size(); i++) { +if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { +return false; +} +} +return true; +} + +@Override +public int hashCode() { +if (hashCode == 0) { +
groovy git commit: Remove AbstractTuple
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 57c221ee6 -> cd5e5b773 Remove AbstractTuple (cherry picked from commit 56b0d4a) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/cd5e5b77 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/cd5e5b77 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/cd5e5b77 Branch: refs/heads/GROOVY_2_6_X Commit: cd5e5b773cd0f21fcc996c9dc04e95a2c6cdc69e Parents: 57c221e Author: sunlanAuthored: Sat Sep 16 20:04:25 2017 +0800 Committer: sunlan Committed: Sat Sep 16 20:05:22 2017 +0800 -- src/main/groovy/lang/AbstractTuple.java | 61 src/main/groovy/lang/Tuple.java | 36 +++- 2 files changed, 35 insertions(+), 62 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/cd5e5b77/src/main/groovy/lang/AbstractTuple.java -- diff --git a/src/main/groovy/lang/AbstractTuple.java b/src/main/groovy/lang/AbstractTuple.java deleted file mode 100644 index c0e0845..000 --- a/src/main/groovy/lang/AbstractTuple.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - *http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package groovy.lang; - -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; - -import java.util.AbstractList; - -/** - * @since 2.5.0 - */ -public abstract class AbstractTuple extends AbstractList { -private int hashCode; - -@Override -public boolean equals(Object o) { -if (this == o) return true; -if (o == null || !(o instanceof AbstractTuple)) return false; - -AbstractTuple that = (AbstractTuple) o; -if (size() != that.size()) return false; -for (int i = 0; i < size(); i++) { -if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { -return false; -} -} -return true; -} - -@Override -public int hashCode() { -if (hashCode == 0) { -for (int i = 0; i < size(); i++) { -Object value = get(i); -int hash = (value != null) ? value.hashCode() : 0xbabe; -hashCode ^= hash; -} -if (hashCode == 0) { -hashCode = 0xbabe; -} -} -return hashCode; -} -} http://git-wip-us.apache.org/repos/asf/groovy/blob/cd5e5b77/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 38d835d..06d501a 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -18,6 +18,9 @@ */ package groovy.lang; +import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; + +import java.util.AbstractList; import java.util.List; /** @@ -25,8 +28,9 @@ import java.util.List; * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractTuple { +public class Tuple extends AbstractList { private final E[] contents; +private int hashCode; public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); @@ -54,4 +58,34 @@ public class Tuple extends AbstractTuple { public Tuple subTuple(int fromIndex, int toIndex) { return (Tuple) subList(fromIndex, toIndex); } + +@Override +public boolean equals(Object o) { +if (this == o) return true; +if (o == null || !(o instanceof Tuple)) return false; + +Tuple that = (Tuple) o; +if (size() != that.size()) return false; +for (int i = 0; i < size(); i++) { +if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { +return false; +} +} +return true; +} + +@Override +public int hashCode() { +if (hashCode == 0) { +
groovy git commit: Remove AbstractTuple
Repository: groovy Updated Branches: refs/heads/master c9d871690 -> 56b0d4a7d Remove AbstractTuple Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/56b0d4a7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/56b0d4a7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/56b0d4a7 Branch: refs/heads/master Commit: 56b0d4a7d16472415b69cf3b58607e8e5a80fb3a Parents: c9d8716 Author: sunlanAuthored: Sat Sep 16 20:04:25 2017 +0800 Committer: sunlan Committed: Sat Sep 16 20:04:25 2017 +0800 -- src/main/groovy/lang/AbstractTuple.java | 61 src/main/groovy/lang/Tuple.java | 36 +++- 2 files changed, 35 insertions(+), 62 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/56b0d4a7/src/main/groovy/lang/AbstractTuple.java -- diff --git a/src/main/groovy/lang/AbstractTuple.java b/src/main/groovy/lang/AbstractTuple.java deleted file mode 100644 index c0e0845..000 --- a/src/main/groovy/lang/AbstractTuple.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - *http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package groovy.lang; - -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; - -import java.util.AbstractList; - -/** - * @since 2.5.0 - */ -public abstract class AbstractTuple extends AbstractList { -private int hashCode; - -@Override -public boolean equals(Object o) { -if (this == o) return true; -if (o == null || !(o instanceof AbstractTuple)) return false; - -AbstractTuple that = (AbstractTuple) o; -if (size() != that.size()) return false; -for (int i = 0; i < size(); i++) { -if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { -return false; -} -} -return true; -} - -@Override -public int hashCode() { -if (hashCode == 0) { -for (int i = 0; i < size(); i++) { -Object value = get(i); -int hash = (value != null) ? value.hashCode() : 0xbabe; -hashCode ^= hash; -} -if (hashCode == 0) { -hashCode = 0xbabe; -} -} -return hashCode; -} -} http://git-wip-us.apache.org/repos/asf/groovy/blob/56b0d4a7/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 38d835d..06d501a 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -18,6 +18,9 @@ */ package groovy.lang; +import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; + +import java.util.AbstractList; import java.util.List; /** @@ -25,8 +28,9 @@ import java.util.List; * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractTuple { +public class Tuple extends AbstractList { private final E[] contents; +private int hashCode; public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); @@ -54,4 +58,34 @@ public class Tuple extends AbstractTuple { public Tuple subTuple(int fromIndex, int toIndex) { return (Tuple) subList(fromIndex, toIndex); } + +@Override +public boolean equals(Object o) { +if (this == o) return true; +if (o == null || !(o instanceof Tuple)) return false; + +Tuple that = (Tuple) o; +if (size() != that.size()) return false; +for (int i = 0; i < size(); i++) { +if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { +return false; +} +} +return true; +} + +@Override +public int hashCode() { +if (hashCode == 0) { +for (int i = 0; i < size(); i++) { +
[2/2] groovy git commit: Add `subTuple` method
Add `subTuple` method (cherry picked from commit c9d8716) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9f9c6625 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9f9c6625 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9f9c6625 Branch: refs/heads/GROOVY_2_5_X Commit: 9f9c6625bff116842547c3a8972ec4892d04ce8b Parents: 4da35cd Author: sunlanAuthored: Sat Sep 16 16:10:16 2017 +0800 Committer: sunlan Committed: Sat Sep 16 16:44:12 2017 +0800 -- src/main/groovy/lang/Tuple.java | 4 + src/test/groovy/lang/TupleTest.java | 214 +++ 2 files changed, 218 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/9f9c6625/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 36b04cb..38d835d 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -50,4 +50,8 @@ public class Tuple extends AbstractTuple { System.arraycopy(contents, fromIndex, newContent, 0, size); return new Tuple<>(newContent); } + +public Tuple subTuple(int fromIndex, int toIndex) { +return (Tuple) subList(fromIndex, toIndex); +} } http://git-wip-us.apache.org/repos/asf/groovy/blob/9f9c6625/src/test/groovy/lang/TupleTest.java -- diff --git a/src/test/groovy/lang/TupleTest.java b/src/test/groovy/lang/TupleTest.java index 2e88659..19f07b7 100644 --- a/src/test/groovy/lang/TupleTest.java +++ b/src/test/groovy/lang/TupleTest.java @@ -68,6 +68,14 @@ public class TupleTest extends TestCase { assertEquals("size", 1, s.size()); } +public void testSubTuple() { +Tuple s = t.subTuple(1, 2); + +assertTrue("is a Tuple", s instanceof Tuple); + +assertEquals("size", 1, s.size()); +} + public void testHashCodeAndEquals() { Tuple a = new Tuple(new Object[]{"a", "b", "c"}); Tuple b = new Tuple(new Object[]{"a", "b", "c"}); @@ -93,4 +101,210 @@ public class TupleTest extends TestCase { public void testIterator() { } +public void testTuple1() { +Tuple1 t = new Tuple1<>(1); + +assertEquals(1, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple2() { +Tuple2 t = new Tuple2<>(1, 2); + +assertEquals(2, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple3() { +Tuple3 t = new Tuple3<>(1, 2, 3); + +assertEquals(3, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple4() { +Tuple4 t = new Tuple4<>(1, 2, 3, 4); + +assertEquals(4, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(new Integer(4), t.getFourth()); +assertEquals(4, t.get(3)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple5() { +Tuple5 t = new Tuple5<>(1, 2, 3, 4, 5); + +assertEquals(5, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(new Integer(4), t.getFourth()); +assertEquals(4, t.get(3)); + +assertEquals(new Integer(5), t.getFifth()); +assertEquals(5, t.get(4)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple6() { +Tuple6 t = new Tuple6<>(1, 2, 3, 4, 5, 6); + +
[1/2] groovy git commit: Refine tuples
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 7c669b46d -> 9f9c6625b Refine tuples (cherry picked from commit d6b0cb4) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4da35cde Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4da35cde Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4da35cde Branch: refs/heads/GROOVY_2_5_X Commit: 4da35cded2f15765a142bd0fc2f7a5e89f0a1ddc Parents: 7c669b4 Author: sunlanAuthored: Sat Sep 16 15:38:43 2017 +0800 Committer: sunlan Committed: Sat Sep 16 16:44:06 2017 +0800 -- src/main/groovy/lang/Tuple1.java | 4 +++- src/main/groovy/lang/Tuple2.java | 4 +++- src/main/groovy/lang/Tuple3.java | 4 +++- src/main/groovy/lang/Tuple4.java | 4 +++- src/main/groovy/lang/Tuple5.java | 4 +++- src/main/groovy/lang/Tuple6.java | 4 +++- src/main/groovy/lang/Tuple7.java | 4 +++- src/main/groovy/lang/Tuple8.java | 4 +++- src/main/groovy/lang/Tuple9.java | 4 +++- 9 files changed, 27 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/4da35cde/src/main/groovy/lang/Tuple1.java -- diff --git a/src/main/groovy/lang/Tuple1.java b/src/main/groovy/lang/Tuple1.java index f57bc3b..1506bb0 100644 --- a/src/main/groovy/lang/Tuple1.java +++ b/src/main/groovy/lang/Tuple1.java @@ -23,10 +23,12 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple1 extends AbstractTuple { +public class Tuple1 extends Tuple { private final T1 first; public Tuple1(T1 first) { +super(first); + this.first = first; } http://git-wip-us.apache.org/repos/asf/groovy/blob/4da35cde/src/main/groovy/lang/Tuple2.java -- diff --git a/src/main/groovy/lang/Tuple2.java b/src/main/groovy/lang/Tuple2.java index fe64d5e..d3a8be7 100644 --- a/src/main/groovy/lang/Tuple2.java +++ b/src/main/groovy/lang/Tuple2.java @@ -21,11 +21,13 @@ package groovy.lang; /** * Represents a list of 2 typed Objects. */ -public class Tuple2 extends AbstractTuple { +public class Tuple2 extends Tuple { private final T1 first; private final T2 second; public Tuple2(T1 first, T2 second) { +super(first, second); + this.first = first; this.second = second; } http://git-wip-us.apache.org/repos/asf/groovy/blob/4da35cde/src/main/groovy/lang/Tuple3.java -- diff --git a/src/main/groovy/lang/Tuple3.java b/src/main/groovy/lang/Tuple3.java index 59b06f5..de539ec 100644 --- a/src/main/groovy/lang/Tuple3.java +++ b/src/main/groovy/lang/Tuple3.java @@ -24,12 +24,14 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple3 extends AbstractTuple { +public class Tuple3 extends Tuple { private final T1 first; private final T2 second; private final T3 third; public Tuple3(T1 first, T2 second, T3 third) { +super(first, second, third); + this.first = first; this.second = second; this.third = third; http://git-wip-us.apache.org/repos/asf/groovy/blob/4da35cde/src/main/groovy/lang/Tuple4.java -- diff --git a/src/main/groovy/lang/Tuple4.java b/src/main/groovy/lang/Tuple4.java index b3cf839..069f3af 100644 --- a/src/main/groovy/lang/Tuple4.java +++ b/src/main/groovy/lang/Tuple4.java @@ -24,13 +24,15 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple4 extends AbstractTuple { +public class Tuple4 extends Tuple { private final T1 first; private final T2 second; private final T3 third; private final T4 fourth; public Tuple4(T1 first, T2 second, T3 third, T4 fourth) { +super(first, second, third, fourth); + this.first = first; this.second = second; this.third = third; http://git-wip-us.apache.org/repos/asf/groovy/blob/4da35cde/src/main/groovy/lang/Tuple5.java -- diff --git a/src/main/groovy/lang/Tuple5.java b/src/main/groovy/lang/Tuple5.java index c83d792..ea61507 100644 --- a/src/main/groovy/lang/Tuple5.java +++ b/src/main/groovy/lang/Tuple5.java @@ -24,7 +24,7 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple5 extends AbstractTuple { +public class Tuple5 extends Tuple { private final T1 first; private final T2 second; private final T3 third; @@ -32,6 +32,8 @@ public class Tuple5 extends AbstractTuple { private
[1/2] groovy git commit: Refine tuples
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 3929d0382 -> 57c221ee6 Refine tuples (cherry picked from commit d6b0cb4) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/42ccfc7b Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/42ccfc7b Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/42ccfc7b Branch: refs/heads/GROOVY_2_6_X Commit: 42ccfc7b7a66e54071c3cf2bb54bc4cc2882a126 Parents: 3929d03 Author: sunlanAuthored: Sat Sep 16 15:38:43 2017 +0800 Committer: sunlan Committed: Sat Sep 16 16:42:57 2017 +0800 -- src/main/groovy/lang/Tuple1.java | 4 +++- src/main/groovy/lang/Tuple2.java | 4 +++- src/main/groovy/lang/Tuple3.java | 4 +++- src/main/groovy/lang/Tuple4.java | 4 +++- src/main/groovy/lang/Tuple5.java | 4 +++- src/main/groovy/lang/Tuple6.java | 4 +++- src/main/groovy/lang/Tuple7.java | 4 +++- src/main/groovy/lang/Tuple8.java | 4 +++- src/main/groovy/lang/Tuple9.java | 4 +++- 9 files changed, 27 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/42ccfc7b/src/main/groovy/lang/Tuple1.java -- diff --git a/src/main/groovy/lang/Tuple1.java b/src/main/groovy/lang/Tuple1.java index f57bc3b..1506bb0 100644 --- a/src/main/groovy/lang/Tuple1.java +++ b/src/main/groovy/lang/Tuple1.java @@ -23,10 +23,12 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple1 extends AbstractTuple { +public class Tuple1 extends Tuple { private final T1 first; public Tuple1(T1 first) { +super(first); + this.first = first; } http://git-wip-us.apache.org/repos/asf/groovy/blob/42ccfc7b/src/main/groovy/lang/Tuple2.java -- diff --git a/src/main/groovy/lang/Tuple2.java b/src/main/groovy/lang/Tuple2.java index fe64d5e..d3a8be7 100644 --- a/src/main/groovy/lang/Tuple2.java +++ b/src/main/groovy/lang/Tuple2.java @@ -21,11 +21,13 @@ package groovy.lang; /** * Represents a list of 2 typed Objects. */ -public class Tuple2 extends AbstractTuple { +public class Tuple2 extends Tuple { private final T1 first; private final T2 second; public Tuple2(T1 first, T2 second) { +super(first, second); + this.first = first; this.second = second; } http://git-wip-us.apache.org/repos/asf/groovy/blob/42ccfc7b/src/main/groovy/lang/Tuple3.java -- diff --git a/src/main/groovy/lang/Tuple3.java b/src/main/groovy/lang/Tuple3.java index 59b06f5..de539ec 100644 --- a/src/main/groovy/lang/Tuple3.java +++ b/src/main/groovy/lang/Tuple3.java @@ -24,12 +24,14 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple3 extends AbstractTuple { +public class Tuple3 extends Tuple { private final T1 first; private final T2 second; private final T3 third; public Tuple3(T1 first, T2 second, T3 third) { +super(first, second, third); + this.first = first; this.second = second; this.third = third; http://git-wip-us.apache.org/repos/asf/groovy/blob/42ccfc7b/src/main/groovy/lang/Tuple4.java -- diff --git a/src/main/groovy/lang/Tuple4.java b/src/main/groovy/lang/Tuple4.java index b3cf839..069f3af 100644 --- a/src/main/groovy/lang/Tuple4.java +++ b/src/main/groovy/lang/Tuple4.java @@ -24,13 +24,15 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple4 extends AbstractTuple { +public class Tuple4 extends Tuple { private final T1 first; private final T2 second; private final T3 third; private final T4 fourth; public Tuple4(T1 first, T2 second, T3 third, T4 fourth) { +super(first, second, third, fourth); + this.first = first; this.second = second; this.third = third; http://git-wip-us.apache.org/repos/asf/groovy/blob/42ccfc7b/src/main/groovy/lang/Tuple5.java -- diff --git a/src/main/groovy/lang/Tuple5.java b/src/main/groovy/lang/Tuple5.java index c83d792..ea61507 100644 --- a/src/main/groovy/lang/Tuple5.java +++ b/src/main/groovy/lang/Tuple5.java @@ -24,7 +24,7 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple5 extends AbstractTuple { +public class Tuple5 extends Tuple { private final T1 first; private final T2 second; private final T3 third; @@ -32,6 +32,8 @@ public class Tuple5 extends AbstractTuple { private
[2/2] groovy git commit: Add `subTuple` method
Add `subTuple` method (cherry picked from commit c9d8716) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/57c221ee Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/57c221ee Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/57c221ee Branch: refs/heads/GROOVY_2_6_X Commit: 57c221ee673cd01874fc603021e886eb200f02c9 Parents: 42ccfc7 Author: sunlanAuthored: Sat Sep 16 16:10:16 2017 +0800 Committer: sunlan Committed: Sat Sep 16 16:43:03 2017 +0800 -- src/main/groovy/lang/Tuple.java | 4 + src/test/groovy/lang/TupleTest.java | 214 +++ 2 files changed, 218 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/57c221ee/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 36b04cb..38d835d 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -50,4 +50,8 @@ public class Tuple extends AbstractTuple { System.arraycopy(contents, fromIndex, newContent, 0, size); return new Tuple<>(newContent); } + +public Tuple subTuple(int fromIndex, int toIndex) { +return (Tuple) subList(fromIndex, toIndex); +} } http://git-wip-us.apache.org/repos/asf/groovy/blob/57c221ee/src/test/groovy/lang/TupleTest.java -- diff --git a/src/test/groovy/lang/TupleTest.java b/src/test/groovy/lang/TupleTest.java index 2e88659..19f07b7 100644 --- a/src/test/groovy/lang/TupleTest.java +++ b/src/test/groovy/lang/TupleTest.java @@ -68,6 +68,14 @@ public class TupleTest extends TestCase { assertEquals("size", 1, s.size()); } +public void testSubTuple() { +Tuple s = t.subTuple(1, 2); + +assertTrue("is a Tuple", s instanceof Tuple); + +assertEquals("size", 1, s.size()); +} + public void testHashCodeAndEquals() { Tuple a = new Tuple(new Object[]{"a", "b", "c"}); Tuple b = new Tuple(new Object[]{"a", "b", "c"}); @@ -93,4 +101,210 @@ public class TupleTest extends TestCase { public void testIterator() { } +public void testTuple1() { +Tuple1 t = new Tuple1<>(1); + +assertEquals(1, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple2() { +Tuple2 t = new Tuple2<>(1, 2); + +assertEquals(2, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple3() { +Tuple3 t = new Tuple3<>(1, 2, 3); + +assertEquals(3, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple4() { +Tuple4 t = new Tuple4<>(1, 2, 3, 4); + +assertEquals(4, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(new Integer(4), t.getFourth()); +assertEquals(4, t.get(3)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple5() { +Tuple5 t = new Tuple5<>(1, 2, 3, 4, 5); + +assertEquals(5, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(new Integer(4), t.getFourth()); +assertEquals(4, t.get(3)); + +assertEquals(new Integer(5), t.getFifth()); +assertEquals(5, t.get(4)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple6() { +Tuple6 t = new Tuple6<>(1, 2, 3, 4, 5, 6); + +
groovy git commit: Add `subTuple` method
Repository: groovy Updated Branches: refs/heads/master d6b0cb468 -> c9d871690 Add `subTuple` method Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c9d87169 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c9d87169 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c9d87169 Branch: refs/heads/master Commit: c9d8716900b8982b194453fca13cffadf86a37b6 Parents: d6b0cb4 Author: sunlanAuthored: Sat Sep 16 16:10:16 2017 +0800 Committer: sunlan Committed: Sat Sep 16 16:10:16 2017 +0800 -- src/main/groovy/lang/Tuple.java | 4 + src/test/groovy/lang/TupleTest.java | 214 +++ 2 files changed, 218 insertions(+) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/c9d87169/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 36b04cb..38d835d 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -50,4 +50,8 @@ public class Tuple extends AbstractTuple { System.arraycopy(contents, fromIndex, newContent, 0, size); return new Tuple<>(newContent); } + +public Tuple subTuple(int fromIndex, int toIndex) { +return (Tuple) subList(fromIndex, toIndex); +} } http://git-wip-us.apache.org/repos/asf/groovy/blob/c9d87169/src/test/groovy/lang/TupleTest.java -- diff --git a/src/test/groovy/lang/TupleTest.java b/src/test/groovy/lang/TupleTest.java index 2e88659..19f07b7 100644 --- a/src/test/groovy/lang/TupleTest.java +++ b/src/test/groovy/lang/TupleTest.java @@ -68,6 +68,14 @@ public class TupleTest extends TestCase { assertEquals("size", 1, s.size()); } +public void testSubTuple() { +Tuple s = t.subTuple(1, 2); + +assertTrue("is a Tuple", s instanceof Tuple); + +assertEquals("size", 1, s.size()); +} + public void testHashCodeAndEquals() { Tuple a = new Tuple(new Object[]{"a", "b", "c"}); Tuple b = new Tuple(new Object[]{"a", "b", "c"}); @@ -93,4 +101,210 @@ public class TupleTest extends TestCase { public void testIterator() { } +public void testTuple1() { +Tuple1 t = new Tuple1<>(1); + +assertEquals(1, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple2() { +Tuple2 t = new Tuple2<>(1, 2); + +assertEquals(2, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple3() { +Tuple3 t = new Tuple3<>(1, 2, 3); + +assertEquals(3, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple4() { +Tuple4 t = new Tuple4<>(1, 2, 3, 4); + +assertEquals(4, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(new Integer(4), t.getFourth()); +assertEquals(4, t.get(3)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple5() { +Tuple5 t = new Tuple5<>(1, 2, 3, 4, 5); + +assertEquals(5, t.size()); + +assertEquals(new Integer(1), t.getFirst()); +assertEquals(1, t.get(0)); + +assertEquals(new Integer(2), t.getSecond()); +assertEquals(2, t.get(1)); + +assertEquals(new Integer(3), t.getThird()); +assertEquals(3, t.get(2)); + +assertEquals(new Integer(4), t.getFourth()); +assertEquals(4, t.get(3)); + +assertEquals(new Integer(5), t.getFifth()); +assertEquals(5, t.get(4)); + +assertEquals(t, t.subTuple(0, t.size())); +} + +public void testTuple6() { +Tuple6 t = new Tuple6<>(1,
groovy git commit: Refine tuples
Repository: groovy Updated Branches: refs/heads/master 6cf958c2f -> d6b0cb468 Refine tuples Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d6b0cb46 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d6b0cb46 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d6b0cb46 Branch: refs/heads/master Commit: d6b0cb468305af3bd8fc7f036aa8b4ef9e6a8d6e Parents: 6cf958c Author: sunlanAuthored: Sat Sep 16 15:38:43 2017 +0800 Committer: sunlan Committed: Sat Sep 16 15:39:06 2017 +0800 -- src/main/groovy/lang/Tuple1.java | 4 +++- src/main/groovy/lang/Tuple2.java | 4 +++- src/main/groovy/lang/Tuple3.java | 4 +++- src/main/groovy/lang/Tuple4.java | 4 +++- src/main/groovy/lang/Tuple5.java | 4 +++- src/main/groovy/lang/Tuple6.java | 4 +++- src/main/groovy/lang/Tuple7.java | 4 +++- src/main/groovy/lang/Tuple8.java | 4 +++- src/main/groovy/lang/Tuple9.java | 4 +++- 9 files changed, 27 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b0cb46/src/main/groovy/lang/Tuple1.java -- diff --git a/src/main/groovy/lang/Tuple1.java b/src/main/groovy/lang/Tuple1.java index f57bc3b..1506bb0 100644 --- a/src/main/groovy/lang/Tuple1.java +++ b/src/main/groovy/lang/Tuple1.java @@ -23,10 +23,12 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple1 extends AbstractTuple { +public class Tuple1 extends Tuple { private final T1 first; public Tuple1(T1 first) { +super(first); + this.first = first; } http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b0cb46/src/main/groovy/lang/Tuple2.java -- diff --git a/src/main/groovy/lang/Tuple2.java b/src/main/groovy/lang/Tuple2.java index fe64d5e..d3a8be7 100644 --- a/src/main/groovy/lang/Tuple2.java +++ b/src/main/groovy/lang/Tuple2.java @@ -21,11 +21,13 @@ package groovy.lang; /** * Represents a list of 2 typed Objects. */ -public class Tuple2 extends AbstractTuple { +public class Tuple2 extends Tuple { private final T1 first; private final T2 second; public Tuple2(T1 first, T2 second) { +super(first, second); + this.first = first; this.second = second; } http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b0cb46/src/main/groovy/lang/Tuple3.java -- diff --git a/src/main/groovy/lang/Tuple3.java b/src/main/groovy/lang/Tuple3.java index 59b06f5..de539ec 100644 --- a/src/main/groovy/lang/Tuple3.java +++ b/src/main/groovy/lang/Tuple3.java @@ -24,12 +24,14 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple3 extends AbstractTuple { +public class Tuple3 extends Tuple { private final T1 first; private final T2 second; private final T3 third; public Tuple3(T1 first, T2 second, T3 third) { +super(first, second, third); + this.first = first; this.second = second; this.third = third; http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b0cb46/src/main/groovy/lang/Tuple4.java -- diff --git a/src/main/groovy/lang/Tuple4.java b/src/main/groovy/lang/Tuple4.java index b3cf839..069f3af 100644 --- a/src/main/groovy/lang/Tuple4.java +++ b/src/main/groovy/lang/Tuple4.java @@ -24,13 +24,15 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple4 extends AbstractTuple { +public class Tuple4 extends Tuple { private final T1 first; private final T2 second; private final T3 third; private final T4 fourth; public Tuple4(T1 first, T2 second, T3 third, T4 fourth) { +super(first, second, third, fourth); + this.first = first; this.second = second; this.third = third; http://git-wip-us.apache.org/repos/asf/groovy/blob/d6b0cb46/src/main/groovy/lang/Tuple5.java -- diff --git a/src/main/groovy/lang/Tuple5.java b/src/main/groovy/lang/Tuple5.java index c83d792..ea61507 100644 --- a/src/main/groovy/lang/Tuple5.java +++ b/src/main/groovy/lang/Tuple5.java @@ -24,7 +24,7 @@ package groovy.lang; * * @since 2.5.0 */ -public class Tuple5 extends AbstractTuple { +public class Tuple5 extends Tuple { private final T1 first; private final T2 second; private final T3 third; @@ -32,6 +32,8 @@ public class Tuple5 extends AbstractTuple { private final T5 fifth; public Tuple5(T1 first, T2
[1/2] groovy git commit: Field version of Tuple1, Tuple3, ... , Tuple9
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 666e3a11b -> 7c669b46d Field version of Tuple1, Tuple3, ... , Tuple9 (cherry picked from commit 0dd461d) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f868f6e0 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f868f6e0 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f868f6e0 Branch: refs/heads/GROOVY_2_5_X Commit: f868f6e0889c3cc3e37a54861bf9b9fe4f466e99 Parents: 666e3a1 Author: Yu KobayashiAuthored: Tue Dec 30 21:04:36 2014 +0800 Committer: sunlan Committed: Sat Sep 16 14:42:52 2017 +0800 -- src/main/groovy/lang/AbstractTuple.java | 61 ++ src/main/groovy/lang/Tuple.java | 40 + src/main/groovy/lang/Tuple1.java| 51 src/main/groovy/lang/Tuple2.java| 31 +-- src/main/groovy/lang/Tuple3.java| 68 src/main/groovy/lang/Tuple4.java| 76 + src/main/groovy/lang/Tuple5.java| 84 +++ src/main/groovy/lang/Tuple6.java| 92 + src/main/groovy/lang/Tuple7.java| 100 +++ src/main/groovy/lang/Tuple8.java| 108 + src/main/groovy/lang/Tuple9.java| 117 +++ 11 files changed, 786 insertions(+), 42 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/f868f6e0/src/main/groovy/lang/AbstractTuple.java -- diff --git a/src/main/groovy/lang/AbstractTuple.java b/src/main/groovy/lang/AbstractTuple.java new file mode 100644 index 000..c0e0845 --- /dev/null +++ b/src/main/groovy/lang/AbstractTuple.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package groovy.lang; + +import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; + +import java.util.AbstractList; + +/** + * @since 2.5.0 + */ +public abstract class AbstractTuple extends AbstractList { +private int hashCode; + +@Override +public boolean equals(Object o) { +if (this == o) return true; +if (o == null || !(o instanceof AbstractTuple)) return false; + +AbstractTuple that = (AbstractTuple) o; +if (size() != that.size()) return false; +for (int i = 0; i < size(); i++) { +if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { +return false; +} +} +return true; +} + +@Override +public int hashCode() { +if (hashCode == 0) { +for (int i = 0; i < size(); i++) { +Object value = get(i); +int hash = (value != null) ? value.hashCode() : 0xbabe; +hashCode ^= hash; +} +if (hashCode == 0) { +hashCode = 0xbabe; +} +} +return hashCode; +} +} http://git-wip-us.apache.org/repos/asf/groovy/blob/f868f6e0/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 16095d9..1eeed45 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -18,64 +18,32 @@ */ package groovy.lang; -import java.util.AbstractList; import java.util.List; -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; - /** * Represents a list of Objects. * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractList { +public class Tuple extends AbstractTuple { private final Object[] contents; -private int hashCode; -public Tuple(Object[] contents) { +public Tuple(Object... contents) { if (contents == null) throw new NullPointerException(); this.contents = contents; } +@Override
[2/2] groovy git commit: Generify Tuple
Generify Tuple (cherry picked from commit 440ae18) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7c669b46 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7c669b46 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7c669b46 Branch: refs/heads/GROOVY_2_5_X Commit: 7c669b46debfded0a011227078fab6f491a44bd3 Parents: f868f6e Author: sunlanAuthored: Sat Sep 16 14:25:39 2017 +0800 Committer: sunlan Committed: Sat Sep 16 14:42:58 2017 +0800 -- src/main/groovy/lang/Tuple.java | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/7c669b46/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 1eeed45..36b04cb 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -25,16 +25,16 @@ import java.util.List; * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractTuple { -private final Object[] contents; +public class Tuple extends AbstractTuple { +private final E[] contents; -public Tuple(Object... contents) { +public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); this.contents = contents; } @Override -public Object get(int index) { +public E get(int index) { return contents[index]; } @@ -44,10 +44,10 @@ public class Tuple extends AbstractTuple { } @Override -public List subList(int fromIndex, int toIndex) { +public List subList(int fromIndex, int toIndex) { int size = toIndex - fromIndex; -Object[] newContent = new Object[size]; +E[] newContent = (E[]) new Object[size]; System.arraycopy(contents, fromIndex, newContent, 0, size); -return new Tuple(newContent); +return new Tuple<>(newContent); } }
[2/2] groovy git commit: Generify Tuple
Generify Tuple (cherry picked from commit 440ae18) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3929d038 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3929d038 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3929d038 Branch: refs/heads/GROOVY_2_6_X Commit: 3929d0382ac9762e8dde335aa5b734b957d8810a Parents: 1409796 Author: sunlanAuthored: Sat Sep 16 14:25:39 2017 +0800 Committer: sunlan Committed: Sat Sep 16 14:42:07 2017 +0800 -- src/main/groovy/lang/Tuple.java | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/3929d038/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 1eeed45..36b04cb 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -25,16 +25,16 @@ import java.util.List; * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractTuple { -private final Object[] contents; +public class Tuple extends AbstractTuple { +private final E[] contents; -public Tuple(Object... contents) { +public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); this.contents = contents; } @Override -public Object get(int index) { +public E get(int index) { return contents[index]; } @@ -44,10 +44,10 @@ public class Tuple extends AbstractTuple { } @Override -public List subList(int fromIndex, int toIndex) { +public List subList(int fromIndex, int toIndex) { int size = toIndex - fromIndex; -Object[] newContent = new Object[size]; +E[] newContent = (E[]) new Object[size]; System.arraycopy(contents, fromIndex, newContent, 0, size); -return new Tuple(newContent); +return new Tuple<>(newContent); } }
[1/2] groovy git commit: Field version of Tuple1, Tuple3, ... , Tuple9
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X f02634c37 -> 3929d0382 Field version of Tuple1, Tuple3, ... , Tuple9 (cherry picked from commit 0dd461d) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1409796d Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1409796d Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1409796d Branch: refs/heads/GROOVY_2_6_X Commit: 1409796d330348db9e594c2047ee8abcc1b3c198 Parents: f02634c Author: Yu KobayashiAuthored: Tue Dec 30 21:04:36 2014 +0800 Committer: sunlan Committed: Sat Sep 16 14:42:00 2017 +0800 -- src/main/groovy/lang/AbstractTuple.java | 61 ++ src/main/groovy/lang/Tuple.java | 40 + src/main/groovy/lang/Tuple1.java| 51 src/main/groovy/lang/Tuple2.java| 31 +-- src/main/groovy/lang/Tuple3.java| 68 src/main/groovy/lang/Tuple4.java| 76 + src/main/groovy/lang/Tuple5.java| 84 +++ src/main/groovy/lang/Tuple6.java| 92 + src/main/groovy/lang/Tuple7.java| 100 +++ src/main/groovy/lang/Tuple8.java| 108 + src/main/groovy/lang/Tuple9.java| 117 +++ 11 files changed, 786 insertions(+), 42 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/1409796d/src/main/groovy/lang/AbstractTuple.java -- diff --git a/src/main/groovy/lang/AbstractTuple.java b/src/main/groovy/lang/AbstractTuple.java new file mode 100644 index 000..c0e0845 --- /dev/null +++ b/src/main/groovy/lang/AbstractTuple.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package groovy.lang; + +import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; + +import java.util.AbstractList; + +/** + * @since 2.5.0 + */ +public abstract class AbstractTuple extends AbstractList { +private int hashCode; + +@Override +public boolean equals(Object o) { +if (this == o) return true; +if (o == null || !(o instanceof AbstractTuple)) return false; + +AbstractTuple that = (AbstractTuple) o; +if (size() != that.size()) return false; +for (int i = 0; i < size(); i++) { +if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) { +return false; +} +} +return true; +} + +@Override +public int hashCode() { +if (hashCode == 0) { +for (int i = 0; i < size(); i++) { +Object value = get(i); +int hash = (value != null) ? value.hashCode() : 0xbabe; +hashCode ^= hash; +} +if (hashCode == 0) { +hashCode = 0xbabe; +} +} +return hashCode; +} +} http://git-wip-us.apache.org/repos/asf/groovy/blob/1409796d/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 16095d9..1eeed45 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -18,64 +18,32 @@ */ package groovy.lang; -import java.util.AbstractList; import java.util.List; -import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; - /** * Represents a list of Objects. * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractList { +public class Tuple extends AbstractTuple { private final Object[] contents; -private int hashCode; -public Tuple(Object[] contents) { +public Tuple(Object... contents) { if (contents == null) throw new NullPointerException(); this.contents = contents; } +@Override
groovy git commit: tweak wording of error message
Repository: groovy Updated Branches: refs/heads/master 440ae1832 -> 6cf958c2f tweak wording of error message Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6cf958c2 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6cf958c2 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6cf958c2 Branch: refs/heads/master Commit: 6cf958c2fa7dab4a028039c7c6e8f23456a5d7e5 Parents: 440ae18 Author: paulkAuthored: Sat Sep 16 15:52:19 2017 +1000 Committer: paulk Committed: Sat Sep 16 16:35:23 2017 +1000 -- src/main/groovy/transform/builder/InitializerStrategy.java | 2 +- .../groovy/transform/stc/StaticTypeCheckingVisitor.java| 2 +- src/spec/doc/core-domain-specific-languages.adoc | 2 +- src/spec/test/typing/TypeCheckingTest.groovy | 6 +++--- .../transform/stc/ClosureParamTypeInferenceSTCTest.groovy | 2 +- src/test/groovy/transform/stc/DelegatesToSTCTest.groovy| 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/6cf958c2/src/main/groovy/transform/builder/InitializerStrategy.java -- diff --git a/src/main/groovy/transform/builder/InitializerStrategy.java b/src/main/groovy/transform/builder/InitializerStrategy.java index 4e0dd82..9a558ac 100644 --- a/src/main/groovy/transform/builder/InitializerStrategy.java +++ b/src/main/groovy/transform/builder/InitializerStrategy.java @@ -104,7 +104,7 @@ import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC; * * then the following compile-time error would result: * - * [Static type checking] - Cannot find matching method Person#(Person$PersonInitializer ). Please check if the declared type is right and if the method exists. + * [Static type checking] - Cannot find matching method Person#(Person$PersonInitializer ). Please check if the declared type is correct and if the method exists. * * The message is a little cryptic, but it is basically the static compiler telling us that the third parameter, {@code age} in our case, is unset. * http://git-wip-us.apache.org/repos/asf/groovy/blob/6cf958c2/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 28c6368..b8be25d 100644 --- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -4671,7 +4671,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { if (isClassClassNodeWrappingConcreteType(receiver)) { receiver = receiver.getGenericsTypes()[0].getType(); } -addStaticTypeError("Cannot find matching method " + receiver.getText() + "#" + toMethodParametersString(name, args) + ". Please check if the declared type is right and if the method exists.", call); +addStaticTypeError("Cannot find matching method " + receiver.getText() + "#" + toMethodParametersString(name, args) + ". Please check if the declared type is correct and if the method exists.", call); } protected void addAmbiguousErrorMessage(final List foundMethods, final String name, final ClassNode[] args, final Expression expr) { http://git-wip-us.apache.org/repos/asf/groovy/blob/6cf958c2/src/spec/doc/core-domain-specific-languages.adoc -- diff --git a/src/spec/doc/core-domain-specific-languages.adoc b/src/spec/doc/core-domain-specific-languages.adoc index 001705f..c9c8e81 100644 --- a/src/spec/doc/core-domain-specific-languages.adoc +++ b/src/spec/doc/core-domain-specific-languages.adoc @@ -353,7 +353,7 @@ include::{projectdir}/src/spec/test/DelegatesToSpecTest.groovy[tags=sendmail_typ will fail compilation with errors like this one: -[Static type checking] - Cannot find matching method MyScript#from(java.lang.String). Please check if the declared type is right and if the method exists. +[Static type checking] - Cannot find matching method MyScript#from(java.lang.String). Please check if the declared type is correct and if the method exists. @ line 31, column 21.
groovy git commit: Generify Tuple
Repository: groovy Updated Branches: refs/heads/master 0dd461d67 -> 440ae1832 Generify Tuple Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/440ae183 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/440ae183 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/440ae183 Branch: refs/heads/master Commit: 440ae1832710d26debba3174881ddd3b28f001a4 Parents: 0dd461d Author: sunlanAuthored: Sat Sep 16 14:25:39 2017 +0800 Committer: sunlan Committed: Sat Sep 16 14:25:39 2017 +0800 -- src/main/groovy/lang/Tuple.java | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/440ae183/src/main/groovy/lang/Tuple.java -- diff --git a/src/main/groovy/lang/Tuple.java b/src/main/groovy/lang/Tuple.java index 1eeed45..36b04cb 100644 --- a/src/main/groovy/lang/Tuple.java +++ b/src/main/groovy/lang/Tuple.java @@ -25,16 +25,16 @@ import java.util.List; * * @author mailto:ja...@coredevelopers.net;>James Strachan */ -public class Tuple extends AbstractTuple { -private final Object[] contents; +public class Tuple extends AbstractTuple { +private final E[] contents; -public Tuple(Object... contents) { +public Tuple(E... contents) { if (contents == null) throw new NullPointerException(); this.contents = contents; } @Override -public Object get(int index) { +public E get(int index) { return contents[index]; } @@ -44,10 +44,10 @@ public class Tuple extends AbstractTuple { } @Override -public List subList(int fromIndex, int toIndex) { +public List subList(int fromIndex, int toIndex) { int size = toIndex - fromIndex; -Object[] newContent = new Object[size]; +E[] newContent = (E[]) new Object[size]; System.arraycopy(contents, fromIndex, newContent, 0, size); -return new Tuple(newContent); +return new Tuple<>(newContent); } }