You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by Leward <gi...@git.apache.org> on 2017/06/04 06:41:24 UTC
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
GitHub user Leward opened a pull request:
https://github.com/apache/groovy/pull/558
GROOVY-8218 @Sortable allows reversed natural ordering
See [GROOVY-8218](https://issues.apache.org/jira/browse/GROOVY-8218)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/Leward/groovy master
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/558.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #558
----
commit 4f4cdbeeb40ed40c6020f1ddfadca3769ee10b67
Author: Paul-Julien Vauthier <pj...@gmail.com>
Date: 2017-06-04T06:31:48Z
GROOVY-8218 @Sortable allows reversed natural ordering
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
Posted by jwagenleitner <gi...@git.apache.org>.
Github user jwagenleitner commented on a diff in the pull request:
https://github.com/apache/groovy/pull/558#discussion_r125555008
--- Diff: src/main/org/codehaus/groovy/transform/SortableASTTransformation.java ---
@@ -82,6 +82,7 @@ public void visit(ASTNode[] nodes, SourceUnit source) {
private void createSortable(AnnotationNode annotation, ClassNode classNode) {
List<String> includes = getMemberStringList(annotation, "includes");
List<String> excludes = getMemberStringList(annotation, "excludes");
+ boolean reversed = getMemberBoolValue(annotation, "reversed");
--- End diff --
`boolean reversed = memberHasValue(annotation, "reversed", true);`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
Posted by jwagenleitner <gi...@git.apache.org>.
Github user jwagenleitner commented on a diff in the pull request:
https://github.com/apache/groovy/pull/558#discussion_r125554738
--- Diff: src/main/org/codehaus/groovy/transform/AbstractASTTransformation.java ---
@@ -115,6 +115,14 @@ public int getMemberIntValue(AnnotationNode node, String name) {
return 0;
}
+ public boolean getMemberBoolValue(AnnotationNode node, String name) {
--- End diff --
I think it's common to use `memberHasValue` for evaluating boolean attributes, so this new method is probably not needed.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/groovy/pull/558
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
Posted by jwagenleitner <gi...@git.apache.org>.
Github user jwagenleitner commented on a diff in the pull request:
https://github.com/apache/groovy/pull/558#discussion_r125552693
--- Diff: src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java ---
@@ -219,10 +219,38 @@ public static ClosureExpression closureX(Statement code) {
return result;
}
+ /**
+ * Build a binary expression that compares two values
+ * @param lhv expression for the value to compare from
+ * @param rhv expression for the value value to compare to
+ * @return the expression comparing two values
+ */
public static BinaryExpression cmpX(Expression lhv, Expression rhv) {
return new BinaryExpression(lhv, CMP, rhv);
}
+ /**
+ * Build a binary expression that compares two values
+ * @param lhv expression for the value to compare from
+ * @param rhv expression for the value value to compare to
+ * @param reversed whether to use natural ordering or reversed natural ordering
+ * @return the expression comparing two values
+ */
+ public static BinaryExpression cmpX(Expression lhv, Expression rhv, boolean reversed) {
+ return (reversed) ? cmpXReversed(lhv, rhv) : cmpX(lhv, rhv);
--- End diff --
What about `return (reversed) ? cmpX(rhv, lhv) : cmpX(lhv, rhv);`? Could eliminate the need for the new `cmpXReversed` method.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
Posted by jwagenleitner <gi...@git.apache.org>.
Github user jwagenleitner commented on a diff in the pull request:
https://github.com/apache/groovy/pull/558#discussion_r125553663
--- Diff: src/main/groovy/transform/Sortable.java ---
@@ -145,4 +170,9 @@
* Must not be used if 'includes' is used.
*/
String[] excludes() default {};
+
+ /**
+ * Set to true so that comparator uses reversed natural order.
+ */
--- End diff --
Would be good to add `@since 2.5.0`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] groovy pull request #558: GROOVY-8218 @Sortable allows reversed natural orde...
Posted by jwagenleitner <gi...@git.apache.org>.
Github user jwagenleitner commented on a diff in the pull request:
https://github.com/apache/groovy/pull/558#discussion_r125553175
--- Diff: src/main/org/codehaus/groovy/transform/SortableASTTransformation.java ---
@@ -112,7 +113,7 @@ private static void implementComparable(ClassNode classNode) {
}
}
- private static Statement createCompareToMethodBody(List<PropertyNode> properties) {
+ private static Statement createCompareToMethodBody(List<PropertyNode> properties, Boolean reversed) {
--- End diff --
`boolean` as the parameter type would be consistent with the other methods below.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---