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/08/03 05:56:03 UTC

[GitHub] [netbeans] jlahoda commented on a change in pull request #3007: [NETBEANS-5799] : Add support for Pattern Matching for switch (Preview)

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



##########
File path: java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask117FeaturesTest.java
##########
@@ -0,0 +1,115 @@
+package org.netbeans.modules.java.completion;
+/*
+ * 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.
+ */
+
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.lang.model.SourceVersion;
+import javax.swing.event.ChangeListener;
+import org.netbeans.junit.NbTestSuite;
+import org.netbeans.modules.java.source.parsing.JavacParser;
+import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+/**
+ *
+ * @author aksinsin
+ */
+public class JavaCompletionTask117FeaturesTest extends CompletionTestBase {
+
+    private static String SOURCE_LEVEL = "17"; //NOI18N
+
+    public JavaCompletionTask117FeaturesTest(String testName) {
+        super(testName);
+    }
+
+    public static NbTestSuite suite() {
+        NbTestSuite suite = new NbTestSuite();
+        try {
+            SourceVersion.valueOf("RELEASE_17"); //NOI18N
+            suite.addTestSuite(JavaCompletionTask117FeaturesTest.class);
+        } catch (IllegalArgumentException ex) {
+            //OK, no RELEASE_13, skip tests
+            suite.addTest(new JavaCompletionTask117FeaturesTest("noop")); //NOI18N
+        }
+        return suite;
+    }
+
+
+    public void testVariableNameSuggestion() throws Exception {
+        EXTRA_OPTIONS.add("--enable-preview");
+        performTest("SwitchPatternMatching", 1011, null, "AutoCompletion_VarNameSuggestion_PatternMatchingSwitch.pass", getLatestSource());
+    } 
+
+    public void testClassMembersAutoCompletion_GuardedPattern() throws Exception {
+        EXTRA_OPTIONS.add("--enable-preview");
+        performTest("SwitchPatternMatching", 1085, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch.pass", getLatestSource());
+    }
+
+    public void testClassMembersAutoCompletion_GuardedPattern_1() throws Exception {
+        EXTRA_OPTIONS.add("--enable-preview");
+        performTest("SwitchPatternMatching", 1093, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch_1.pass", getLatestSource());
+    }
+    public void testClassMembersAutoCompletion_GuardedPattern_2() throws Exception {
+        EXTRA_OPTIONS.add("--enable-preview");
+        performTest("SwitchPatternMatching", 1113, null, "AutoCompletion_MembersSelect_GuardedPatternMatchingSwitch_2.pass", getLatestSource());
+    }
+    public void testClassMembersAutoCompletion_ParanthesizedPattern() throws Exception {
+        EXTRA_OPTIONS.add("--enable-preview");
+        performTest("SwitchPatternMatching", 1200, null, "AutoCompletion_MembersSelect_ParenthesizedPatternMatchingSwitch.pass", getLatestSource());
+    }
+    public void testClassMembersAutoCompletion_ParanthesizedPattern_1() throws Exception {
+        EXTRA_OPTIONS.add("--enable-preview");
+        performTest("SwitchPatternMatching", 1224, null, "AutoCompletion_MembersSelect_ParenthesizedPatternMatchingSwitch_1.pass", getLatestSource());
+    }
+    public void noop() {
+    }
+
+    static {
+        JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;
+    }
+    
+    private String getLatestSource(){
+        return SourceVersion.latest().name().substring(SourceVersion.latest().name().indexOf("_")+1);
+    }
+    private static final List<String> EXTRA_OPTIONS = new ArrayList<>();

Review comment:
       Please move the EXTRA_OPTIONS into the TestCompilerOptionsQueryImplementation, as was done in: https://github.com/apache/netbeans/commit/8ec77c94d70e94af015ecccc2327626954c82237
   
   This is so that other tests are not so much effected by the completion tests.

##########
File path: java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
##########
@@ -2809,6 +2815,41 @@ private Boolean scanBindingPattern(Tree node, Void p) {
             return true;
         }
 
+        private Boolean scanGuardedPattern(Tree node, Void p) {
+            try {
+                Tree gpt = TreeShims.getGuardedPattern(node);
+                if (gpt != null) {
+                    Name name = TreeShims.getBinding(gpt);

Review comment:
       I am not sure if this works - the nested pattern in the guarded pattern can be parenthesized pattern. Probably should just call `scan` on `gpt`? (Which can't be null?)

##########
File path: java/java.source.base/src/org/netbeans/api/java/source/TreeMaker.java
##########
@@ -267,6 +267,18 @@ public CaseTree Case(List<? extends ExpressionTree> patterns, Tree body) {
         return delegate.Case(patterns, body);
     }
     
+    /**
+     * Creates a new CaseTree for a rule case (case &lt;constants&gt; -> &lt;body&gt;).
+     *
+     * @param patterns the labels for this case statement.
+     * @param body the case's body
+     * @see com.sun.source.tree.CaseTree
+     * @since 2.39
+     */
+    public CaseTree CaseMultipleSwitchPatterns(List<? extends Tree> patterns, Tree body) {

Review comment:
       Maybe just `CaseMultiplePatterns`? Just a suggestion.
   
   Also - there should probably be the similar method taking statements instead of body.

##########
File path: java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
##########
@@ -2809,6 +2815,41 @@ private Boolean scanBindingPattern(Tree node, Void p) {
             return true;
         }
 
+        private Boolean scanGuardedPattern(Tree node, Void p) {
+            try {
+                Tree gpt = TreeShims.getGuardedPattern(node);
+                if (gpt != null) {
+                    Name name = TreeShims.getBinding(gpt);
+                    Tree type = TreeShims.getBindingPatternType(gpt);
+                    scan(type, p);
+                    if (name != null) {
+                        removeWhiteSpace(IDENTIFIER);

Review comment:
       It is not quite clear what `remoteWhitespace` does - would `space();` work?




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