[
https://issues.apache.org/jira/browse/GROOVY-10682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17611742#comment-17611742
]
ASF GitHub Bot commented on GROOVY-10682:
-----------------------------------------
sonatype-lift[bot] commented on code in PR #1785:
URL: https://github.com/apache/groovy/pull/1785#discussion_r984915130
##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -6246,123 +6126,39 @@ private static Object sum(Iterator<?> self, Object
initialValue, boolean first)
return result;
}
- /**
- * Sums the items in an array, adding the result to some initial value.
- * <pre class="groovyTestCase">assert (5+1+2+3+4 as byte) == ([1,2,3,4] as
byte[]).sum(5 as byte)</pre>
- *
- * @param self an array of values to sum
- * @param initialValue the items in the array will be summed to this
initial value
- * @return The sum of all of the items.
- * @since 2.4.2
- */
+ @Deprecated
public static byte sum(byte[] self, byte initialValue) {
- byte s = initialValue;
- for (byte v : self) {
- s += v;
- }
- return s;
+ return ArrayGroovyMethods.sum(self, initialValue);
}
- /**
- * Sums the items in an array, adding the result to some initial value.
- * <pre class="groovyTestCase">assert (5+1+2+3+4 as short) == ([1,2,3,4]
as short[]).sum(5 as short)</pre>
- *
- * @param self an array of values to sum
- * @param initialValue the items in the array will be summed to this
initial value
- * @return The sum of all of the items.
- * @since 2.4.2
- */
+ @Deprecated
public static short sum(short[] self, short initialValue) {
Review Comment:
*[InlineMeSuggester](https://errorprone.info/bugpattern/InlineMeSuggester):*
This deprecated API looks inlineable. If you'd like the body of the API to be
inlined to its callers, please annotate it with @InlineMe.
---
```suggestion
@InlineMe(replacement = "ArrayGroovyMethods.sum(self, initialValue)",
imports = "org.codehaus.groovy.runtime.ArrayGroovyMethods")
```
---
<details><summary><b>ℹ️ Learn about @sonatype-lift commands</b></summary>
You can reply with the following commands. For example, reply with
***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| -----------
> Provide eachWithIndex for primitive arrays
> ------------------------------------------
>
> Key: GROOVY-10682
> URL: https://issues.apache.org/jira/browse/GROOVY-10682
> Project: Groovy
> Issue Type: Improvement
> Components: groovy-jdk
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Minor
>
> Consider the following:
> {code:groovy}
> @groovy.transform.TypeChecked
> void test(int[] ints) {
> ints.eachWithIndex { value, index ->
> println "$index: ${value.doubleValue()}"
> }
> }
> test(0,1,2,3,4,5)
> {code}
> Compiler reports "[Static type checking] - Cannot find matching method
> java.lang.Object#doubleValue()"
> {{eachWithIndex}} is only provided for reference types, so "value" is seen as
> Object by the type checker.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)