You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/11/02 04:17:07 UTC

[GitHub] [netbeans] jlahoda commented on a change in pull request #3283: [jackpot] Attempt to make JackpotTrees more robust.

jlahoda commented on a change in pull request #3283:
URL: https://github.com/apache/netbeans/pull/3283#discussion_r740709108



##########
File path: java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/JackpotTrees.java
##########
@@ -61,7 +60,36 @@
 public class JackpotTrees {
 
     private static final Map<Class<?>, Class<?>> baseClass2Impl = new HashMap<>();
-    public static <T> T createInstance(Context ctx, Class<T> clazz, Name ident, JCIdent jcIdent, Class<?>[] requiredConstructor, Object[] params) {
+
+    // JDK 8-11
+    public static JCCase createJCCase(Name ident, JCIdent jcIdent, com.sun.tools.javac.util.List<?> stats) {
+        return createInstance(JCCase.class, ident, jcIdent,
+                new Class<?>[] {JCExpression.class, com.sun.tools.javac.util.List.class},
+                new Object[] {jcIdent, stats});
+    }
+
+    // JDK 12-17+
+    public static JCCase createJCCase(Name ident, JCIdent jcIdent, com.sun.tools.javac.util.List<?> labels, com.sun.tools.javac.util.List<?> stats, JCTree body) throws ReflectiveOperationException {
+        
+        // WARNING: CaseKind is deprecated for removal
+        @SuppressWarnings("rawtypes")
+        Class caseKind = Class.forName("com.sun.source.tree.CaseTree$CaseKind", false, JCCase.class.getClassLoader());
+        @SuppressWarnings("unchecked")
+        Object statement = Enum.valueOf(caseKind, "STATEMENT");
+
+        return createInstance(JCCase.class, ident, jcIdent,
+                    new Class<?>[] {caseKind, com.sun.tools.javac.util.List.class, com.sun.tools.javac.util.List.class, JCTree.class},
+                    new Object[] {statement, labels, stats, body});
+    }

Review comment:
       Sorry, I forgot to write about `CaseKind` - it actually is not deprecated anymore. It was deprecated for removal when it was part of a preview feature, but switch expressions are a stable feature now, and `CaseKind` is an ordinary enum. (For the record, deprecating new API elements for removal is an idiom that is no longer used - the new idiom is annotating the element with `PreviewFeature`.)




-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists