You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jl...@apache.org on 2018/06/18 04:39:05 UTC
[incubator-netbeans] 13/20: [NETBEANS-481] JDK10-LVTI: Handled
scenarios related to empty array/invalid array as var initializer
This is an automated email from the ASF dual-hosted git repository.
jlahoda pushed a commit to branch release90
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
commit 0071754da5e2384458bf1ea310a2a9d2d78ce7e8
Author: Arunava Sinha <ar...@oracle.com>
AuthorDate: Thu May 24 15:10:10 2018 +0530
[NETBEANS-481] JDK10-LVTI: Handled scenarios related to empty array/invalid array as var initializer
---
.../hints/errors/ConvertInvalidVarToExplicitArrayType.java | 12 +++++++++---
.../errors/ConvertInvalidVarToExplicitArrayTypeTest.java | 12 ++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java b/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java
index 8c7fda3..428cb05 100644
--- a/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java
+++ b/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java
@@ -47,7 +47,7 @@ import javax.lang.model.util.Types;
* @author arusinha
*/
@Messages({
- "DN_ConvertVarToExplicitType=Replace var with explicit type"
+ "DN_ConvertVarToExplicitType=Replace var with explicit type"
})
public class ConvertInvalidVarToExplicitArrayType implements ErrorRule<Void> {
@@ -83,6 +83,11 @@ public class ConvertInvalidVarToExplicitArrayType implements ErrorRule<Void> {
NewArrayTree arrayTree = (NewArrayTree) oldVariableTree.getInitializer();
List<? extends ExpressionTree> currentValues = arrayTree.getInitializers();
+
+ if (currentValues.isEmpty()) {
+ return null;
+ }
+
TreePath initArrayTreePath = new TreePath(treePath, arrayTree);
Types types = compilationInfo.getTypes();
Trees trees = compilationInfo.getTrees();
@@ -91,8 +96,9 @@ public class ConvertInvalidVarToExplicitArrayType implements ErrorRule<Void> {
TypeMirror etType = trees.getTypeMirror(new TreePath(initArrayTreePath, tree));
- //skipped fix for parameterized array member as parameterized array is not possible.
- if (etType.getKind() == TypeKind.DECLARED && !((DeclaredType) etType).getTypeArguments().isEmpty()) {
+ //skipped fix for invalid array member and for parameterized array member.
+ if (etType == null || etType.getKind() == TypeKind.ERROR || (etType.getKind() == TypeKind.DECLARED
+ && !((DeclaredType) etType).getTypeArguments().isEmpty())) {
return null;
}
diff --git a/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayTypeTest.java b/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayTypeTest.java
index 50d07eb..a36d16f 100644
--- a/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayTypeTest.java
+++ b/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayTypeTest.java
@@ -52,6 +52,18 @@ public class ConvertInvalidVarToExplicitArrayTypeTest extends ErrorHintsTestBase
super.tearDown();
}
+ public void testEmptyArrayAsInitializer() throws Exception {
+ performAnalysisTest("test/Test.java",
+ "package test; public class Test {{final var j = {};}}",
+ -1);
+ }
+
+ public void testInvalidArrayAsInitializer() throws Exception {
+ performAnalysisTest("test/Test.java",
+ "package test; public class Test {{final var j = {int1,var1,\"hello\"};}}",
+ -1);
+ }
+
public void testParameterizedElements() throws Exception {
performAnalysisTest("test/Test.java",
"package test; public class Test {{final var j = {new java.util.ArrayList<String>(),new java.util.ArrayList<String>()};}}",
--
To stop receiving notification emails like this one, please contact
jlahoda@apache.org.
---------------------------------------------------------------------
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