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/05/13 05:14:28 UTC

[GitHub] [netbeans] mishrasandeep opened a new pull request #2953: Added regular expression window and hint

mishrasandeep opened a new pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953


   


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


[GitHub] [netbeans] ebarboni merged pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
ebarboni merged pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953


   


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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r655252725



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",

Review comment:
       Thanks for the input. Have made the changes.




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


[GitHub] [netbeans] jkovalsky commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r662974742



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       It is better now but backward selecting of text using **Shift+Left Arrow** does not allow selection of more than 1 character. Can you please take a look at this?




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


[GitHub] [netbeans] mishrasandeep commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-873805524


   > 
   > 
   > Maybe, We should also update this file: https://github.com/apache/netbeans/blob/master/java/java.hints/licenseinfo.xml
   > 
   > @matthiasblaesing Aren't the license of png files checked via CI(RAT)?
   
   @junichi11 should I go ahead and update the file?


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


[GitHub] [netbeans] ebarboni merged pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
ebarboni merged pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953


   


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


[GitHub] [netbeans] ebarboni merged pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
ebarboni merged pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953


   


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


[GitHub] [netbeans] mishrasandeep commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-874690059


   > 
   > 
   > > should I go ahead and update the file?
   > 
   > @mishrasandeep Yes. Let's update it for your new png files.
   
   @junichi11 have updated the license file


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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r663641526



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       Thanks. Have made the changes. The match won't be re-evaluated now when there is the selection in the exampleTextArea.




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


[GitHub] [netbeans] jkovalsky commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r651809486



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,235 @@
+/*
+ * 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.AssignmentTree;
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.ExpressionStatementTree;
+import com.sun.source.tree.ExpressionTree;
+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.annotations.common.CheckForNull;
+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")
+                })
+    })
+    @CheckForNull
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {
+
+        String originalString = null;
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();  // NOI18N
+
+        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();
+
+            Tree statement = tp.getLeaf();
+            BlockTree bt = null;
+            while (originalString == null && tp != null) {
+
+                if (tp.getLeaf() instanceof JCBlock) {
+                    originalString = identifierBlockSearch(tp.getLeaf(), name, statement, bt);
+                    bt = (BlockTree) tp.getLeaf();
+                } else if (tp.getLeaf() instanceof JCClassDecl) {
+                    originalString = identifierClassSearch(tp.getLeaf(), name, statement);
+                }
+                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());
+    }
+
+    @CheckForNull
+    private static String identifierBlockSearch(Tree leaf, Name name, Tree statement, BlockTree blocktree) {
+        String res = null;
+        try {
+            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.equals(statement)) {
+                    return res;
+                }
+                if (st.equals(blocktree)) {
+                    return res;
+                }
+                if (st instanceof VariableTree) {
+                    VariableTree vt = (VariableTree) st;
+                    if (vt.getType().toString().equalsIgnoreCase("String") && vt.getName().equals(name)) {
+                        LiteralTree lt = (LiteralTree) vt.getInitializer();
+                        res = (String) lt.getValue();
+                    }
+                } else if (st instanceof ExpressionStatementTree) {
+                    ExpressionStatementTree est = (ExpressionStatementTree) st;
+                    ExpressionTree et = est.getExpression();
+                    if (et instanceof AssignmentTree) {
+                        AssignmentTree at = (AssignmentTree) et;
+                        if (at.getVariable().toString().equals(name.toString())) {
+                            res = (String) ((LiteralTree) ((AssignmentTree) est.getExpression()).getExpression()).getValue();
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return res;
+    }
+
+    @CheckForNull
+    private static String identifierClassSearch(Tree leaf, Name name, Tree statement) {

Review comment:
       What is the _statement_ parameter good for?

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",

Review comment:
       Commented out code should be removed.

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegex.java
##########
@@ -0,0 +1,235 @@
+/*
+ * 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.AssignmentTree;
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.ExpressionStatementTree;
+import com.sun.source.tree.ExpressionTree;
+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.annotations.common.CheckForNull;
+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")
+                })
+    })
+    @CheckForNull
+    @Messages("ERR_CheckRegex=Check regular expression")
+    public static ErrorDescription computeWarning(HintContext ctx) {
+
+        String originalString = null;
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();  // NOI18N
+
+        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();
+
+            Tree statement = tp.getLeaf();
+            BlockTree bt = null;
+            while (originalString == null && tp != null) {
+
+                if (tp.getLeaf() instanceof JCBlock) {
+                    originalString = identifierBlockSearch(tp.getLeaf(), name, statement, bt);
+                    bt = (BlockTree) tp.getLeaf();
+                } else if (tp.getLeaf() instanceof JCClassDecl) {
+                    originalString = identifierClassSearch(tp.getLeaf(), name, statement);
+                }
+                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());
+    }
+
+    @CheckForNull
+    private static String identifierBlockSearch(Tree leaf, Name name, Tree statement, BlockTree blocktree) {
+        String res = null;
+        try {
+            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.equals(statement)) {
+                    return res;
+                }
+                if (st.equals(blocktree)) {
+                    return res;
+                }
+                if (st instanceof VariableTree) {
+                    VariableTree vt = (VariableTree) st;
+                    if (vt.getType().toString().equalsIgnoreCase("String") && vt.getName().equals(name)) {
+                        LiteralTree lt = (LiteralTree) vt.getInitializer();
+                        res = (String) lt.getValue();
+                    }
+                } else if (st instanceof ExpressionStatementTree) {
+                    ExpressionStatementTree est = (ExpressionStatementTree) st;
+                    ExpressionTree et = est.getExpression();
+                    if (et instanceof AssignmentTree) {
+                        AssignmentTree at = (AssignmentTree) et;
+                        if (at.getVariable().toString().equals(name.toString())) {
+                            res = (String) ((LiteralTree) ((AssignmentTree) est.getExpression()).getExpression()).getValue();
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return res;
+    }
+
+    @CheckForNull
+    private static String identifierClassSearch(Tree leaf, Name name, Tree statement) {
+        String res = null;
+        try {
+            ClassTree ct = (ClassTree) leaf;
+            List<? extends Tree> members = ct.getMembers();
+            for (int i = 0; i < members.size(); i++) {
+                Tree t = members.get(i);
+                if (t instanceof VariableTree) {
+                    VariableTree vt = (VariableTree) t;
+                    if (vt.getType().toString().equalsIgnoreCase("String") && vt.getName().equals(name)) {
+                        LiteralTree lt = (LiteralTree) vt.getInitializer();
+                        res = lt != null ? (String) lt.getValue() : null;
+                    }
+                } else if (t instanceof ExpressionStatementTree) {
+                    ExpressionStatementTree est = (ExpressionStatementTree) t;
+                    ExpressionTree et = est.getExpression();
+                    if (et instanceof AssignmentTree) {
+                        AssignmentTree at = (AssignmentTree) et;
+                        if (at.getVariable().toString().equals(name.toString())) {
+                            res = (String) ((LiteralTree) ((AssignmentTree) est.getExpression()).getExpression()).getValue();
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        return res;
+    }
+
+    private static final class FixImpl extends JavaFix {
+
+        private String origString;

Review comment:
       _origString_ variable can be final.

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name="Check Regex",path = "Menu/Window", position = 900),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "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);
+        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.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(355, 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)
+                .addGap(15, 15, 15)
+                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(15, 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N

Review comment:
       Why do we read the version property here?




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


[GitHub] [netbeans] junichi11 commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r663656772



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -197,7 +197,8 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
     }// </editor-fold>//GEN-END:initComponents
 
     private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
-        matchPattern();
+        if (exampleTextArea.getSelectedText() == null)

Review comment:
       Nitpick: I would use `{}`.




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


[GitHub] [netbeans] jkovalsky commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r660637743



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return <b>SourceVersion.latest()</b>; most Processors are not affected by future language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:

Review comment:
       Maybe we could annotate shortcut keys for both JTextAreas and JCheckBox components with & character?

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return <b>SourceVersion.latest()</b>; most Processors are not affected by future language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:
+CheckRegexTopComponent.exampleLabel.text=Example:
+CheckRegexTopComponent.strictCheckBox.text=Strict Check
+
+#{0}: PatternSyntaxException.getDescription()

Review comment:
       Commented out code should be removed.

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       I am afraid that because of this removal of all highlights if one selects an example text it just disappears. Please reconsider this solution.




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


[GitHub] [netbeans] jkovalsky commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r664116035



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       Finally, have no more comments. Thanks a lot! 




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


[GitHub] [netbeans] sdedic commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
sdedic commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-876944172


   Is it possible to include this in `12.5` ?


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


[GitHub] [netbeans] mishrasandeep edited a comment on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep edited a comment on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-872935985


   > @mishrasandeep
   > Thank you for your contribution!
   > Could you please squash as one commit with a proper commit message after you fix all? (We don't use the `squash and merge` button.)
   
   @junichi11 
   Have addressed all the comments and squashed the commits. Any other inputs from your end?


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


[GitHub] [netbeans] junichi11 commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r662970577



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Regexp.java
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.BinaryTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.MemberSelectTree;
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Severity;
+import org.netbeans.spi.java.hints.Hint.Options;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author lahvac
+ */
+@Hint(displayName = "#DN_org.netbeans.modules.java.hints.jdk.Regexp", description = "#DESC_org.netbeans.modules.java.hints.jdk.Regexp", category = "bugs", severity = Severity.ERROR, suppressWarnings = {"MalformedRegexp", "", "MalformedRegex"}, options = Options.QUERY)
+@NbBundle.Messages({"DN_org.netbeans.modules.java.hints.jdk.Regexp=Malformed regular expression",
+    "DESC_org.netbeans.modules.java.hints.jdk.Regexp=Warns about malformed regular expressions"})
+public class Regexp {
+
+    @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")
+                })
+    })
+    public static ErrorDescription hint(final HintContext ctx) {
+        final StringBuilder regexp = new StringBuilder();
+        final boolean[] accept = {true};
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        if (leaf.getKind() == Kind.STRING_LITERAL) {
+            TreePath pattern = ctx.getVariables().get("$pattern");
+            new ErrorAwareTreePathScanner<Void, Void>() {
+                @Override
+                public Void visitLiteral(LiteralTree node, Void p) {
+                    if (node.getValue() instanceof String) {
+                        regexp.append(node.getValue());
+                        return null;
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitIdentifier(IdentifierTree node, Void p) {
+                    Element el = ctx.getInfo().getTrees().getElement(getCurrentPath());
+
+                    if (el != null && el.getKind() == ElementKind.FIELD) {
+                        VariableElement ve = (VariableElement) el;
+
+                        if (ve.getConstantValue() instanceof String) {
+                            regexp.append(ve.getConstantValue());
+                            return null;
+                        }
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitMemberSelect(MemberSelectTree node, Void p) {
+                    Element el = ctx.getInfo().getTrees().getElement(getCurrentPath());
+
+                    if (el != null && el.getKind() == ElementKind.FIELD) {
+                        VariableElement ve = (VariableElement) el;
+
+                        if (ve.getConstantValue() instanceof String) {
+                            regexp.append(ve.getConstantValue());
+                            return null;
+                        }
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitBinary(BinaryTree node, Void p) {
+                    if (node.getKind() != Kind.PLUS) {
+                        return super.visitBinary(node, p);
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
+                    accept[0] = false;
+                    return null;
+                }
+            }.scan(pattern, null);
+
+            if (!accept[0] || regexp.length() == 0) {
+                return null;
+            }
+        }else if(leaf.getKind() == Kind.IDENTIFIER){
+            String val = CheckRegex.identifierSearch(leaf, ctx);
+            if(val != null)
+                regexp.append(val);
+        }
+        try {
+            Pattern.compile(regexp.toString());
+            return null;
+        } catch (PatternSyntaxException pse) {
+            String displayName = NbBundle.getMessage(Regexp.class, "DN_RegExp", new Object[]{

Review comment:
       Please add `// NOI18N`

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Regexp.java
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.BinaryTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.MemberSelectTree;
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Severity;
+import org.netbeans.spi.java.hints.Hint.Options;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author lahvac
+ */
+@Hint(displayName = "#DN_org.netbeans.modules.java.hints.jdk.Regexp", description = "#DESC_org.netbeans.modules.java.hints.jdk.Regexp", category = "bugs", severity = Severity.ERROR, suppressWarnings = {"MalformedRegexp", "", "MalformedRegex"}, options = Options.QUERY)
+@NbBundle.Messages({"DN_org.netbeans.modules.java.hints.jdk.Regexp=Malformed regular expression",
+    "DESC_org.netbeans.modules.java.hints.jdk.Regexp=Warns about malformed regular expressions"})
+public class Regexp {
+
+    @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")
+                })
+    })
+    public static ErrorDescription hint(final HintContext ctx) {
+        final StringBuilder regexp = new StringBuilder();
+        final boolean[] accept = {true};
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        if (leaf.getKind() == Kind.STRING_LITERAL) {
+            TreePath pattern = ctx.getVariables().get("$pattern");

Review comment:
       Please add `// NOI18N`

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Regexp.java
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.BinaryTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.MemberSelectTree;
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Severity;
+import org.netbeans.spi.java.hints.Hint.Options;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author lahvac
+ */
+@Hint(displayName = "#DN_org.netbeans.modules.java.hints.jdk.Regexp", description = "#DESC_org.netbeans.modules.java.hints.jdk.Regexp", category = "bugs", severity = Severity.ERROR, suppressWarnings = {"MalformedRegexp", "", "MalformedRegex"}, options = Options.QUERY)
+@NbBundle.Messages({"DN_org.netbeans.modules.java.hints.jdk.Regexp=Malformed regular expression",
+    "DESC_org.netbeans.modules.java.hints.jdk.Regexp=Warns about malformed regular expressions"})
+public class Regexp {
+
+    @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")
+                })
+    })
+    public static ErrorDescription hint(final HintContext ctx) {
+        final StringBuilder regexp = new StringBuilder();
+        final boolean[] accept = {true};
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        if (leaf.getKind() == Kind.STRING_LITERAL) {
+            TreePath pattern = ctx.getVariables().get("$pattern");
+            new ErrorAwareTreePathScanner<Void, Void>() {
+                @Override
+                public Void visitLiteral(LiteralTree node, Void p) {
+                    if (node.getValue() instanceof String) {
+                        regexp.append(node.getValue());
+                        return null;
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitIdentifier(IdentifierTree node, Void p) {
+                    Element el = ctx.getInfo().getTrees().getElement(getCurrentPath());
+
+                    if (el != null && el.getKind() == ElementKind.FIELD) {
+                        VariableElement ve = (VariableElement) el;
+
+                        if (ve.getConstantValue() instanceof String) {
+                            regexp.append(ve.getConstantValue());
+                            return null;
+                        }
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitMemberSelect(MemberSelectTree node, Void p) {
+                    Element el = ctx.getInfo().getTrees().getElement(getCurrentPath());
+
+                    if (el != null && el.getKind() == ElementKind.FIELD) {
+                        VariableElement ve = (VariableElement) el;
+
+                        if (ve.getConstantValue() instanceof String) {
+                            regexp.append(ve.getConstantValue());
+                            return null;
+                        }
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitBinary(BinaryTree node, Void p) {
+                    if (node.getKind() != Kind.PLUS) {
+                        return super.visitBinary(node, p);
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
+                    accept[0] = false;
+                    return null;
+                }
+            }.scan(pattern, null);
+
+            if (!accept[0] || regexp.length() == 0) {
+                return null;
+            }
+        }else if(leaf.getKind() == Kind.IDENTIFIER){
+            String val = CheckRegex.identifierSearch(leaf, ctx);
+            if(val != null)
+                regexp.append(val);
+        }

Review comment:
       Please reformat.




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


[GitHub] [netbeans] junichi11 commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
junichi11 commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-872961183


   Maybe, We should also update this file: https://github.com/apache/netbeans/blob/master/java/java.hints/licenseinfo.xml
   
   @matthiasblaesing Aren't the license of png files checked via CI(RAT)?


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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r651666667



##########
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:
       Thanks for your input. Have made the changes.




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


[GitHub] [netbeans] junichi11 commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
junichi11 commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-873826111


   > should I go ahead and update the file?
   
   @mishrasandeep Yes. Let's update it for your new png files. 


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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r651667092



##########
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.
+ */
+@TopComponent.Description(
+        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:
       These are auto-generated names for the components and cannot be changed




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


[GitHub] [netbeans] junichi11 commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r651678131



##########
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.
+ */
+@TopComponent.Description(
+        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:
       We should be able to change them in the Navigator window.
   
   - Click a component
   - Press `F2`
   - Change the name
   
   or
   
   - Right-click a component
   - Click "Change Variable Name..." 
   
   Please give it a try.
   
   ![nb-pr-2953-1](https://user-images.githubusercontent.com/738383/122040579-eca68000-ce12-11eb-9dc5-6e23f14a48c5.png)
   




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


[GitHub] [netbeans] jkovalsky commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r664116035



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       Finally, have no more comments. Thanks a lot! 




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


[GitHub] [netbeans] junichi11 commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
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.
+ */
+@TopComponent.Description(
+        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.
+ */
+@TopComponent.Description(
+        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:
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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r662122747



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       Thanks for the input. Have resolved it manually in the code.




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


[GitHub] [netbeans] ebarboni commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
ebarboni commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-877018171


   > Should be - it's a timeout (happens sometimes).
   
   Too often :D,  Let's merge this


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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r663641763



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Regexp.java
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.BinaryTree;
+import com.sun.source.tree.IdentifierTree;
+import com.sun.source.tree.LiteralTree;
+import com.sun.source.tree.MemberSelectTree;
+import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.TreePath;
+import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.VariableElement;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Severity;
+import org.netbeans.spi.java.hints.Hint.Options;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author lahvac
+ */
+@Hint(displayName = "#DN_org.netbeans.modules.java.hints.jdk.Regexp", description = "#DESC_org.netbeans.modules.java.hints.jdk.Regexp", category = "bugs", severity = Severity.ERROR, suppressWarnings = {"MalformedRegexp", "", "MalformedRegex"}, options = Options.QUERY)
+@NbBundle.Messages({"DN_org.netbeans.modules.java.hints.jdk.Regexp=Malformed regular expression",
+    "DESC_org.netbeans.modules.java.hints.jdk.Regexp=Warns about malformed regular expressions"})
+public class Regexp {
+
+    @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")
+                })
+    })
+    public static ErrorDescription hint(final HintContext ctx) {
+        final StringBuilder regexp = new StringBuilder();
+        final boolean[] accept = {true};
+        Tree leaf = ctx.getVariables().get("$pattern").getLeaf();
+        if (leaf.getKind() == Kind.STRING_LITERAL) {
+            TreePath pattern = ctx.getVariables().get("$pattern");
+            new ErrorAwareTreePathScanner<Void, Void>() {
+                @Override
+                public Void visitLiteral(LiteralTree node, Void p) {
+                    if (node.getValue() instanceof String) {
+                        regexp.append(node.getValue());
+                        return null;
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitIdentifier(IdentifierTree node, Void p) {
+                    Element el = ctx.getInfo().getTrees().getElement(getCurrentPath());
+
+                    if (el != null && el.getKind() == ElementKind.FIELD) {
+                        VariableElement ve = (VariableElement) el;
+
+                        if (ve.getConstantValue() instanceof String) {
+                            regexp.append(ve.getConstantValue());
+                            return null;
+                        }
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitMemberSelect(MemberSelectTree node, Void p) {
+                    Element el = ctx.getInfo().getTrees().getElement(getCurrentPath());
+
+                    if (el != null && el.getKind() == ElementKind.FIELD) {
+                        VariableElement ve = (VariableElement) el;
+
+                        if (ve.getConstantValue() instanceof String) {
+                            regexp.append(ve.getConstantValue());
+                            return null;
+                        }
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitBinary(BinaryTree node, Void p) {
+                    if (node.getKind() != Kind.PLUS) {
+                        return super.visitBinary(node, p);
+                    }
+                    accept[0] = false;
+                    return null;
+                }
+
+                @Override
+                public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
+                    accept[0] = false;
+                    return null;
+                }
+            }.scan(pattern, null);
+
+            if (!accept[0] || regexp.length() == 0) {
+                return null;
+            }
+        }else if(leaf.getKind() == Kind.IDENTIFIER){
+            String val = CheckRegex.identifierSearch(leaf, ctx);
+            if(val != null)
+                regexp.append(val);
+        }

Review comment:
       Thanks. Have made the changes and checked the formatting of the files.




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


[GitHub] [netbeans] mishrasandeep commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-872935985


   > @mishrasandeep
   > Thank you for your contribution!
   > Could you please squash as one commit with a proper commit message after you fix all? (We don't use the `squash and merge` button.)
   
   @junichi11 
   Have addressed all the comments and squashed the comments. Any other inputs from your end?


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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r655252725



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",

Review comment:
       Thanks for the input. Have made the changes.

##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name="Check Regex",path = "Menu/Window", position = 900),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "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);
+        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.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(355, 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)
+                .addGap(15, 15, 15)
+                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(15, 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N

Review comment:
       readProperties and writeProperties method are added on using the ConvertAsProperties setting. The version property was auto-generated and other properties can be added as required.




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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r662122378



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return <b>SourceVersion.latest()</b>; most Processors are not affected by future language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:

Review comment:
       Thanks. Have made the changes.




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


[GitHub] [netbeans] junichi11 commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
junichi11 commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-876951030


   @sdedic @jkovalsky @Akshay-Gupta-Oracle @singh-akhilesh 
   If it's OK for you please feel free to merge this after commits are squashed. (Is the Travis error OK?)


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


[GitHub] [netbeans] sdedic commented on pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
sdedic commented on pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#issuecomment-876954055


   > Is the Travis error OK?
   
   Should be - it's a timeout (happens sometimes).


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


[GitHub] [netbeans] jkovalsky commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
jkovalsky commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r662972831



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return <b>SourceVersion.latest()</b>; most Processors are not affected by future language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:

Review comment:
       Shortcuts work great now!




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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r662123951



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/Bundle.properties
##########
@@ -111,3 +111,12 @@ DESC_AnnoProcessor_ObsoleteSupportedSource=If the project's source level is grea
     another useless warning during compilation. <p/>\
     It is recommended to return at least the current project's source level. \
     For future compatibility, consider to return <b>SourceVersion.latest()</b>; most Processors are not affected by future language changes.
+CheckRegexTopComponent.regexLabel.text=Regular Expression:
+CheckRegexTopComponent.exampleLabel.text=Example:
+CheckRegexTopComponent.strictCheckBox.text=Strict Check
+
+#{0}: PatternSyntaxException.getDescription()

Review comment:
       It is the documentation for the String format parameters. Gives a warning "Udocumented format parameter" otherwise.




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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: NETBEANS-5661 - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r655260429



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name="Check Regex",path = "Menu/Window", position = 900),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "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);
+        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.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(355, 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)
+                .addGap(15, 15, 15)
+                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(15, 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N

Review comment:
       readProperties and writeProperties method are added on using the ConvertAsProperties setting. The version property was auto-generated and other properties can be added as required.




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


[GitHub] [netbeans] mishrasandeep commented on a change in pull request #2953: [NETBEANS-5661] - Added regular expression window and hint

Posted by GitBox <gi...@apache.org>.
mishrasandeep commented on a change in pull request #2953:
URL: https://github.com/apache/netbeans/pull/2953#discussion_r663641526



##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/jdk/CheckRegexTopComponent.java
##########
@@ -0,0 +1,336 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle;
+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.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.modules.java.hints.jdk//CheckRegex//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "CheckRegexTopComponent",
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "output", openAtStartup = false, position = 13000)
+@ActionID(category = "Window", id = "org.netbeans.modules.java.hints.jdk.CheckRegexTopComponent")
+@ActionReferences({
+    @ActionReference(name = "Check Regex", path = "Menu/Window", position = 950),
+    @ActionReference(path = "Shortcuts", name = "C-8")})
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_CheckRegexAction",
+        preferredID = "CheckRegexTopComponent"
+)
+@Messages({
+    "CTL_CheckRegexAction=Check Regex",
+    "CTL_CheckRegexTopComponent=Check Regular Expression",
+    "HINT_CheckRegexTopComponent=This is a Check Regex window"
+})
+public final class CheckRegexTopComponent extends TopComponent {
+
+    private static CheckRegexTopComponent instance;
+    private static final String PREFERRED_ID = "CheckRegexTopComponent";
+    private static boolean isStrictMatch;
+
+    public CheckRegexTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_CheckRegexTopComponent());
+        setToolTipText(Bundle.HINT_CheckRegexTopComponent());
+        isStrictMatch = false;
+    }
+
+    /**
+     * 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() {
+
+        regexLabel = new javax.swing.JLabel();
+        regexScrollPane = new javax.swing.JScrollPane();
+        regexTextArea = new javax.swing.JTextArea();
+        exampleLabel = new javax.swing.JLabel();
+        exampleLayeredPane = new javax.swing.JLayeredPane();
+        iconLabel = new javax.swing.JLabel();
+        exampleScrollPane = new javax.swing.JScrollPane();
+        exampleTextArea = new javax.swing.JTextArea();
+        strictCheckBox = new javax.swing.JCheckBox();
+        errorLabel = new javax.swing.JLabel();
+
+        org.openide.awt.Mnemonics.setLocalizedText(regexLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.regexLabel.text")); // NOI18N
+
+        regexScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        regexScrollPane.setPreferredSize(new java.awt.Dimension(164, 74));
+
+        regexTextArea.setColumns(20);
+        regexTextArea.setRows(5);
+        regexTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                regexTextAreaKeyReleased(evt);
+            }
+        });
+        regexScrollPane.setViewportView(regexTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(exampleLabel, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.exampleLabel.text")); // NOI18N
+
+        exampleScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+        exampleScrollPane.setOpaque(false);
+
+        exampleTextArea.setColumns(20);
+        exampleTextArea.setRows(5);
+        exampleTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
+            public void keyReleased(java.awt.event.KeyEvent evt) {
+                exampleTextAreaKeyReleased(evt);
+            }
+        });
+        exampleScrollPane.setViewportView(exampleTextArea);
+
+        org.openide.awt.Mnemonics.setLocalizedText(strictCheckBox, org.openide.util.NbBundle.getMessage(CheckRegexTopComponent.class, "CheckRegexTopComponent.strictCheckBox.text")); // NOI18N
+        strictCheckBox.addItemListener(new java.awt.event.ItemListener() {
+            public void itemStateChanged(java.awt.event.ItemEvent evt) {
+                strictCheckBoxItemStateChanged(evt);
+            }
+        });
+
+        exampleLayeredPane.setLayer(iconLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(exampleScrollPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
+        exampleLayeredPane.setLayer(strictCheckBox, javax.swing.JLayeredPane.DEFAULT_LAYER);
+
+        javax.swing.GroupLayout exampleLayeredPaneLayout = new javax.swing.GroupLayout(exampleLayeredPane);
+        exampleLayeredPane.setLayout(exampleLayeredPaneLayout);
+        exampleLayeredPaneLayout.setHorizontalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exampleLayeredPaneLayout.createSequentialGroup()
+                .addContainerGap(297, Short.MAX_VALUE)
+                .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addGap(12, 12, 12)
+                .addComponent(strictCheckBox))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 15, Short.MAX_VALUE)))
+        );
+        exampleLayeredPaneLayout.setVerticalGroup(
+            exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                .addGap(21, 21, 21)
+                .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(strictCheckBox)
+                    .addComponent(iconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            .addGroup(exampleLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(exampleLayeredPaneLayout.createSequentialGroup()
+                    .addComponent(exampleScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(0, 6, Short.MAX_VALUE)))
+        );
+
+        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)
+                    .addComponent(regexLabel)
+                    .addComponent(exampleLabel)
+                    .addGroup(layout.createSequentialGroup()
+                        .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(errorLabel))
+                    .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addContainerGap(266, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(regexLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(regexScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addComponent(errorLabel))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(exampleLabel)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(exampleLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void exampleTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_exampleTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_exampleTextAreaKeyReleased
+
+    private void regexTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_regexTextAreaKeyReleased
+        matchPattern();
+    }//GEN-LAST:event_regexTextAreaKeyReleased
+
+    private void strictCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_strictCheckBoxItemStateChanged
+        isStrictMatch = !isStrictMatch;
+        matchPattern();
+    }//GEN-LAST:event_strictCheckBoxItemStateChanged
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel errorLabel;
+    private javax.swing.JLabel exampleLabel;
+    private javax.swing.JLayeredPane exampleLayeredPane;
+    private javax.swing.JScrollPane exampleScrollPane;
+    private javax.swing.JTextArea exampleTextArea;
+    private javax.swing.JLabel iconLabel;
+    private javax.swing.JLabel regexLabel;
+    private javax.swing.JScrollPane regexScrollPane;
+    private javax.swing.JTextArea regexTextArea;
+    private javax.swing.JCheckBox strictCheckBox;
+    // 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");    // NOI18N
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");  // NOI18N
+        // TODO read your settings according to their version
+    }
+
+    public static synchronized CheckRegexTopComponent getDefault() {
+        if (instance == null) {
+            instance = new CheckRegexTopComponent();
+        }
+        Mode outputMode = WindowManager.getDefault().findMode("output");    // NOI18N
+        if (outputMode != null) {
+            outputMode.dockInto(instance);
+        }
+        return instance;
+    }
+
+    public static synchronized CheckRegexTopComponent findInstance() {
+        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
+        if (win == null) {
+            Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");   // NOI18N
+            return getDefault();
+        }
+        if (win instanceof CheckRegexTopComponent) {
+            return (CheckRegexTopComponent) win;
+        }
+        Logger.getLogger(CheckRegexTopComponent.class.getName()).warning(
+                "There seem to be multiple components with the '" + PREFERRED_ID
+                + "' ID. That is a potential source of errors and unexpected behavior.");   // NOI18N
+        return getDefault();
+    }
+
+    void setData(String origString) {
+        regexTextArea.setText(origString);
+        matchPattern();
+    }
+
+    @NbBundle.Messages({
+        "CheckRegexTopComponent.tooltip.match.regex=The Example Matches the Regular Expression",
+        "CheckRegexTopComponent.tooltip.need.more.input=Need more input to match",
+        "CheckRegexTopComponent.tooltip.not.match=The example does not match the Regular Expression.",
+        "# {0} - matchCount",
+        "CheckRegexTopComponent.tooltop.sub.match={0} substring(s) match the Regular Expression",
+        "# {0} - invalidRegex",
+        "CheckRegexTopComponent.label.error=Invalid regular expression: {0}"
+    })
+    private void matchPattern() {
+
+        errorLabel.setText("");
+        if (regexTextArea.getText().length() == 0 || exampleTextArea.getText().length() == 0) {
+            iconLabel.setIcon(null);
+            return;
+        }
+        Pattern p;
+        try {
+            p = Pattern.compile(regexTextArea.getText());
+        } catch (PatternSyntaxException pse) {
+            errorLabel.setText(Bundle.CheckRegexTopComponent_label_error(pse.getDescription()));
+            return;
+        }
+        Matcher m = p.matcher(exampleTextArea.getText());
+
+        Highlighter highlighter = exampleTextArea.getHighlighter();
+        highlighter.removeAllHighlights();

Review comment:
       Thanks. Have made the changes. The match won't re-evaluated now when there is the selection in the exampleTextArea.




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