mbien commented on a change in pull request #3166:
URL: https://github.com/apache/netbeans/pull/3166#discussion_r720820460



##########
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:
       I implemented it here locally, but i gotta say it still looks very 
hacky. Esp the 
   `MODEL_VERSION_11 != null && MODEL_VERSION_11.compareTo(version) >= 0
   The main issue i see is that it will spread, other hints would have to keep 
doing the same thing, there is no nice way to make utility method out of this, 
to keep the ugly part in one place.
   
   I am glad that `Runtime.Version` uses ints to represent the feature version 
since this shows that enums are a bad idea for things like that (many other 
projects ran into the same trap).
   
   what we actually want to write is
   ```
   version.supports(11)
   ```
   or even better
   ```
   version.feature() >= 11
   ```
   Thats it, no time traveling needed to figure out potential future enums.
   
   what would you say to a reusable utility like:
    ```
       public static boolean supports(SourceVersion model, int 
featureVersionToCheck) {
           return model.ordinal() >= featureVersionToCheck;
       }
   ```
   This should be forward compatible for a long time, until JDK hopefully adds 
`version.feature()` to make it compatible with their own 
Runtime.version().feature() before breaking the enum ordering.




-- 
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

Reply via email to