mbien commented on code in PR #4592:
URL: https://github.com/apache/netbeans/pull/4592#discussion_r985187786


##########
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CanUseVT.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 org.netbeans.modules.java.hints.jdk;
+
+import org.netbeans.api.java.queries.CompilerOptionsQuery;
+import org.netbeans.modules.java.hints.errors.Utilities;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Fix;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author mjayan
+ */
[email protected]({
+    "DN_CanUseVT=Can use Virtual Threads",
+    "DESC_CanUseVT=Can use virtual threads if workload is not CPU bound or 
number of concurrent tasks is high",
+    "ERR_CanUseVT=Can Use Virtual Thread Executor",
+    "ERR_CanUseThreadPerTask=Can Use Executors.newThreadPerTaskExecutor"
+})
+@Hint(displayName = "#DN_CanUseVT", description = "#DESC_CanUseVT", category = 
"rules15",
+        minSourceVersion = "19")
+public class CanUseVT {
+
+    private static final int VT_PREVIEW_JDK_VERSION = 19;
+
+    @TriggerPatterns({
+        @TriggerPattern(value = 
"java.util.concurrent.Executors.newFixedThreadPool($size)", constraints = 
@ConstraintVariableType(variable = "$size", type = "int")),
+        @TriggerPattern(value = 
"java.util.concurrent.Executors.newFixedThreadPool($size, $factory)", 
constraints = {
+            @ConstraintVariableType(variable = "$factory", type = 
"java.util.concurrent.ThreadFactory"),
+            @ConstraintVariableType(variable = "$size", type = "int")}),
+        @TriggerPattern(value = 
"java.util.concurrent.Executors.newCachedThreadPool()"),
+        @TriggerPattern(value = 
"java.util.concurrent.Executors.newCachedThreadPool($factory)", constraints
+                = @ConstraintVariableType(variable = "$factory", type = 
"java.util.concurrent.ThreadFactory"))})
+    public static ErrorDescription compute(HintContext ctx) {
+        if (Utilities.isJDKVersionLower(VT_PREVIEW_JDK_VERSION) && 
!CompilerOptionsQuery.getOptions(ctx.getInfo().getFileObject()).getArguments().contains("--enable-preview"))
 {
+            return null;
+        }
+        if (ctx.getVariables().get("$factory") != null) {
+            return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), 
Bundle.ERR_CanUseThreadPerTask(), new Fix[0]);
+        } else {
+            return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), 
Bundle.ERR_CanUseVT(), new Fix[0]);
+        }

Review Comment:
   sorry for the delay.
   
   I believe this could be definitively useful as refactor-and-transform 
inspection. A dev can inspect a project and check if there are pools which can 
be moved to VTs on a case by case basis. If the code rule can convert the easy 
cases to the VT executor - why not (the difficult cases would be only marked 
without a transformation).
   
   I just don't think it should be enabled by default, because light bulbs can 
be perceived as something you should fix. But if a dev enables the hint 
manually, the situation is different since the choice has been already made.
   
   Those are just my thoughts, I don't have a strong opinion on it.



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