You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "lkishalmi (via GitHub)" <gi...@apache.org> on 2026/07/16 03:49:23 UTC

[PR] Facelift on spellchecker module [netbeans]

lkishalmi opened a new pull request, #9515:
URL: https://github.com/apache/netbeans/pull/9515

   Well this is one of the old code we have. Before adding HunSpell support a little facelift won't hurt.
   
   The `SpellcheckerOptionsPanel` could see an iteration or two. The `+/-` prefixes in the strings in CheckboxList model bothers me. Though I wanted to avoid accidental functionality changes.
   
   The `ErrorHighlightPainter` in `ComponentPeer` became an instance method and used as a method reference instead of creating one instance for each miss-spelled word.
   
   I've removed the `getDictionary()` method in `DictionaryImpl` which was supposed to lazy initialize the `dictionary` field. Though as it was called multiple times during the construction it seems to be pretty useless. 
   
   Added a few records where it made sense.
   


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


Re: [PR] Facelift on spellchecker module [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #9515:
URL: https://github.com/apache/netbeans/pull/9515#discussion_r3736718184


##########
ide/spellchecker/src/org/netbeans/modules/spellchecker/options/SpellcheckerOptionsPanel.java:
##########
@@ -451,15 +451,16 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
     }// </editor-fold>//GEN-END:initComponents
 
     private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
-        for (Object o : installedLocalesList.getSelectedValues()) {
+        for (Object o : installedLocalesList.getSelectedValuesList()) {
             removedDictionaries.add((Locale) o);
         }
         updateLocales();
         fireChanged();
     }//GEN-LAST:event_removeButtonActionPerformed
 
     private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
-        Collection<String> currentLocales = new HashSet<String>();
+        Collection<String> currentLocales;
+        currentLocales = new HashSet<>();

Review Comment:
   one line?



##########
ide/spellchecker/src/org/netbeans/modules/spellchecker/TrieDictionary.java:
##########
@@ -77,16 +77,14 @@ private TrieDictionary(File data) throws IOException {
         this.array = null;
 
         FileInputStream ins = new FileInputStream(data);
-        FileChannel channel = ins.getChannel();
-        
-        try {
+        try (FileChannel channel = ins.getChannel()) {

Review Comment:
   add `ins` to the ARM block.



##########
ide/spellchecker/src/org/netbeans/modules/spellchecker/DefaultLocaleQueryImplementation.java:
##########
@@ -23,71 +23,68 @@
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 import java.util.StringTokenizer;
 import org.netbeans.modules.spellchecker.spi.LocaleQueryImplementation;
 import org.openide.ErrorManager;
-import org.openide.filesystems.FileLock;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 /**
  *
  * @author Jan Lahoda
  */
 @org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.spellchecker.spi.LocaleQueryImplementation.class, position=2000)
 public class DefaultLocaleQueryImplementation implements LocaleQueryImplementation {
-    
+
+    private static final String DEFAULT_LOCALE_FILE = "spellchecker-default-locale";
+
     /** Creates a new instance of DefaultLocaleQueryImplementation */
     public DefaultLocaleQueryImplementation() {
     }
 
+    @Override
     public Locale findLocale(FileObject file) {
         return getDefaultLocale();
     }
-    
-    private static final String FILE_NAME = "spellchecker-default-locale";
-    
+
+
     private static FileObject getDefaultLocaleFile() {
-        return FileUtil.getConfigFile(FILE_NAME);
+        return FileUtil.getConfigFile(DEFAULT_LOCALE_FILE);
     }
-    
+
     public static Locale getDefaultLocale() {
         FileObject file = getDefaultLocaleFile();
-        
+
         if (file == null)
-            return Locale.getDefault ();
-        
-        Charset UTF8 = StandardCharsets.UTF_8;
-        
+            return Locale.getDefault();
+
         BufferedReader r = null;
-        
+
         try {
-            r = new BufferedReader(new InputStreamReader(file.getInputStream(), UTF8));
-            
+            r = new BufferedReader(new InputStreamReader(file.getInputStream(), UTF_8));

Review Comment:
   ARM block?



##########
ide/spellchecker/src/org/netbeans/modules/spellchecker/options/DictionaryInstallerPanel.java:
##########
@@ -296,31 +295,37 @@ else if (description.rCurrentUser)
             file.getParentFile().mkdirs();
 
             //TODO: if the dictionary already exists, provide user with a warning.
-            input = new InputStreamReader (new FileInputStream (description.dictionaryFile), description.fileEncoding);
-            output = new OutputStreamWriter (new FileOutputStream (file), StandardCharsets.UTF_8);
+            input = new InputStreamReader(new FileInputStream(description.dictionaryFile), description.fileEncoding);
+            output = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
             char[] buffer = new char[BUFFER_LENGTH];
             int len = BUFFER_LENGTH;
             do {
-                len = input.read (buffer);
-                output.write (buffer, 0, len);
+                len = input.read(buffer);
+                output.write(buffer, 0, len);
             } while (len == BUFFER_LENGTH);
-            StatusDisplayer.getDefault ().setStatusText (getMessage ("MSG_DictionaryWasInstalled")); // NOI18N
+            StatusDisplayer.getDefault().setStatusText(getMessage("MSG_DictionaryWasInstalled")); // NOI18N
         } catch (FileNotFoundException e) {
-            DialogDisplayer.getDefault ().notify (new NotifyDescriptor.Message (getMessage ("MSG_InputFileNotFound"), NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
+            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(getMessage("MSG_InputFileNotFound"), NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
         } catch (UnsupportedEncodingException e) {
-            DialogDisplayer.getDefault ().notify (new NotifyDescriptor.Message (getMessage ("MSG_UnsupportedEncoding"), NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
+            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(getMessage("MSG_UnsupportedEncoding"), NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
         } catch (IOException e) {
-            DialogDisplayer.getDefault ().notify (new NotifyDescriptor.Message (getMessage ("MSG_IOErrorDuringInstallation"), NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
+            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(getMessage("MSG_IOErrorDuringInstallation"), NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
         } finally {
-            if (input != null) try { input.close (); } catch (IOException e) {}
-            if (output != null) try { output.close (); } catch (IOException e) {}
-            
+            if (input != null) try {
+                input.close();
+            } catch (IOException e) {
+            }
+            if (output != null) try {
+                output.close();
+            } catch (IOException e) {
+            }

Review Comment:
   you could put the streams into an ARM block and replace the custom impl with `in.transferTo(out)`



##########
ide/spellchecker/src/org/netbeans/modules/spellchecker/DictionaryImpl.java:
##########
@@ -80,119 +73,99 @@ public DictionaryImpl(Project p, AuxiliaryConfiguration ac, Locale locale) {
         this.dictionaryComparator = prepareDictionaryComparator(locale);
         loadDictionary(ac);
     }
-    
-    private Comparator<String> prepareDictionaryComparator(final Locale locale) {
-        return new Comparator<String>() {
-            public int compare(String s1, String s2) {
-                return s1.toLowerCase(locale).compareTo(s2.toLowerCase(locale));
-            }
-        };
+
+    private Comparator<String> prepareDictionaryComparator(Locale locale) {
+        return (String s1, String s2) -> s1.toLowerCase(locale).compareTo(s2.toLowerCase(locale));
     }
 
     private void loadDictionary(File source) {
         if (!source.canRead())
             return ;
-        
-        BufferedReader reader = null;
 
-        try {
-            reader = new BufferedReader(new InputStreamReader(new FileInputStream(source), StandardCharsets.UTF_8));
-
-            String line = null;
-
-            while ((line = reader.readLine()) != null) {
-                addEntryImpl(line);
-            }
-        } catch (IOException e) {
-            e.printStackTrace(System.err);
-        } finally {
+        
+        synchronized (dictionary) {
             try {
-                if (reader != null) {
-                    reader.close();
-                }
+                dictionary.addAll(Files.readAllLines(source.toPath()));
             } catch (IOException e) {
                 e.printStackTrace(System.err);
-            }
+            }            
+            dictionary.sort(dictionaryComparator);
         }
-        
-        getDictionary().sort(dictionaryComparator);
+
    }
-    
+
     private static final String WORDLIST = "spellchecker-wordlist";
     private static final String NAMESPACE = "http://www.netbeans.org/ns/spellchecker-wordlist/1";
-    
+
     private void loadDictionary(final AuxiliaryConfiguration ac) {
-        ProjectManager.mutex().readAccess(new Action<Void>() {
-            public Void run() {
-                Element conf = ac.getConfigurationFragment(WORDLIST, NAMESPACE, true);
+        ProjectManager.mutex().readAccess(() -> {
+            Element conf = ac.getConfigurationFragment(WORDLIST, NAMESPACE, true);
 
-                if (conf == null) {
-                    return null;
-                }
-                
-                NodeList childNodes = conf.getChildNodes();
+            if (conf == null) {
+                return;
+            }
 
-                for (int cntr = 0; cntr < childNodes.getLength(); cntr++) {
-                    Node n = childNodes.item(cntr);
+            NodeList childNodes = conf.getChildNodes();
 
-                    if ("word".equals(n.getLocalName())) {
-                        addEntryImpl(n.getTextContent());
-                    }
+            for (int cntr = 0; cntr < childNodes.getLength(); cntr++) {
+                Node n = childNodes.item(cntr);
+
+                if ("word".equals(n.getLocalName())) {
+                    addEntryImpl(n.getTextContent());
                 }
-                return null;
             }
         });
-        
-        getDictionary().sort(dictionaryComparator);
+
+        dictionary.sort(dictionaryComparator);

Review Comment:
   similar to changes in `loadDictionary(File source)`, this should probably be in a synchronized block and use the `dictionary` field directly. Once done, `addEntryImpl()` can be removed since it has no usages.



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


Re: [PR] Facelift on spellchecker module [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #9515:
URL: https://github.com/apache/netbeans/pull/9515#issuecomment-6174954616

   moving to NB 33


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