You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ar...@apache.org on 2019/05/02 08:34:07 UTC

[netbeans] branch master updated: [NETBEANS-2350]NPE while doing auto complete in rule switch block

This is an automated email from the ASF dual-hosted git repository.

arusinha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new a2af32d  [NETBEANS-2350]NPE while doing auto complete in rule switch block
     new 3c8e4f4  Merge pull request #1211 from vikasprabhakar/NPE_Switch_expression
a2af32d is described below

commit a2af32da3af7e818b86bba234aa45639d3ed4ca2
Author: Vikas Prabhakar <vi...@oracle.com>
AuthorDate: Mon Apr 22 21:49:36 2019 -0700

    [NETBEANS-2350]NPE while doing auto complete in rule switch block
---
 .../java/completion/JavaCompletionTask.java        |  9 +++++-
 .../1.7/ruleSwitchAutoCompleteCaseValues.pass      |  2 ++
 .../1.8/ruleSwitchAutoCompleteCaseValues.pass      |  1 +
 .../10/ruleSwitchAutoCompleteCaseValues.pass       |  1 +
 .../11/ruleSwitchAutoCompleteCaseValues.pass       |  1 +
 .../12/ruleSwitchAutoCompleteCaseValues.pass       |  1 +
 .../data/RuleSwitchAutoCompleteCaseValue.java      | 33 ++++++++++++++++++++++
 .../JavaCompletionTask112FeaturesTest.java         |  4 +++
 8 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
index 8e925dc..ddfd78a 100644
--- a/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
+++ b/java/java.completion/src/org/netbeans/modules/java/completion/JavaCompletionTask.java
@@ -2293,7 +2293,14 @@ public final class JavaCompletionTask<T> extends BaseTask {
             }
             if (lastCase != null) {
                 StatementTree last = null;
-                for (StatementTree stat : lastCase.getStatements()) {
+                List<? extends StatementTree> statements = lastCase.getStatements();
+                if (statements == null) {
+                    Tree caseBody = TreeShims.getBody(lastCase);
+                    if (caseBody instanceof StatementTree) {
+                        statements = Collections.singletonList((StatementTree) caseBody);
+                    }
+                }
+                for (StatementTree stat : statements) {
                     int pos = (int) sourcePositions.getStartPosition(root, stat);
                     if (pos == Diagnostic.NOPOS || offset <= pos) {
                         break;
diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.7/ruleSwitchAutoCompleteCaseValues.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.7/ruleSwitchAutoCompleteCaseValues.pass
new file mode 100644
index 0000000..9ce5b19
--- /dev/null
+++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.7/ruleSwitchAutoCompleteCaseValues.pass
@@ -0,0 +1,2 @@
+case
+
diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/ruleSwitchAutoCompleteCaseValues.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/ruleSwitchAutoCompleteCaseValues.pass
new file mode 100644
index 0000000..9a33383
--- /dev/null
+++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/1.8/ruleSwitchAutoCompleteCaseValues.pass
@@ -0,0 +1 @@
+case
diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/10/ruleSwitchAutoCompleteCaseValues.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/10/ruleSwitchAutoCompleteCaseValues.pass
new file mode 100644
index 0000000..9a33383
--- /dev/null
+++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/10/ruleSwitchAutoCompleteCaseValues.pass
@@ -0,0 +1 @@
+case
diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/11/ruleSwitchAutoCompleteCaseValues.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/11/ruleSwitchAutoCompleteCaseValues.pass
new file mode 100644
index 0000000..9a33383
--- /dev/null
+++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/11/ruleSwitchAutoCompleteCaseValues.pass
@@ -0,0 +1 @@
+case
diff --git a/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/12/ruleSwitchAutoCompleteCaseValues.pass b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/12/ruleSwitchAutoCompleteCaseValues.pass
new file mode 100644
index 0000000..9a33383
--- /dev/null
+++ b/java/java.completion/test/unit/data/goldenfiles/org/netbeans/modules/java/completion/JavaCompletionTaskTest/12/ruleSwitchAutoCompleteCaseValues.pass
@@ -0,0 +1 @@
+case
diff --git a/java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/RuleSwitchAutoCompleteCaseValue.java b/java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/RuleSwitchAutoCompleteCaseValue.java
new file mode 100644
index 0000000..8a5c95d
--- /dev/null
+++ b/java/java.completion/test/unit/data/org/netbeans/modules/java/completion/data/RuleSwitchAutoCompleteCaseValue.java
@@ -0,0 +1,33 @@
+/*
+ * 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 test;
+
+public class Test {
+
+    enum colors {RED, GREEN, BLUE}
+
+    public void op(int a) {
+        colors color = colors.RED;
+        switch (color) {
+            case RED -> a = 10;
+                
+	}
+    }
+}
diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask112FeaturesTest.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask112FeaturesTest.java
index 6923635..242a2bc 100644
--- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask112FeaturesTest.java
+++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask112FeaturesTest.java
@@ -73,6 +73,10 @@ public class JavaCompletionTask112FeaturesTest extends CompletionTestBase {
         performTest("RuleSwitchWithMultiEnumValues", 1024, null, "ruleSwitchEnumCaseValues.pass");
     }
 
+    public void testRuleSwitchAutoCompleteCaseValue() throws Exception {
+        performTest("RuleSwitchAutoCompleteCaseValue", 1013, "ca", "ruleSwitchAutoCompleteCaseValues.pass");
+    }
+
     public void noop() {
     }
 


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

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