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 2018/05/08 02:32:39 UTC

[GitHub] arusinha commented on a change in pull request #519: [NETBEANS-481] JDK10-LVTI: Added new ErrorRule to fix compiler error on initialization of var type variable with array

arusinha commented on a change in pull request #519: [NETBEANS-481] JDK10-LVTI: Added new ErrorRule to fix compiler error on initialization of var type variable with array
URL: https://github.com/apache/incubator-netbeans/pull/519#discussion_r186603021
 
 

 ##########
 File path: java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * 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 org.netbeans.modules.java.hints.errors;
+
+import com.sun.source.tree.ExpressionTree;
+import com.sun.source.tree.NewArrayTree;
+import com.sun.source.tree.NewClassTree;
+import com.sun.source.tree.Scope;
+import com.sun.source.tree.Tree;
+import com.sun.source.util.TreePath;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.Trees;
+import java.util.HashMap;
+import java.util.Map;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.TreeMaker;
+import org.netbeans.api.java.source.WorkingCopy;
+import org.netbeans.modules.java.hints.spi.ErrorRule;
+import org.netbeans.spi.editor.hints.Fix;
+import org.netbeans.spi.java.hints.JavaFix;
+import org.openide.util.NbBundle.Messages;
+import javax.lang.model.util.Types;
+
+/**
+ *
+ * @author arusinha
+ */
+@Messages({
+    "DN_ConvertVarToExplicitType=Convert Var to Explicit Type"
+})
+public class ConvertInvalidVarToExplicitArrayType implements ErrorRule<Void> {
+
+    private static final Set<String> CODES;
+
+    static {
+        Set<String> codes = new HashSet<>();
+        codes.add("compiler.err.cant.infer.local.var.type"); // NOI18N
+        CODES = Collections.unmodifiableSet(codes);
+    }
+
+    @Override
+    public Set<String> getCodes() {
+        return CODES;
+    }
+
+    @Override
+    public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
+
+        if (treePath.getParentPath() == null) {
+            return null;
+        }
+
+        TypeMirror arrayType = null;
+        if (treePath.getLeaf().getKind() == Tree.Kind.VARIABLE) {
+            VariableTree oldVariableTree = (VariableTree) treePath.getLeaf();
+            NewArrayTree arrayTree = (NewArrayTree) oldVariableTree.getInitializer();
+            List<? extends ExpressionTree> currentValues = arrayTree.getInitializers();
+            TreePath initArrayTreePath = new TreePath(treePath, arrayTree);
+            Types types = compilationInfo.getTypes();
+            Trees trees = compilationInfo.getTrees();
+
+            for (ExpressionTree tree : currentValues) {
+
+                TypeMirror etType = trees.getTypeMirror(new TreePath(initArrayTreePath, tree));
+
+                //skipped fix for parameterized array member as parameterized array is not possible.
+                if (tree.getKind() == Tree.Kind.NEW_CLASS) {
 
 Review comment:
   Had implemented the review comment in last commit

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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