junichi11 commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r647037148



##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.jdk;
+
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.StatementTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Name;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.JavaFix;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle.Messages;
+
+@Hint(displayName = "#DN_CheckRegex", description = "#DESC_CheckRegex", 
category = "general")
+@Messages({
+    "DN_CheckRegex=Check Regular Expression",
+    "DESC_CheckRegex=Check Regular Expression"
+})
+public class CheckRegex {
+
+        @TriggerPatterns({
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern, 
$flags)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$flags", 
type="int")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.matches($pattern, 
$text)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$text", 
type="java.lang.CharSequence")
+                        }),
+        @TriggerPattern(value="$str.split($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.split($pattern, $limit)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$limit", 
type="int")
+                        }),
+        @TriggerPattern(value="$str.matches($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceFirst($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceAll($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        })
+    })
+ 
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {

Review comment:
       Please add `@CheckForNull`

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,226 @@
+/*
+ * 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.jdk;
+
+import java.awt.Color;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.openide.util.Exceptions;
+import org.openide.windows.TopComponent;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.Mode;
+import org.openide.windows.WindowManager;
+
+/**
+ * Top component which displays something.
+ */
[email protected](
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@Messages({
+    "CTL_CheckRegexAction=CheckRegex",
+    "CTL_CheckRegexTopComponent=CheckRegex Window",
+    "HINT_CheckRegexTopComponent=This is a CheckRegex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+    
+    private static CheckRegexTopComponent instance;
+    
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the 
form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    // <editor-fold defaultstate="collapsed" desc="Generated 
Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        jLabel1 = new javax.swing.JLabel();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        jTextArea1 = new javax.swing.JTextArea();
+        jLabel2 = new javax.swing.JLabel();
+        jScrollPane2 = new javax.swing.JScrollPane();
+        jTextArea2 = new javax.swing.JTextArea();
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.jLabel1.text")); // NOI18N
+
+        
jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        jScrollPane1.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        jTextArea1.setColumns(20);
+        jTextArea1.setRows(5);
+        jTextArea1.setPreferredSize(new java.awt.Dimension(164, 74));
+        jScrollPane1.setViewportView(jTextArea1);
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.jLabel2.text")); // NOI18N
+
+        
jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+
+        jTextArea2.setColumns(20);
+        jTextArea2.setRows(5);
+        jTextArea2.setPreferredSize(new java.awt.Dimension(164, 74));
+        jTextArea2.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                jTextArea2KeyReleased(evt);
+            }
+        });
+        jScrollPane2.setViewportView(jTextArea2);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+        this.setLayout(layout);
+        layout.setHorizontalGroup(
+            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, 
false)
+                    .addComponent(jLabel1)
+                    .addComponent(jLabel2)
+                    .addComponent(jScrollPane1, 
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE)
+                    .addComponent(jScrollPane2, 
javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
+                .addContainerGap(198, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(jLabel1)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(jScrollPane1, 
javax.swing.GroupLayout.PREFERRED_SIZE, 42, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(jLabel2)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(jScrollPane2, 
javax.swing.GroupLayout.PREFERRED_SIZE, 41, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(19, Short.MAX_VALUE))
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void jTextArea2KeyReleased(java.awt.event.KeyEvent evt) 
{//GEN-FIRST:event_jTextArea2KeyReleased
+        matchPattern();      
+    }//GEN-LAST:event_jTextArea2KeyReleased
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel jLabel1;
+    private javax.swing.JLabel jLabel2;
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JScrollPane jScrollPane2;
+    private javax.swing.JTextArea jTextArea1;
+    private javax.swing.JTextArea jTextArea2;

Review comment:
       Should change component names to proper ones.

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.jdk;
+
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.StatementTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Name;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.JavaFix;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle.Messages;
+
+@Hint(displayName = "#DN_CheckRegex", description = "#DESC_CheckRegex", 
category = "general")
+@Messages({
+    "DN_CheckRegex=Check Regular Expression",
+    "DESC_CheckRegex=Check Regular Expression"
+})
+public class CheckRegex {
+
+        @TriggerPatterns({
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern, 
$flags)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$flags", 
type="int")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.matches($pattern, 
$text)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$text", 
type="java.lang.CharSequence")
+                        }),
+        @TriggerPattern(value="$str.split($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.split($pattern, $limit)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$limit", 
type="int")
+                        }),
+        @TriggerPattern(value="$str.matches($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceFirst($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceAll($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        })
+    })
+ 
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {
+        
+        String originalString = null;
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        
+        if(leaf.getKind() == Kind.STRING_LITERAL){
+            originalString = (String)((LiteralTree)leaf).getValue();
+        }
+        else if(leaf.getKind() == Kind.IDENTIFIER){
+            Name name = ((IdentifierTree)leaf).getName();
+            TreePath tp = ctx.getPath().getParentPath();
+            
+            while(originalString == null && tp !=null){
+                if(tp.getLeaf() instanceof JCBlock){
+                    originalString = identifierBlockSearch(tp.getLeaf(), name);
+                }
+                else if(tp.getLeaf() instanceof JCClassDecl) {
+                    originalString = identifierClassSearch(tp.getLeaf(), name);
+                }
+                tp = tp.getParentPath();
+            }   
+        }
+        if(originalString != null){
+            try{
+                Pattern.compile(originalString);
+            }catch(PatternSyntaxException e){
+                return null;
+            }
+        }
+        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), 
Bundle.ERR_CheckRegex(),new FixImpl(ctx.getInfo(), ctx.getPath(), 
originalString).toEditorFix());
+    }
+
+    private static String identifierBlockSearch(Tree leaf,Name name) {

Review comment:
       Please add `@CheckForNull`.

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.jdk;
+
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.StatementTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Name;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.JavaFix;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle.Messages;
+
+@Hint(displayName = "#DN_CheckRegex", description = "#DESC_CheckRegex", 
category = "general")
+@Messages({
+    "DN_CheckRegex=Check Regular Expression",
+    "DESC_CheckRegex=Check Regular Expression"
+})
+public class CheckRegex {
+
+        @TriggerPatterns({
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern, 
$flags)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$flags", 
type="int")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.matches($pattern, 
$text)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$text", 
type="java.lang.CharSequence")
+                        }),
+        @TriggerPattern(value="$str.split($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.split($pattern, $limit)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$limit", 
type="int")
+                        }),
+        @TriggerPattern(value="$str.matches($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceFirst($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceAll($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        })
+    })
+ 
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {
+        
+        String originalString = null;
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        
+        if(leaf.getKind() == Kind.STRING_LITERAL){

Review comment:
       Please reformat this file.

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.jdk;
+
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.StatementTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Name;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.JavaFix;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle.Messages;
+
+@Hint(displayName = "#DN_CheckRegex", description = "#DESC_CheckRegex", 
category = "general")
+@Messages({
+    "DN_CheckRegex=Check Regular Expression",
+    "DESC_CheckRegex=Check Regular Expression"
+})
+public class CheckRegex {
+
+        @TriggerPatterns({
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern, 
$flags)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$flags", 
type="int")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.matches($pattern, 
$text)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$text", 
type="java.lang.CharSequence")
+                        }),
+        @TriggerPattern(value="$str.split($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.split($pattern, $limit)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$limit", 
type="int")
+                        }),
+        @TriggerPattern(value="$str.matches($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceFirst($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceAll($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        })
+    })
+ 
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {
+        
+        String originalString = null;
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();

Review comment:
       Please add `// NOI18N`.

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.jdk;
+
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.StatementTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.tree.VariableTree;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.tree.JCTree.JCBlock;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Name;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.JavaFix;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle.Messages;
+
+@Hint(displayName = "#DN_CheckRegex", description = "#DESC_CheckRegex", 
category = "general")
+@Messages({
+    "DN_CheckRegex=Check Regular Expression",
+    "DESC_CheckRegex=Check Regular Expression"
+})
+public class CheckRegex {
+
+        @TriggerPatterns({
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.compile($pattern, 
$flags)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$flags", 
type="int")
+                        }),
+        @TriggerPattern(value="java.util.regex.Pattern.matches($pattern, 
$text)",
+                        constraints={
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$text", 
type="java.lang.CharSequence")
+                        }),
+        @TriggerPattern(value="$str.split($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.split($pattern, $limit)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$limit", 
type="int")
+                        }),
+        @TriggerPattern(value="$str.matches($pattern)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceFirst($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        }),
+        @TriggerPattern(value="$str.replaceAll($pattern, $repl)",
+                        constraints={
+                            @ConstraintVariableType(variable="$str", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$pattern", 
type="java.lang.String"),
+                            @ConstraintVariableType(variable="$repl", 
type="java.lang.String")
+                        })
+    })
+ 
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {
+        
+        String originalString = null;
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        
+        if(leaf.getKind() == Kind.STRING_LITERAL){
+            originalString = (String)((LiteralTree)leaf).getValue();
+        }
+        else if(leaf.getKind() == Kind.IDENTIFIER){
+            Name name = ((IdentifierTree)leaf).getName();
+            TreePath tp = ctx.getPath().getParentPath();
+            
+            while(originalString == null && tp !=null){
+                if(tp.getLeaf() instanceof JCBlock){
+                    originalString = identifierBlockSearch(tp.getLeaf(), name);
+                }
+                else if(tp.getLeaf() instanceof JCClassDecl) {
+                    originalString = identifierClassSearch(tp.getLeaf(), name);
+                }
+                tp = tp.getParentPath();
+            }   
+        }
+        if(originalString != null){
+            try{
+                Pattern.compile(originalString);
+            }catch(PatternSyntaxException e){
+                return null;
+            }
+        }
+        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), 
Bundle.ERR_CheckRegex(),new FixImpl(ctx.getInfo(), ctx.getPath(), 
originalString).toEditorFix());
+    }
+
+    private static String identifierBlockSearch(Tree leaf,Name name) {
+        BlockTree bt = (BlockTree)leaf;
+        List<? extends StatementTree> statements = bt.getStatements();
+        for(int i=0;i<statements.size();i++){
+            StatementTree st = statements.get(i);
+            if(st instanceof VariableTree){
+                VariableTree vt = (VariableTree) st;
+                if(vt.getType().toString().equalsIgnoreCase("String") && 
vt.getName().equals(name)){
+                    LiteralTree lt= (LiteralTree)vt.getInitializer();
+                    return(String)lt.getValue();
+                }
+            }    
+        }
+        return null;            
+    }
+
+    private static String identifierClassSearch(Tree leaf, Name name) {

Review comment:
       Please add `@CheckForNull`.

##########
File path: 
java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,226 @@
+/*
+ * 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.jdk;
+
+import java.awt.Color;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.openide.util.Exceptions;
+import org.openide.windows.TopComponent;
+import org.openide.util.NbBundle.Messages;
+import org.openide.windows.Mode;
+import org.openide.windows.WindowManager;
+
+/**
+ * Top component which displays something.
+ */
[email protected](
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@Messages({
+    "CTL_CheckRegexAction=CheckRegex",
+    "CTL_CheckRegexTopComponent=CheckRegex Window",
+    "HINT_CheckRegexTopComponent=This is a CheckRegex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+    
+    private static CheckRegexTopComponent instance;
+    
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the 
form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    // <editor-fold defaultstate="collapsed" desc="Generated 
Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        jLabel1 = new javax.swing.JLabel();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        jTextArea1 = new javax.swing.JTextArea();
+        jLabel2 = new javax.swing.JLabel();
+        jScrollPane2 = new javax.swing.JScrollPane();
+        jTextArea2 = new javax.swing.JTextArea();
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.jLabel1.text")); // NOI18N
+
+        
jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        jScrollPane1.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        jTextArea1.setColumns(20);
+        jTextArea1.setRows(5);
+        jTextArea1.setPreferredSize(new java.awt.Dimension(164, 74));
+        jScrollPane1.setViewportView(jTextArea1);
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, 
org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, 
"CheckRegexTopComponent.jLabel2.text")); // NOI18N
+
+        
jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+
+        jTextArea2.setColumns(20);
+        jTextArea2.setRows(5);
+        jTextArea2.setPreferredSize(new java.awt.Dimension(164, 74));
+        jTextArea2.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                jTextArea2KeyReleased(evt);
+            }
+        });
+        jScrollPane2.setViewportView(jTextArea2);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+        this.setLayout(layout);
+        layout.setHorizontalGroup(
+            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, 
false)
+                    .addComponent(jLabel1)
+                    .addComponent(jLabel2)
+                    .addComponent(jScrollPane1, 
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE)
+                    .addComponent(jScrollPane2, 
javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
+                .addContainerGap(198, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(jLabel1)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(jScrollPane1, 
javax.swing.GroupLayout.PREFERRED_SIZE, 42, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(jLabel2)
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(jScrollPane2, 
javax.swing.GroupLayout.PREFERRED_SIZE, 41, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(19, Short.MAX_VALUE))
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void jTextArea2KeyReleased(java.awt.event.KeyEvent evt) 
{//GEN-FIRST:event_jTextArea2KeyReleased
+        matchPattern();      
+    }//GEN-LAST:event_jTextArea2KeyReleased
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel jLabel1;
+    private javax.swing.JLabel jLabel2;
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JScrollPane jScrollPane2;
+    private javax.swing.JTextArea jTextArea1;
+    private javax.swing.JTextArea jTextArea2;
+    // End of variables declaration//GEN-END:variables
+    @Override
+    public void componentOpened() {
+        // TODO add custom code on component opening
+    }
+    
+    @Override
+    public void componentClosed() {
+        // TODO add custom code on component closing
+    }
+    
+    void writeProperties(java.util.Properties p) {
+        // better to version settings since initial version as advocated at
+        // http://wiki.apidesign.org/wiki/PropertyFiles
+        p.setProperty("version", "1.0");

Review comment:
       should add `// NOI18N` if we need not translate it.
   Strings below as well.




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

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