lahodaj commented on a change in pull request #3156:
URL: https://github.com/apache/netbeans/pull/3156#discussion_r736378571



##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToSwitchPatternInstanceOf.java
##########
@@ -177,11 +276,81 @@ protected void 
performRewrite(JavaFix.TransformationContext ctx) {
 
     }
 
+
+    @TriggerTreeKind(Tree.Kind.SWITCH)
+    public static ErrorDescription switchPatternMatchToSwitchNull(HintContext 
ctx) {
+
+        SwitchTree switchTree = (SwitchTree) ctx.getPath().getLeaf();
+        boolean isPatternMatch = false;
+        try {
+            isPatternMatch = 
switchTree.getClass().getDeclaredField("patternSwitch").getBoolean(switchTree);
+        } catch (NoSuchFieldException | SecurityException | 
IllegalArgumentException | IllegalAccessException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        if (!isPatternMatch) {
+            return null;
+        }
+        Tree expression = null;
+        try {
+            expression = ((ParenthesizedTree) 
switchTree.getExpression()).getExpression();
+        } catch (ClassCastException cce) {
+            Exceptions.printStackTrace(cce);

Review comment:
       This seems clearly wrong - either we expect the expression can be 
something else that `ParenthesizedTree`, and then we should check, or we are 
sure it will be a `ParenthesizedTree`, and there should be no try-catch (and if 
that expectation will turn out to be wrong, that's will cause an error report 
somewhere - that is OK, as it is unexpected and will simply be fixed).

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToSwitchPatternInstanceOf.java
##########
@@ -177,11 +276,81 @@ protected void 
performRewrite(JavaFix.TransformationContext ctx) {
 
     }
 
+
+    @TriggerTreeKind(Tree.Kind.SWITCH)
+    public static ErrorDescription switchPatternMatchToSwitchNull(HintContext 
ctx) {
+
+        SwitchTree switchTree = (SwitchTree) ctx.getPath().getLeaf();
+        boolean isPatternMatch = false;
+        try {
+            isPatternMatch = 
switchTree.getClass().getDeclaredField("patternSwitch").getBoolean(switchTree);

Review comment:
       This depends on a particular implementation detail. Please don't do that 
in `java.hints`. If it is something that cannot be reasonable detected 
otherwise (not 100% sure here - probably not so complex to write a predicate 
manually), add a method somewhere in `java.source.base` (e.g. `TreeUtilities`). 
It is more OK to depend on internals inside `java.source.base`.




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