diff --git a/ide/spellchecker.bindings.htmlxml/nbproject/project.xml b/ide/spellchecker.bindings.htmlxml/nbproject/project.xml
index db6969d0890d..380634c1e52c 100644
--- a/ide/spellchecker.bindings.htmlxml/nbproject/project.xml
+++ b/ide/spellchecker.bindings.htmlxml/nbproject/project.xml
@@ -94,7 +94,7 @@
- org.openide.util.ui
+ org.openide.util
@@ -102,19 +102,19 @@
- org.openide.util
+ org.openide.util.lookup
- 9.3
+ 8.16
- org.openide.util.lookup
+ org.openide.util.ui
- 8.16
+ 9.3
diff --git a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/AbstractTokenList.java b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/AbstractTokenList.java
index a06925676236..8c3ca159ccfc 100644
--- a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/AbstractTokenList.java
+++ b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/AbstractTokenList.java
@@ -36,9 +36,13 @@
*
* @author Riha, Poppenreiter
*/
-public abstract class AbstractTokenList implements TokenList {
+public abstract sealed class AbstractTokenList implements TokenList permits HtmlTokenList, XmlTokenList {
- protected BaseDocument doc;
+ record SpellSpan(int begin, int end) {
+ public static final SpellSpan NONE = new SpellSpan(-1, -1);
+ };
+
+ protected final BaseDocument doc;
private CharSequence currentWord;
private int currentStartOffset;
protected int nextSearchOffset;
@@ -49,6 +53,7 @@ public abstract class AbstractTokenList implements TokenList {
this.doc = doc;
}
+ @Override
public void setStartOffset(int offset) {
currentWord = null;
currentStartOffset = (-1);
@@ -61,37 +66,40 @@ public void setStartOffset(int offset) {
}
}
+ @Override
public int getCurrentWordStartOffset() {
return currentStartOffset;
}
+ @Override
public CharSequence getCurrentWordText() {
return currentWord;
}
- protected abstract int[] findNextSpellSpan() throws BadLocationException;
+ abstract SpellSpan findNextSpellSpan() throws BadLocationException;
+ @Override
public boolean nextWord() {
boolean next = nextWordImpl();
-
- while (next && (currentStartOffset + currentWord.length()) < ignoreBefore)
+
+ while (next && (currentStartOffset + currentWord.length()) < ignoreBefore) {
next = nextWordImpl();
-
+ }
+
return next;
}
-
+
private boolean nextWordImpl() {
try {
- int[] span = findNextSpellSpan();
+ SpellSpan span = findNextSpellSpan();
- while (span[0] != -1) {
- int offset = (span[0] < nextSearchOffset) ? nextSearchOffset : span[0];
+ while (span.begin != -1) {
+ int offset = (span.begin < nextSearchOffset) ? nextSearchOffset : span.begin;
- int length = span[1];
boolean searching = true;
/* find next word */
- while (offset < length) {
+ while (offset < span.end) {
String t = doc.getText(offset, 1);
char c = t.charAt(0);
@@ -130,10 +138,12 @@ private boolean nextWordImpl() {
}
}
+ @Override
public void addChangeListener(ChangeListener l) {
//ignored...
}
+ @Override
public void removeChangeListener(ChangeListener l) {
//ignored...
}
diff --git a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlTokenList.java b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlTokenList.java
index d3176c176dcc..2e918c6975d8 100644
--- a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlTokenList.java
+++ b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlTokenList.java
@@ -36,9 +36,9 @@
*
* @author Tor Norbye, Marek Fukala
*/
-public class HtmlTokenList extends AbstractTokenList {
+public final class HtmlTokenList extends AbstractTokenList {
- private String fileType;
+ private final String fileType;
private boolean hidden = false;
private Iterator> tss;
private TokenSequence> ts;
@@ -84,16 +84,16 @@ public void setStartOffset(int offset) {
} else {
//no html code in the file
}
-
+
}
//fast hack for making the spellchecking embedding aware, should be fixed properly
//performance: the current approach is wrong since a new token sequence is obtained
//and positioned for each search offset!
@Override
- protected int[] findNextSpellSpan() throws BadLocationException {
+ protected SpellSpan findNextSpellSpan() throws BadLocationException {
if (ts == null || !ts.isValid() || hidden) {
- return new int[]{-1, -1};
+ return SpellSpan.NONE;
}
ts.move(nextSearchOffset);
@@ -102,7 +102,7 @@ protected int[] findNextSpellSpan() throws BadLocationException {
TokenId id = ts.token().id();
if (id == HTMLTokenId.SGML_COMMENT || id == HTMLTokenId.BLOCK_COMMENT || id == HTMLTokenId.TEXT) {
- return new int[]{ts.offset(), ts.offset() + ts.token().length()};
+ return new SpellSpan(ts.offset(), ts.offset() + ts.token().length());
}
}
@@ -112,7 +112,7 @@ protected int[] findNextSpellSpan() throws BadLocationException {
return findNextSpellSpan();
}
- return new int[]{-1, -1};
+ return SpellSpan.NONE;
}
diff --git a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlXmlTokenListProvider.java b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlXmlTokenListProvider.java
index 69b80365c729..7ec3884c0066 100644
--- a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlXmlTokenListProvider.java
+++ b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/HtmlXmlTokenListProvider.java
@@ -18,7 +18,6 @@
*/
package org.netbeans.modules.spellchecker.bindings.htmlxml;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
@@ -37,36 +36,29 @@
*
* @author Poppenreiter, Riha
*/
-public class HtmlXmlTokenListProvider implements TokenListProvider {
+public final class HtmlXmlTokenListProvider implements TokenListProvider {
- private static final Map MIME_TO_SETTING_NAME = new HashMap();
- static {
- MIME_TO_SETTING_NAME.put("text/html", "HTML"); //NOI18N
- MIME_TO_SETTING_NAME.put("text/xhtml", "XHTML"); //NOI18N
- MIME_TO_SETTING_NAME.put("text/x-jsp", "JSP"); //NOI18N
- MIME_TO_SETTING_NAME.put("text/x-tag", "JSP"); //NOI18N
- MIME_TO_SETTING_NAME.put("text/x-gsp", "GSP"); //NOI18N
- MIME_TO_SETTING_NAME.put("text/x-php5", "PHP"); //NOI18N
- }
+ private static final Map MIME_TO_SETTING_NAME = Map.ofEntries(
+ Map.entry("text/html", "HTML"), //NOI18N
+ Map.entry("text/xhtml", "XHTML"), //NOI18N
+ Map.entry("text/x-jsp", "JSP"), //NOI18N
+ Map.entry("text/x-tag", "JSP"), //NOI18N
+ Map.entry("text/x-gsp", "GSP"), //NOI18N
+ Map.entry("text/x-php5", "PHP") //NOI18N
+ );
/** Creates a new instance of RubyTokenListProvider */
public HtmlXmlTokenListProvider() {
}
+ @Override
public TokenList findTokenList(Document doc) {
- if (!(doc instanceof BaseDocument)) {
- Logger.getLogger(HtmlXmlTokenListProvider.class.getName()).log(Level.INFO, null,
- new IllegalStateException("The given document is not an instance of the BaseDocument, is just " + //NOI18N
- doc.getClass().getName()));
- return null;
- }
+ if (doc instanceof BaseDocument bdoc) {
+ //html
+ String docMimetype = NbEditorUtilities.getMimeType(doc);
- //html
- final BaseDocument bdoc = (BaseDocument) doc;
- final String docMimetype = NbEditorUtilities.getMimeType(doc);
- final AtomicReference ret = new AtomicReference();
- doc.render(new Runnable() {
- public void run() {
+ AtomicReference ret = new AtomicReference<>();
+ bdoc.render(() -> {
TokenHierarchy> th = TokenHierarchy.get(bdoc);
Set paths = th.languagePaths();
for(LanguagePath path : paths) {
@@ -76,17 +68,22 @@ public void run() {
break;
}
}
+ });
+
+ if(ret.get() != null) {
+ return ret.get();
}
- });
- if(ret.get() != null) {
- return ret.get();
- }
- //xml
- if ((docMimetype != null) && (docMimetype.contains("xml"))) { //NOI18N
- return new XmlTokenList(bdoc);
- }
+ //xml
+ if ((docMimetype != null) && (docMimetype.contains("xml"))) { //NOI18N
+ return new XmlTokenList(bdoc);
+ }
+ } else {
+ Logger.getLogger(HtmlXmlTokenListProvider.class.getName()).log(Level.INFO, null,
+ new IllegalStateException("The given document is not an instance of the BaseDocument, is just " + //NOI18N
+ (doc != null ? doc.getClass().getName() : "")));
+ }
return null;
}
}
diff --git a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/XmlTokenList.java b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/XmlTokenList.java
index 8f73460c0f74..394a3ea01f7b 100644
--- a/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/XmlTokenList.java
+++ b/ide/spellchecker.bindings.htmlxml/src/org/netbeans/modules/spellchecker/bindings/htmlxml/XmlTokenList.java
@@ -34,7 +34,7 @@
*
* @author Tor Norbye
*/
-public class XmlTokenList extends AbstractTokenList {
+public final class XmlTokenList extends AbstractTokenList {
private boolean hidden = false;
@@ -51,11 +51,12 @@ public void setStartOffset(int offset) {
hidden = Boolean.TRUE.equals (b);
}
- protected int[] findNextSpellSpan() throws BadLocationException {
+ @Override
+ protected SpellSpan findNextSpellSpan() throws BadLocationException {
TokenHierarchy h = TokenHierarchy.get((Document) doc);
TokenSequence> ts = h.tokenSequence();
if (ts == null || hidden) {
- return new int[]{-1, -1};
+ return SpellSpan.NONE;
}
ts.move(nextSearchOffset);
@@ -64,9 +65,9 @@ protected int[] findNextSpellSpan() throws BadLocationException {
TokenId id = ts.token().id();
if (id == XMLTokenId.BLOCK_COMMENT || id == XMLTokenId.TEXT) {
- return new int[]{ts.offset(), ts.offset() + ts.token().length()};
+ return new SpellSpan(ts.offset(), ts.offset() + ts.token().length());
}
}
- return new int[]{-1, -1};
+ return SpellSpan.NONE;
}
}