jlahoda commented on a change in pull request #3166:
URL: https://github.com/apache/netbeans/pull/3166#discussion_r719963605
##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/perf/Tiny.java
##########
@@ -337,11 +353,24 @@ public static ErrorDescription
collectionsToArray(HintContext ctx) {
Fix[] fixes;
if (pureMemberSelect) {
- String fixDisplayName = NbBundle.getMessage(Tiny.class,
"FIX_Tiny_collectionsToArray");
- fixes = new Fix[] {
- JavaFixUtilities.rewriteFix(ctx, fixDisplayName,
ctx.getPath(), "$collection.toArray(new $clazz[$collection.size()])")
- };
+ SourceVersion version = ctx.getInfo().getSourceVersion();
+ TreePath type = ctx.getVariables().get("$clazz");
+ String typeName = type.getLeaf().toString();
+
+ if
(Integer.parseInt(version.name().substring(version.name().indexOf('_')+1)) >=
11) {
Review comment:
Use of `SourceVersion`/`CompilationInfo.getSourceVersion()` is correct,
but `SourceVersion` is `Comparable`, so can be compared without integer tricks.
Please see method `unnecessaryTempFromString` in this class for an example.
##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/perf/Tiny.java
##########
@@ -314,15 +323,22 @@ private static ErrorDescription enumHint(HintContext ctx,
String baseName, Strin
@Hint(displayName =
"#DN_org.netbeans.modules.java.hints.perf.Tiny.collectionsToArray",
description =
"#DESC_org.netbeans.modules.java.hints.perf.Tiny.collectionsToArray",
category="performance",
- enabled=false,
+ enabled=true,
suppressWarnings="CollectionsToArray")
- @TriggerPattern(value = "$collection.toArray(new $clazz[0])",
- constraints=@ConstraintVariableType(variable="$collection",
-
type="java.util.Collection"))
+ @TriggerPatterns({
+ @TriggerPattern(value = "$collection.toArray(new
$clazz[$collection.size()])",
+ constraints =
@ConstraintVariableType(variable="$collection", type="java.util.Collection")),
+ @TriggerPattern(value = "$collection.toArray(new $clazz[0])",
Review comment:
The two patterns with `$clazz[0]` and `$clazz[]{}` should not be needed,
correct? (And if only the `$collection.size()` pattern would remain, there
probably would be no need for `isNewArrayWithSize`? Or do I miss something?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists