diff --git a/enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigUtilities.java b/enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigUtilities.java index 029b05829c83..8414ea7fa23b 100644 --- a/enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigUtilities.java +++ b/enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigUtilities.java @@ -126,7 +126,7 @@ public static ConfigurationMetadataProperty resolveProperty(Document doc, int of } } } else { - int lineEnd = LineDocumentUtils.getLineEnd(lineDocument, offset); + int lineEnd = LineDocumentUtils.getLineEndOffset(lineDocument, offset); String text = lineDocument.getText(lineStart, lineEnd - lineStart); if (!text.startsWith("#") && !text.startsWith("!")) { int colIdx = text.indexOf(':'); diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/navigation/actions/CdiGlyphAction.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/navigation/actions/CdiGlyphAction.java index be5722f1da69..4111d76f729b 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/navigation/actions/CdiGlyphAction.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/navigation/actions/CdiGlyphAction.java @@ -25,6 +25,7 @@ import javax.swing.Action; import javax.swing.text.Document; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.AnnotationDesc; import org.netbeans.editor.Annotations; @@ -270,7 +271,7 @@ private static class AnnotationPositionStrategy implements @Override public void run() { Line line = myPart.getLine(); - int startOffset = Utilities.getRowStartFromLineOffset(myDocument, + int startOffset = LineDocumentUtils.getLineStartFromIndex(myDocument, line.getLineNumber()); myOffset = startOffset+myPart.getColumn(); } diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/EmbeddedSectionsHighlighting.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/EmbeddedSectionsHighlighting.java index 8d35ad04ba9b..790472ad572c 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/EmbeddedSectionsHighlighting.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/EmbeddedSectionsHighlighting.java @@ -27,6 +27,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.StyleConstants; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.settings.AttributesUtilities; import org.netbeans.api.editor.settings.FontColorSettings; @@ -36,7 +37,6 @@ import org.netbeans.api.lexer.TokenHierarchyListener; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.netbeans.lib.editor.util.swing.DocumentUtilities; import org.netbeans.spi.editor.highlighting.HighlightsLayer; import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory; @@ -185,13 +185,13 @@ public boolean moveNext() { try { int docLen = document.getLength(); - int startLine = Utilities.getLineOffset((BaseDocument) document, Math.min(sectionStart, docLen)); - int endLine = Utilities.getLineOffset((BaseDocument) document, Math.min(sectionEnd, docLen)); + int startLine = LineDocumentUtils.getLineIndex((BaseDocument) document, Math.min(sectionStart, docLen)); + int endLine = LineDocumentUtils.getLineIndex((BaseDocument) document, Math.min(sectionEnd, docLen)); if (startLine != endLine) { // multiline scriplet section // adjust the sections start to the beginning of the firts line - int firstLineStartOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, startLine); + int firstLineStartOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, startLine); if (firstLineStartOffset < sectionStart - 2 && isWhitespace(document, firstLineStartOffset, sectionStart - 2)) // always preceeded by '<%' hence -2 { @@ -199,10 +199,10 @@ public boolean moveNext() { } // adjust the sections end to the end of the last line - int lines = Utilities.getRowCount((BaseDocument) document); + int lines = LineDocumentUtils.getLineCount((BaseDocument) document); int lastLineEndOffset; if (endLine + 1 < lines) { - lastLineEndOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, endLine + 1); + lastLineEndOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, endLine + 1); } else { lastLineEndOffset = document.getLength(); } diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/ErrorAnnotationImpl.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/ErrorAnnotationImpl.java index f11c5bfa2e10..f823cf4844fa 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/ErrorAnnotationImpl.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/ErrorAnnotationImpl.java @@ -34,6 +34,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import javax.swing.text.StyledDocument; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.editor.NbEditorDocument; @@ -159,8 +160,8 @@ private Collection getAnnotations(ErrorInfo[] errors, StyledD if (line<0){ // place error annotation on the 1st non-empty line try { - int firstNonWS = Utilities.getFirstNonWhiteFwd(doc, 0); - line = Utilities.getLineOffset(doc, firstNonWS) + 1; + int firstNonWS = LineDocumentUtils.getNextNonWhitespace(doc, 0); + line = LineDocumentUtils.getLineIndex(doc, firstNonWS) + 1; } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspKit.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspKit.java index 03a8cf36a7a4..6ea4c0d0a806 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspKit.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspKit.java @@ -22,7 +22,6 @@ import java.util.Map; import org.netbeans.editor.ext.ExtKit; -import org.netbeans.modules.csl.api.KeystrokeHandler; import org.netbeans.modules.editor.NbEditorDocument; import org.netbeans.modules.editor.NbEditorKit; import org.netbeans.modules.web.core.syntax.deprecated.Jsp11Syntax; @@ -33,6 +32,7 @@ import javax.swing.SwingUtilities; import javax.swing.text.*; import org.netbeans.api.editor.completion.Completion; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; @@ -48,9 +48,7 @@ import org.netbeans.modules.web.core.api.JspColoringData; import org.netbeans.api.jsp.lexer.JspTokenId; import org.netbeans.api.lexer.InputAttributes; -import org.netbeans.editor.BaseKit.InsertBreakAction; import org.netbeans.editor.ext.ExtKit.ExtDefaultKeyTypedAction; -import org.netbeans.editor.ext.ExtKit.ExtDeleteCharAction; import org.netbeans.modules.csl.api.*; import org.netbeans.spi.lexer.MutableTextInput; @@ -232,7 +230,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) { BaseDocument doc = (BaseDocument) target.getDocument(); // inside scriptlet - int startPos = org.netbeans.editor.Utilities.getRowStart(doc, target.getSelectionStart()); + int startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart()); TokenHierarchy th = TokenHierarchy.create(target.getText(), JspTokenId.language()); List ets = th.embeddedTokenSequences(startPos, false); if (!ets.isEmpty() diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspTypedTextInterceptor.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspTypedTextInterceptor.java index ae955255c921..b7b54625f204 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspTypedTextInterceptor.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/JspTypedTextInterceptor.java @@ -25,6 +25,7 @@ import javax.swing.text.Document; import javax.swing.text.Position; import org.netbeans.api.editor.completion.Completion; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.mimelookup.MimeRegistration; import org.netbeans.api.editor.mimelookup.MimeRegistrations; @@ -147,8 +148,8 @@ public void run() { //since the code runs under document read lock, we cannot lock the //indentation infrastructure directly. Instead of that create a new //AWT task and post it for later execution. - final Position from = doc.createPosition(Utilities.getRowStart(doc, ts.offset())); - final Position to = doc.createPosition(Utilities.getRowEnd(doc, ts.offset())); + final Position from = doc.createPosition(LineDocumentUtils.getLineStartOffset(doc, ts.offset())); + final Position to = doc.createPosition(LineDocumentUtils.getLineEndOffset(doc, ts.offset())); SwingUtilities.invokeLater(new Runnable() { diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/completion/api/JspCompletionItem.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/completion/api/JspCompletionItem.java index 395afb4f317e..30521d094977 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/completion/api/JspCompletionItem.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/completion/api/JspCompletionItem.java @@ -52,6 +52,7 @@ import org.netbeans.modules.web.jsps.parserapi.TagAttributeInfo; import org.netbeans.modules.web.jsps.parserapi.TagInfo; import org.netbeans.modules.web.jsps.parserapi.TagVariableInfo; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.spi.editor.completion.support.AsyncCompletionTask; import org.netbeans.spi.editor.completion.support.CompletionUtilities; import org.netbeans.swing.plaf.LFCustoms; @@ -249,8 +250,8 @@ private void reindent(JTextComponent component) { public void run() { try { - int startOffset = Utilities.getRowStart(doc, dotPos); - int endOffset = Utilities.getRowEnd(doc, dotPos); + int startOffset = LineDocumentUtils.getLineStartOffset(doc, dotPos); + int endOffset = LineDocumentUtils.getLineEndOffset(doc, dotPos); indent.reindent(startOffset, endOffset); } catch (BadLocationException ex) { //ignore diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/ExpressionLanguageIndenter.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/ExpressionLanguageIndenter.java index 19cc6d2743e7..a5dfc3335c5f 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/ExpressionLanguageIndenter.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/ExpressionLanguageIndenter.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import javax.swing.text.BadLocationException; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.editor.Utilities; import org.netbeans.modules.editor.indent.spi.Context; @@ -67,7 +68,7 @@ protected List getLineIndent(IndenterContextData conte inExression = true; context.getJoinedTokenSequences().move(context.getLineStartOffset()); // try to find fixed indent: - int lineRealFirstNonWhite = Utilities.getRowFirstNonWhite(getDocument(), context.getLineStartOffset()); + int lineRealFirstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(getDocument(), context.getLineStartOffset()); if (lineRealFirstNonWhite != -1 && context.getLineStartOffset() > lineRealFirstNonWhite) { int start = context.getLineStartOffset(); context.getJoinedTokenSequences().move(context.getLineStartOffset()); diff --git a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/JspIndenter.java b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/JspIndenter.java index 2fe360375f82..12d55d404ca7 100644 --- a/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/JspIndenter.java +++ b/enterprise/web.core.syntax/src/org/netbeans/modules/web/core/syntax/formatting/JspIndenter.java @@ -21,9 +21,9 @@ import java.util.Set; import javax.swing.text.BadLocationException; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.jsp.lexer.JspTokenId; import org.netbeans.api.lexer.Token; -import org.netbeans.editor.Utilities; import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.web.indent.api.embedding.JoinedTokenSequence; import org.netbeans.modules.web.indent.api.support.IndenterContextData; @@ -152,7 +152,7 @@ protected int getPreservedLineInitialIndentation(JoinedTokenSequence } while (ts.movePrevious()); int indent = 0; if (found) { - int lineStart = Utilities.getRowStart(getDocument(), ts.offset()); + int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), ts.offset()); // TODO: can comment token start with spaces?? if yes then adjust // column to point to first non-whitespace int column = ts.offset(); diff --git a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/AutoCompletionTest.java b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/AutoCompletionTest.java index 57b5998b8e36..3d7d3d1f05b9 100644 --- a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/AutoCompletionTest.java +++ b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/AutoCompletionTest.java @@ -25,6 +25,7 @@ import javax.swing.event.DocumentListener; import javax.swing.text.Caret; import junit.framework.Test; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.Utilities; import org.netbeans.jellytools.EditorOperator; import org.netbeans.editor.BaseDocument; @@ -114,8 +115,8 @@ public void changedUpdate(DocumentEvent e) { } waitTypingFinished(doc); waitTypingFinished(doc); - int rowStart = Utilities.getRowStart(doc, step.getOffset() + 1); - int rowEnd = Utilities.getRowEnd(doc, step.getOffset() + 1); + int rowStart = LineDocumentUtils.getLineStartOffset(doc, step.getOffset() + 1); + int rowEnd = LineDocumentUtils.getLineEndOffset(doc, step.getOffset() + 1); String result = doc.getText(new int[]{rowStart, rowEnd}).trim(); if (!result.equals(step.getResult())) { ref("EE: unexpected CC result:\n< " + result + "\n> " + step.getResult()); diff --git a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/CompletionTest.java b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/CompletionTest.java index 60af2347a2f4..855f49114dc1 100644 --- a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/CompletionTest.java +++ b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/CompletionTest.java @@ -39,6 +39,7 @@ import javax.swing.event.DocumentListener; import javax.swing.text.Caret; import junit.framework.Test; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.Utilities; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.modules.j2ee.J2eeTestCase; @@ -404,8 +405,8 @@ protected void exec(JEditorPane editor, TestStep step) throws Exception { } } waitTypingFinished(doc); - int rowStart = Utilities.getRowStart(doc, step.getOffset() + 1); - int rowEnd = Utilities.getRowEnd(doc, step.getOffset() + 1); + int rowStart = LineDocumentUtils.getLineStartOffset(doc, step.getOffset() + 1); + int rowEnd = LineDocumentUtils.getLineEndOffset(doc, step.getOffset() + 1); String fullResult = doc.getText(new int[]{rowStart, rowEnd}); String result = fullResult.trim(); int removed_whitespaces = fullResult.length() - result.length(); diff --git a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/IndentCasesTest.java b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/IndentCasesTest.java index c21fece03a42..f8da7b0e0fc9 100644 --- a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/IndentCasesTest.java +++ b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/IndentCasesTest.java @@ -23,8 +23,8 @@ import java.io.IOException; import javax.swing.JSpinner; import junit.framework.Test; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.OptionsOperator; import org.netbeans.jellytools.modules.j2ee.J2eeTestCase; @@ -198,8 +198,8 @@ private void test(String fileName, int lineNum, int offset, int endLineNum, int op.pressKey(KeyEvent.VK_ENTER); op.waitModified(true); int newPossition = op.txtEditorPane().getCaretPosition(); - int newLine = Utilities.getLineOffset(doc, newPossition) + 1; - int newOffset = newPossition - Utilities.getRowStart(doc, newPossition); + int newLine = LineDocumentUtils.getLineIndex(doc, newPossition) + 1; + int newOffset = newPossition - LineDocumentUtils.getLineStartOffset(doc, newPossition); if (debug) { Thread.sleep(3000); // to be visible ;-) } diff --git a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/TagAlignmentTest.java b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/TagAlignmentTest.java index c6733e77605d..8a36a0173b72 100644 --- a/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/TagAlignmentTest.java +++ b/enterprise/web.core.syntax/test/qa-functional/src/org/netbeans/test/syntax/TagAlignmentTest.java @@ -21,8 +21,8 @@ import java.io.File; import java.io.IOException; import junit.framework.Test; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.modules.j2ee.J2eeTestCase; import org.netbeans.jemmy.JemmyProperties; @@ -118,8 +118,8 @@ private void test(String fileName, int lineNum, int offset, String text, int end } CompletionTest.waitTypingFinished(doc); int newPossition = op.txtEditorPane().getCaretPosition(); - int newLine = Utilities.getLineOffset(doc, newPossition) + 1; - int newOffset = newPossition - Utilities.getRowStart(doc, newPossition); + int newLine = LineDocumentUtils.getLineIndex(doc, newPossition) + 1; + int newOffset = newPossition - LineDocumentUtils.getLineStartOffset(doc, newPossition); if (debug) { Thread.sleep(3000); // to be visible ;-) } diff --git a/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/actions/FixNamespacesPerformer.java b/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/actions/FixNamespacesPerformer.java index 690e3a87bd23..92668b737a2b 100644 --- a/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/actions/FixNamespacesPerformer.java +++ b/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/actions/FixNamespacesPerformer.java @@ -22,6 +22,7 @@ import java.util.List; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.html.editor.api.gsf.HtmlParserResult; @@ -78,8 +79,8 @@ private void removeUnusedNamespaces() { int from = attribute.from(); int to = attribute.to(); //check if the line before the area is white - int lineBeginning = Utilities.getRowStart(baseDocument, attribute.from()); - int firstNonWhite = Utilities.getFirstNonWhiteBwd(baseDocument, attribute.from()); + int lineBeginning = LineDocumentUtils.getLineStartOffset(baseDocument, attribute.from()); + int firstNonWhite = LineDocumentUtils.getPreviousNonWhitespace(baseDocument, attribute.from()); if (lineBeginning > firstNonWhite) { //delete the white content before the area inclusing the newline from = lineBeginning - 1; // (-1 => includes the line end) diff --git a/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/hints/LibraryDeclarationChecker.java b/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/hints/LibraryDeclarationChecker.java index 011d7ac5cc3e..ae7042066188 100644 --- a/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/hints/LibraryDeclarationChecker.java +++ b/enterprise/web.jsf.editor/src/org/netbeans/modules/web/jsf/editor/hints/LibraryDeclarationChecker.java @@ -28,11 +28,14 @@ import java.util.Map; import java.util.Objects; import java.util.Set; + import static java.util.function.Predicate.not; + import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; import javax.swing.text.BadLocationException; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Language; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; @@ -483,8 +486,8 @@ public void run() { int from = range.getFrom(); int to = range.getTo(); //check if the line before the area is white - int lineBeginning = Utilities.getRowStart(document, from); - int firstNonWhite = Utilities.getFirstNonWhiteBwd(document, from); + int lineBeginning = LineDocumentUtils.getLineStartOffset(document, from); + int firstNonWhite = LineDocumentUtils.getPreviousNonWhitespace(document, from); if (lineBeginning > firstNonWhite) { //delete the white content before the area inclusing the newline from = lineBeginning - 1; // (-1 => includes the line end) diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/ASTUtils.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/ASTUtils.java index e34c353d0b16..2ce197f005f5 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/ASTUtils.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/ASTUtils.java @@ -31,6 +31,7 @@ import org.codehaus.groovy.ast.stmt.ForStatement; import org.codehaus.groovy.ast.stmt.Statement; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.api.lexer.TokenUtilities; @@ -162,7 +163,7 @@ public static OffsetRange getRange(ASTNode node, BaseDocument doc) { } try { - start = Utilities.getFirstNonWhiteFwd(doc, start); + start = LineDocumentUtils.getNextNonWhitespace(doc, start); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } @@ -343,7 +344,7 @@ public static int getOffset(BaseDocument doc, int lineNumber, int columnNumber) assert lineNumber > 0 : "Line number must be at least 1 and was: " + lineNumber; assert columnNumber > 0 : "Column number must be at least 1 ans was: " + columnNumber; - int offset = Utilities.getRowStartFromLineOffset(doc, lineNumber - 1); + int offset = LineDocumentUtils.getLineStartFromIndex(doc, lineNumber - 1); offset += (columnNumber - 1); // some sanity checks diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/StructureAnalyzer.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/StructureAnalyzer.java index 99dff500bd6d..1cd279f6ca41 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/StructureAnalyzer.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/StructureAnalyzer.java @@ -52,6 +52,7 @@ import org.codehaus.groovy.ast.ConstructorNode; import org.codehaus.groovy.ast.PropertyNode; import org.netbeans.api.annotations.common.NullAllowed; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.modules.csl.api.ElementHandle; import org.netbeans.modules.csl.api.ElementKind; import org.netbeans.modules.csl.api.HtmlFormatter; @@ -284,7 +285,7 @@ public void run() { } } try { - importEnd = Utilities.getRowEnd(doc, importEnd); + importEnd = LineDocumentUtils.getLineEndOffset(doc, importEnd); importsRange[0] = new OffsetRange(importStart, importEnd); } catch (BadLocationException ble) { Exceptions.printStackTrace(ble); @@ -327,11 +328,11 @@ private void addFolds(BaseDocument doc, List elements, || (kind == ElementKind.FIELD && ((FieldNode) node).getInitialExpression() instanceof ClosureExpression) // Only make nested classes/modules foldable, similar to what the java editor is doing - || (range.getStart() > Utilities.getRowStart(doc, range.getStart())) && kind != ElementKind.FIELD) { + || (range.getStart() > LineDocumentUtils.getLineStartOffset(doc, range.getStart())) && kind != ElementKind.FIELD) { int start = range.getStart(); // Start the fold at the END of the line behind last non-whitespace, remove curly brace, if any - start = Utilities.getRowLastNonWhite(doc, start); + start = LineDocumentUtils.getLineLastNonWhitespace(doc, start); if (start >= 0 && doc.getChars(start, 1)[0] != '{') { start++; } diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java index 751bbae87194..fa5883a7b7c5 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java @@ -37,6 +37,7 @@ import org.codehaus.groovy.ast.expr.RangeExpression; import org.codehaus.groovy.ast.expr.VariableExpression; import org.codehaus.groovy.ast.stmt.BlockStatement; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; @@ -47,8 +48,10 @@ import org.netbeans.modules.groovy.editor.api.completion.CaretLocation; import org.netbeans.modules.groovy.editor.completion.inference.GroovyTypeAnalyzer; import org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId; + import static org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId.LITERAL_new; import static org.netbeans.modules.groovy.editor.api.lexer.GroovyTokenId.LPAREN; + import org.netbeans.modules.groovy.editor.api.lexer.LexUtilities; import org.netbeans.modules.groovy.editor.completion.AccessLevel; import org.openide.filesystems.FileObject; @@ -905,8 +908,8 @@ public boolean isBehindImportStatement() { int nonWhite = 0; try { - rowStart = Utilities.getRowStart(doc, lexOffset); - nonWhite = Utilities.getFirstNonWhiteFwd(doc, rowStart); + rowStart = LineDocumentUtils.getLineStartOffset(doc, lexOffset); + nonWhite = LineDocumentUtils.getNextNonWhitespace(doc, rowStart); } catch (BadLocationException ex) { } diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/Call.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/Call.java index 79a1abe0a2f6..0d4230262baa 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/Call.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/Call.java @@ -22,12 +22,12 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.openide.util.Exceptions; /** @@ -203,7 +203,7 @@ public static Call getCallType(BaseDocument doc, TokenHierarchy th, in offset = doc.getLength(); } - lineStart = Utilities.getRowStart(doc, offset); + lineStart = LineDocumentUtils.getLineStartOffset(doc, offset); } catch (BadLocationException ble) { Exceptions.printStackTrace(ble); } diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/LexUtilities.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/LexUtilities.java index dc7aa9586216..ba3233b88cec 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/LexUtilities.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/LexUtilities.java @@ -27,6 +27,7 @@ import javax.swing.text.Document; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.editor.document.LineDocument; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; @@ -485,7 +486,7 @@ public static boolean isEndmatchingDo(BaseDocument doc, int offset) { // Look at the first token of the current line try { - int first = Utilities.getRowFirstNonWhite(doc, offset); + int first = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset); if (first != -1) { Token token = getToken(doc, first); if (token != null) { @@ -554,8 +555,8 @@ public static boolean isIndentToken(TokenId id) { */ public static int getBeginEndLineBalance(BaseDocument doc, int offset, boolean upToOffset) { try { - int begin = Utilities.getRowStart(doc, offset); - int end = upToOffset ? offset : Utilities.getRowEnd(doc, offset); + int begin = LineDocumentUtils.getLineStartOffset(doc, offset); + int end = upToOffset ? offset : LineDocumentUtils.getLineEndOffset(doc, offset); TokenSequence ts = LexUtilities.getGroovyTokenSequence(doc, begin); if (ts == null) { @@ -592,8 +593,8 @@ public static int getBeginEndLineBalance(BaseDocument doc, int offset, boolean u /** Compute the balance of begin/end tokens on the line. */ public static int getLineBalance(BaseDocument doc, int offset, TokenId up, TokenId down) { try { - int begin = Utilities.getRowStart(doc, offset); - int end = Utilities.getRowEnd(doc, offset); + int begin = LineDocumentUtils.getLineStartOffset(doc, offset); + int end = LineDocumentUtils.getLineEndOffset(doc, offset); TokenSequence ts = LexUtilities.getGroovyTokenSequence(doc, begin); if (ts == null) { @@ -669,7 +670,7 @@ public static int getTokenBalance(BaseDocument doc, TokenId open, TokenId close, */ public static boolean isCommentOnlyLine(BaseDocument doc, int offset) throws BadLocationException { - int begin = Utilities.getRowFirstNonWhite(doc, offset); + int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset); if (begin == -1) { return false; // whitespace only @@ -742,16 +743,16 @@ public static OffsetRange getCommentBlock(BaseDocument doc, int caretOffset) { if ((token != null) && (token.id() == GroovyTokenId.LINE_COMMENT)) { // First add a range for the current line - int begin = Utilities.getRowStart(doc, caretOffset); - int end = Utilities.getRowEnd(doc, caretOffset); + int begin = LineDocumentUtils.getLineStartOffset(doc, caretOffset); + int end = LineDocumentUtils.getLineEndOffset(doc, caretOffset); if (LexUtilities.isCommentOnlyLine(doc, caretOffset)) { while (begin > 0) { - int newBegin = Utilities.getRowStart(doc, begin - 1); + int newBegin = LineDocumentUtils.getLineStartOffset(doc, begin - 1); if ((newBegin < 0) || !LexUtilities.isCommentOnlyLine(doc, newBegin)) { - begin = Utilities.getRowFirstNonWhite(doc, begin); + begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, begin); break; } @@ -761,10 +762,10 @@ public static OffsetRange getCommentBlock(BaseDocument doc, int caretOffset) { int length = doc.getLength(); while (true) { - int newEnd = Utilities.getRowEnd(doc, end + 1); + int newEnd = LineDocumentUtils.getLineEndOffset(doc, end + 1); if ((newEnd >= length) || !LexUtilities.isCommentOnlyLine(doc, newEnd)) { - end = Utilities.getRowLastNonWhite(doc, end) + 1; + end = LineDocumentUtils.getLineLastNonWhitespace(doc, end) + 1; break; } @@ -801,10 +802,10 @@ public static int findSpaceBegin(BaseDocument doc, int lexOffset) { boolean allowPrevLine = false; int lineStart; try { - lineStart = Utilities.getRowStart(doc, Math.min(lexOffset, doc.getLength())); + lineStart = LineDocumentUtils.getLineStartOffset(doc, Math.min(lexOffset, doc.getLength())); int prevLast = lineStart - 1; if (lineStart > 0) { - prevLast = Utilities.getRowLastNonWhite(doc, lineStart - 1); + prevLast = LineDocumentUtils.getLineLastNonWhitespace(doc, lineStart - 1); if (prevLast != -1) { char c = doc.getText(prevLast, 1).charAt(0); if (c == ',') { @@ -814,13 +815,13 @@ public static int findSpaceBegin(BaseDocument doc, int lexOffset) { } } if (!allowPrevLine) { - int firstNonWhite = Utilities.getRowFirstNonWhite(doc, lineStart); + int firstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, lineStart); if (lexOffset <= firstNonWhite || firstNonWhite == -1) { return lexOffset; } } else { // Make lineStart so small that Math.max won't cause any problems - int firstNonWhite = Utilities.getRowFirstNonWhite(doc, lineStart); + int firstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, lineStart); if (prevLast >= 0 && (lexOffset <= firstNonWhite || firstNonWhite == -1)) { return prevLast + 1; } diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/SurroundWithHint.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/SurroundWithHint.java index 850cfe94257a..198199ee3c2f 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/SurroundWithHint.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/SurroundWithHint.java @@ -23,6 +23,7 @@ import java.util.logging.Logger; import javax.swing.text.JTextComponent; import org.codehaus.groovy.ast.ASTNode; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.csl.api.EditList; @@ -161,7 +162,7 @@ public void implement() throws Exception { edits.replace(end, 0, END_INSERT, false, 0); - int startOfRow = Utilities.getRowStart(baseDoc, start); + int startOfRow = LineDocumentUtils.getLineStartOffset(baseDoc, start); edits.replace(startOfRow, 0, START_INSERT, false, 1); edits.setFormatAll(true); diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/utils/HintUtils.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/utils/HintUtils.java index bf40f6fd1e03..077722200633 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/utils/HintUtils.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/hints/utils/HintUtils.java @@ -22,6 +22,7 @@ import javax.swing.text.BadLocationException; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.Utilities; import org.netbeans.modules.csl.api.OffsetRange; import org.netbeans.modules.csl.api.RuleContext; @@ -56,8 +57,8 @@ public static OffsetRange getLineOffset( // This should be replaced with marking the indentifier only. try { - int lineStart = Utilities.getRowStart(context.doc, error.getStartPosition()); - int lineEnd = Utilities.getRowEnd(context.doc, error.getEndPosition()); + int lineStart = LineDocumentUtils.getLineStartOffset(context.doc, error.getStartPosition()); + int lineEnd = LineDocumentUtils.getLineEndOffset(context.doc, error.getEndPosition()); return new OffsetRange(lineStart, lineEnd); diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/imports/ImportHelper.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/imports/ImportHelper.java index a3bf7d81e064..a6a38abbe86b 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/imports/ImportHelper.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/imports/ImportHelper.java @@ -35,6 +35,7 @@ import javax.lang.model.element.TypeElement; import javax.swing.Icon; import javax.swing.text.BadLocationException; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.source.ClassIndex; import org.netbeans.api.java.source.ClassIndex.NameKind; @@ -44,7 +45,6 @@ import org.netbeans.api.lexer.TokenSequence; import org.netbeans.api.progress.BaseProgressUtils; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.netbeans.modules.csl.api.EditList; import org.netbeans.modules.groovy.editor.api.GroovyIndex; import org.netbeans.modules.groovy.editor.api.elements.index.IndexedClass; @@ -328,11 +328,11 @@ private static EditList addImportStatements(FileObject fo, List fqNames) try { int packageLine = getPackageLineIndex(doc); int afterPackageLine = packageLine + 1; - int afterPackageOffset = Utilities.getRowStartFromLineOffset(doc, afterPackageLine); + int afterPackageOffset = LineDocumentUtils.getLineStartFromIndex(doc, afterPackageLine); int importLine = getAppropriateLine(doc, fqName); if (importLine >= 0) { // If the line after the package statement isn't empty, put one empty line there - if (!Utilities.isRowWhite(doc, afterPackageOffset)) { + if (!LineDocumentUtils.isLineWhitespace(doc, afterPackageOffset)) { edits.replace(afterPackageOffset, 0, "\n", false, 0); } else { if (collectImports(doc).isEmpty()) { @@ -341,14 +341,14 @@ private static EditList addImportStatements(FileObject fo, List fqNames) } // Find appropriate place to import and put it there - int importOffset = Utilities.getRowStartFromLineOffset(doc, importLine); + int importOffset = LineDocumentUtils.getLineStartFromIndex(doc, importLine); edits.replace(importOffset, 0, "import " + fqName + "\n", false, 0); // If it's the last import and if the line after the last import // statement isn't empty, put one empty line there - int afterImportsOffset = Utilities.getRowStartFromLineOffset(doc, importLine); + int afterImportsOffset = LineDocumentUtils.getLineStartFromIndex(doc, importLine); - if (!Utilities.isRowWhite(doc, afterImportsOffset) && isLastImport(doc, fqName)) { + if (!LineDocumentUtils.isLineWhitespace(doc, afterImportsOffset) && isLastImport(doc, fqName)) { edits.replace(afterImportsOffset, 0, "\n", false, 0); } } @@ -440,7 +440,7 @@ private static Map collectImports(BaseDocument doc) throws BadL break IMPORT_COUNTER; } } - result.put(sb.toString(), Utilities.getLineOffset(doc, ts.offset())); + result.put(sb.toString(), LineDocumentUtils.getLineIndex(doc, ts.offset())); } } return result; @@ -458,7 +458,7 @@ private static int getPackageLineIndex(BaseDocument doc) { try { int lastPackageOffset = getLastPackageStatementOffset(doc); if (lastPackageOffset != -1) { - return Utilities.getLineOffset(doc, lastPackageOffset); + return LineDocumentUtils.getLineIndex(doc, lastPackageOffset); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); @@ -499,7 +499,7 @@ private static int getLastImportLineIndex(BaseDocument doc) { try { int lastImportOffset = getLastImportStatementOffset(doc); if (lastImportOffset != -1) { - return Utilities.getLineOffset(doc, lastImportOffset); + return LineDocumentUtils.getLineIndex(doc, lastImportOffset); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyBracketCompleter.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyBracketCompleter.java index 7c56b5f60663..4cc77fee1d50 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyBracketCompleter.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyBracketCompleter.java @@ -26,6 +26,7 @@ import javax.swing.text.Document; import javax.swing.text.JTextComponent; import org.codehaus.groovy.ast.ASTNode; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; @@ -119,21 +120,21 @@ public List findLogicalRanges(ParserResult info, int caretOffset) { ranges.add(new OffsetRange(begin, end)); } else if ((token != null) && (token.id() == GroovyTokenId.LINE_COMMENT)) { // First add a range for the current line - int begin = Utilities.getRowStart(doc, caretOffset); - int end = Utilities.getRowEnd(doc, caretOffset); + int begin = LineDocumentUtils.getLineStartOffset(doc, caretOffset); + int end = LineDocumentUtils.getLineEndOffset(doc, caretOffset); if (LexUtilities.isCommentOnlyLine(doc, caretOffset)) { - ranges.add(new OffsetRange(Utilities.getRowFirstNonWhite(doc, begin), - Utilities.getRowLastNonWhite(doc, end)+1)); + ranges.add(new OffsetRange(LineDocumentUtils.getLineFirstNonWhitespace(doc, begin), + LineDocumentUtils.getLineLastNonWhitespace(doc, end)+1)); int lineBegin = begin; int lineEnd = end; while (begin > 0) { - int newBegin = Utilities.getRowStart(doc, begin - 1); + int newBegin = LineDocumentUtils.getLineStartOffset(doc, begin - 1); if ((newBegin < 0) || !LexUtilities.isCommentOnlyLine(doc, newBegin)) { - begin = Utilities.getRowFirstNonWhite(doc, begin); + begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, begin); break; } @@ -141,10 +142,10 @@ public List findLogicalRanges(ParserResult info, int caretOffset) { } while (true) { - int newEnd = Utilities.getRowEnd(doc, end + 1); + int newEnd = LineDocumentUtils.getLineEndOffset(doc, end + 1); if ((newEnd >= length) || !LexUtilities.isCommentOnlyLine(doc, newEnd)) { - end = Utilities.getRowLastNonWhite(doc, end)+1; + end = LineDocumentUtils.getLineLastNonWhitespace(doc, end)+1; break; } diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyFormatter.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyFormatter.java index 95a66c220a11..baf897539817 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyFormatter.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyFormatter.java @@ -463,7 +463,7 @@ private void computeIndents(LineDocument doc, int initialIndent, int startOffset indent = balance * indentSize + hangingIndent + initialIndent; } - int endOfLine = LineDocumentUtils.getLineEnd(doc, offset) + 1; + int endOfLine = LineDocumentUtils.getLineEndOffset(doc, offset) + 1; if (isJavaDocComment(doc, offset, endOfLine)) { indent++; diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedBreakInterceptor.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedBreakInterceptor.java index 7d5dd6087216..efa96a2b7abc 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedBreakInterceptor.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedBreakInterceptor.java @@ -21,6 +21,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.mimelookup.MimeRegistration; import org.netbeans.api.lexer.Token; @@ -63,8 +64,8 @@ public void insert(MutableContext context) throws BadLocationException { int offset = context.getCaretOffset(); boolean insertMatching = TypingHooksUtil.isMatchingBracketsEnabled(doc); - int lineBegin = Utilities.getRowStart(doc, offset); - int lineEnd = Utilities.getRowEnd(doc, offset); + int lineBegin = LineDocumentUtils.getLineStartOffset(doc, offset); + int lineEnd = LineDocumentUtils.getLineEndOffset(doc, offset); if (lineBegin == offset && lineEnd == offset) { // Pressed return on a blank newline - do nothing @@ -92,7 +93,7 @@ public void insert(MutableContext context) throws BadLocationException { if (id != GroovyTokenId.ERROR && id != GroovyTokenId.BLOCK_COMMENT && insertMatching && insertRightBrace) { int indent = GsfUtilities.getLineIndent(doc, offset); - int afterLastNonWhite = Utilities.getRowLastNonWhite(doc, offset); + int afterLastNonWhite = LineDocumentUtils.getLineLastNonWhitespace(doc, offset); // We've either encountered a further indented line, or a line that doesn't // look like the end we're after, so insert a matching end. @@ -118,7 +119,7 @@ public void insert(MutableContext context) throws BadLocationException { // I'm inserting a newline in the middle of a sentence, such as the scenario in #118656 // I should insert the end AFTER the text on the line String restOfLine = doc.getText(offset, - Math.min(end, Utilities.getRowEnd(doc, afterLastNonWhite)) - offset); + Math.min(end, LineDocumentUtils.getLineEndOffset(doc, afterLastNonWhite)) - offset); sb.append("\n"); // XXX On Windows, do \r\n? sb.append(IndentUtils.createIndentString(doc, indent + IndentUtils.indentLevelSize(doc))); // right brace must be included into the correct context - issue #219683 @@ -146,7 +147,7 @@ public void insert(MutableContext context) throws BadLocationException { if (id == GroovyTokenId.ERROR) { // See if it's a block comment opener String text = token.text().toString(); - if (text.startsWith("/*") && ts.offset() == Utilities.getRowFirstNonWhite(doc, offset)) { + if (text.startsWith("/*") && ts.offset() == LineDocumentUtils.getLineFirstNonWhitespace(doc, offset)) { int indent = GsfUtilities.getLineIndent(doc, offset); StringBuilder sb = new StringBuilder(); sb.append("\n"); // NOI18N @@ -225,7 +226,7 @@ public void insert(MutableContext context) throws BadLocationException { // Pressing newline in the whitespace before a comment // should be identical to pressing newline with the caret // at the beginning of the comment - int begin = Utilities.getRowFirstNonWhite(doc, offset); + int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset); if (begin != -1 && offset < begin) { ts.move(begin); if (ts.moveNext()) { @@ -240,8 +241,8 @@ public void insert(MutableContext context) throws BadLocationException { if ((id == GroovyTokenId.BLOCK_COMMENT) && offset > ts.offset() && offset < ts.offset()+ts.token().length()) { // Continue *'s - int begin = Utilities.getRowFirstNonWhite(doc, offset); - int end = Utilities.getRowEnd(doc, offset)+1; + int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset); + int end = LineDocumentUtils.getLineEndOffset(doc, offset)+1; if (begin == -1) { begin = end; } @@ -263,7 +264,7 @@ public void insert(MutableContext context) throws BadLocationException { // Copy existing indentation inside the block sb.append("*"); //NOI18N int afterStar = isBlockStart ? begin+2 : begin+1; - line = doc.getText(afterStar, Utilities.getRowEnd(doc, afterStar)-afterStar); + line = doc.getText(afterStar, LineDocumentUtils.getLineEndOffset(doc, afterStar)-afterStar); for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (c == ' ' || c == '\t') { //NOI18N @@ -297,15 +298,15 @@ public void insert(MutableContext context) throws BadLocationException { // or if the next line is a comment! boolean continueComment = false; - int begin = Utilities.getRowFirstNonWhite(doc, offset); + int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset); // We should only continue comments if the previous line had a comment // (and a comment from the beginning, not a trailing comment) boolean previousLineWasComment = false; boolean nextLineIsComment = false; - int rowStart = Utilities.getRowStart(doc, offset); + int rowStart = LineDocumentUtils.getLineStartOffset(doc, offset); if (rowStart > 0) { - int prevBegin = Utilities.getRowFirstNonWhite(doc, rowStart - 1); + int prevBegin = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowStart - 1); if (prevBegin != -1) { Token firstToken = LexUtilities.getToken(doc, prevBegin); if (firstToken != null && firstToken.id() == GroovyTokenId.LINE_COMMENT) { @@ -313,9 +314,9 @@ public void insert(MutableContext context) throws BadLocationException { } } } - int rowEnd = Utilities.getRowEnd(doc, offset); + int rowEnd = LineDocumentUtils.getLineEndOffset(doc, offset); if (rowEnd < doc.getLength()) { - int nextBegin = Utilities.getRowFirstNonWhite(doc, rowEnd + 1); + int nextBegin = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowEnd + 1); if (nextBegin != -1) { Token firstToken = LexUtilities.getToken(doc, nextBegin); if (firstToken != null && firstToken.id() == GroovyTokenId.LINE_COMMENT) { @@ -331,7 +332,7 @@ public void insert(MutableContext context) throws BadLocationException { || (offset > ts.offset() && offset < ts.offset() + ts.token().length())) { if (ts.offset() + token.length() > offset + 1) { // See if the remaining text is just whitespace - String trailing = doc.getText(offset, Utilities.getRowEnd(doc, offset) - offset); + String trailing = doc.getText(offset, LineDocumentUtils.getLineEndOffset(doc, offset) - offset); if (trailing.trim().length() != 0) { continueComment = true; } @@ -346,9 +347,9 @@ public void insert(MutableContext context) throws BadLocationException { if (!continueComment) { // See if the next line is a comment; if so we want to continue // comments editing the middle of the comment - int nextLine = Utilities.getRowEnd(doc, offset) + 1; + int nextLine = LineDocumentUtils.getLineEndOffset(doc, offset) + 1; if (nextLine < doc.getLength()) { - int nextLineFirst = Utilities.getRowFirstNonWhite(doc, nextLine); + int nextLineFirst = LineDocumentUtils.getLineFirstNonWhitespace(doc, nextLine); if (nextLineFirst != -1) { Token firstToken = LexUtilities.getToken(doc, nextLineFirst); if (firstToken != null && firstToken.id() == GroovyTokenId.LINE_COMMENT) { @@ -370,7 +371,7 @@ public void insert(MutableContext context) throws BadLocationException { sb.append("//"); // NOI18N // Copy existing indentation int afterSlash = begin + 2; - String line = doc.getText(afterSlash, Utilities.getRowEnd(doc, afterSlash) - afterSlash); + String line = doc.getText(afterSlash, LineDocumentUtils.getLineEndOffset(doc, afterSlash) - afterSlash); for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (c == ' ' || c == '\t') { @@ -425,7 +426,7 @@ private int getNextLineIndentation(BaseDocument doc, int offset) throws BadLocat int indent = GsfUtilities.getLineIndent(doc, offset); int currentOffset = offset; while (currentOffset > 0) { - if (!Utilities.isRowEmpty(doc, currentOffset) && !Utilities.isRowWhite(doc, currentOffset) + if (!LineDocumentUtils.isLineEmpty(doc, currentOffset) && !LineDocumentUtils.isLineWhitespace(doc, currentOffset) && !LexUtilities.isCommentOnlyLine(doc, currentOffset)) { indent = GsfUtilities.getLineIndent(doc, currentOffset); int parenBalance = LexUtilities.getLineBalance(doc, currentOffset, @@ -440,7 +441,7 @@ private int getNextLineIndentation(BaseDocument doc, int offset) throws BadLocat } return indent; } - currentOffset = Utilities.getRowStart(doc, currentOffset) - 1; + currentOffset = LineDocumentUtils.getLineStartOffset(doc, currentOffset) - 1; } return indent; @@ -468,7 +469,7 @@ private boolean isAddRightBrace(BaseDocument doc, int caretOffset) throws BadLoc if (LexUtilities.getTokenBalance(doc, GroovyTokenId.LBRACE, GroovyTokenId.RBRACE, caretOffset) <= 0) { return false; } - int caretRowStartOffset = org.netbeans.editor.Utilities.getRowStart(doc, caretOffset); + int caretRowStartOffset = LineDocumentUtils.getLineStartOffset(doc, caretOffset); TokenSequence ts = LexUtilities.getPositionedSequence(doc, caretOffset); if (ts == null) { return false; @@ -505,7 +506,7 @@ private boolean isAddRightBrace(BaseDocument doc, int caretOffset) throws BadLoc * character on the caret row is returned. */ private int getRowOrBlockEnd(BaseDocument doc, int caretOffset, boolean[] insert) throws BadLocationException { - int rowEnd = org.netbeans.editor.Utilities.getRowLastNonWhite(doc, caretOffset); + int rowEnd = LineDocumentUtils.getLineLastNonWhitespace(doc, caretOffset); if (rowEnd == -1 || caretOffset >= rowEnd) { return caretOffset; } diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedTextInterceptor.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedTextInterceptor.java index ea5aba7b7a53..0041126776e5 100644 --- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedTextInterceptor.java +++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/typinghooks/GroovyTypedTextInterceptor.java @@ -24,6 +24,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Caret; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.mimelookup.MimeRegistration; import org.netbeans.api.lexer.Token; @@ -314,7 +315,7 @@ private void reindent(BaseDocument doc, int offset, TokenId id, Caret caret) Token token = ts.token(); if ((token.id() == id)) { - final int rowFirstNonWhite = Utilities.getRowFirstNonWhite(doc, offset); + final int rowFirstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset); // Ensure that this token is at the beginning of the line if (ts.offset() > rowFirstNonWhite) { return; @@ -395,7 +396,7 @@ private boolean completeQuote(BaseDocument doc, int dotPos, Caret caret, char br previousToken = ts.token(); } - int lastNonWhite = Utilities.getRowLastNonWhite(doc, dotPos); + int lastNonWhite = LineDocumentUtils.getLineLastNonWhitespace(doc, dotPos); // eol - true if the caret is at the end of line (ignoring whitespaces) boolean eol = lastNonWhite < dotPos; @@ -521,13 +522,13 @@ private boolean isQuoteCompletablePosition(BaseDocument doc, int dotPos) return true; } else { // test that we are in front of ) , " or ' ... etc. - int eol = Utilities.getRowEnd(doc, dotPos); + int eol = LineDocumentUtils.getLineEndOffset(doc, dotPos); if ((dotPos == eol) || (eol == -1)) { return false; } - int firstNonWhiteFwd = Utilities.getFirstNonWhiteFwd(doc, dotPos, eol); + int firstNonWhiteFwd = LineDocumentUtils.getNextNonWhitespace(doc, dotPos, eol); if (firstNonWhiteFwd == -1) { return false; diff --git a/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/embedding/EmbeddedSectionsHighlighting.java b/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/embedding/EmbeddedSectionsHighlighting.java index 9c227fd55186..a98bb1de7546 100644 --- a/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/embedding/EmbeddedSectionsHighlighting.java +++ b/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/embedding/EmbeddedSectionsHighlighting.java @@ -27,6 +27,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.StyleConstants; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.settings.AttributesUtilities; import org.netbeans.api.editor.settings.FontColorSettings; @@ -35,7 +36,6 @@ import org.netbeans.api.lexer.TokenHierarchyListener; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.netbeans.lib.editor.util.swing.DocumentUtilities; import org.netbeans.modules.groovy.gsp.lexer.GspLexerLanguage; import org.netbeans.modules.groovy.gsp.lexer.GspTokenId; @@ -173,13 +173,13 @@ public boolean moveNext() { try { int docLen = document.getLength(); - int startLine = Utilities.getLineOffset((BaseDocument) document, Math.min(sectionStart, docLen)); - int endLine = Utilities.getLineOffset((BaseDocument) document, Math.min(sectionEnd, docLen)); + int startLine = LineDocumentUtils.getLineIndex((BaseDocument) document, Math.min(sectionStart, docLen)); + int endLine = LineDocumentUtils.getLineIndex((BaseDocument) document, Math.min(sectionEnd, docLen)); if (startLine != endLine) { // multiline scriplet section // adjust the sections start to the beginning of the firts line - int firstLineStartOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, startLine); + int firstLineStartOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, startLine); if (firstLineStartOffset < sectionStart - delimiterSize && isWhitespace(document, firstLineStartOffset, sectionStart - delimiterSize)) // always preceeded by the delimiter { @@ -187,10 +187,10 @@ public boolean moveNext() { } // adjust the sections end to the end of the last line - int lines = Utilities.getRowCount((BaseDocument) document); + int lines = LineDocumentUtils.getLineCount((BaseDocument) document); int lastLineEndOffset; if (endLine + 1 < lines) { - lastLineEndOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, endLine + 1); + lastLineEndOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, endLine + 1); } else { lastLineEndOffset = document.getLength() + 1; } diff --git a/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/indent/GspIndenter.java b/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/indent/GspIndenter.java index d87044c6fe51..0438a39b8e9d 100644 --- a/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/indent/GspIndenter.java +++ b/groovy/groovy.gsp/src/org/netbeans/modules/groovy/gsp/editor/indent/GspIndenter.java @@ -21,8 +21,8 @@ import java.util.Set; import javax.swing.text.BadLocationException; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; -import org.netbeans.editor.Utilities; import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.groovy.gsp.lexer.GspLexerLanguage; import org.netbeans.modules.groovy.gsp.lexer.GspTokenId; @@ -134,7 +134,7 @@ protected int getPreservedLineInitialIndentation(JoinedTokenSequence } while (ts.movePrevious()); int indent = 0; if (found) { - int lineStart = Utilities.getRowStart(getDocument(), ts.offset()); + int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), ts.offset()); int column = ts.offset(); indent = column - lineStart; } diff --git a/ide/csl.api/src/org/netbeans/modules/csl/api/ToggleBlockCommentAction.java b/ide/csl.api/src/org/netbeans/modules/csl/api/ToggleBlockCommentAction.java index e9f854dd227e..782e963018a2 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/api/ToggleBlockCommentAction.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/api/ToggleBlockCommentAction.java @@ -202,10 +202,10 @@ private void commentUncommentBlock(LineDocument doc, JTextComponent target, Toke if (to > 0 && LineDocumentUtils.getLineStart(doc, to) == to) { to--; } - to = LineDocumentUtils.getLineEnd(doc, to); + to = LineDocumentUtils.getLineEndOffset(doc, to); } else { // selection not visible from = LineDocumentUtils.getLineStart(doc, caret.getDot()); - to = LineDocumentUtils.getLineEnd(doc, caret.getDot()); + to = LineDocumentUtils.getLineEndOffset(doc, caret.getDot()); } boolean lineSelection = false; @@ -219,7 +219,7 @@ private void commentUncommentBlock(LineDocument doc, JTextComponent target, Toke if (!inComment) { //extend the range to the whole line from = LineDocumentUtils.getNextNonWhitespace(doc, LineDocumentUtils.getLineStart(doc, from)); - to = LineDocumentUtils.getPreviousNonWhitespace(doc, LineDocumentUtils.getLineEnd(doc, to)) + 1; + to = LineDocumentUtils.getPreviousNonWhitespace(doc, LineDocumentUtils.getLineEndOffset(doc, to)) + 1; lineSelection = true; } else { // check if the line does not begin with WS+comment start or end with WS+comment end @@ -502,7 +502,7 @@ private void commentUncommentLines(JTextComponent target, int offset, LanguagePa to--; } } else { // selection not visible - to = LineDocumentUtils.getLineEnd(doc, target.getCaretPosition()); + to = LineDocumentUtils.getLineEndOffset(doc, target.getCaretPosition()); } int fromLineStartOffset = LineDocumentUtils.getLineStart(doc, from); @@ -572,7 +572,7 @@ private void commentUncommentLines(JTextComponent target, int offset, LanguagePa } lastLineOffset = Math.max(LineDocumentUtils.getLineStart(doc, block[1]), block[0]); - lastLineEndOffset = LineDocumentUtils.getLineEnd(doc, block[1]); + lastLineEndOffset = LineDocumentUtils.getLineEndOffset(doc, block[1]); } if (LOG.isLoggable(Level.FINE)) { @@ -615,7 +615,7 @@ private boolean allComments(LineDocument doc, int startOffset, int lineCount, St return false; } - if (LineDocumentUtils.getLineEnd(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) { + if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) { return false; } @@ -645,7 +645,7 @@ private void uncomment(LineDocument doc, int startOffset, int lineCount, String // If there is any, check wheter it's the line-comment-chars and remove them if (firstNonWhitePos != -1) { - if (LineDocumentUtils.getLineEnd(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) { + if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) { CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen); if (CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) { doc.remove(firstNonWhitePos, lineCommentStringLen); diff --git a/ide/csl.api/src/org/netbeans/modules/csl/editor/fold/GsfFoldManager.java b/ide/csl.api/src/org/netbeans/modules/csl/editor/fold/GsfFoldManager.java index d118baa5b546..a748bb01bf94 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/editor/fold/GsfFoldManager.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/editor/fold/GsfFoldManager.java @@ -37,6 +37,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.fold.Fold; import org.netbeans.spi.editor.fold.FoldInfo; import org.netbeans.api.editor.fold.FoldTemplate; @@ -469,7 +470,7 @@ public void run() { try { // Start the fold at the END of the line - startOffset = org.netbeans.editor.Utilities.getRowEnd((BaseDocument) doc, startOffset); + startOffset = LineDocumentUtils.getLineEndOffset((BaseDocument) doc, startOffset); if (startOffset >= endOffset) { return; } diff --git a/ide/csl.api/src/org/netbeans/modules/csl/editor/overridden/IsOverriddenAnnotationAction.java b/ide/csl.api/src/org/netbeans/modules/csl/editor/overridden/IsOverriddenAnnotationAction.java index 9a489dc807fc..24cb6b713e23 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/editor/overridden/IsOverriddenAnnotationAction.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/editor/overridden/IsOverriddenAnnotationAction.java @@ -41,6 +41,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.AnnotationDesc; import org.netbeans.editor.Annotations; import org.netbeans.editor.BaseDocument; @@ -176,8 +177,8 @@ boolean invokeDefaultAction(final JTextComponent comp) { doc.render(new Runnable() { public void run() { try { - int line = Utilities.getLineOffset((BaseDocument) doc, currentPosition); - int startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) doc, line); + int line = LineDocumentUtils.getLineIndex((BaseDocument) doc, currentPosition); + int startOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) doc, line); p[0] = comp.modelToView(startOffset).getLocation(); AnnotationDesc desc = annotations.getActiveAnnotation(line); diff --git a/ide/csl.api/src/org/netbeans/modules/csl/navigation/GsfStructureProvider.java b/ide/csl.api/src/org/netbeans/modules/csl/navigation/GsfStructureProvider.java index 8e5c1870c773..ae6e0ec76337 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/navigation/GsfStructureProvider.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/navigation/GsfStructureProvider.java @@ -217,7 +217,7 @@ private static void convertStructureItems(Document doc, List result, int caretOff int index = 0; int length = text.length(); while (index < length) { - int lineStart = Utilities.getRowStart(doc, index); - int lineEnd = Utilities.getRowEnd(doc, index); + int lineStart = LineDocumentUtils.getLineStartOffset(doc, index); + int lineEnd = LineDocumentUtils.getLineEndOffset(doc, index); OffsetRange lineRange = new OffsetRange(lineStart, lineEnd); boolean skipLine = true; for (OffsetRange range : ranges) { diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/CssExternalDropHandler.java b/ide/css.editor/src/org/netbeans/modules/css/editor/CssExternalDropHandler.java index eaa8a8bd5be9..9f71cb3c2656 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/CssExternalDropHandler.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/CssExternalDropHandler.java @@ -39,10 +39,10 @@ import javax.swing.JEditorPane; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; -import org.netbeans.editor.Utilities; import org.netbeans.modules.csl.api.DataLoadersBridge; import org.netbeans.modules.css.lib.api.CssTokenId; import org.netbeans.modules.editor.indent.api.Indent; @@ -99,7 +99,7 @@ public void run() { private int getLineEndOffset(JEditorPane pane, Point location) { int offset = pane.getUI().viewToModel(pane, location); try { - return Utilities.getRowEnd((BaseDocument) pane.getDocument(), offset); + return LineDocumentUtils.getLineEndOffset((BaseDocument) pane.getDocument(), offset); } catch (BadLocationException ex) { //highly unlikely to happen Exceptions.printStackTrace(ex); @@ -212,15 +212,15 @@ public boolean handleDrop(DropTargetDropEvent e) { public void run() { try { int ofs = offset; - if (!Utilities.isRowWhite(document, ofs)) { + if (!LineDocumentUtils.isLineWhitespace(document, ofs)) { document.insertString(ofs, "\n", null); ofs++; } document.insertString(ofs, sb.toString(), null); //reformat the line - final int from = Utilities.getRowStart(document, ofs); - final int to = Utilities.getRowEnd(document, ofs); + final int from = LineDocumentUtils.getLineStartOffset(document, ofs); + final int to = LineDocumentUtils.getLineEndOffset(document, ofs); indent.reindent(from, to); diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/indent/CssIndenter.java b/ide/css.editor/src/org/netbeans/modules/css/editor/indent/CssIndenter.java index 3bfc84c4f572..96bd2761aabd 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/indent/CssIndenter.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/indent/CssIndenter.java @@ -25,9 +25,9 @@ import java.util.ListIterator; import java.util.Stack; import javax.swing.text.BadLocationException; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenId; -import org.netbeans.editor.Utilities; import org.netbeans.modules.css.lib.api.CssTokenId; import org.netbeans.modules.editor.indent.spi.Context; import org.netbeans.modules.web.indent.api.LexUtilities; @@ -323,7 +323,7 @@ protected List getLineIndent(IndenterContextData cont if (end < commentEndOffset) { // if comment ends on next line put formatter to IN_COMMENT state inComment = true; - int lineStart = Utilities.getRowStart(getDocument(), ts.offset()); + int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), ts.offset()); preservedLineIndentation = start - lineStart; } } else if (end == commentEndOffset) { diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedBreakInterceptor.java b/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedBreakInterceptor.java index 95568e33f104..8d578e904f4e 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedBreakInterceptor.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedBreakInterceptor.java @@ -20,6 +20,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Position; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.mimelookup.MimeRegistration; import org.netbeans.editor.BaseDocument; @@ -53,8 +54,8 @@ public void insert(MutableContext context) throws BadLocationException { //context.setText("\n\n", 1, 1, 0, 2); //reformat workaround -- the preferred //won't work as the reformatter will not reformat the line with the closing tag - int from = Utilities.getRowStart(doc, offset); - int to = Utilities.getRowEnd(doc, offset); + int from = LineDocumentUtils.getLineStartOffset(doc, offset); + int to = LineDocumentUtils.getLineEndOffset(doc, offset); reformat = new Position[]{doc.createPosition(from), doc.createPosition(to)}; context.setText("\n\n", 1, 1); } diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedTextInterceptor.java b/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedTextInterceptor.java index 9e566ceb7dc2..2ffdebe49a71 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedTextInterceptor.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/typinghooks/CssTypedTextInterceptor.java @@ -24,6 +24,7 @@ import javax.swing.SwingUtilities; import javax.swing.text.BadLocationException; import javax.swing.text.Position; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.mimelookup.MimeRegistration; import org.netbeans.api.lexer.Token; @@ -243,7 +244,7 @@ public void insert(MutableContext context) throws BadLocationException { public void afterInsert(Context context) throws BadLocationException { char ch = context.getText().charAt(0); if ('}' == ch) { - final int lineStart = Utilities.getRowFirstNonWhite((BaseDocument) context.getDocument(), context.getOffset()); + final int lineStart = LineDocumentUtils.getLineFirstNonWhitespace((BaseDocument) context.getDocument(), context.getOffset()); if (lineStart == context.getOffset()) { reindentLater((BaseDocument) context.getDocument(), context.getOffset(), context.getOffset()); } @@ -254,8 +255,8 @@ public void afterInsert(Context context) throws BadLocationException { //indentation infrastructure directly. Instead of that create a new //AWT task and post it for later execution. private void reindentLater(final BaseDocument doc, int start, int end) throws BadLocationException { - final Position from = doc.createPosition(Utilities.getRowStart(doc, start)); - final Position to = doc.createPosition(Utilities.getRowEnd(doc, end)); + final Position from = doc.createPosition(LineDocumentUtils.getLineStartOffset(doc, start)); + final Position to = doc.createPosition(LineDocumentUtils.getLineEndOffset(doc, end)); Runnable rn = new Runnable() { @Override diff --git a/ide/css.editor/src/org/netbeans/modules/css/refactoring/WhereUsedElement.java b/ide/css.editor/src/org/netbeans/modules/css/refactoring/WhereUsedElement.java index 648bd145c8b5..6a115cb8b466 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/refactoring/WhereUsedElement.java +++ b/ide/css.editor/src/org/netbeans/modules/css/refactoring/WhereUsedElement.java @@ -22,6 +22,7 @@ import java.util.Collections; import javax.swing.Icon; import javax.swing.text.Position.Bias; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.csl.api.ElementKind; @@ -119,16 +120,16 @@ public static WhereUsedElement create(FileObject fileObject, Entry entry, Elemen // for for example find subclasses (using a singly dummy FileInfo) I need // to read it here instead content = bdoc.getText(0, bdoc.getLength()); - sta = Utilities.getRowFirstNonWhite(bdoc, start); + sta = LineDocumentUtils.getLineFirstNonWhitespace(bdoc, start); if (sta == -1) { - sta = Utilities.getRowStart(bdoc, start); + sta = LineDocumentUtils.getLineStartOffset(bdoc, start); } - en = Utilities.getRowLastNonWhite(bdoc, start); + en = LineDocumentUtils.getLineLastNonWhitespace(bdoc, start); if (en == -1) { - en = Utilities.getRowEnd(bdoc, start); + en = LineDocumentUtils.getLineEndOffset(bdoc, start); } else { // Last nonwhite - left side of the last char, not inclusive en++; diff --git a/ide/css.prep/src/org/netbeans/modules/css/prep/editor/refactoring/WhereUsedElement.java b/ide/css.prep/src/org/netbeans/modules/css/prep/editor/refactoring/WhereUsedElement.java index 7397891423e7..59a7094f2c70 100644 --- a/ide/css.prep/src/org/netbeans/modules/css/prep/editor/refactoring/WhereUsedElement.java +++ b/ide/css.prep/src/org/netbeans/modules/css/prep/editor/refactoring/WhereUsedElement.java @@ -21,6 +21,7 @@ import java.util.Collections; import javax.swing.Icon; import javax.swing.text.Position.Bias; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.modules.csl.api.Modifier; import org.netbeans.modules.csl.api.OffsetRange; @@ -29,7 +30,6 @@ import org.netbeans.modules.csl.api.ElementKind; import org.netbeans.modules.csl.api.UiUtils; import org.netbeans.modules.csl.spi.GsfUtilities; -import org.netbeans.modules.css.refactoring.api.Entry; import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation; import org.openide.filesystems.FileObject; import org.openide.text.CloneableEditorSupport; @@ -108,16 +108,16 @@ public static WhereUsedElement create(FileObject fileObject, String name, Offset // for for example find subclasses (using a singly dummy FileInfo) I need // to read it here instead content = bdoc.getText(0, bdoc.getLength()); - sta = Utilities.getRowFirstNonWhite(bdoc, start); + sta = LineDocumentUtils.getLineFirstNonWhitespace(bdoc, start); if (sta == -1) { - sta = Utilities.getRowStart(bdoc, start); + sta = LineDocumentUtils.getLineStartOffset(bdoc, start); } - en = Utilities.getRowLastNonWhite(bdoc, start); + en = LineDocumentUtils.getLineLastNonWhitespace(bdoc, start); if (en == -1) { - en = Utilities.getRowEnd(bdoc, start); + en = LineDocumentUtils.getLineEndOffset(bdoc, start); } else { // Last nonwhite - left side of the last char, not inclusive en++; diff --git a/ide/css.visual/src/org/netbeans/modules/css/visual/RuleEditorNode.java b/ide/css.visual/src/org/netbeans/modules/css/visual/RuleEditorNode.java index ed6ff5707f73..170d0f3503e2 100644 --- a/ide/css.visual/src/org/netbeans/modules/css/visual/RuleEditorNode.java +++ b/ide/css.visual/src/org/netbeans/modules/css/visual/RuleEditorNode.java @@ -46,6 +46,7 @@ import javax.swing.table.TableCellRenderer; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.css.lib.api.properties.FixedTextGrammarElement; @@ -872,7 +873,7 @@ private CharSequence getLocationPrefix() { @Override public void run() { try { - int lineOffset = 1 + Utilities.getLineOffset((BaseDocument) doc, doc_from); + int lineOffset = 1 + LineDocumentUtils.getLineIndex((BaseDocument) doc, doc_from); sb.append(':'); sb.append(lineOffset); } catch (BadLocationException ex) { diff --git a/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/DiffViewManager.java b/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/DiffViewManager.java index 42df7139fa50..45c27c16b7e1 100644 --- a/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/DiffViewManager.java +++ b/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/DiffViewManager.java @@ -37,6 +37,7 @@ import java.util.logging.Logger; import java.util.logging.Level; import java.io.*; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.openide.util.RequestProcessor; /** @@ -254,7 +255,7 @@ private void computeFirstHighlights() { static int getRowStartFromLineOffset(Document doc, int lineIndex) { if (doc instanceof BaseDocument) { - return Utilities.getRowStartFromLineOffset((BaseDocument) doc, lineIndex); + return LineDocumentUtils.getLineStartFromIndex((BaseDocument) doc, lineIndex); } else { // TODO: find row start from line offet Element element = doc.getDefaultRootElement(); @@ -474,10 +475,10 @@ private boolean canRollback(Document doc, Difference diff) { GuardedDocument document = (GuardedDocument) doc; int start, end; if (diff.getType() == Difference.DELETE) { - start = end = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart()); + start = end = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart()); } else { - start = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart() > 0 ? diff.getSecondStart() - 1 : 0); - end = Utilities.getRowStartFromLineOffset(document, diff.getSecondEnd()); + start = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart() > 0 ? diff.getSecondStart() - 1 : 0); + end = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondEnd()); } MarkBlockChain mbc = ((GuardedDocument) document).getGuardedBlockChain(); return (mbc.compareBlock(start, end) & MarkBlock.OVERLAP) == 0; diff --git a/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/LineNumbersActionsBar.java b/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/LineNumbersActionsBar.java index 3aa8a45d02a9..88eba1fecd07 100644 --- a/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/LineNumbersActionsBar.java +++ b/ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/LineNumbersActionsBar.java @@ -50,6 +50,7 @@ import javax.swing.text.AttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.View; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.settings.EditorStyleConstants; import org.netbeans.api.editor.settings.FontColorNames; @@ -388,7 +389,7 @@ protected void paintComponent(Graphics gr) { if(rootView == null) { // this might happen return; } - int lineNumber = Utilities.getLineOffset((BaseDocument) master.getEditorPane().getDocument(), master.getEditorPane().viewToModel(new Point(clip.x, clip.y))); + int lineNumber = LineDocumentUtils.getLineIndex((BaseDocument) master.getEditorPane().getDocument(), master.getEditorPane().viewToModel(new Point(clip.x, clip.y))); if (lineNumber > 0) { --lineNumber; } @@ -403,7 +404,7 @@ protected void paintComponent(Graphics gr) { int yOffset; int localLineHeight = rec.height; int linesDrawn = clip.height / localLineHeight + 4; // draw past clipping rectangle to avoid partially drawn numbers - int docLines = Utilities.getRowCount((BaseDocument) master.getEditorPane().getDocument()); + int docLines = LineDocumentUtils.getLineCount((BaseDocument) master.getEditorPane().getDocument()); if (lineNumber + linesDrawn > docLines) { linesDrawn = docLines - lineNumber; } diff --git a/ide/docker.editor/src/org/netbeans/modules/docker/editor/completion/DockerfileCompletion.java b/ide/docker.editor/src/org/netbeans/modules/docker/editor/completion/DockerfileCompletion.java index 32b931b8e52a..7acf477e4be3 100644 --- a/ide/docker.editor/src/org/netbeans/modules/docker/editor/completion/DockerfileCompletion.java +++ b/ide/docker.editor/src/org/netbeans/modules/docker/editor/completion/DockerfileCompletion.java @@ -212,7 +212,7 @@ private CodeCompletionResult completeImpl(@NonNull final CodeCompletionContext c } if (prev != null && prev.id() == DockerfileTokenId.ONBUILD && - LineDocumentUtils.getLineStart(doc,seq.offset()) == LineDocumentUtils.getLineStart(doc,anchor)) { + LineDocumentUtils.getLineStart(doc, seq.offset()) == LineDocumentUtils.getLineStart(doc, anchor)) { //Commands after onbuild return commands(prefix, anchor, true); } diff --git a/ide/docker.editor/src/org/netbeans/modules/docker/editor/indent/DockerfileTypedBreakInterceptor.java b/ide/docker.editor/src/org/netbeans/modules/docker/editor/indent/DockerfileTypedBreakInterceptor.java index b41eab9a7d81..df1fe1536fd0 100644 --- a/ide/docker.editor/src/org/netbeans/modules/docker/editor/indent/DockerfileTypedBreakInterceptor.java +++ b/ide/docker.editor/src/org/netbeans/modules/docker/editor/indent/DockerfileTypedBreakInterceptor.java @@ -51,8 +51,8 @@ public boolean beforeInsert(Context context) throws BadLocationException { public void insert(MutableContext context) throws BadLocationException { final BaseDocument doc = (BaseDocument) context.getDocument(); final int offset = context.getCaretOffset(); - final int lineStart = LineDocumentUtils.getLineStart(doc, offset); - final int lineEnd = LineDocumentUtils.getLineEnd(doc, offset); + final int lineStart = LineDocumentUtils.getLineStartOffset(doc, offset); + final int lineEnd = LineDocumentUtils.getLineEndOffset(doc, offset); if (lineStart == lineEnd) { //Empty line return; diff --git a/ide/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java b/ide/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java index 8177aaa16fde..05aea4e37822 100644 --- a/ide/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java +++ b/ide/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java @@ -29,6 +29,7 @@ import org.netbeans.api.editor.caret.CaretInfo; import org.netbeans.api.editor.caret.CaretMoveContext; import org.netbeans.api.editor.caret.EditorCaret; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.editor.BaseCaret; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.BaseKit; @@ -90,11 +91,11 @@ public void moveCarets(final CaretMoveContext context) { int wsPos; if (r == null) { if (isForward()) { - int eolPos = Utilities.getRowEnd(doc, dotPos); + int eolPos = LineDocumentUtils.getLineEndOffset(doc, dotPos); wsPos = Utilities.getNextWord(target, dotPos); wsPos = (dotPos == eolPos) ? wsPos : Math.min(eolPos, wsPos); } else { - int bolPos = Utilities.getRowStart(doc, dotPos); + int bolPos = LineDocumentUtils.getLineStartOffset(doc, dotPos); wsPos = Utilities.getPreviousWord(target, dotPos); wsPos = (dotPos == bolPos) ? wsPos : Math.max(bolPos, wsPos); } @@ -145,11 +146,11 @@ public void run() { int wsPos; if (r == null) { if (isForward()) { - int eolPos = Utilities.getRowEnd(doc, dotPos); + int eolPos = LineDocumentUtils.getLineEndOffset(doc, dotPos); wsPos = Utilities.getNextWord(target, dotPos); wsPos = (dotPos == eolPos) ? wsPos : Math.min(eolPos, wsPos); } else { - int bolPos = Utilities.getRowStart(doc, dotPos); + int bolPos = LineDocumentUtils.getLineStartOffset(doc, dotPos); wsPos = Utilities.getPreviousWord(target, dotPos); wsPos = (dotPos == bolPos) ? wsPos : Math.max(bolPos, wsPos); } diff --git a/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceMatchingSidebarComponent.java b/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceMatchingSidebarComponent.java index 8fb296fd2b3e..d6df63a6dcd5 100644 --- a/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceMatchingSidebarComponent.java +++ b/ide/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BraceMatchingSidebarComponent.java @@ -58,6 +58,7 @@ import javax.swing.text.JTextComponent; import javax.swing.text.Position; import javax.swing.text.StyleConstants; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.settings.AttributesUtilities; @@ -713,7 +714,7 @@ private void showTooltip() { contentHeight += lineHeight; int startAfterRelated = Utilities.getRowStart(bdoc, rel.getEnd().getOffset(), 1); - int startAtContext = Utilities.getRowStart(bdoc, yFrom); + int startAtContext = LineDocumentUtils.getLineStartOffset(bdoc, yFrom); // measure the indent so the view can align the ellipsis int indent = Utilities.getRowIndent(bdoc, startAfterRelated); // suppress the ellipsis if just a single line should be cut diff --git a/ide/editor.codetemplates/src/org/netbeans/lib/editor/codetemplates/textsync/TextRegionManager.java b/ide/editor.codetemplates/src/org/netbeans/lib/editor/codetemplates/textsync/TextRegionManager.java index 6aec6865c30c..720083a92e24 100644 --- a/ide/editor.codetemplates/src/org/netbeans/lib/editor/codetemplates/textsync/TextRegionManager.java +++ b/ide/editor.codetemplates/src/org/netbeans/lib/editor/codetemplates/textsync/TextRegionManager.java @@ -46,6 +46,7 @@ import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.TextAction; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.settings.AttributesUtilities; @@ -1342,12 +1343,12 @@ void requestRepaint() { int startOffset = masterRegion.startOffset(); int endOffset = masterRegion.endOffset(); - int startLine = Utilities.getLineOffset((BaseDocument) doc, startOffset); - int endLine = Utilities.getLineOffset((BaseDocument) doc, endOffset); + int startLine = LineDocumentUtils.getLineIndex((BaseDocument) doc, startOffset); + int endLine = LineDocumentUtils.getLineIndex((BaseDocument) doc, endOffset); for (int i = startLine; i <= endLine; i++) { - int s = Math.max(Utilities.getRowStartFromLineOffset((BaseDocument) doc, i), startOffset); - int e = Math.min(Utilities.getRowEnd((BaseDocument) doc, s), endOffset); + int s = Math.max(LineDocumentUtils.getLineStartFromIndex((BaseDocument) doc, i), startOffset); + int e = Math.min(LineDocumentUtils.getLineEndOffset((BaseDocument) doc, s), endOffset); int size = e - s; if (size == 1) { diff --git a/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/Formatter.java b/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/Formatter.java index 57324f773154..3a7706b55272 100644 --- a/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/Formatter.java +++ b/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/Formatter.java @@ -32,6 +32,7 @@ import javax.swing.text.Document; import javax.swing.text.BadLocationException; import javax.swing.text.EditorKit; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.settings.SimpleValueNames; @@ -388,8 +389,8 @@ public void insertTabString (final BaseDocument doc, final int dotPos) public void run () { try { // Determine first white char before dotPos - int rsPos = Utilities.getRowStart(doc, dotPos); - int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos); + int rsPos = LineDocumentUtils.getLineStartOffset(doc, dotPos); + int startPos = LineDocumentUtils.getPreviousNonWhitespace(doc, dotPos, rsPos); startPos = (startPos >= 0) ? (startPos + 1) : rsPos; int startCol = Utilities.getVisualColumn(doc, startPos); @@ -430,11 +431,11 @@ public void changeRowIndent (final BaseDocument doc, final int pos, final int ne public void run () { try { int indent = newIndent < 0 ? 0 : newIndent; - int firstNW = Utilities.getRowFirstNonWhite(doc, pos); + int firstNW = LineDocumentUtils.getLineFirstNonWhitespace(doc, pos); if (firstNW == -1) { // valid first non-blank - firstNW = Utilities.getRowEnd(doc, pos); + firstNW = LineDocumentUtils.getLineEndOffset(doc, pos); } - int replacePos = Utilities.getRowStart(doc, pos); + int replacePos = LineDocumentUtils.getLineStartOffset(doc, pos); int removeLen = firstNW - replacePos; CharSequence removeText = DocumentUtilities.getText(doc, replacePos, removeLen); String newIndentText = getIndentString(doc, indent); @@ -494,15 +495,15 @@ public void changeBlockIndent (final BaseDocument doc, final int startPos, final public void run () { try { int indentDelta = shiftCnt * doc.getShiftWidth(); - int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ? + int end = (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) ? endPos - 1 : endPos; - int pos = Utilities.getRowStart(doc, startPos ); - for (int lineCnt = Utilities.getRowCount(doc, startPos, end); + int pos = LineDocumentUtils.getLineStartOffset(doc, startPos ); + for (int lineCnt = LineDocumentUtils.getLineCount(doc, startPos, end); lineCnt > 0; lineCnt-- ) { int indent = Utilities.getRowIndent(doc, pos); - if (Utilities.isRowWhite(doc, pos)) { + if (LineDocumentUtils.isLineWhitespace(doc, pos)) { indent = -indentDelta; // zero indentation for white line } changeRowIndent(doc, pos, Math.max(indent + indentDelta, 0)); @@ -530,7 +531,7 @@ public void shiftLine(BaseDocument doc, int dotPos, boolean right) ind = -ind; } - if (Utilities.isRowWhite(doc, dotPos)) { + if (LineDocumentUtils.isLineWhitespace(doc, dotPos)) { ind += Utilities.getVisualColumn(doc, dotPos); } else { ind += Utilities.getRowIndent(doc, dotPos); diff --git a/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/ext/ExtFormatter.java b/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/ext/ExtFormatter.java index 747882072436..909b76df2bad 100644 --- a/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/ext/ExtFormatter.java +++ b/ide/editor.deprecated.pre65formatting/src/org/netbeans/editor/ext/ExtFormatter.java @@ -33,6 +33,7 @@ import javax.swing.text.Document; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.editor.BaseDocument; @@ -331,7 +332,7 @@ protected boolean hasTextBefore(JTextComponent target, String typedText) { BaseDocument doc = Utilities.getDocument(target); int dotPos = target.getCaret().getDot(); try { - int fnw = Utilities.getRowFirstNonWhite(doc, dotPos); + int fnw = LineDocumentUtils.getLineFirstNonWhitespace(doc, dotPos); return dotPos != fnw+typedText.length(); } catch (BadLocationException e) { return false; @@ -354,13 +355,13 @@ protected boolean hasTextBefore(JTextComponent target, String typedText) { if (doc instanceof BaseDocument) { try { BaseDocument bdoc = (BaseDocument)doc; - int lineStart = Utilities.getRowStart(bdoc, offset); + int lineStart = LineDocumentUtils.getLineStartOffset(bdoc, offset); int nextLineStart = Utilities.getRowStart(bdoc, offset, 1); if (nextLineStart < 0) { // end of doc nextLineStart = bdoc.getLength(); } reformat(bdoc, lineStart, nextLineStart, false); - return Utilities.getRowEnd(bdoc, lineStart); + return LineDocumentUtils.getLineEndOffset(bdoc, lineStart); } catch (GuardedException e) { java.awt.Toolkit.getDefaultToolkit().beep(); @@ -379,7 +380,7 @@ protected boolean hasTextBefore(JTextComponent target, String typedText) { /** Returns offset of EOL for the white line */ protected int getEOLOffset(BaseDocument bdoc, int offset) throws BadLocationException{ - return Utilities.getRowEnd(bdoc, offset); + return LineDocumentUtils.getLineEndOffset(bdoc, offset); } /** Inserts new line at given position and indents the new line with @@ -402,14 +403,14 @@ public void run () { result [0]++; newLineInserted = true; - int eolOffset = Utilities.getRowEnd(bdoc, result [0]); + int eolOffset = LineDocumentUtils.getLineEndOffset(bdoc, result [0]); // Try to change the indent of the new line // It may fail when inserting '\n' before the guarded block Writer w = reformat(bdoc, result [0], eolOffset, true); // Find the caret position - eolOffset = Utilities.getRowFirstNonWhite(bdoc, result [0]); + eolOffset = LineDocumentUtils.getLineFirstNonWhitespace(bdoc, result [0]); if (eolOffset < 0) { // white line eolOffset = getEOLOffset(bdoc, result [0]); } diff --git a/ide/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/LegacyFormattersProvider.java b/ide/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/LegacyFormattersProvider.java index a7676d92af1e..b3ace665f0cb 100644 --- a/ide/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/LegacyFormattersProvider.java +++ b/ide/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/LegacyFormattersProvider.java @@ -35,6 +35,7 @@ import javax.swing.text.Element; import javax.swing.text.Position; import javax.swing.text.StyledDocument; +import org.netbeans.api.editor.document.LineDocumentUtils; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.editor.BaseDocument; @@ -349,8 +350,8 @@ public void afterInsert(Context context) throws BadLocationException { if (fmtBlk != null) { try { - fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]); - fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]); + fmtBlk[0] = LineDocumentUtils.getLineStartOffset(doc, fmtBlk[0]); + fmtBlk[1] = LineDocumentUtils.getLineEndOffset(doc, fmtBlk[1]); //this was the of #18922, that causes the bug #20198 //ef.reformat(doc, fmtBlk[0], fmtBlk[1]); diff --git a/ide/editor.document/src/org/netbeans/api/editor/document/LineDocumentUtils.java b/ide/editor.document/src/org/netbeans/api/editor/document/LineDocumentUtils.java index 247dda8b82ee..663ae40a00a7 100644 --- a/ide/editor.document/src/org/netbeans/api/editor/document/LineDocumentUtils.java +++ b/ide/editor.document/src/org/netbeans/api/editor/document/LineDocumentUtils.java @@ -35,11 +35,11 @@ /** * Line and word related utility methods. - *
+ *

* All the methods working with the document assume that the document is locked against * a parallel modification e.g. by including the call within * {@link Document#render(java.lang.Runnable)}. - *
+ *

* The utilities were moved from the former Editor Library 2's Utilities * and work with {@link LineDocument} only. The methods work only with document * data. Utilities that connect document with the UI elements (Swing) can be @@ -50,8 +50,6 @@ public final class LineDocumentUtils { - private static final String WRONG_POSITION_LOCALE = "wrong_position"; // NOI18N - private LineDocumentUtils() { // instantiation has no sense } @@ -61,14 +59,46 @@ private LineDocumentUtils() { * @param doc non-null document to operate on * @param offset position in document where to start searching * @return offset of character right above newline prior the given offset or zero. + * @deprecated Use {@link #getLineStartOffset} instead */ + @Deprecated public static int getLineStart(@NonNull LineDocument doc, int offset) { return doc.getParagraphElement(offset).getStartOffset(); } - public static int getLineEnd(@NonNull LineDocument doc, int offset) - throws BadLocationException - { + /** + * Get end offset of a (newline character separated) line. + * @param doc non-null document to operate on + * @param offset position in document where to start searching + * @return offset of character right above newline prior the given offset or zero. + * @throws javax.swing.text.BadLocationException If offset is out of bounds + * @deprecated Use {@link #getLineEndOffset} instead + */ + @Deprecated + public static int getLineEnd(@NonNull LineDocument doc, int offset) throws BadLocationException { + return getLineEndOffset(doc, offset); + } + + /** + * Get start offset of a (newline character separated) line. + * @param doc non-null document to operate on + * @param offset position in document where to start searching + * @return offset of character right above newline prior the given offset or zero. + * @throws javax.swing.text.BadLocationException If offset is out of bounds + */ + public static int getLineStartOffset(@NonNull LineDocument doc, int offset) throws BadLocationException { + checkOffsetValid(doc, offset); + return doc.getParagraphElement(offset).getStartOffset(); + } + + /** + * Get end offset of a (newline character separated) line. + * @param doc non-null document to operate on + * @param offset position in document where to start searching + * @return offset of character right above newline prior the given offset or zero. + * @throws javax.swing.text.BadLocationException If offset is out of bounds + */ + public static int getLineEndOffset(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); return doc.getParagraphElement(offset).getEndOffset() - 1; } @@ -407,7 +437,7 @@ private static CharClassifier getValidClassifier(Document doc) { /** * Locates the appropriate service for the document. May return {@code null} * if the interface/service is not supported by the document. - *

+ *

* For example, if a code needs to perform an atomic action on the document, * it can do so as follows: *

@@ -500,13 +530,13 @@ public V(T delegate) {
             if (useStub) {
                 lkp = DocumentServices.getInstance().getStubLookup(d);
                 serv = lkp.lookup(documentService);
-                d.putProperty(documentService, new V(serv));
+                d.putProperty(documentService, new V<>(serv));
                 if (serv == null) {
                     throw new IllegalArgumentException();
                 }
             }
         } else {
-            d.putProperty(documentService, serv == null ? NOT_FOUND : serv);
+            d.putProperty(documentService, serv);
         }
         @SuppressWarnings("unchecked")
         T res = (T) serv;
diff --git a/ide/editor.errorstripe/src/org/netbeans/modules/editor/errorstripe/AnnotationView.java b/ide/editor.errorstripe/src/org/netbeans/modules/editor/errorstripe/AnnotationView.java
index ab9caf6aae43..1ad74c794918 100644
--- a/ide/editor.errorstripe/src/org/netbeans/modules/editor/errorstripe/AnnotationView.java
+++ b/ide/editor.errorstripe/src/org/netbeans/modules/editor/errorstripe/AnnotationView.java
@@ -52,13 +52,13 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.StyledDocument;
 import javax.swing.text.View;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.fold.FoldHierarchyEvent;
 import org.netbeans.api.editor.fold.FoldHierarchyListener;
 
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.BaseTextUI;
-import org.netbeans.editor.Utilities;
 import org.netbeans.lib.editor.util.StringEscapeUtils;
 import org.netbeans.modules.editor.errorstripe.caret.CaretMark;
 import org.netbeans.modules.editor.errorstripe.privatespi.Mark;
@@ -183,7 +183,7 @@ private synchronized void updateForNewDocument() {
             while (position == _modelToView(startLine - 1, componentHeight, usableHeight) && startLine > 0)
                 startLine--;
 
-            while ((endLine + 1) < Utilities.getRowCount(doc) && position == _modelToView(endLine + 1, componentHeight, usableHeight))
+            while ((endLine + 1) < LineDocumentUtils.getLineCount(doc) && position == _modelToView(endLine + 1, componentHeight, usableHeight))
                 endLine++;
 
             return new int[] {startLine, endLine};
@@ -473,7 +473,7 @@ public void run() {
     }
     
     private void documentChange() {
-        fullRepaint(lines != Utilities.getRowCount(doc));
+        fullRepaint(lines != LineDocumentUtils.getLineCount(doc));
     }
     
     private double getComponentHeight() {
@@ -549,11 +549,11 @@ private int getYFromPos(int offset) throws BadLocationException {
     }
     
     private synchronized int getModelToViewImpl(int line) throws BadLocationException {
-        int docLines = Utilities.getRowCount(doc);
+        int docLines = LineDocumentUtils.getLineCount(doc);
         
         if (modelToViewCache == null || height != pane.getHeight() || lines != docLines) {
-            modelToViewCache = new int[Utilities.getRowCount(doc) + 2];
-            lines = Utilities.getRowCount(doc);
+            modelToViewCache = new int[LineDocumentUtils.getLineCount(doc) + 2];
+            lines = LineDocumentUtils.getLineCount(doc);
             height = pane.getHeight();
         }
         
@@ -563,7 +563,7 @@ private synchronized int getModelToViewImpl(int line) throws BadLocationExceptio
         int result = modelToViewCache[line + 1];
         
         if (result == 0) {
-            int lineOffset = Utilities.getRowStartFromLineOffset((BaseDocument) pane.getDocument(), line);
+            int lineOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) pane.getDocument(), line);
             
             modelToViewCache[line + 1] = result = getYFromPos(lineOffset);
         }
@@ -619,7 +619,7 @@ private double _modelToView(int line, double componentHeight, double usableHeigh
                 if (positionOffset == -1) {
                     return null;
                 }
-                int line = Utilities.getLineOffset(doc, positionOffset);
+                int line = LineDocumentUtils.getLineIndex(doc, positionOffset);
                 
                 if (ERR.isLoggable(VIEW_TO_MODEL_IMPORTANCE)) {
                     ERR.log(VIEW_TO_MODEL_IMPORTANCE, "AnnotationView.viewToModel: line=" + line); // NOI18N
@@ -643,7 +643,7 @@ private double _modelToView(int line, double componentHeight, double usableHeigh
                 if (positionOffset == -1) {
                     return null;
                 }
-                int    line = Utilities.getLineOffset(doc, positionOffset) + 1;
+                int    line = LineDocumentUtils.getLineIndex(doc, positionOffset) + 1;
                 int[] span = getLinesSpan(line);
                 double normalizedOffset = modelToView(span[0]);
                 
@@ -777,7 +777,7 @@ public void mouseClicked(MouseEvent e) {
         Mark mark = getMarkForPoint(e.getPoint().getY());
         
         if (mark!= null) {
-            pane.setCaretPosition(Utilities.getRowStartFromLineOffset(doc, mark.getAssignedLines()[0]));
+            pane.setCaretPosition(LineDocumentUtils.getLineStartFromIndex(doc, mark.getAssignedLines()[0]));
         }
     }
     
diff --git a/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationTestUtilities.java b/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationTestUtilities.java
index 61800b054a08..7ab9ed6c10fa 100644
--- a/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationTestUtilities.java
+++ b/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationTestUtilities.java
@@ -23,6 +23,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Position;
 import junit.framework.*;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.AnnotationDesc;
 import org.netbeans.editor.AnnotationType;
 import org.netbeans.editor.AnnotationType.Severity;
@@ -70,7 +71,7 @@ public int getOffset() {
 
         public int getLine() {
             try {
-                return Utilities.getLineOffset(doc, getOffset());
+                return LineDocumentUtils.getLineIndex(doc, getOffset());
             } catch (BadLocationException e) {
                 IllegalStateException exc = new IllegalStateException();
                 
@@ -107,7 +108,7 @@ public int getOffset() {
 
         public int getLine() {
             try {
-                return Utilities.getLineOffset(doc, getOffset());
+                return LineDocumentUtils.getLineIndex(doc, getOffset());
             } catch (BadLocationException e) {
                 IllegalStateException exc = new IllegalStateException();
                 
diff --git a/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewDataImplTest.java b/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewDataImplTest.java
index 929f740eaff4..55094b7a23e4 100644
--- a/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewDataImplTest.java
+++ b/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewDataImplTest.java
@@ -34,6 +34,7 @@
 import javax.swing.JEditorPane;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Position;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.AnnotationDesc;
 import org.netbeans.editor.AnnotationType;
 import org.netbeans.editor.AnnotationTypes;
@@ -192,7 +193,7 @@ public void testComputeTotalStatus() throws Exception {
         
         bd.insertString(0, "\n\n\n\n\n\n\n\n\n\n", null);
         
-        Position start = bd.createPosition(Utilities.getRowStartFromLineOffset(bd, 2));
+        Position start = bd.createPosition(LineDocumentUtils.getLineStartFromIndex(bd, 2));
         
         AnnotationDesc a1 = new AnnotationTestUtilities.TestAnnotationDesc1(bd, start);
         AnnotationDesc a2 = new AnnotationTestUtilities.TestAnnotationDesc2(bd, start);
@@ -426,7 +427,7 @@ public int getOffset() {
 
         public int getLine() {
             try {
-                return Utilities.getLineOffset(doc, getOffset());
+                return LineDocumentUtils.getLineIndex(doc, getOffset());
             } catch (BadLocationException e) {
                 IllegalStateException exc = new IllegalStateException();
                 
diff --git a/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewTest.java b/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewTest.java
index 125d6b7d302f..ab856660b3e1 100644
--- a/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewTest.java
+++ b/ide/editor.errorstripe/test/unit/src/org/netbeans/modules/editor/errorstripe/AnnotationViewTest.java
@@ -27,9 +27,9 @@
 import javax.swing.JEditorPane;
 import javax.swing.JFrame;
 import javax.swing.JScrollPane;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.BaseKit;
-import org.netbeans.editor.Utilities;
 import org.netbeans.junit.NbTestCase;
 import org.netbeans.modules.editor.errorstripe.caret.CaretMarkProviderCreator;
 import org.netbeans.modules.editor.errorstripe.privatespi.Mark;
@@ -63,7 +63,7 @@ public void test(AnnotationView aView, BaseDocument document) throws Exception {
                 
                 assertEquals(aView.viewToModel(pos)[0], aView.viewToModel(aView.modelToView(aView.viewToModel(pos)[0]))[0]);
                 
-                assertEquals((-1.0), aView.modelToView(Utilities.getLineOffset(document, document.getLength()) + 1), 0.0001d);
+                assertEquals((-1.0), aView.modelToView(LineDocumentUtils.getLineIndex(document, document.getLength()) + 1), 0.0001d);
             }
         });
     }
@@ -120,7 +120,7 @@ public void testGetLinesSpanIsContinuous() throws Exception {
         performTest(new Action() {
             public void test(AnnotationView aView, BaseDocument document) throws Exception {
                 int startLine = 1;
-                int linesCount = Utilities.getRowCount(document);
+                int linesCount = LineDocumentUtils.getLineCount(document);
                 
                 while (startLine < linesCount) {
                     int[] span = aView.getLinesSpan(startLine);
diff --git a/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java b/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java
index f76f1513b53d..90920bb6809a 100644
--- a/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java
+++ b/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java
@@ -57,6 +57,7 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.StyleConstants;
 import javax.swing.text.View;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.Fold;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.fold.FoldHierarchyEvent;
@@ -480,8 +481,8 @@ protected List getPaintInfo(Rectangle clip) throws BadLocat
                 return Collections.emptyList();
             }
             
-            startPos = Utilities.getRowStart(bdoc, startPos);
-            endPos = Utilities.getRowEnd(bdoc, endPos);
+            startPos = LineDocumentUtils.getLineStartOffset(bdoc, startPos);
+            endPos = LineDocumentUtils.getLineEndOffset(bdoc, endPos);
             
             FoldHierarchy hierarchy = FoldHierarchy.get(component);
             hierarchy.lock();
@@ -574,8 +575,8 @@ private boolean traverseForward(Fold f, BaseDocument doc, BaseTextUI btui, int l
             return false;
         }
 
-        int lineStartOffset1 = Utilities.getRowStart(doc, f.getStartOffset());
-        int lineStartOffset2 = Utilities.getRowStart(doc, f.getEndOffset());
+        int lineStartOffset1 = LineDocumentUtils.getLineStartOffset(doc, f.getStartOffset());
+        int lineStartOffset2 = LineDocumentUtils.getLineStartOffset(doc, f.getEndOffset());
         int y1 = btui.getYFromPos(lineStartOffset1);
         int h = btui.getEditorUI().getLineHeight();
         int y2 = btui.getYFromPos(lineStartOffset2);
@@ -719,8 +720,8 @@ private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int
             return false;
         }
 
-        int lineStartOffset1 = Utilities.getRowStart(doc, f.getStartOffset());
-        int lineStartOffset2 = Utilities.getRowStart(doc, f.getEndOffset());
+        int lineStartOffset1 = LineDocumentUtils.getLineStartOffset(doc, f.getStartOffset());
+        int lineStartOffset2 = LineDocumentUtils.getLineStartOffset(doc, f.getEndOffset());
         int h = btui.getEditorUI().getLineHeight();
 
         boolean activeMark = false;
diff --git a/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldView.java b/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldView.java
index 0e1f6777afb4..be58eb8355de 100644
--- a/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldView.java
+++ b/ide/editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/FoldView.java
@@ -42,6 +42,7 @@
 import javax.swing.text.Position.Bias;
 import javax.swing.text.StyleConstants;
 import javax.swing.text.View;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.Fold;
 import org.netbeans.api.editor.fold.FoldTemplate;
 import org.netbeans.api.editor.settings.FontColorNames;
@@ -54,6 +55,7 @@
 import org.openide.util.NbBundle;
 
 import static org.netbeans.modules.editor.fold.ui.Bundle.*;
+
 import org.netbeans.modules.editor.lib2.caret.CaretFoldExpander;
 
 
@@ -215,8 +217,8 @@ private String resolvePlaceholder(String text, int at) {
             if ((options & 2) > 0) {
                 int start = fold.getStartOffset();
                 int end = fold.getEndOffset();
-                int startLine = Utilities.getLineOffset(bd, start);
-                int endLine = Utilities.getLineOffset(bd, end) + 1;
+                int startLine = LineDocumentUtils.getLineIndex(bd, start);
+                int endLine = LineDocumentUtils.getLineIndex(bd, end) + 1;
                 
                 if (endLine <= startLine + 1) {
                     mask &= ~2;
diff --git a/ide/editor.lib/src/org/netbeans/editor/ActionFactory.java b/ide/editor.lib/src/org/netbeans/editor/ActionFactory.java
index 1f7837377354..75c8dc48fe26 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ActionFactory.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ActionFactory.java
@@ -77,6 +77,7 @@
 import org.netbeans.api.editor.NavigationHistory;
 import org.netbeans.api.editor.caret.CaretMoveContext;
 import org.netbeans.api.progress.BaseProgressUtils;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.spi.editor.caret.CaretMoveHandler;
 import org.netbeans.modules.editor.lib2.RectangularSelectionUtils;
 import org.netbeans.modules.editor.lib2.view.DocumentView;
@@ -154,16 +155,16 @@ public void moveCarets(CaretMoveContext context) {
                                             } else { // no selected text
                                                 try {
                                                     int dot = caretInfo.getDot();
-                                                    int lineStartOffset = Utilities.getRowStart(doc, dot);
-                                                    int firstNW = Utilities.getRowFirstNonWhite(doc, dot);
+                                                    int lineStartOffset = LineDocumentUtils.getLineStartOffset(doc, dot);
+                                                    int firstNW = LineDocumentUtils.getLineFirstNonWhitespace(doc, dot);
                                                     if (firstNW != -1 && dot <= firstNW) {
                                                         // Non-white row and caret inside initial whitespace => decrease text indent
-                                                        int lineEndOffset = Utilities.getRowEnd(doc, dot);
+                                                        int lineEndOffset = LineDocumentUtils.getLineEndOffset(doc, dot);
                                                         BaseKit.changeBlockIndent(doc, lineStartOffset, lineEndOffset, -1);
                                                     } else {
                                                         int endNW = (firstNW == -1)
                                                                 ? lineStartOffset
-                                                                : (Utilities.getRowLastNonWhite(doc, dot) + 1);
+                                                                : (LineDocumentUtils.getLineLastNonWhitespace(doc, dot) + 1);
                                                         if (dot > endNW) {
                                                             int shiftWidth = doc.getShiftWidth();
                                                             if (shiftWidth > 0) {
@@ -211,16 +212,16 @@ public void moveCarets(CaretMoveContext context) {
                                 } else { // no selected text
                                     try {
                                         int dot = caret.getDot();
-                                        int lineStartOffset = Utilities.getRowStart(doc, dot);
-                                        int firstNW = Utilities.getRowFirstNonWhite(doc, dot);
+                                        int lineStartOffset = LineDocumentUtils.getLineStartOffset(doc, dot);
+                                        int firstNW = LineDocumentUtils.getLineFirstNonWhitespace(doc, dot);
                                         if (firstNW != -1 && dot <= firstNW) {
                                             // Non-white row and caret inside initial whitespace => decrease text indent
-                                            int lineEndOffset = Utilities.getRowEnd(doc, dot);
+                                            int lineEndOffset = LineDocumentUtils.getLineEndOffset(doc, dot);
                                             BaseKit.changeBlockIndent(doc, lineStartOffset, lineEndOffset, -1);
                                         } else {
                                             int endNW = (firstNW == -1)
                                                     ? lineStartOffset
-                                                    : (Utilities.getRowLastNonWhite(doc, dot) + 1);
+                                                    : (LineDocumentUtils.getLineLastNonWhitespace(doc, dot) + 1);
                                             if (dot > endNW) {
                                                 int shiftWidth = doc.getShiftWidth();
                                                 if (shiftWidth > 0) {
@@ -286,7 +287,7 @@ public void run () {
                         DocumentUtilities.setTypingModification(doc, true);
                         try {
                             int dotPos = caret.getDot();
-                            int bolPos = Utilities.getRowStart(doc, dotPos);
+                            int bolPos = LineDocumentUtils.getLineStartOffset(doc, dotPos);
                             int wsPos = Utilities.getPreviousWord(target, dotPos);
                             wsPos = (dotPos == bolPos) ? wsPos : Math.max(bolPos, wsPos);
                             doc.remove(wsPos, dotPos - wsPos);
@@ -326,7 +327,7 @@ public void run () {
                         DocumentUtilities.setTypingModification(doc, true);
                         try {
                             int dotPos = caret.getDot();
-                            int eolPos = Utilities.getRowEnd(doc, dotPos);
+                            int eolPos = LineDocumentUtils.getLineEndOffset(doc, dotPos);
                             int wsPos = Utilities.getNextWord(target, dotPos);
                             wsPos = (dotPos == eolPos) ? wsPos : Math.min(eolPos, wsPos);
                             doc.remove(dotPos , wsPos - dotPos);
@@ -365,7 +366,7 @@ public void run () {
                         DocumentUtilities.setTypingModification(doc, true);
                         try {
                             int dotPos = caret.getDot();
-                            int bolPos = Utilities.getRowStart(doc, dotPos);
+                            int bolPos = LineDocumentUtils.getLineStartOffset(doc, dotPos);
                             if (dotPos == bolPos) { // at begining of the line
                                 if (dotPos > 0) {
                                     doc.remove(dotPos - 1, 1); // remove previous new-line
@@ -375,7 +376,7 @@ public void run () {
                                 if (Analyzer.isWhitespace(chars, 0, chars.length)) {
                                     doc.remove(bolPos, dotPos - bolPos); // remove whitespace
                                 } else {
-                                    int firstNW = Utilities.getRowFirstNonWhite(doc, bolPos);
+                                    int firstNW = LineDocumentUtils.getLineFirstNonWhitespace(doc, bolPos);
                                     if (firstNW >= 0 && firstNW < dotPos) {
                                         doc.remove(firstNW, dotPos - firstNW);
                                     }
@@ -425,8 +426,8 @@ public void moveCarets(CaretMoveContext context) {
                                             try {
                                                 int start = Math.min(caretInfo.getDot(), caretInfo.getMark());
                                                 int end = Math.max(caretInfo.getDot(), caretInfo.getMark());
-                                                int bolPos = Utilities.getRowStart(doc, start);
-                                                int eolPos = Utilities.getRowEnd(doc, end);
+                                                int bolPos = LineDocumentUtils.getLineStartOffset(doc, start);
+                                                int eolPos = LineDocumentUtils.getLineEndOffset(doc, end);
                                                 if (eolPos == doc.getLength()) {
                                                     // Ending newline can't be removed so instead remove starting newline if it exist
                                                     if (bolPos > 0) {
@@ -1675,8 +1676,8 @@ public void run () {
                                     startPos = target.getSelectionStart();
                                     endPosition = doc.createPosition(target.getSelectionEnd());
                                 } else {
-                                    startPos = Utilities.getRowStart(doc, caret.getDot());
-                                    endPosition = doc.createPosition(Utilities.getRowEnd(doc, caret.getDot()));
+                                    startPos = LineDocumentUtils.getLineStartOffset(doc, caret.getDot());
+                                    endPosition = doc.createPosition(LineDocumentUtils.getLineEndOffset(doc, caret.getDot()));
                                 }
 
                                 int pos = startPos;
@@ -1946,7 +1947,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
             if (target != null) {
                 Caret caret = target.getCaret();
                 try {
-                    int pos = Utilities.getRowFirstNonWhite((BaseDocument)target.getDocument(),
+                    int pos = LineDocumentUtils.getLineFirstNonWhitespace((BaseDocument)target.getDocument(),
                                                             caret.getDot());
                     if (pos >= 0) {
                         boolean select = BaseKit.selectionFirstNonWhiteAction.equals(getValue(Action.NAME));
@@ -1979,7 +1980,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
             if (target != null) {
                 Caret caret = target.getCaret();
                 try {
-                    int pos = Utilities.getRowLastNonWhite((BaseDocument)target.getDocument(),
+                    int pos = LineDocumentUtils.getLineLastNonWhitespace((BaseDocument)target.getDocument(),
                                                            caret.getDot());
                     if (pos >= 0) {
                         boolean select = BaseKit.selectionLastNonWhiteAction.equals(getValue(Action.NAME));
@@ -2292,7 +2293,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
         public JMenuItem getPopupMenuItem(JTextComponent target) {
             EditorUI ui = Utilities.getEditorUI(target);
             try {
-                return ui.getDocument().getAnnotations().createMenu(Utilities.getKit(target), Utilities.getLineOffset(ui.getDocument(),target.getCaret().getDot()));
+                return ui.getDocument().getAnnotations().createMenu(Utilities.getKit(target), LineDocumentUtils.getLineIndex(ui.getDocument(),target.getCaret().getDot()));
             } catch (BadLocationException ex) {
                 return null;
             }
@@ -2355,7 +2356,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
                 try {
                     Caret caret = target.getCaret();
                     BaseDocument doc = Utilities.getDocument(target);
-                    int caretLine = Utilities.getLineOffset(doc, caret.getDot());
+                    int caretLine = LineDocumentUtils.getLineIndex(doc, caret.getDot());
                     AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine);
                 } catch (BadLocationException e) {
                     e.printStackTrace();
@@ -2536,7 +2537,7 @@ public void moveCarets(CaretMoveContext context) {
                                         try {
                                             BaseDocument doc = (BaseDocument) context.getDocument();
                                             // insert new line, caret moves to the new line
-                                            int eolDot = Utilities.getRowEnd(doc, caretInfo.getDot());
+                                            int eolDot = LineDocumentUtils.getLineEndOffset(doc, caretInfo.getDot());
                                             doc.insertString(eolDot, "\n", null); //NOI18N
 
                                             // reindent the new line
diff --git a/ide/editor.lib/src/org/netbeans/editor/BaseDocument.java b/ide/editor.lib/src/org/netbeans/editor/BaseDocument.java
index 9fbf99e09427..165cb7ca7400 100644
--- a/ide/editor.lib/src/org/netbeans/editor/BaseDocument.java
+++ b/ide/editor.lib/src/org/netbeans/editor/BaseDocument.java
@@ -64,6 +64,7 @@
 import javax.swing.undo.UndoableEdit;
 import org.netbeans.api.editor.document.CustomUndoDocument;
 import org.netbeans.api.editor.document.LineDocument;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.settings.SimpleValueNames;
@@ -888,8 +889,8 @@ private void appendContext(StringBuilder sb, int offset) {
 
     public void checkTrailingSpaces(int offset) {
         try {
-            int lineNum = Utilities.getLineOffset(this, offset);
-            int lastEditedLine = lastPositionEditedByTyping != null ? Utilities.getLineOffset(this, lastPositionEditedByTyping.getOffset()) : -1;
+            int lineNum = LineDocumentUtils.getLineIndex(this, offset);
+            int lastEditedLine = lastPositionEditedByTyping != null ? LineDocumentUtils.getLineIndex(this, lastPositionEditedByTyping.getOffset()) : -1;
             if (lastEditedLine != -1 && lastEditedLine != lineNum) {
                 // clear trailing spaces in the last edited line
                 Element root = getDefaultRootElement();
diff --git a/ide/editor.lib/src/org/netbeans/editor/BaseKit.java b/ide/editor.lib/src/org/netbeans/editor/BaseKit.java
index def86eecdd8e..1ebd84416790 100644
--- a/ide/editor.lib/src/org/netbeans/editor/BaseKit.java
+++ b/ide/editor.lib/src/org/netbeans/editor/BaseKit.java
@@ -97,6 +97,7 @@
 import org.netbeans.api.editor.NavigationHistory;
 import org.netbeans.api.editor.caret.CaretMoveContext;
 import org.netbeans.api.editor.caret.MoveCaretsOrigin;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.spi.editor.caret.CaretMoveHandler;
 import org.netbeans.lib.editor.util.swing.PositionRegion;
 import org.netbeans.modules.editor.lib.SettingsConversions;
@@ -1748,11 +1749,11 @@ public void moveCarets(CaretMoveContext context) {
                                                             doc.remove(start, end - start);
                                                             insertTabString(doc, start);
                                                         } else {
-                                                            boolean selectionAtLineStart = Utilities.getRowStart(doc, start) == start;
+                                                            boolean selectionAtLineStart = LineDocumentUtils.getLineStartOffset(doc, start) == start;
                                                             changeBlockIndent(doc, start, end, +1);
                                                             if (selectionAtLineStart) {
                                                                 int newSelectionStartOffset = start;
-                                                                int lineStartOffset = Utilities.getRowStart(doc, start);
+                                                                int lineStartOffset = LineDocumentUtils.getLineStartOffset(doc, start);
                                                                 if (lineStartOffset != newSelectionStartOffset) {
                                                                     context.setDotAndMark(caretInfo,
                                                                         doc.createPosition(lineStartOffset), Position.Bias.Forward,
@@ -1788,7 +1789,7 @@ public void moveCarets(CaretMoveContext context) {
                                                                 changeRowIndent(doc, dotOffset, upperCol > nextTabCol ? upperCol : nextTabCol);
                                                                 // Fix of #32240
                                                                 dotOffset = caretInfo.getDot();
-                                                                Position newDotPos = doc.createPosition(Utilities.getRowEnd(doc, dotOffset));
+                                                                Position newDotPos = doc.createPosition(LineDocumentUtils.getLineEndOffset(doc, dotOffset));
                                                                 context.setDot(caretInfo, newDotPos, Position.Bias.Forward);
                                                             }
                                                         } else { // already chars on the line
@@ -1813,11 +1814,11 @@ public void moveCarets(CaretMoveContext context) {
                                             doc.remove(target.getSelectionStart(), target.getSelectionEnd() - target.getSelectionStart());
                                             insertTabString(doc, target.getSelectionStart());
                                         } else {
-                                            boolean selectionAtLineStart = Utilities.getRowStart(doc, target.getSelectionStart()) == target.getSelectionStart();
+                                            boolean selectionAtLineStart = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart()) == target.getSelectionStart();
                                             changeBlockIndent(doc, target.getSelectionStart(), target.getSelectionEnd(), +1);
                                             if (selectionAtLineStart) {
                                                 int newSelectionStartOffset = target.getSelectionStart();
-                                                int lineStartOffset = Utilities.getRowStart(doc, newSelectionStartOffset);
+                                                int lineStartOffset = LineDocumentUtils.getLineStartOffset(doc, newSelectionStartOffset);
                                                 if (lineStartOffset != newSelectionStartOffset)
                                                 target.select(lineStartOffset, target.getSelectionEnd());
                                             }
@@ -1850,7 +1851,7 @@ public void moveCarets(CaretMoveContext context) {
                                                 changeRowIndent(doc, dotPos, upperCol > nextTabCol ? upperCol : nextTabCol);
                                                 // Fix of #32240
                                                 dotPos = caret.getDot();
-                                                caret.setDot(Utilities.getRowEnd(doc, dotPos));
+                                                caret.setDot(LineDocumentUtils.getLineEndOffset(doc, dotPos));
                                             }
                                         } else { // already chars on the line
                                             insertTabString(doc, dotPos);
@@ -2373,7 +2374,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
                         if (emptySelection && !disableNoSelectionCopy) {
                             Element elem = ((AbstractDocument) target.getDocument()).getParagraphElement(
                                     caretPosition);
-                            if (!Utilities.isRowWhite((BaseDocument) target.getDocument(), elem.getStartOffset())) {
+                            if (!LineDocumentUtils.isLineWhitespace((BaseDocument) target.getDocument(), elem.getStartOffset())) {
                                 target.select(elem.getStartOffset(), elem.getEndOffset());
                             }
                         }
@@ -3412,7 +3413,7 @@ public void moveCarets(CaretMoveContext context) {
                                                     dot = lineStartPos;
                                                 } else { // either to line start or text start
                                                     BaseDocument doc = (BaseDocument) target.getDocument();
-                                                    int textStartPos = Utilities.getRowFirstNonWhite(doc, lineStartPos);
+                                                    int textStartPos = LineDocumentUtils.getLineFirstNonWhitespace(doc, lineStartPos);
                                                     if (textStartPos < 0) { // no text on the line
                                                         textStartPos = Utilities.getRowEnd(target, lineStartPos);
                                                     } else if (textStartPos < lineStartPos) {
@@ -3483,7 +3484,7 @@ public void moveCarets(CaretMoveContext context) {
                             if (homeKeyColumnOne) { // to first column
                                 dot = lineStartPos;
                             } else { // either to line start or text start
-                                int textStartPos = Utilities.getRowFirstNonWhite(((BaseDocument)doc), lineStartPos);
+                                int textStartPos = LineDocumentUtils.getLineFirstNonWhitespace(((BaseDocument)doc), lineStartPos);
                                 if (textStartPos < 0) { // no text on the line
                                     textStartPos = Utilities.getRowEnd(target, lineStartPos);
                                 } else if (textStartPos < lineStartPos) {
@@ -4187,8 +4188,8 @@ static void insertTabString (final BaseDocument doc, final int dotPos) throws Ba
             public void run () {
                 try {
                     // Determine first white char before dotPos
-                    int rsPos = Utilities.getRowStart(doc, dotPos);
-                    int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos);
+                    int rsPos = LineDocumentUtils.getLineStartOffset(doc, dotPos);
+                    int startPos = LineDocumentUtils.getPreviousNonWhitespace(doc, dotPos, rsPos);
                     startPos = (startPos >= 0) ? (startPos + 1) : rsPos;
 
                     int startCol = Utilities.getVisualColumn(doc, startPos);
@@ -4227,11 +4228,11 @@ static void changeRowIndent (final BaseDocument doc, final int pos, final int ne
             public void run () {
                 try {
                     int indent = newIndent < 0 ? 0 : newIndent;
-                    int firstNW = Utilities.getRowFirstNonWhite(doc, pos);
+                    int firstNW = LineDocumentUtils.getLineFirstNonWhitespace(doc, pos);
                     if (firstNW == -1) { // valid first non-blank
-                        firstNW = Utilities.getRowEnd(doc, pos);
+                        firstNW = LineDocumentUtils.getLineEndOffset(doc, pos);
                     }
-                    int replacePos = Utilities.getRowStart(doc, pos);
+                    int replacePos = LineDocumentUtils.getLineStartOffset(doc, pos);
                     int removeLen = firstNW - replacePos;
                     CharSequence removeText = DocumentUtilities.getText(doc, replacePos, removeLen);
                     String newIndentText = IndentUtils.createIndentString(doc, indent);
@@ -4309,11 +4310,11 @@ public void run () {
                         return;
                     }
                     int indentDelta = shiftCnt * shiftWidth;
-                    int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ?
+                    int end = (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) ?
                         endPos - 1 : endPos;
 
-                    int lineStartOffset = Utilities.getRowStart(doc, startPos );
-                    int lineCount = Utilities.getRowCount(doc, startPos, end);
+                    int lineStartOffset = LineDocumentUtils.getLineStartOffset(doc, startPos );
+                    int lineCount = LineDocumentUtils.getLineCount(doc, startPos, end);
                     Integer delta = null;
                     for (int i = lineCount - 1; i >= 0; i--) {
                         int indent = Utilities.getRowIndent(doc, lineStartOffset);
@@ -4342,7 +4343,7 @@ static void shiftLine(BaseDocument doc, int dotPos, boolean right) throws BadLoc
             ind = -ind;
         }
 
-        if (Utilities.isRowWhite(doc, dotPos)) {
+        if (LineDocumentUtils.isLineWhitespace(doc, dotPos)) {
             ind += Utilities.getVisualColumn(doc, dotPos);
         } else {
             ind += Utilities.getRowIndent(doc, dotPos);
@@ -4374,11 +4375,11 @@ public void run () {
                         return;
                     }
                     int indentDelta = right ? shiftWidth : -shiftWidth;
-                    int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ?
+                    int end = (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) ?
                         endPos - 1 : endPos;
 
-                    int lineStartOffset = Utilities.getRowStart(doc, startPos );
-                    int lineCount = Utilities.getRowCount(doc, startPos, end);
+                    int lineStartOffset = LineDocumentUtils.getLineStartOffset(doc, startPos );
+                    int lineCount = LineDocumentUtils.getLineCount(doc, startPos, end);
                     for (int i = lineCount - 1; i >= 0; i--) {
                         int indent = Utilities.getRowIndent(doc, lineStartOffset);
                         int newIndent = (indent == -1) ? 0 : // Zero indent if row is white
diff --git a/ide/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java b/ide/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java
index 06a2e2a86be4..3c005e025c42 100644
--- a/ide/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java
+++ b/ide/editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java
@@ -55,6 +55,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.View;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.Fold;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.fold.FoldHierarchyEvent;
@@ -409,8 +410,8 @@ protected List getPaintInfo(Rectangle clip) throws BadLocat
                 return Collections.emptyList();
             }
             
-            startPos = Utilities.getRowStart(bdoc, startPos);
-            endPos = Utilities.getRowEnd(bdoc, endPos);
+            startPos = LineDocumentUtils.getLineStartOffset(bdoc, startPos);
+            endPos = LineDocumentUtils.getLineEndOffset(bdoc, endPos);
             
             FoldHierarchy hierarchy = FoldHierarchy.get(component);
             hierarchy.lock();
@@ -497,8 +498,8 @@ private boolean traverseForward(Fold f, BaseDocument doc, BaseTextUI btui, int l
             return false;
         }
 
-        int lineStartOffset1 = Utilities.getRowStart(doc, f.getStartOffset());
-        int lineStartOffset2 = Utilities.getRowStart(doc, f.getEndOffset());
+        int lineStartOffset1 = LineDocumentUtils.getLineStartOffset(doc, f.getStartOffset());
+        int lineStartOffset2 = LineDocumentUtils.getLineStartOffset(doc, f.getEndOffset());
         int y1 = btui.getYFromPos(lineStartOffset1);
         int h = btui.getEditorUI().getLineHeight();
         int y2 = btui.getYFromPos(lineStartOffset2);
@@ -642,8 +643,8 @@ private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int
             return false;
         }
 
-        int lineStartOffset1 = Utilities.getRowStart(doc, f.getStartOffset());
-        int lineStartOffset2 = Utilities.getRowStart(doc, f.getEndOffset());
+        int lineStartOffset1 = LineDocumentUtils.getLineStartOffset(doc, f.getStartOffset());
+        int lineStartOffset2 = LineDocumentUtils.getLineStartOffset(doc, f.getEndOffset());
         int h = btui.getEditorUI().getLineHeight();
 
         boolean activeMark = false;
diff --git a/ide/editor.lib/src/org/netbeans/editor/EditorUI.java b/ide/editor.lib/src/org/netbeans/editor/EditorUI.java
index f08865935c4c..59cf3b8cf53c 100644
--- a/ide/editor.lib/src/org/netbeans/editor/EditorUI.java
+++ b/ide/editor.lib/src/org/netbeans/editor/EditorUI.java
@@ -66,6 +66,7 @@
 import org.netbeans.api.editor.settings.SimpleValueNames;
 import org.netbeans.editor.ext.ExtKit;
 import org.netbeans.api.editor.StickyWindowSupport;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.ext.ToolTipSupport;
 import org.netbeans.modules.editor.lib.ColoringMap;
 import org.netbeans.modules.editor.lib.EditorExtPackageAccessor;
@@ -1153,7 +1154,7 @@ public void updateLineNumberWidth(int maxDigitCount) {
             try {
                 if (maxDigitCount <= 0) {
                     BaseDocument doc = getDocument();
-                    int lineCnt = Utilities.getLineOffset(doc, doc.getLength()) + 1;
+                    int lineCnt = LineDocumentUtils.getLineIndex(doc, doc.getLength()) + 1;
                     maxDigitCount = Integer.toString(lineCnt).length();
                 }
 
diff --git a/ide/editor.lib/src/org/netbeans/editor/GlyphGutter.java b/ide/editor.lib/src/org/netbeans/editor/GlyphGutter.java
index 87d5d5608cd4..60fe1c2e34d4 100644
--- a/ide/editor.lib/src/org/netbeans/editor/GlyphGutter.java
+++ b/ide/editor.lib/src/org/netbeans/editor/GlyphGutter.java
@@ -64,6 +64,7 @@
 import javax.swing.text.Element;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.View;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
 import org.netbeans.api.editor.settings.FontColorNames;
@@ -385,7 +386,7 @@ protected int getLineCount() {
             if (document != null) {
                 document.readLock();
                 try {
-                    lineCnt = Utilities.getLineOffset(document, document.getLength()) + 1;
+                    lineCnt = LineDocumentUtils.getLineIndex(document, document.getLength()) + 1;
                 } finally {
                     document.readUnlock();
                 }
@@ -842,7 +843,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 BaseDocument document = eui.getDocument();
                 BaseTextUI textUI = (BaseTextUI)component.getUI();
                 int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                line = Utilities.getLineOffset(document, clickOffset);
+                line = LineDocumentUtils.getLineIndex(document, clickOffset);
             }catch (BadLocationException ble) {
                 LOG.log(Level.WARNING, null, ble);
             }
@@ -938,12 +939,12 @@ private void handleMouseClicked(MouseEvent e) {
                     if (toInvoke != null && toInvoke.isEnabled()){
                         BaseDocument document = eui.getDocument();
                         try {
-                            currentLine = Utilities.getLineOffset(document, eui.getComponent().getCaret().getDot());
+                            currentLine = LineDocumentUtils.getLineIndex(document, eui.getComponent().getCaret().getDot());
                         } catch (BadLocationException ex) {
                             return;
                         }
                         if (line != currentLine) {
-                            int offset = Utilities.getRowStartFromLineOffset(document, line);
+                            int offset = LineDocumentUtils.getLineStartFromIndex(document, line);
                             JumpList.checkAddEntry();
                             eui.getComponent().getCaret().setDot(offset);
                         }
@@ -990,7 +991,7 @@ private void showPopup(MouseEvent e) {
                     offset = annos.getActiveAnnotation(line).getOffset();
                 } else {
                     BaseDocument document = eui.getDocument();
-                    offset = Utilities.getRowStartFromLineOffset(document, line);
+                    offset = LineDocumentUtils.getLineStartFromIndex(document, line);
                 }
                 if (eui.getComponent().getCaret().getDot() != offset)
                     JumpList.checkAddEntry();
@@ -1060,11 +1061,11 @@ private void showPopup(MouseEvent e) {
                         }
                         // Check if the sele
                         // Extend to next line's begining
-                        dragEndOffset = Math.min(Utilities.getRowEnd((BaseDocument) aDoc, lineStartOffset) + 1, aDoc.getLength());
+                        dragEndOffset = Math.min(LineDocumentUtils.getLineEndOffset((BaseDocument) aDoc, lineStartOffset) + 1, aDoc.getLength());
                     } else { // Backward selection
                         // Check if the selection is already reverted i.e. it starts at dragStartOffset's line end
                         if (caret.getMark() == dragStartOffset) {
-                            caret.setDot(Utilities.getRowEnd((BaseDocument)aDoc, dragStartOffset) + 1);
+                            caret.setDot(LineDocumentUtils.getLineEndOffset((BaseDocument)aDoc, dragStartOffset) + 1);
                         }
                         dragEndOffset = lineStartOffset;
                     }
diff --git a/ide/editor.lib/src/org/netbeans/editor/LeafView.java b/ide/editor.lib/src/org/netbeans/editor/LeafView.java
index 3387116bb3cb..bf5746b9cbb3 100644
--- a/ide/editor.lib/src/org/netbeans/editor/LeafView.java
+++ b/ide/editor.lib/src/org/netbeans/editor/LeafView.java
@@ -29,6 +29,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 import javax.swing.event.DocumentEvent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.modules.editor.lib.drawing.DrawContext;
 import org.netbeans.modules.editor.lib.drawing.DrawEngine;
 import org.netbeans.modules.editor.lib.drawing.DrawGraphics;
@@ -152,7 +153,7 @@ protected void paintAreas(Graphics g, int clipY, int clipHeight, int paintAreas)
                 BaseDocument doc = (BaseDocument)getDocument();
                 try {
                     int pos = getPosFromY(clipY + clipHeight - 1);
-                    int endPos = Utilities.getRowEnd(doc, pos);
+                    int endPos = LineDocumentUtils.getLineEndOffset(doc, pos);
                     int baseY = getYFromPos(startPos);
                     DrawEngine.getDrawEngine().draw(
                         new DrawGraphics.GraphicsDG(g),
@@ -218,7 +219,7 @@ protected int getPosFromY(int y) {
 
         int startOffset = getStartOffset();
         int pos;
-        pos = Utilities.getRowStartFromLineOffset(((BaseDocument)getDocument()), line);
+        pos = LineDocumentUtils.getLineStartFromIndex(((BaseDocument)getDocument()), line);
         if (pos == -1) {
             pos = startOffset;
         }
@@ -284,7 +285,7 @@ public int getBaseX(int y) {
     protected int getYFromPos(int pos) throws BadLocationException {
         int relLine = 0;
         try {
-            relLine = Utilities.getLineOffset(((BaseDocument)getDocument()), pos)
+            relLine = LineDocumentUtils.getLineIndex(((BaseDocument)getDocument()), pos)
                       - ((BaseElement)getElement()).getStartMark().getLine();
         } catch (InvalidMarkException e) {
             Utilities.annotateLoggable(e);
@@ -372,7 +373,7 @@ public int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn) {
             int pos = getPosFromY(intY); // first get BOL of target line
             EditorUI editorUI = getEditorUI();
             try {
-                int eolPos = Utilities.getRowEnd((BaseDocument)getDocument(), pos);
+                int eolPos = LineDocumentUtils.getLineEndOffset((BaseDocument)getDocument(), pos);
                 synchronized (viewToModelDG) {
                     viewToModelDG.setTargetX(intX);
                     viewToModelDG.setEOLOffset(eolPos);
diff --git a/ide/editor.lib/src/org/netbeans/editor/StatusBar.java b/ide/editor.lib/src/org/netbeans/editor/StatusBar.java
index 752ad18da5c5..dafa4140c202 100644
--- a/ide/editor.lib/src/org/netbeans/editor/StatusBar.java
+++ b/ide/editor.lib/src/org/netbeans/editor/StatusBar.java
@@ -63,6 +63,7 @@
 import javax.swing.text.AttributeSet;
 import javax.swing.text.BadLocationException;
 import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.FontColorNames;
 import org.netbeans.api.editor.settings.FontColorSettings;
@@ -630,8 +631,8 @@ public void actionPerformed(ActionEvent evt) {
                         if (hasSelection) {
                             try {
                                 //count of selected lines
-                                int lineEnd = Utilities.getLineOffset(doc, component.getSelectionEnd());
-                                int lineStart = Utilities.getLineOffset(doc, component.getSelectionStart());
+                                int lineEnd = LineDocumentUtils.getLineIndex(doc, component.getSelectionEnd());
+                                int lineStart = LineDocumentUtils.getLineIndex(doc, component.getSelectionStart());
                                 s += "/" + (lineEnd - lineStart + 1);
                             } catch (BadLocationException ex) {
                             }
diff --git a/ide/editor.lib/src/org/netbeans/editor/Utilities.java b/ide/editor.lib/src/org/netbeans/editor/Utilities.java
index 874f82e9c491..7e832a3ffc79 100644
--- a/ide/editor.lib/src/org/netbeans/editor/Utilities.java
+++ b/ide/editor.lib/src/org/netbeans/editor/Utilities.java
@@ -193,12 +193,12 @@ static int getVisColFromPos(LineDocument doc, int offset) throws BadLocationExce
     * @param doc document to operate on
     * @param offset position in document where to start searching
     * @return position of the start of the row or -1 for invalid position
-    * @deprecated use {@link LineDocumentUtils}
+    * @deprecated use {@link LineDocumentUtils#getLineStartOffset}
     */
     @Deprecated
     public static int getRowStart(BaseDocument doc, int offset)
     throws BadLocationException {
-        return LineDocumentUtils.getLineStart(doc, offset);
+        return LineDocumentUtils.getLineStartOffset(doc, offset);
     }
 
     /** Get the starting position of the row while providing relative count
@@ -238,7 +238,9 @@ public static int getRowStart(BaseDocument doc, int offset, int lineShift)
     * @param offset position in document anywhere on the line
     * @return position of the first non-white char on the line or -1
     *   if there's no non-white character on that line.
+    * @deprecated use {@link LineDocumentUtils#getLineFirstNonWhitespace}
     */
+    @Deprecated
     public static int getRowFirstNonWhite(BaseDocument doc, int offset)
     throws BadLocationException {
         return LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
@@ -267,7 +269,7 @@ public static int getRowLastNonWhite(BaseDocument doc, int offset)
     */
     public static int getRowIndent(BaseDocument doc, int offset)
     throws BadLocationException {
-        offset = getRowFirstNonWhite(doc, offset);
+        offset = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
         if (offset == -1) {
             return -1;
         }
@@ -287,13 +289,13 @@ public static int getRowIndent(BaseDocument doc, int offset)
     */
     public static int getRowIndent(BaseDocument doc, int offset, boolean downDir)
     throws BadLocationException {
-        int p = getRowFirstNonWhite(doc, offset);
+        int p = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
         if (p == -1) {
             p = getFirstNonWhiteRow(doc, offset, downDir);
             if (p == -1) {
                 return -1; // non-white line not found
             }
-            p = getRowFirstNonWhite(doc, p);
+            p = LineDocumentUtils.getLineFirstNonWhitespace(doc, p);
             if (p == -1) {
                 return -1; // non-white line not found
             }
@@ -328,7 +330,7 @@ public static int getRowEnd(JTextComponent c, int offset)
     @Deprecated
     public static int getRowEnd(BaseDocument doc, int offset)
     throws BadLocationException {
-        return LineDocumentUtils.getLineEnd(doc, offset);
+        return LineDocumentUtils.getLineEndOffset(doc, offset);
     }
     
     private static int findBestSpan(JTextComponent c, int lineBegin, int lineEnd, int x)
@@ -439,7 +441,7 @@ public static int getWordEnd(BaseDocument doc, int offset)
     @Deprecated
     public static int getNextWord(JTextComponent c, int offset)
     throws BadLocationException {
-        int nextWordOffset = getNextWord((BaseDocument)c.getDocument(), offset);
+        int nextWordOffset = LineDocumentUtils.getNextWordStart((BaseDocument)c.getDocument(), offset);
         int nextVisualPosition = -1;
         if (nextWordOffset > 0){
             nextVisualPosition = c.getUI().getNextVisualPositionFrom(c,
@@ -457,7 +459,7 @@ public static int getNextWord(BaseDocument doc, int offset)
     @Deprecated
     public static int getPreviousWord(JTextComponent c, int offset)
     throws BadLocationException {
-        int prevWordOffset = getPreviousWord((BaseDocument)c.getDocument(), offset);
+        int prevWordOffset = LineDocumentUtils.getPreviousWordStart((BaseDocument)c.getDocument(), offset);
         int nextVisualPosition = c.getUI().getNextVisualPositionFrom(c,
                               prevWordOffset, Position.Bias.Forward, javax.swing.SwingConstants.WEST, null);
         if (nextVisualPosition == 0 && prevWordOffset == 0){
@@ -964,8 +966,8 @@ public static int reformat (final BaseDocument doc, final int startOffset, final
      */
     public static void reformatLine(BaseDocument doc, int pos)
     throws BadLocationException {
-        int lineStart = getRowStart(doc, pos);
-        int lineEnd = getRowEnd(doc, pos);
+        int lineStart = LineDocumentUtils.getLineStartOffset(doc, pos);
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, pos);
         reformat(doc, lineStart, lineEnd);
     }
 
@@ -1113,7 +1115,7 @@ public static String debugPosition(BaseDocument doc, int offset, String separato
 
         if (offset >= 0) {
             try {
-                int line = getLineOffset(doc, offset) + 1;
+                int line = LineDocumentUtils.getLineIndex(doc, offset) + 1;
                 int col = getVisualColumn(doc, offset) + 1;
                 ret = String.valueOf(line) + separator + String.valueOf(col); // NOI18N
             } catch (BadLocationException e) {
diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/ExtFinderFactory.java b/ide/editor.lib/src/org/netbeans/editor/ext/ExtFinderFactory.java
index 7859c8479584..739ea8ec0e1e 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ext/ExtFinderFactory.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ext/ExtFinderFactory.java
@@ -20,10 +20,10 @@
 package org.netbeans.editor.ext;
 
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.Analyzer;
 import org.netbeans.editor.FinderFactory;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
 
 /**
 * Various finders are located here.
@@ -50,7 +50,7 @@ public LineFwdFinder() {
         public int adjustStartPos(BaseDocument doc, int startPos) {
             origStartPos = startPos;
             try {
-                return Utilities.getRowStart(doc, startPos);
+                return LineDocumentUtils.getLineStartOffset(doc, startPos);
             } catch (BadLocationException e) {
                 return startPos;
             }
@@ -59,7 +59,7 @@ public int adjustStartPos(BaseDocument doc, int startPos) {
         public int adjustLimitPos(BaseDocument doc, int limitPos) {
             origLimitPos = limitPos;
             try {
-                return Utilities.getRowEnd(doc, limitPos);
+                return LineDocumentUtils.getLineEndOffset(doc, limitPos);
             } catch (BadLocationException e) {
                 return limitPos;
             }
@@ -123,7 +123,7 @@ public LineBwdFinder() {
         public int adjustStartPos(BaseDocument doc, int startPos) {
             origStartPos = startPos;
             try {
-                return Utilities.getRowEnd(doc, startPos);
+                return LineDocumentUtils.getLineEndOffset(doc, startPos);
             } catch (BadLocationException e) {
                 return startPos;
             }
@@ -132,7 +132,7 @@ public int adjustStartPos(BaseDocument doc, int startPos) {
         public int adjustLimitPos(BaseDocument doc, int limitPos) {
             origLimitPos = limitPos;
             try {
-                return Utilities.getRowStart(doc, limitPos);
+                return LineDocumentUtils.getLineStartOffset(doc, limitPos);
             } catch (BadLocationException e) {
                 return limitPos;
             }
@@ -203,7 +203,7 @@ public LineBlocksFinder() {
         public int adjustStartPos(BaseDocument doc, int startPos) {
             origStartPos = startPos;
             try {
-                return Utilities.getRowStart(doc, startPos);
+                return LineDocumentUtils.getLineStartOffset(doc, startPos);
             } catch (BadLocationException e) {
                 return startPos;
             }
@@ -212,7 +212,7 @@ public int adjustStartPos(BaseDocument doc, int startPos) {
         public int adjustLimitPos(BaseDocument doc, int limitPos) {
             origLimitPos = limitPos;
             try {
-                return Utilities.getRowEnd(doc, limitPos);
+                return LineDocumentUtils.getLineEndOffset(doc, limitPos);
             } catch (BadLocationException e) {
                 return limitPos;
             }
diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java b/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java
index e7ffd7a1e53d..e9f03628f096 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ext/ExtKit.java
@@ -48,6 +48,7 @@
 import org.netbeans.api.editor.EditorActionNames;
 import org.netbeans.api.editor.caret.CaretInfo;
 import org.netbeans.api.editor.caret.EditorCaret;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.openide.util.Lookup;
 import org.openide.util.NbBundle;
 
@@ -475,7 +476,7 @@ public GotoAction() {
         *  of the line with the line-number equal to (lineOffset + 1).
         */
         protected int getOffsetFromLine(BaseDocument doc, int lineOffset) {
-            return Utilities.getRowStartFromLineOffset(doc, lineOffset);
+            return LineDocumentUtils.getLineStartFromIndex(doc, lineOffset);
         }
 
         public void actionPerformed(ActionEvent evt, JTextComponent target) {
@@ -905,18 +906,18 @@ public void run () {
                                     if (caretInfo.isSelectionShowing()) {
                                         int start = Math.min(caretInfo.getDot(), caretInfo.getMark());
                                         int end = Math.max(caretInfo.getDot(), caretInfo.getMark());
-                                        startPos = Utilities.getRowStart(doc, start);
+                                        startPos = LineDocumentUtils.getLineStartOffset(doc, start);
                                         endPos = end;
-                                        if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
+                                        if (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) {
                                             endPos--;
                                         }
-                                        endPos = Utilities.getRowEnd(doc, endPos);
+                                        endPos = LineDocumentUtils.getLineEndOffset(doc, endPos);
                                     } else { // selection not visible
-                                        startPos = Utilities.getRowStart(doc, caretInfo.getDot());
-                                        endPos = Utilities.getRowEnd(doc, caretInfo.getDot());
+                                        startPos = LineDocumentUtils.getLineStartOffset(doc, caretInfo.getDot());
+                                        endPos = LineDocumentUtils.getLineEndOffset(doc, caretInfo.getDot());
                                     }
 
-                                    int lineCount = Utilities.getRowCount(doc, startPos, endPos);
+                                    int lineCount = LineDocumentUtils.getLineCount(doc, startPos, endPos);
                                     boolean comment = forceComment != null ? forceComment : !allComments(doc, startPos, lineCount);
 
                                     if (comment) {
@@ -939,18 +940,18 @@ public void run () {
                                 int endPos;
 
                                 if (Utilities.isSelectionShowing(caret)) {
-                                    startPos = Utilities.getRowStart(doc, target.getSelectionStart());
+                                    startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                                     endPos = target.getSelectionEnd();
-                                    if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
+                                    if (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) {
                                         endPos--;
                                     }
-                                    endPos = Utilities.getRowEnd(doc, endPos);
+                                    endPos = LineDocumentUtils.getLineEndOffset(doc, endPos);
                                 } else { // selection not visible
-                                    startPos = Utilities.getRowStart(doc, caret.getDot());
-                                    endPos = Utilities.getRowEnd(doc, caret.getDot());
+                                    startPos = LineDocumentUtils.getLineStartOffset(doc, caret.getDot());
+                                    endPos = LineDocumentUtils.getLineEndOffset(doc, caret.getDot());
                                 }
 
-                                int lineCount = Utilities.getRowCount(doc, startPos, endPos);
+                                int lineCount = LineDocumentUtils.getLineCount(doc, startPos, endPos);
                                 boolean comment = forceComment != null ? forceComment : !allComments(doc, startPos, lineCount);
 
                                 if (comment) {
@@ -970,12 +971,12 @@ public void run () {
         
         private boolean allComments(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
             for (int offset = startOffset; lineCount > 0; lineCount--) {
-                int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
+                int firstNonWhitePos = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
                 if (firstNonWhitePos == -1) {
                     return false;
                 }
                 
-                if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) {
+                if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) {
                     return false;
                 }
                 
@@ -999,11 +1000,11 @@ private void comment(BaseDocument doc, int startOffset, int lineCount) throws Ba
         private void uncomment(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
             for (int offset = startOffset; lineCount > 0; lineCount--) {
                 // Get the first non-whitespace char on the current line
-                int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
+                int firstNonWhitePos = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
 
                 // If there is any, check wheter it's the line-comment-chars and remove them
                 if (firstNonWhitePos != -1) {
-                    if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) {
+                    if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) {
                         CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
                         if (CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
                             doc.remove(firstNonWhitePos, lineCommentStringLen);
diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/ExtSyntaxSupport.java b/ide/editor.lib/src/org/netbeans/editor/ext/ExtSyntaxSupport.java
index 42e801a7da3b..c63298f8149b 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ext/ExtSyntaxSupport.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ext/ExtSyntaxSupport.java
@@ -25,6 +25,7 @@
 import javax.swing.event.DocumentEvent;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.SyntaxSupport;
 import org.netbeans.editor.Utilities;
@@ -251,7 +252,7 @@ public TokenID getTokenID(int offset) throws BadLocationException {
     */
     public int[] getFunctionBlock(int[] identifierBlock) throws BadLocationException {
         if (identifierBlock != null) {
-            int nwPos = Utilities.getFirstNonWhiteFwd(getDocument(), identifierBlock[1]);
+            int nwPos = LineDocumentUtils.getNextNonWhitespace(getDocument(), identifierBlock[1]);
             if ((nwPos >= 0) && (getDocument().getChars(nwPos, 1)[0] == '(')) {
                 return new int[] { identifierBlock[0], nwPos + 1 };
             }
@@ -279,7 +280,7 @@ public boolean isCommentOrWhitespace(int startPos, int endPos)
     */
     public int getRowLastValidChar(int offset)
     throws BadLocationException {
-        return Utilities.getRowLastNonWhite(getDocument(), offset);
+        return LineDocumentUtils.getLineLastNonWhitespace(getDocument(), offset);
     }
 
     /** Does the line contain some valid code besides of possible white space
@@ -287,7 +288,7 @@ public int getRowLastValidChar(int offset)
     */
     public boolean isRowValid(int offset)
     throws BadLocationException {
-        return Utilities.isRowWhite(getDocument(), offset);
+        return LineDocumentUtils.isLineWhitespace(getDocument(), offset);
     }
 
     /** Get the array of token IDs that denote the comments.
diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/GotoDialogSupport.java b/ide/editor.lib/src/org/netbeans/editor/ext/GotoDialogSupport.java
index 5a0439fdfd8b..eedf833a866a 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ext/GotoDialogSupport.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ext/GotoDialogSupport.java
@@ -33,6 +33,7 @@
 import javax.swing.text.Caret;
 import javax.swing.text.JTextComponent;
 import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.BaseKit;
 import org.netbeans.editor.Utilities;
@@ -206,12 +207,12 @@ protected boolean performGoto() {
                 
                 BaseDocument doc = Utilities.getDocument(c);
                 if (doc != null) {
-                    int rowCount = Utilities.getRowCount(doc);
+                    int rowCount = LineDocumentUtils.getLineCount(doc);
                     if (line > rowCount)
                         line = rowCount;
                     
                     // Obtain the offset where to jump
-                    int pos = Utilities.getRowStartFromLineOffset(doc, line - 1);
+                    int pos = LineDocumentUtils.getLineStartFromIndex(doc, line - 1);
                     
                     BaseKit kit = Utilities.getKit(c);
                     if (kit != null) {
diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java b/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
index f5d82b2c807a..1942119d45d5 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
@@ -60,6 +60,7 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.Keymap;
 import javax.swing.text.TextAction;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.BaseKit;
 import org.netbeans.editor.BaseTextUI;
@@ -876,7 +877,7 @@ public String getIdentifierUnderCursor() {
                 int pos = ui.viewToModel(component, lmePoint);
                 if (pos >= 0) {
                     BaseDocument doc = (BaseDocument)component.getDocument();
-                    int eolPos = Utilities.getRowEnd(doc, pos);
+                    int eolPos = LineDocumentUtils.getLineEndOffset(doc, pos);
                     Rectangle eolRect = ui.modelToView(component, eolPos);
                     int lineHeight = extEditorUI.getLineHeight();
                     if (lmePoint.x <= eolRect.x && lmePoint.y <= eolRect.y + lineHeight) {
diff --git a/ide/editor.lib/src/org/netbeans/modules/editor/lib/drawing/DrawEngine.java b/ide/editor.lib/src/org/netbeans/modules/editor/lib/drawing/DrawEngine.java
index 3dbe0f33e61c..98cbae06e1e2 100644
--- a/ide/editor.lib/src/org/netbeans/modules/editor/lib/drawing/DrawEngine.java
+++ b/ide/editor.lib/src/org/netbeans/modules/editor/lib/drawing/DrawEngine.java
@@ -37,6 +37,7 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.Segment;
 import javax.swing.text.View;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.settings.FontColorNames;
 import org.netbeans.editor.Analyzer;
 import org.netbeans.editor.BaseDocument;
@@ -94,7 +95,7 @@ private void initLineNumbering(DrawInfo ctx, EditorUI eui) {
         // create buffer for showing line numbers
         if (ctx.lineNumbering) {
             try {
-                ctx.startLineNumber = Utilities.getLineOffset(ctx.doc, ctx.startOffset) + 1;
+                ctx.startLineNumber = LineDocumentUtils.getLineIndex(ctx.doc, ctx.startOffset) + 1;
             } catch (BadLocationException e) {
                 LOG.log(Level.WARNING, null, e);
             }
@@ -131,7 +132,7 @@ private void initLineNumbering(DrawInfo ctx, EditorUI eui) {
 
             } else { // non-synced line numbering - need to remember line start offsets
                 try {
-                    int endLineNumber = Utilities.getLineOffset(ctx.doc, ctx.endOffset) + 1;
+                    int endLineNumber = LineDocumentUtils.getLineIndex(ctx.doc, ctx.endOffset) + 1;
                     ctx.lineStartOffsets = new int[endLineNumber - ctx.startLineNumber + 2]; // reserve more
                 } catch (BadLocationException e) {
                     LOG.log(Level.WARNING, null, e);
diff --git a/ide/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java b/ide/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java
index eb80c80df717..a772d69dba41 100644
--- a/ide/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java
+++ b/ide/editor.lib2/src/org/netbeans/api/editor/caret/EditorCaret.java
@@ -3164,7 +3164,7 @@ public void mouseDragged(MouseEvent evt) {
 
                         case LINE_SELECTION:
                             if (offset >= mark) { // Selection extends forward
-                                offset = Math.min(LineDocumentUtils.getLineEnd(lineDoc, offset) + 1, c.getDocument().getLength());
+                                offset = Math.min(LineDocumentUtils.getLineEndOffset(lineDoc, offset) + 1, c.getDocument().getLength());
                             } else { // Selection extends backward
                                 offset = LineDocumentUtils.getLineStart(lineDoc, offset);
                             }
diff --git a/ide/editor.search/nbproject/project.xml b/ide/editor.search/nbproject/project.xml
index f7a8842fbcd1..861c4fe91bd7 100644
--- a/ide/editor.search/nbproject/project.xml
+++ b/ide/editor.search/nbproject/project.xml
@@ -51,6 +51,14 @@
                         1.29
                     
                 
+                
+                    org.netbeans.modules.editor.document
+                    
+                    
+                    
+                        1.40
+                    
+                
                 
                     org.netbeans.modules.editor.lib
                     
diff --git a/ide/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java b/ide/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java
index 61ce33ab5299..03e2dac3e694 100755
--- a/ide/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java
+++ b/ide/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java
@@ -45,6 +45,7 @@
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.settings.SimpleValueNames;
 import org.netbeans.api.editor.caret.EditorCaret;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.search.ReplacePattern;
 import org.netbeans.api.search.SearchHistory;
 import org.netbeans.api.search.SearchPattern;
@@ -1091,8 +1092,8 @@ void initBlockSearch(boolean persistanceStatus) {
             if (doc instanceof BaseDocument) {
                 BaseDocument bdoc = (BaseDocument) doc;
                 try {
-                    int startLine = org.netbeans.editor.Utilities.getLineOffset(bdoc, startSelection);
-                    int endLine = org.netbeans.editor.Utilities.getLineOffset(bdoc, endSelection);
+                    int startLine = LineDocumentUtils.getLineIndex(bdoc, startSelection);
+                    int endLine = LineDocumentUtils.getLineIndex(bdoc, endSelection);
                     if (endLine > startLine) {
                         blockSearchVisible = true;
                     }
diff --git a/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedFormatter.java b/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedFormatter.java
index 94757e84ec5a..ca0623258b10 100644
--- a/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedFormatter.java
+++ b/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedFormatter.java
@@ -28,6 +28,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.Position;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.TokenItem;
 import org.netbeans.editor.Utilities;
@@ -79,7 +80,7 @@ protected boolean isWSTag(TokenItem tag){
     }
     
     protected int getIndentForTagParameter(BaseDocument doc, TokenItem tag) throws BadLocationException{
-        int tagStartLine = Utilities.getLineOffset(doc, tag.getOffset());
+        int tagStartLine = LineDocumentUtils.getLineIndex(doc, tag.getOffset());
         TokenItem currentToken = tag.getNext();
         
         /*
@@ -87,12 +88,12 @@ protected int getIndentForTagParameter(BaseDocument doc, TokenItem tag) throws B
          * e.g. 
@@ -347,8 +348,8 @@ protected void enterPressed(JTextComponent txtComponent, int dotPos) throws BadL
                     TokenItem tknOpeningTag = getMatchingOpeningTag(tknPrecedingToken);
                     
                     if (tknOpeningTag != null){
-                        int openingTagLine = Utilities.getLineOffset(doc, tknOpeningTag.getOffset());
-                        int closingTagSymbolLine = Utilities.getLineOffset(doc, dotPos);
+                        int openingTagLine = LineDocumentUtils.getLineIndex(doc, tknOpeningTag.getOffset());
+                        int closingTagSymbolLine = LineDocumentUtils.getLineIndex(doc, dotPos);
                         
                         if(openingTagLine != closingTagSymbolLine){
                             return new int[]{tknPrecedingToken.getOffset(), dotPos};
@@ -399,8 +400,8 @@ protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int
         int initialIndent = 0;
         
         if (line > 0){
-            int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
-            int previousNonWhiteLineEnd = Utilities.getFirstNonWhiteBwd(doc, lineStart);
+            int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, line);
+            int previousNonWhiteLineEnd = LineDocumentUtils.getPreviousNonWhitespace(doc, lineStart);
             
             if (previousNonWhiteLineEnd > 0){
                 initialIndent = Utilities.getRowIndent(doc, previousNonWhiteLineEnd);
@@ -415,9 +416,9 @@ private int getInitialIndentFromNextLine(final BaseDocument doc, final int line)
         // get initial indent from the next line
         int initialIndent = 0;
         
-        int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
-        int lineEnd = Utilities.getRowEnd(doc, lineStart);
-        int nextNonWhiteLineStart = Utilities.getFirstNonWhiteFwd(doc, lineEnd);
+        int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, line);
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, lineStart);
+        int nextNonWhiteLineStart = LineDocumentUtils.getNextNonWhitespace(doc, lineEnd);
         
         if (nextNonWhiteLineStart > 0){
             initialIndent = Utilities.getRowIndent(doc, nextNonWhiteLineStart, true);
@@ -441,7 +442,7 @@ private boolean hasValidSyntaxSupport(BaseDocument doc){
     }
 
     protected static int getNumberOfLines(BaseDocument doc) throws BadLocationException{
-        return Utilities.getLineOffset(doc, doc.getLength() - 1) + 1;
+        return LineDocumentUtils.getLineIndex(doc, doc.getLength() - 1) + 1;
     }
     
     protected TokenItem getNextClosingTag(BaseDocument doc, int offset) throws BadLocationException{
diff --git a/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedLexerFormatter.java b/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedLexerFormatter.java
index ae3e853abe56..9bb16e1390c7 100644
--- a/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedLexerFormatter.java
+++ b/ide/editor.structure/src/org/netbeans/modules/editor/structure/formatting/TagBasedLexerFormatter.java
@@ -28,6 +28,7 @@
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Position;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.LanguagePath;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenHierarchy;
@@ -130,8 +131,8 @@ public void process(Context context) throws BadLocationException{
             //
             // A temporary workaround for issue #178512
             BaseDocument doc = (BaseDocument)context.document();
-            int firstLine = Utilities.getLineOffset(doc, context.startOffset());
-            int lastLine = Utilities.getLineOffset(doc, context.endOffset());
+            int firstLine = LineDocumentUtils.getLineIndex(doc, context.startOffset());
+            int lastLine = LineDocumentUtils.getLineIndex(doc, context.endOffset());
             if (firstLine == lastLine) {
                 enterPressed(context);
             } else {
@@ -240,7 +241,7 @@ protected boolean isWSToken(Token token) {
 
     protected int getIndentForTagParameter(BaseDocument doc, JoinedTokenSequence tokenSequence, int tagOffset) throws BadLocationException {
         int originalOffset = tokenSequence.offset();
-        int tagStartLine = Utilities.getLineOffset(doc, tagOffset);
+        int tagStartLine = LineDocumentUtils.getLineIndex(doc, tagOffset);
         tokenSequence.move(tagOffset);
         Token token;
         int tokenOffset;
@@ -257,11 +258,11 @@ protected int getIndentForTagParameter(BaseDocument doc, JoinedTokenSequence tok
             tokenOffset = tokenSequence.offset();
             boolean isWSToken = isWSToken(token);
             
-            if (thereWasWS && (!isWSToken || tagStartLine != Utilities.getLineOffset(doc, tokenOffset))) {
-                if (!isWSToken && tagStartLine == Utilities.getLineOffset(doc, tokenOffset)) {
+            if (thereWasWS && (!isWSToken || tagStartLine != LineDocumentUtils.getLineIndex(doc, tokenOffset))) {
+                if (!isWSToken && tagStartLine == LineDocumentUtils.getLineIndex(doc, tokenOffset)) {
                     
                     shift = tokenOffset - Utilities.getRowIndent(doc, tokenOffset)
-                            - Utilities.getRowStart(doc, tokenOffset);
+                            - LineDocumentUtils.getLineStartOffset(doc, tokenOffset);
                 }
                 break;
             } else if (isWSToken){
@@ -279,14 +280,14 @@ private boolean calcIndents_processOpeningTag(final BaseDocument doc, final Join
 
         boolean thereAreMoreTokens = true;
         // format content of a tag that spans across multiple lines
-        int firstTagLine = Utilities.getLineOffset(doc, tokenSequence.offset());
+        int firstTagLine = LineDocumentUtils.getLineIndex(doc, tokenSequence.offset());
         int tagEndOffset = getTagEndOffset(tokenSequence, tokenSequence.offset());
         
         if (tagEndOffset == -1){
             return true; // unterminated tag, ignore
         }
         
-        int lastTagLine = Utilities.getLineOffset(doc, tagEndOffset);
+        int lastTagLine = LineDocumentUtils.getLineIndex(doc, tagEndOffset);
 
         TagIndentationData tagData = new TagIndentationData(tagName, lastTagLine);
         unprocessedOpeningTags.add(tagData);
@@ -338,8 +339,8 @@ protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int
         int initialIndent = 0;
 
         if (line > 0) {
-            int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
-            int previousNonWhiteLineEnd = Utilities.getFirstNonWhiteBwd(doc, lineStart);
+            int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, line);
+            int previousNonWhiteLineEnd = LineDocumentUtils.getPreviousNonWhitespace(doc, lineStart);
 
             if (previousNonWhiteLineEnd > 0) {
                 initialIndent = Utilities.getRowIndent(doc, previousNonWhiteLineEnd);
@@ -350,7 +351,7 @@ protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int
     }
 
     protected static int getNumberOfLines(BaseDocument doc) throws BadLocationException {
-        return Utilities.getLineOffset(doc, doc.getLength()) + 1;
+        return LineDocumentUtils.getLineIndex(doc, doc.getLength()) + 1;
     }
 
     protected int getNextClosingTagOffset(JoinedTokenSequence tokenSequence, int offset) throws BadLocationException {
@@ -434,8 +435,8 @@ private TextBounds findTokenSequenceBounds(BaseDocument doc, TokenSequence token
         }
 
         int languageBlockStart = tokenSequence.offset() + whiteSpacePrefixLen;
-        int firstLineOfTheLanguageBlock = Utilities.getLineOffset(doc, languageBlockStart);
-        int lastLineOfTheLanguageBlock = Utilities.getLineOffset(doc, languageBlockEnd);
+        int firstLineOfTheLanguageBlock = LineDocumentUtils.getLineIndex(doc, languageBlockStart);
+        int lastLineOfTheLanguageBlock = LineDocumentUtils.getLineIndex(doc, languageBlockEnd);
         return new TextBounds(absoluteStart, absoluteEnd, languageBlockStart, languageBlockEnd, firstLineOfTheLanguageBlock, lastLineOfTheLanguageBlock);
     }
 
@@ -446,9 +447,9 @@ private void markCurrentLanguageLines(BaseDocument doc, TextBounds languageBound
         
         int firstLineOfTheLanguageBlock = languageBounds.getStartLine();
 
-        int lineStart = Utilities.getRowStartFromLineOffset(doc, firstLineOfTheLanguageBlock);
+        int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, firstLineOfTheLanguageBlock);
 
-        if (Utilities.getFirstNonWhiteFwd(doc, lineStart) < languageBounds.getStartPos()) {
+        if (LineDocumentUtils.getNextNonWhitespace(doc, lineStart) < languageBounds.getStartPos()) {
             firstLineOfTheLanguageBlock++;
         }
 
@@ -462,7 +463,7 @@ protected boolean isTopLevelLanguage(BaseDocument doc) {
     }
     
     protected static int getExistingIndent(BaseDocument doc, int line) throws BadLocationException{
-        int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
+        int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, line);
         return IndentUtils.lineIndent(doc, lineStart);
     }
 
@@ -504,7 +505,7 @@ private void enterPressed() throws BadLocationException{
                     int lineNumber = Utilities.getLineOffset(doc, dotPos);
                     boolean firstRow = false;
                     
-                    if (Utilities.getRowStart(doc, origDotPos) == origDotPos){
+                    if (LineDocumentUtils.getLineStartOffset(doc, origDotPos) == origDotPos){
                         newIndent = getExistingIndent(doc, lineNumber);
                         firstRow = true;
                     } else if (lineNumber > 0){
@@ -576,13 +577,13 @@ public boolean handleSmartEnter(Context context) throws BadLocationException {
         wasSmartEnter = isSmartEnter(doc, dotPos);
 
         if (wasSmartEnter) {
-            int line = Utilities.getLineOffset(doc, dotPos);
+            int line = LineDocumentUtils.getLineIndex(doc, dotPos);
             assert line > 0;
             int baseIndent = getExistingIndent(doc, line - 1);
             doc.insertString(dotPos, "\n", null); //NOI18N
             Position position = doc.createPosition(dotPos);
-            context.modifyIndent(Utilities.getRowStartFromLineOffset(doc, line), baseIndent + doc.getShiftWidth());
-            context.modifyIndent(Utilities.getRowStartFromLineOffset(doc, line + 1), baseIndent);
+            context.modifyIndent(LineDocumentUtils.getLineStartFromIndex(doc, line), baseIndent + doc.getShiftWidth());
+            context.modifyIndent(LineDocumentUtils.getLineStartFromIndex(doc, line + 1), baseIndent);
             context.setCaretOffset(position.getOffset());
         }
 
@@ -681,8 +682,8 @@ private void reformat() throws BadLocationException{
             // PASS 1: Calculate EmbeddingType and AbsoluteIndentLevel 
             // (determined by the tags of the current language) for each line
             
-            int firstRefBlockLine = Utilities.getLineOffset(doc, startOffset);
-            int lastRefBlockLine = Utilities.getLineOffset(doc, endOffset);
+            int firstRefBlockLine = LineDocumentUtils.getLineIndex(doc, startOffset);
+            int lastRefBlockLine = LineDocumentUtils.getLineIndex(doc, endOffset);
             int firstUnformattableLine = -1;
 
             EmbeddingType embeddingType[] = new EmbeddingType[transferData.getNumberOfLines()];
@@ -721,7 +722,7 @@ private void reformat() throws BadLocationException{
                             thereAreMoreTokens &= calcIndents_processOpeningTag(doc,
                                     tokenSequence, tagName, unprocessedOpeningTags, indentsWithinTags);
                         } else {
-                            int tagLine = Utilities.getLineOffset(doc, tokenSequence.offset());
+                            int tagLine = LineDocumentUtils.getLineIndex(doc, tokenSequence.offset());
                             
                             calcIndents_processClosingTag(tagName, tagLine, transferData,
                                     unprocessedOpeningTags, matchedOpeningTags);
@@ -734,14 +735,14 @@ private void reformat() throws BadLocationException{
                             || isUnformattableToken(tokenSequence, tokenSequence.offset());
 
                     if (wasPreviousTokenUnformattable && firstUnformattableLine == -1) {
-                        firstUnformattableLine = Utilities.getLineOffset(doc, tokenSequence.offset());
+                        firstUnformattableLine = LineDocumentUtils.getLineIndex(doc, tokenSequence.offset());
                     }
 
                     // detect the end of an unformattable block; mark it
                     if (firstUnformattableLine > -1 && (!wasPreviousTokenUnformattable || !thereAreMoreTokens)) {
 
                         int lastUnformattableLine = thereAreMoreTokens ?
-                            Utilities.getLineOffset(doc, tokenSequence.offset() - 1) : transferData.getNumberOfLines() - 1;
+                            LineDocumentUtils.getLineIndex(doc, tokenSequence.offset() - 1) : transferData.getNumberOfLines() - 1;
 
                         for (int i = firstUnformattableLine + 1; i < lastUnformattableLine; i++) {
                             transferData.setNonFormattable(i);
@@ -752,13 +753,13 @@ private void reformat() throws BadLocationException{
                     
                     // Mark blocks of embedded language
                     if (tokenSequence.embedded() != null && !isWSToken(tokenSequence.token())) {
-                        int firstLineOfEmbeddedBlock = Utilities.getLineOffset(doc, tokenSequence.offset());
+                        int firstLineOfEmbeddedBlock = LineDocumentUtils.getLineIndex(doc, tokenSequence.offset());
 
-                        int lastLineOfEmbeddedBlock = Utilities.getLineOffset(doc,
+                        int lastLineOfEmbeddedBlock = LineDocumentUtils.getLineIndex(doc,
                                 tokenSequence.offset() + getTxtLengthWithoutWhitespaceSuffix(tokenSequence.token().text()));
 
-                        if (Utilities.getFirstNonWhiteFwd(doc, Utilities.getRowStartFromLineOffset(doc,
-                                firstLineOfEmbeddedBlock)) < Utilities.getFirstNonWhiteFwd(doc, tokenSequence.offset())) {
+                        if (LineDocumentUtils.getNextNonWhitespace(doc, LineDocumentUtils.getLineStartFromIndex(doc,
+                                firstLineOfEmbeddedBlock)) < LineDocumentUtils.getNextNonWhitespace(doc, tokenSequence.offset())) {
 
                             firstLineOfEmbeddedBlock++;
                         }
@@ -856,7 +857,7 @@ private void reformat() throws BadLocationException{
             // PASS 4: apply line indents
             
             for (int line = firstRefBlockLine; line <= lastRefBlockLine; line++) {
-                int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
+                int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, line);
                 int newIndent = newIndents[line] + lineBeforeSelectionBias;
                 context.modifyIndent(lineStart, newIndent > 0 ? newIndent : 0);
             }
@@ -867,7 +868,7 @@ private void reformat() throws BadLocationException{
                 StringBuilder buff = new StringBuilder();
 
                 for (int i = 0; i < transferData.getNumberOfLines(); i++) {
-                    int lineStart = Utilities.getRowStartFromLineOffset(doc, i);
+                    int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, i);
 
                     char formattingTypeSymbol = 0;
                     
@@ -884,7 +885,7 @@ private void reformat() throws BadLocationException{
                     char formattingRange = (i >= firstRefBlockLine && i <= lastRefBlockLine) 
                             ? '*' : ' ';
 
-                    buff.append(i + ":" + formattingRange + ":" + indentLevels[i] + ":" + formattingTypeSymbol + ":" + doc.getText(lineStart, Utilities.getRowEnd(doc, lineStart) - lineStart) + ".\n"); //NOI18N
+                    buff.append(i + ":" + formattingRange + ":" + indentLevels[i] + ":" + formattingTypeSymbol + ":" + doc.getText(lineStart, LineDocumentUtils.getLineEndOffset(doc, lineStart) - lineStart) + ".\n"); //NOI18N
                 }
 
                 buff.append("\n-------------\n"); //NOI18N
diff --git a/ide/editor/src/org/netbeans/modules/editor/NbEditorDocument.java b/ide/editor/src/org/netbeans/modules/editor/NbEditorDocument.java
index c9c0003461cc..95eff2a364b0 100644
--- a/ide/editor/src/org/netbeans/modules/editor/NbEditorDocument.java
+++ b/ide/editor/src/org/netbeans/modules/editor/NbEditorDocument.java
@@ -43,6 +43,7 @@
 import org.netbeans.editor.BaseDocument;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.settings.SimpleValueNames;
 import org.netbeans.editor.AnnotationDesc;
@@ -343,7 +344,7 @@ public int getLine() {
             }
 
             try {
-                lastKnownLine = Utilities.getLineOffset(doc, offset);
+                lastKnownLine = LineDocumentUtils.getLineIndex(doc, offset);
                 lastKnownOffset = offset;
             } catch (BadLocationException e) {
                 lastKnownOffset = -1;
diff --git a/ide/editor/src/org/netbeans/modules/editor/NbEditorUtilities.java b/ide/editor/src/org/netbeans/modules/editor/NbEditorUtilities.java
index 780abbffe557..ab5f378c76db 100644
--- a/ide/editor/src/org/netbeans/modules/editor/NbEditorUtilities.java
+++ b/ide/editor/src/org/netbeans/modules/editor/NbEditorUtilities.java
@@ -45,6 +45,7 @@
 import org.openide.util.NbBundle;
 import java.util.MissingResourceException;
 import java.awt.Toolkit;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.lib.editor.util.swing.DocumentUtilities;
 import org.openide.filesystems.FileObject;
 
@@ -135,7 +136,7 @@ public static Line getLine(BaseDocument doc, int offset, boolean original) {
                 Line.Set lineSet = lc.getLineSet();
                 if (lineSet != null) {
                     try {
-                        int lineOffset = Utilities.getLineOffset(doc, offset);
+                        int lineOffset = LineDocumentUtils.getLineIndex(doc, offset);
                         return original
                                ? lineSet.getOriginal(lineOffset)
                                : lineSet.getCurrent(lineOffset);
diff --git a/ide/editor/src/org/netbeans/modules/editor/NbToolTip.java b/ide/editor/src/org/netbeans/modules/editor/NbToolTip.java
index afa8ec61bafa..87c98876f5dc 100644
--- a/ide/editor/src/org/netbeans/modules/editor/NbToolTip.java
+++ b/ide/editor/src/org/netbeans/modules/editor/NbToolTip.java
@@ -53,6 +53,7 @@
 import javax.swing.JEditorPane;
 import javax.swing.text.AttributeSet;
 import javax.swing.text.EditorKit;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
 import org.netbeans.editor.EditorUI;
 import org.netbeans.lib.editor.hyperlink.HyperlinkOperation;
@@ -227,8 +228,8 @@ private void buildTip(JTextComponent target) {
 
                                 if (annos != null) {
                                     // Get the annotations stuff
-                                    int line = Utilities.getLineOffset(doc, offset);
-                                    int col = offset - Utilities.getRowStartFromLineOffset(doc, line);
+                                    int line = LineDocumentUtils.getLineIndex(doc, offset);
+                                    int col = offset - LineDocumentUtils.getLineStartFromIndex(doc, line);
                                     Line.Set ls = ec.getLineSet();
                                     if (ls != null) {
                                         Line l = ls.getCurrent(line);
@@ -279,7 +280,7 @@ private static int getOffsetForPoint(Point p, JTextComponent c, BaseDocument doc
             int relY = p.y - r.y;
             if (eui != null && relY < eui.getLineHeight()) {
                 // Check that p is on a line with text before its EOL.
-                if (offset < Utilities.getRowEnd(doc, offset)) {
+                if (offset < LineDocumentUtils.getLineEndOffset(doc, offset)) {
                     return offset;
                 }
             }
diff --git a/ide/editor/src/org/netbeans/modules/editor/url/HighlightURLs.java b/ide/editor/src/org/netbeans/modules/editor/url/HighlightURLs.java
index 37fade65c98c..7618859cc526 100644
--- a/ide/editor/src/org/netbeans/modules/editor/url/HighlightURLs.java
+++ b/ide/editor/src/org/netbeans/modules/editor/url/HighlightURLs.java
@@ -30,6 +30,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.Position;
 import javax.swing.text.Position.Bias;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
@@ -167,9 +168,9 @@ public void run() {
                         
                         if (endOffset == (-1)) return;
                         
-                        startOffset = Utilities.getRowStart(doc, startOffset);
+                        startOffset = LineDocumentUtils.getLineStartOffset(doc, startOffset);
                         endOffset = Math.min(doc.getLength(), endOffset);
-                        endOffset = Utilities.getRowEnd(doc, endOffset);
+                        endOffset = LineDocumentUtils.getLineEndOffset(doc, endOffset);
 
                         text[0] = DocumentUtilities.getText(doc, startOffset, endOffset - startOffset);
                         version[0] = DocumentUtilities.getDocumentVersion(doc);
diff --git a/ide/editor/src/org/netbeans/modules/editor/url/HyperlinkImpl.java b/ide/editor/src/org/netbeans/modules/editor/url/HyperlinkImpl.java
index fa093a23de96..7744c5c2e519 100644
--- a/ide/editor/src/org/netbeans/modules/editor/url/HyperlinkImpl.java
+++ b/ide/editor/src/org/netbeans/modules/editor/url/HyperlinkImpl.java
@@ -39,6 +39,7 @@
 import org.netbeans.api.actions.Editable;
 import org.netbeans.api.actions.Openable;
 import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lsp.HyperlinkLocation;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
@@ -86,8 +87,8 @@ public int[] getHyperlinkSpan(Document doc, int offset, HyperlinkType type) {
 
         try {
             BaseDocument bdoc = (BaseDocument) doc;
-            int start = Utilities.getRowStart(bdoc, offset);
-            int end = Utilities.getRowEnd(bdoc, offset);
+            int start = LineDocumentUtils.getLineStartOffset(bdoc, offset);
+            int end = LineDocumentUtils.getLineEndOffset(bdoc, offset);
 
             for (int[] span : Parser.recognizeURLs(DocumentUtilities.getText(doc, start, end - start))) {
                 if (span[0] + start <= offset && offset <= span[1] + start) {
diff --git a/ide/git/src/org/netbeans/modules/git/ui/blame/AnnotationBar.java b/ide/git/src/org/netbeans/modules/git/ui/blame/AnnotationBar.java
index 01b7cb2f1ab2..5624791b0910 100644
--- a/ide/git/src/org/netbeans/modules/git/ui/blame/AnnotationBar.java
+++ b/ide/git/src/org/netbeans/modules/git/ui/blame/AnnotationBar.java
@@ -45,6 +45,7 @@
 import java.text.SimpleDateFormat;
 import java.util.logging.Logger;
 import org.netbeans.api.diff.Difference;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
@@ -870,7 +871,7 @@ public void run() {
         int line = -1;
         int offset = carett.getDot();
         try {
-            line = Utilities.getLineOffset(doc, offset);
+            line = LineDocumentUtils.getLineIndex(doc, offset);
         } catch (BadLocationException ex) {
             LOG.log(Level.SEVERE, "Can not get line for caret at offset ", offset); // NOI18N
             clearRecentFeedback();
@@ -1253,7 +1254,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 JTextComponent component = editorUI.getComponent();
                 BaseTextUI textUI = (BaseTextUI)component.getUI();
                 int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                line = Utilities.getLineOffset(doc, clickOffset);
+                line = LineDocumentUtils.getLineIndex(doc, clickOffset);
             }catch (BadLocationException ble){
             }
         }
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java
index 758d88205056..8e398768dfce 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java
@@ -209,7 +209,7 @@ private void handleEdits(int offset, int length, boolean inserted) {
 
             int lineStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
             if (lineStart == -1) {
-                lineStart = LineDocumentUtils.getLineStart(doc, offset);
+                lineStart = LineDocumentUtils.getLineStartOffset(doc, offset);
             }
             List positions = lastPositions;
             if (positions != null) {
@@ -315,7 +315,7 @@ private Highlights(long version, int startOffset, int endOffset, FileCoverageDet
             try {
                 int lineStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, startOffsetBoundary);
                 if (lineStart == -1) {
-                    lineStart = LineDocumentUtils.getLineStart(doc, startOffsetBoundary);
+                    lineStart = LineDocumentUtils.getLineStartOffset(doc, startOffsetBoundary);
                     index = findPositionIndex(positions, lineStart);
                     if (index < 0) {
                         index = -index;
@@ -329,14 +329,14 @@ private boolean _moveNext() {
             for (; index < positions.size(); index++) {
                 Position pos = positions.get(index);
                 int offset = pos.getOffset();
-                offset = LineDocumentUtils.getLineStart(doc, offset);
-                if (offset > endOffsetBoundary) {
-                    break;
-                }
-                if (offset >= startOffsetBoundary) {
-                    startOffset = offset;
-                    try {
-                        endOffset = LineDocumentUtils.getLineEnd(doc, offset);
+                try {
+                    offset = LineDocumentUtils.getLineStartOffset(doc, offset);
+                    if (offset > endOffsetBoundary) {
+                        break;
+                    }
+                    if (offset >= startOffsetBoundary) {
+                        startOffset = offset;
+                        endOffset = LineDocumentUtils.getLineEndOffset(doc, offset);
                         if (endOffset < doc.getLength()) {
                             endOffset++; // Include end of line
                         }
@@ -357,11 +357,11 @@ private boolean _moveNext() {
                             default:
                                 throw new IllegalArgumentException();
                         }
-                    } catch (BadLocationException ex) {
-                        Exceptions.printStackTrace(ex);
+                        index++;
+                        return true;
                     }
-                    index++;
-                    return true;
+                } catch (BadLocationException ex) {
+                    Exceptions.printStackTrace(ex);
                 }
             }
 
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/HtmlExternalDropHandler.java b/ide/html.editor/src/org/netbeans/modules/html/editor/HtmlExternalDropHandler.java
index 09a7b3bc3d86..0a6a64cd66e9 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/HtmlExternalDropHandler.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/HtmlExternalDropHandler.java
@@ -40,11 +40,11 @@
 import javax.swing.JEditorPane;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.html.lexer.HTMLTokenId;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
 import org.netbeans.modules.csl.api.DataLoadersBridge;
 import org.netbeans.modules.editor.indent.api.Indent;
 import org.netbeans.modules.web.common.api.WebUtils;
@@ -100,7 +100,7 @@ public void run() {
     private int getLineEndOffset(JEditorPane pane, Point location) {
         int offset = pane.getUI().viewToModel(pane, location);
         try {
-            return Utilities.getRowEnd((BaseDocument) pane.getDocument(), offset);
+            return LineDocumentUtils.getLineEndOffset((BaseDocument) pane.getDocument(), offset);
         } catch (BadLocationException ex) {
             //highly unlikely to happen
             Exceptions.printStackTrace(ex);
@@ -260,15 +260,15 @@ public boolean handleDrop(DropTargetDropEvent e) {
                 public void run() {
                     try {
                         int ofs = offset;
-                        if (!Utilities.isRowWhite(document, ofs)) {
+                        if (!LineDocumentUtils.isLineWhitespace(document, ofs)) {
                             document.insertString(ofs, "\n", null);
                             ofs++;
                         }
                         document.insertString(ofs, sb.toString(), null);
 
                         //reformat the line
-                        final int from = Utilities.getRowStart(document, ofs);
-                        final int to = Utilities.getRowEnd(document, ofs + sb.length());
+                        final int from = LineDocumentUtils.getLineStartOffset(document, ofs);
+                        final int to = LineDocumentUtils.getLineEndOffset(document, ofs + sb.length());
 
                         indent.reindent(from, to);
 
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/api/completion/HtmlCompletionItem.java b/ide/html.editor/src/org/netbeans/modules/html/editor/api/completion/HtmlCompletionItem.java
index d763ee0fff94..278b5d75db14 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/api/completion/HtmlCompletionItem.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/api/completion/HtmlCompletionItem.java
@@ -42,6 +42,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
 import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.modules.html.editor.lib.api.model.HtmlTagAttribute;
 import org.netbeans.modules.html.editor.HtmlPreferences;
 import org.netbeans.modules.html.editor.javadoc.HelpManager;
@@ -267,8 +268,8 @@ void reindent(JTextComponent component) {
                 @Override
                 public void run() {
                     try {
-                        int startOffset = Utilities.getRowStart(doc, dotPos);
-                        int endOffset = Utilities.getRowEnd(doc, dotPos);
+                        int startOffset = LineDocumentUtils.getLineStartOffset(doc, dotPos);
+                        int endOffset = LineDocumentUtils.getLineEndOffset(doc, dotPos);
                         indent.reindent(startOffset, endOffset);
                     } catch (BadLocationException ex) {
                         //ignore
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/codegen/LoremIpsumGenerator.java b/ide/html.editor/src/org/netbeans/modules/html/editor/codegen/LoremIpsumGenerator.java
index 9b804e76e738..d18f5d991c72 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/codegen/LoremIpsumGenerator.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/codegen/LoremIpsumGenerator.java
@@ -26,10 +26,8 @@
 import javax.swing.JComponent;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
-import org.netbeans.api.editor.EditorUtilities;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
-import org.netbeans.modules.editor.indent.api.IndentUtils;
 import org.netbeans.modules.editor.indent.api.Reformat;
 import org.netbeans.spi.editor.codegen.CodeGenerator;
 import org.openide.DialogDescriptor;
@@ -104,7 +102,7 @@ static void insertLoremIpsumText(final BaseDocument document, final List
                 public void run() {
                     try {
                         StringBuilder litext = getLoremIpsumText(paragraphs, tag);
-                        if(!Utilities.isRowWhite(document, offset)) {
+                        if(!LineDocumentUtils.isLineWhitespace(document, offset)) {
                             //generate the li text at a new line if the current one is not empty
                             litext.insert(0, '\n');
                         }
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/coloring/EmbeddingHighlightsContainer.java b/ide/html.editor/src/org/netbeans/modules/html/editor/coloring/EmbeddingHighlightsContainer.java
index 846e10273107..ee8de2eb1850 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/coloring/EmbeddingHighlightsContainer.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/coloring/EmbeddingHighlightsContainer.java
@@ -30,6 +30,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyleConstants;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.AttributesUtilities;
 import org.netbeans.api.editor.settings.FontColorSettings;
@@ -221,17 +222,17 @@ private boolean _moveNext() {
                                         endOffset = eTokenSequence.offset() + eTokenSequence.token().length();
                                     } while (eTokenSequence.moveNext());
                                     realEndOffset = endOffset > realEndOffset ? endOffset : realEndOffset + 1;
-                                    int startLO = Utilities.getLineOffset((BaseDocument) document, startOffset);
-                                    int endLO = Utilities.getLineOffset((BaseDocument) document, endOffset);
+                                    int startLO = LineDocumentUtils.getLineIndex((BaseDocument) document, startOffset);
+                                    int endLO = LineDocumentUtils.getLineIndex((BaseDocument) document, endOffset);
                                     if (startLO != endLO) {
                                         //not just one line block - test boundaries
-                                        if ((Utilities.getFirstNonWhiteBwd((BaseDocument) document, Utilities.getRowEnd((BaseDocument) document, startOffset)) + 1) == startOffset) {
+                                        if ((LineDocumentUtils.getPreviousNonWhitespace((BaseDocument) document, LineDocumentUtils.getLineEndOffset((BaseDocument) document, startOffset)) + 1) == startOffset) {
                                             //just  tag on the first line -> move start to next line
-                                            startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, startLO + 1);
+                                            startOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, startLO + 1);
                                         }
-                                        if (Utilities.getFirstNonWhiteFwd((BaseDocument) document, Utilities.getRowStartFromLineOffset((BaseDocument) document, endLO)) == endOffset) {
+                                        if (LineDocumentUtils.getNextNonWhitespace((BaseDocument) document, LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, endLO)) == endOffset) {
                                             //just  tag on the last line -> move block end to previous line end
-                                            endOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, endLO);
+                                            endOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, endLO);
                                         }
                                     }
 
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/completion/HtmlCompletionProvider.java b/ide/html.editor/src/org/netbeans/modules/html/editor/completion/HtmlCompletionProvider.java
index 8f38113c4588..bcffed074503 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/completion/HtmlCompletionProvider.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/completion/HtmlCompletionProvider.java
@@ -30,6 +30,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
 import org.netbeans.api.editor.completion.Completion;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.html.lexer.HTMLTokenId;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenHierarchy;
@@ -215,7 +216,7 @@ protected void doQuery(CompletionResultSet resultSet, Document doc, int caretOff
                         return;
                     }
                         try {
-                            int rowEnd = Utilities.getRowEnd((BaseDocument)doc, caretOffset);
+                            int rowEnd = LineDocumentUtils.getLineEndOffset((BaseDocument)doc, caretOffset);
                             final String documentText = doc.getText(result.getAnchor(), rowEnd - result.getAnchor());
 
                             // Go through result items and select completionItem 
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/indent/HtmlIndenter.java b/ide/html.editor/src/org/netbeans/modules/html/editor/indent/HtmlIndenter.java
index 3a4cff27b390..abce8a76d365 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/indent/HtmlIndenter.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/indent/HtmlIndenter.java
@@ -34,6 +34,7 @@
 import org.netbeans.modules.web.indent.api.support.MarkupAbstractIndenter;
 import java.util.Set;
 import java.util.TreeSet;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.html.lexer.HTMLTokenId;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.editor.Utilities;
@@ -224,7 +225,7 @@ protected int getPreservedLineInitialIndentation(JoinedTokenSequenceput the section at the beginning of the next line
-                                            int newPos = Utilities.getRowEnd(doc, appendOffset.get()) + 1;
+                                            int newPos = LineDocumentUtils.getLineEndOffset(doc, appendOffset.get()) + 1;
                                             appendOffset.set(newPos);
                                         } else {
                                             //put right after the open curly bracket
@@ -561,7 +562,7 @@ private static int getPreviousLineIndent(final Document doc, final int insertOff
             public void run() {
                 try {
                     //find last nonwhite line indent
-                    int firstNonWhiteBw = Utilities.getFirstNonWhiteBwd((BaseDocument) doc, insertOffset);
+                    int firstNonWhiteBw = LineDocumentUtils.getPreviousNonWhitespace((BaseDocument) doc, insertOffset);
                     //get the line indent
                     ret.set(firstNonWhiteBw == -1 ? 0 : Utilities.getRowIndent((BaseDocument) doc, firstNonWhiteBw));
                 } catch (BadLocationException ex) {
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/refactoring/WhereUsedElement.java b/ide/html.editor/src/org/netbeans/modules/html/editor/refactoring/WhereUsedElement.java
index 63c5f2d6a128..cf96c7fd7556 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/refactoring/WhereUsedElement.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/refactoring/WhereUsedElement.java
@@ -22,6 +22,7 @@
 import java.util.Collections;
 import javax.swing.Icon;
 import javax.swing.text.Position.Bias;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 import org.netbeans.modules.csl.api.ElementKind;
@@ -122,16 +123,16 @@ public static WhereUsedElement create(FileObject fileObject, Entry entry, Elemen
             // for for example find subclasses (using a singly dummy FileInfo) I need
             // to read it here instead
             content = bdoc.getText(0, bdoc.getLength());
-            sta = Utilities.getRowFirstNonWhite(bdoc, start);
+            sta = LineDocumentUtils.getLineFirstNonWhitespace(bdoc, start);
 
             if (sta == -1) {
-                sta = Utilities.getRowStart(bdoc, start);
+                sta = LineDocumentUtils.getLineStartOffset(bdoc, start);
             }
 
-            en = Utilities.getRowLastNonWhite(bdoc, start);
+            en = LineDocumentUtils.getLineLastNonWhitespace(bdoc, start);
 
             if (en == -1) {
-                en = Utilities.getRowEnd(bdoc, start);
+                en = LineDocumentUtils.getLineEndOffset(bdoc, start);
             } else {
                 // Last nonwhite - left side of the last char, not inclusive
                 en++;
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedBreakInterceptor.java b/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedBreakInterceptor.java
index c7645dc7e512..c20b603307f6 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedBreakInterceptor.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedBreakInterceptor.java
@@ -20,6 +20,7 @@
 
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Position;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
 import org.netbeans.api.html.lexer.HTMLTokenId;
@@ -86,8 +87,8 @@ public void insert(MutableContext context) throws BadLocationException {
             //reformat workaround -- the preferred 
             //context.setText("\n\n", 1, 1, 0, 2);
             //won't work as the reformatter will not reformat the line with the closing tag
-            int from = Utilities.getRowStart(doc, offset);
-            int to = Utilities.getRowEnd(doc, offset);
+            int from = LineDocumentUtils.getLineStartOffset(doc, offset);
+            int to = LineDocumentUtils.getLineEndOffset(doc, offset);
             reformat = new Position[]{doc.createPosition(from), doc.createPosition(to)};
         }
     }
diff --git a/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedTextInterceptor.java b/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedTextInterceptor.java
index 376480f1c634..63fdbfc84263 100644
--- a/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedTextInterceptor.java
+++ b/ide/html.editor/src/org/netbeans/modules/html/editor/typinghooks/HtmlTypedTextInterceptor.java
@@ -26,6 +26,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.Position;
 import org.netbeans.api.editor.completion.Completion;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
 import org.netbeans.api.editor.mimelookup.MimeRegistrations;
@@ -152,8 +153,8 @@ private static void indentLineAfterTagClosingSymbol(MutableContext context) {
                 //since the code runs under document atomic lock, we cannot lock the
                 //indentation infrastructure directly. Instead of that create a new
                 //AWT task and post it for later execution.
-                final Position from = doc.createPosition(Utilities.getRowStart(doc, offset));
-                final Position to = doc.createPosition(Utilities.getRowEnd(doc, offset));
+                final Position from = doc.createPosition(LineDocumentUtils.getLineStartOffset(doc, offset));
+                final Position to = doc.createPosition(LineDocumentUtils.getLineEndOffset(doc, offset));
 
                 Runnable r = new Runnable() {
                     @Override
diff --git a/ide/languages.toml/src/org/netbeans/modules/languages/toml/TomlTypedTextInterceptor.java b/ide/languages.toml/src/org/netbeans/modules/languages/toml/TomlTypedTextInterceptor.java
index 511de08a8b05..785c8aac93b9 100644
--- a/ide/languages.toml/src/org/netbeans/modules/languages/toml/TomlTypedTextInterceptor.java
+++ b/ide/languages.toml/src/org/netbeans/modules/languages/toml/TomlTypedTextInterceptor.java
@@ -140,7 +140,7 @@ private static boolean isInMultilineString(Context context){
     private static int quotesInLine(Context context, char quote) throws BadLocationException {
         LineDocument doc = (LineDocument) context.getDocument();
         int lineStart = LineDocumentUtils.getLineStart(doc, context.getOffset());
-        int lineEnd = LineDocumentUtils.getLineEnd(doc, context.getOffset());
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, context.getOffset());
         char[] line = doc.getText(lineStart, lineEnd - lineStart).toCharArray();
 
         int quotes = 0;
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/EmbeddedSectionsHighlighting.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/EmbeddedSectionsHighlighting.java
index b01e5e91a44d..9e9292e35fc4 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/EmbeddedSectionsHighlighting.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/EmbeddedSectionsHighlighting.java
@@ -177,7 +177,7 @@ public boolean moveNext() {
                                 if (startLine != endLine) {
                                     // multiline scriplet section
                                     // adjust the sections start to the beginning of the firts line
-                                    int firstLineStartOffset = LineDocumentUtils.getLineStart((BaseDocument)document, startLine);
+                                    int firstLineStartOffset = LineDocumentUtils.getLineStartOffset((BaseDocument)document, startLine);
                                     if (firstLineStartOffset < sectionStart - delimiterSize
                                             && isWhitespace(document, firstLineStartOffset, sectionStart - delimiterSize)) // always preceeded by the delimiter
                                     {
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/InsertTabAction.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/InsertTabAction.java
index 2e84ffb38f5a..48c100ca6f29 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/InsertTabAction.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/InsertTabAction.java
@@ -83,14 +83,14 @@ public void run() {
         }
 
         private void tryReplaceTab() throws BadLocationException {
-            int rowFirstNonWhite = Utilities.getRowFirstNonWhite(baseDocument, caretOffset);
+            int rowFirstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(baseDocument, caretOffset);
             if (shouldBeReplaced(rowFirstNonWhite, caretOffset)) {
                 replaceTab();
             }
         }
 
         private void replaceTab() throws BadLocationException {
-            final int rowStart = LineDocumentUtils.getLineStart(baseDocument, caretOffset);
+            final int rowStart = LineDocumentUtils.getLineStartOffset(baseDocument, caretOffset);
             assert caretOffset >= rowStart : "Caret: " + caretOffset + " rowStart: " + rowStart;
             final String indentString = baseDocument.getText(rowStart, caretOffset - rowStart);
             if (indentString.contains(TAB_CHARACTER)) {
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlKeystrokeHandler.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlKeystrokeHandler.java
index 4005df2c73fd..564a9bad5488 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlKeystrokeHandler.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlKeystrokeHandler.java
@@ -133,8 +133,8 @@ public boolean beforeCharInserted(Document document, int caretOffset, JTextCompo
                 caret.setDot(send + 2);
                 return true;
             }
-            int lineStart = LineDocumentUtils.getLineStart(doc, dotPos);
-            int lineEnd = LineDocumentUtils.getLineEnd(doc, dotPos);
+            int lineStart = LineDocumentUtils.getLineStartOffset(doc, dotPos);
+            int lineEnd = LineDocumentUtils.getLineEndOffset(doc, dotPos);
             char[] line = doc.getChars(lineStart, lineEnd - lineStart);
 
             int quotes = 0;
@@ -171,7 +171,7 @@ public boolean beforeCharInserted(Document document, int caretOffset, JTextCompo
                     Token token = ts.token();
                     if (token.id() == YamlTokenId.TEXT && doc.getText(dotPos - 1, 1).charAt(0) == '<') {
                         // See if there's anything ahead
-                        int first = LineDocumentUtils.getNextNonWhitespace(doc, dotPos, LineDocumentUtils.getLineEnd(doc, dotPos));
+                        int first = LineDocumentUtils.getNextNonWhitespace(doc, dotPos, LineDocumentUtils.getLineEndOffset(doc, dotPos));
                         if (first == -1) {
                             doc.insertString(dotPos, "%%>", null); // NOI18N
                             caret.setDot(dotPos + 1);
@@ -189,7 +189,7 @@ public boolean beforeCharInserted(Document document, int caretOffset, JTextCompo
                             }
                         } else if (tokenText.endsWith("<")) {
                             // See if there's anything ahead
-                            int first = LineDocumentUtils.getNextNonWhitespace(doc, dotPos, LineDocumentUtils.getLineEnd(doc, dotPos));
+                            int first = LineDocumentUtils.getNextNonWhitespace(doc, dotPos, LineDocumentUtils.getLineEndOffset(doc, dotPos));
                             if (first == -1) {
                                 doc.insertString(dotPos, "%%>", null); // NOI18N
                                 caret.setDot(dotPos + 1);
@@ -279,8 +279,8 @@ public int beforeBreak(Document document, int offset, JTextComponent target) thr
         // Basically, use the same indent as the current line, unless the caret is immediately preceeded by a ":" (possibly with whitespace
         // in between)
 
-        int lineBegin = LineDocumentUtils.getLineStart(doc, offset);
-        int lineEnd = LineDocumentUtils.getLineEnd(doc, offset);
+        int lineBegin = LineDocumentUtils.getLineStartOffset(doc, offset);
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, offset);
 
         if (lineBegin == offset && lineEnd == offset) {
             // Pressed return on a blank newline - do nothing
@@ -368,11 +368,11 @@ public int getNextWordOffset(Document doc, int caretOffset, boolean reverse) {
 
     public static int getLineIndent(BaseDocument doc, int offset) {
         try {
-            int start = LineDocumentUtils.getLineStart(doc, offset);
+            int start = LineDocumentUtils.getLineStartOffset(doc, offset);
             int end;
 
             if (LineDocumentUtils.isLineWhitespace(doc, start)) {
-                end = LineDocumentUtils.getLineEnd(doc, offset);
+                end = LineDocumentUtils.getLineEndOffset(doc, offset);
             } else {
                 end = LineDocumentUtils.getLineFirstNonWhitespace(doc, start);
             }
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java
index 8237d8332941..7e17ec09c488 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java
@@ -25,6 +25,7 @@
 import java.util.Map;
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 import org.netbeans.modules.csl.api.OffsetRange;
@@ -78,8 +79,8 @@ private void addBlocks(BaseDocument doc, CharSequence text, List co
         int docLength = doc == null ? text.length() : doc.getLength();
         int begin = Math.min((int) item.getPosition(), docLength);
         int end = Math.min((int) item.getEndPosition(), docLength);
-        int firstRowEnd = doc == null ? GsfUtilities.getRowEnd(text, begin) : Utilities.getRowEnd(doc, begin);
-        int lastRowEnd = doc == null ? GsfUtilities.getRowEnd(text, end) : Utilities.getRowEnd(doc, end);
+        int firstRowEnd = doc == null ? GsfUtilities.getRowEnd(text, begin) : LineDocumentUtils.getLineEndOffset(doc, begin);
+        int lastRowEnd = doc == null ? GsfUtilities.getRowEnd(text, end) : LineDocumentUtils.getLineEndOffset(doc, end);
         if (begin < end && firstRowEnd != lastRowEnd) {
             codeblocks.add(new OffsetRange(firstRowEnd, end));
         } else {
diff --git a/ide/languages/src/org/netbeans/modules/languages/features/CodeCommentAction.java b/ide/languages/src/org/netbeans/modules/languages/features/CodeCommentAction.java
index 31549f9b8093..851d7c46215d 100644
--- a/ide/languages/src/org/netbeans/modules/languages/features/CodeCommentAction.java
+++ b/ide/languages/src/org/netbeans/modules/languages/features/CodeCommentAction.java
@@ -26,6 +26,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Caret;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.languages.LanguageDefinitionNotFoundException;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
@@ -48,6 +49,7 @@ public CodeCommentAction() {
         super(""); // NOI18N
     }
 
+    @Override
     public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
         if (target != null) {
             if (!target.isEditable() || !target.isEnabled()) {
@@ -63,14 +65,14 @@ public void actionPerformed (final ActionEvent evt, final JTextComponent target)
             final TokenSequence ts = th.tokenSequence();
             try {
                 if (caret.isSelectionVisible()) {
-                    final int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
+                    final int startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                     final int endPos = target.getSelectionEnd();
                     doc.runAtomicAsUser (new Runnable () {
                         public void run () {
                             try {
-                                int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ?
+                                int end = (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) ?
                                     endPos-1 : endPos;
-                                int lineCnt = Utilities.getRowCount(doc, startPos, end);
+                                int lineCnt = LineDocumentUtils.getLineCount(doc, startPos, end);
                                 List mimeTypes = new ArrayList<>(lineCnt);
                                 int pos = startPos;
                                 for (int x = lineCnt ; x > 0; x--) {
@@ -89,15 +91,13 @@ public void run () {
                         }
                     });
                 } else { // selection not visible
-                    final int pos = Utilities.getRowStart(doc, target.getSelectionStart());
+                    final int pos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                     final String mt = getRealMimeType(ts, pos);
-                    doc.runAtomicAsUser (new Runnable () {
-                        public void run () {
-                            try {
-                                modifyLine(doc, mt, pos);
-                            } catch (BadLocationException e) {
-                                target.getToolkit().beep();
-                            }
+                    doc.runAtomicAsUser (() -> {
+                        try {
+                            modifyLine(doc, mt, pos);
+                        } catch (BadLocationException e) {
+                            target.getToolkit().beep();
                         }
                     });
                 }
@@ -134,7 +134,7 @@ private void modifyLine(BaseDocument doc, String mimeType, int offset) throws Ba
             }
             String suffix = (String) feature.getValue("suffix"); // NOI18N
             if (suffix != null) {
-                int end = Utilities.getRowEnd(doc, offset);
+                int end = LineDocumentUtils.getLineEndOffset(doc, offset);
                 doc.insertString(end, suffix, null);
             }
             doc.insertString(offset, prefix, null);
diff --git a/ide/languages/src/org/netbeans/modules/languages/features/CodeUncommentAction.java b/ide/languages/src/org/netbeans/modules/languages/features/CodeUncommentAction.java
index e95b36de32be..68e99991e237 100644
--- a/ide/languages/src/org/netbeans/modules/languages/features/CodeUncommentAction.java
+++ b/ide/languages/src/org/netbeans/modules/languages/features/CodeUncommentAction.java
@@ -26,6 +26,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Caret;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.languages.LanguageDefinitionNotFoundException;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
@@ -48,6 +49,7 @@ public CodeUncommentAction() {
         super(""); // NOI18N
     }
     
+    @Override
     public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
         if (target != null) {
             if (!target.isEditable() || !target.isEnabled()) {
@@ -63,14 +65,14 @@ public void actionPerformed (final ActionEvent evt, final JTextComponent target)
             final TokenSequence ts = th.tokenSequence();
             try {
                 if (caret.isSelectionVisible()) {
-                    final int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
+                    final int startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                     final int endPos = target.getSelectionEnd();
                     doc.runAtomicAsUser (new Runnable () {
                         public void run () {
                             try {
-                                int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ?
+                                int end = (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) ?
                                     endPos - 1 : endPos;
-                                int lineCnt = Utilities.getRowCount(doc, startPos, end);
+                                int lineCnt = LineDocumentUtils.getLineCount(doc, startPos, end);
                                 List mimeTypes = new ArrayList<>(lineCnt);
                                 int pos = startPos;
                                 for (int x = lineCnt ; x > 0; x--) {
@@ -89,15 +91,13 @@ public void run () {
                         }
                     });
                 } else { // selection not visible
-                    final int pos = Utilities.getRowStart(doc, target.getSelectionStart());
+                    final int pos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                     final String mt = getRealMimeType(ts, pos);
-                    doc.runAtomicAsUser (new Runnable () {
-                        public void run () {
-                            try {
-                                modifyLine(doc, mt, pos);
-                            } catch (BadLocationException e) {
-                                target.getToolkit().beep();
-                            }
+                    doc.runAtomicAsUser (() -> {
+                        try {
+                            modifyLine(doc, mt, pos);
+                        } catch (BadLocationException e) {
+                            target.getToolkit().beep();
                         }
                     });
                 }
@@ -134,10 +134,10 @@ private void modifyLine(BaseDocument doc, String mimeType, int offset) throws Ba
             }
             String suffix = (String) feature.getValue("suffix"); // NOI18N
             if (suffix != null) {
-                int lastNonWhitePos = Utilities.getRowLastNonWhite(doc, offset);
+                int lastNonWhitePos = LineDocumentUtils.getLineLastNonWhitespace(doc, offset);
                 if (lastNonWhitePos != -1) {
                     int commentLen = suffix.length();
-                    if (lastNonWhitePos - Utilities.getRowStart(doc, offset) >= commentLen) {
+                    if (lastNonWhitePos - LineDocumentUtils.getLineStartOffset(doc, offset) >= commentLen) {
                         CharSequence maybeLineComment = DocumentUtilities.getText(doc, lastNonWhitePos - commentLen + 1, commentLen);
                         if (CharSequenceUtilities.textEquals(maybeLineComment, suffix)) {
                             doc.remove(lastNonWhitePos - commentLen + 1, commentLen);
@@ -145,10 +145,10 @@ private void modifyLine(BaseDocument doc, String mimeType, int offset) throws Ba
                     }
                 }
             }
-            int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
+            int firstNonWhitePos = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
             if (firstNonWhitePos != -1) {
                 int commentLen = prefix.length();
-                if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= prefix.length()) {
+                if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos >= prefix.length()) {
                     CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, commentLen);
                     if (CharSequenceUtilities.textEquals(maybeLineComment, prefix)) {
                         doc.remove(firstNonWhitePos, commentLen);
diff --git a/ide/languages/src/org/netbeans/modules/languages/features/LanguagesFoldManager.java b/ide/languages/src/org/netbeans/modules/languages/features/LanguagesFoldManager.java
index b4eefba9417a..5adf63e5b8ca 100644
--- a/ide/languages/src/org/netbeans/modules/languages/features/LanguagesFoldManager.java
+++ b/ide/languages/src/org/netbeans/modules/languages/features/LanguagesFoldManager.java
@@ -32,6 +32,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.BadLocationException;
 import javax.swing.event.DocumentEvent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 
 import org.netbeans.api.editor.fold.FoldUtilities;
 import org.netbeans.editor.Utilities;
@@ -248,7 +249,7 @@ public void run () {
                     while(genItr.hasNext()) {
                         FoldItem fi = (FoldItem)genItr.next();
                         //do not add more newborns with the same lineoffset
-                        int fiLineOffset = Utilities.getLineOffset((BaseDocument)doc, fi.start);
+                        int fiLineOffset = LineDocumentUtils.getLineIndex((BaseDocument)doc, fi.start);
                         FoldItem found = (FoldItem)newbornsLinesCache.get(Integer.valueOf(fiLineOffset));
                         if(found != null) {
                             //figure out whether the new element is a descendant of the already added one
@@ -310,7 +311,7 @@ public void run () {
                             zombies.add(f);
                         } else {
                             //store the fold lineoffset 2 fold mapping
-                            int lineoffset = Utilities.getLineOffset((BaseDocument)doc, f.getStartOffset());
+                            int lineoffset = LineDocumentUtils.getLineIndex((BaseDocument)doc, f.getStartOffset());
                             linesToFoldsCache.put(Integer.valueOf(lineoffset), f);
                         }
         //                }
@@ -323,7 +324,7 @@ public void run () {
                     HashSet newbornsToRemove = new HashSet();
                     while(newbornsItr.hasNext()) {
                         FoldItem fi = (FoldItem)newbornsItr.next();
-                        Fold existing = (Fold)linesToFoldsCache.get(Integer.valueOf(Utilities.getLineOffset((BaseDocument)doc, fi.start)));
+                        Fold existing = (Fold)linesToFoldsCache.get(Integer.valueOf(LineDocumentUtils.getLineIndex((BaseDocument)doc, fi.start)));
                         if(existing != null) {
                             //test if the fold is my descendant
                             if(existing.getEndOffset() < fi.end) {
diff --git a/ide/languages/src/org/netbeans/modules/languages/features/MarkOccurrencesSupport.java b/ide/languages/src/org/netbeans/modules/languages/features/MarkOccurrencesSupport.java
index f420bc8fc29d..15c292894f46 100644
--- a/ide/languages/src/org/netbeans/modules/languages/features/MarkOccurrencesSupport.java
+++ b/ide/languages/src/org/netbeans/modules/languages/features/MarkOccurrencesSupport.java
@@ -38,6 +38,7 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyleConstants;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 
 import org.netbeans.api.languages.ASTItem;
 import org.netbeans.api.languages.ASTNode;
@@ -120,7 +121,7 @@ public void run () {
                             continue;
                         }
                         highlights.add (h);
-                        int lineNumber = Utilities.getLineOffset(doc, i.getOffset());
+                        int lineNumber = LineDocumentUtils.getLineIndex(doc, i.getOffset());
                         if (!lines.contains(lineNumber)) {
                             LanguagesAnnotation la = new LanguagesAnnotation (
                                 "Usage",
diff --git a/ide/languages/src/org/netbeans/modules/languages/features/ToggleCommentAction.java b/ide/languages/src/org/netbeans/modules/languages/features/ToggleCommentAction.java
index e7f14df9b2d8..e2024e0bf199 100644
--- a/ide/languages/src/org/netbeans/modules/languages/features/ToggleCommentAction.java
+++ b/ide/languages/src/org/netbeans/modules/languages/features/ToggleCommentAction.java
@@ -26,6 +26,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Caret;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.languages.LanguageDefinitionNotFoundException;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
@@ -66,12 +67,12 @@ public void actionPerformed (final ActionEvent evt, final JTextComponent target)
                 public void run () {
                     try {
                         if (caret.isSelectionVisible()) {
-                            int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
+                            int startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                             int endPos = target.getSelectionEnd();
-                            if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
+                            if (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) {
                                 endPos--;
                             }
-                            int lineCnt = Utilities.getRowCount(doc, startPos, endPos);
+                            int lineCnt = LineDocumentUtils.getLineCount(doc, startPos, endPos);
                             List mimeTypes = new ArrayList<>(lineCnt);
                             int pos = startPos;
                             boolean commented = isCommented;
@@ -92,7 +93,7 @@ public void run () {
                                 pos = Utilities.getRowStart(doc, pos, 1);
                             }
                         } else { // selection not visible
-                            int pos = Utilities.getRowStart(doc, target.getSelectionStart());
+                            int pos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                             String mt = getRealMimeType(ts, pos);
                             if (isCommentedLine(doc, mt, pos)) {
                                 uncommentLine(doc, mt, pos);
@@ -135,7 +136,7 @@ private void commentLine(BaseDocument doc, String mimeType, int offset) throws B
             }
             String suffix = (String) feature.getValue("suffix"); // NOI18N
             if (suffix != null) {
-                int end = Utilities.getRowEnd(doc, offset);
+                int end = LineDocumentUtils.getLineEndOffset(doc, offset);
                 doc.insertString(end, suffix, null);
             }
             doc.insertString(offset, prefix, null);
@@ -156,10 +157,10 @@ private void uncommentLine(BaseDocument doc, String mimeType, int offset) throws
             }
             String suffix = (String) feature.getValue("suffix"); // NOI18N
             if (suffix != null) {
-                int lastNonWhitePos = Utilities.getRowLastNonWhite(doc, offset);
+                int lastNonWhitePos = LineDocumentUtils.getLineLastNonWhitespace(doc, offset);
                 if (lastNonWhitePos != -1) {
                     int commentLen = suffix.length();
-                    if (lastNonWhitePos - Utilities.getRowStart(doc, offset) >= commentLen) {
+                    if (lastNonWhitePos - LineDocumentUtils.getLineStartOffset(doc, offset) >= commentLen) {
                         CharSequence maybeLineComment = DocumentUtilities.getText(doc, lastNonWhitePos - commentLen + 1, commentLen);
                         if (CharSequenceUtilities.textEquals(maybeLineComment, suffix)) {
                             doc.remove(lastNonWhitePos - commentLen + 1, commentLen);
@@ -167,10 +168,10 @@ private void uncommentLine(BaseDocument doc, String mimeType, int offset) throws
                     }
                 }
             }
-            int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
+            int firstNonWhitePos = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
             if (firstNonWhitePos != -1) {
                 int commentLen = prefix.length();
-                if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= prefix.length()) {
+                if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos >= prefix.length()) {
                     CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, commentLen);
                     if (CharSequenceUtilities.textEquals(maybeLineComment, prefix)) {
                         doc.remove(firstNonWhitePos, commentLen);
@@ -196,10 +197,10 @@ private boolean isCommentedLine(BaseDocument doc, String mimeType, int offset) t
             }
             String suffix = (String) feature.getValue("suffix"); // NOI18N
             if (suffix != null) {
-                int lastNonWhitePos = Utilities.getRowLastNonWhite(doc, offset);
+                int lastNonWhitePos = LineDocumentUtils.getLineLastNonWhitespace(doc, offset);
                 if (lastNonWhitePos != -1) {
                     int commentLen = suffix.length();
-                    if (lastNonWhitePos - Utilities.getRowStart(doc, offset) >= commentLen) {
+                    if (lastNonWhitePos - LineDocumentUtils.getLineStartOffset(doc, offset) >= commentLen) {
                         CharSequence maybeLineComment = DocumentUtilities.getText(doc, lastNonWhitePos - commentLen + 1, commentLen);
                         if (CharSequenceUtilities.textEquals(maybeLineComment, suffix)) {
                             suffixCommentOk = true;
@@ -209,10 +210,10 @@ private boolean isCommentedLine(BaseDocument doc, String mimeType, int offset) t
             } else {
                 suffixCommentOk = true;
             }
-            int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
+            int firstNonWhitePos = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
             if (firstNonWhitePos != -1) {
                 int commentLen = prefix.length();
-                if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= prefix.length()) {
+                if (LineDocumentUtils.getLineEndOffset(doc, firstNonWhitePos) - firstNonWhitePos >= prefix.length()) {
                     CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, commentLen);
                     if (CharSequenceUtilities.textEquals(maybeLineComment, prefix)) {
                         prefixCommentOk = true;
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java
index 7bd4b2b8abda..b797a92ab6d4 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java
@@ -99,7 +99,7 @@ public static int getOffset(Document doc, Position pos) {
     public static int getEndCharacter(Document doc, int line) {
         int start = LineDocumentUtils.getLineStartFromIndex((LineDocument) doc, line);
         try {
-            return LineDocumentUtils.getLineEnd((LineDocument) doc, start) - start;
+            return LineDocumentUtils.getLineEndOffset((LineDocument) doc, start) - start;
         } catch (BadLocationException ex) {
             Exceptions.printStackTrace(ex);
         }
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotationBar.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotationBar.java
index 203b41b9415a..ecdedd2ef33e 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotationBar.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/annotate/AnnotationBar.java
@@ -73,6 +73,7 @@
 import javax.swing.text.StyledDocument;
 import javax.swing.text.View;
 import org.netbeans.api.diff.Difference;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
@@ -840,7 +841,7 @@ public void run() {
         int line = -1;
         int offset = carett.getDot();
         try {
-            line = Utilities.getLineOffset(doc, offset);
+            line = LineDocumentUtils.getLineIndex(doc, offset);
         } catch (BadLocationException ex) {
             Mercurial.LOG.log(Level.SEVERE, "Can not get line for caret at offset ", offset); // NOI18N
             clearRecentFeedback();
@@ -1213,7 +1214,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 JTextComponent component = editorUI.getComponent();
                 BaseTextUI textUI = (BaseTextUI)component.getUI();
                 int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                line = Utilities.getLineOffset(doc, clickOffset);
+                line = LineDocumentUtils.getLineIndex(doc, clickOffset);
             }catch (BadLocationException ble){
             }
         }
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 a72ba7da49d8..a06925676236 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
@@ -25,8 +25,8 @@
 import java.util.logging.Logger;
 import javax.swing.event.ChangeListener;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
 import org.netbeans.modules.spellchecker.spi.language.TokenList;
 import org.openide.ErrorManager;
 
@@ -54,7 +54,7 @@ public void setStartOffset(int offset) {
         currentStartOffset = (-1);
         this.ignoreBefore = offset;
         try {
-            this.nextSearchOffset = Utilities.getRowStart(doc, offset);
+            this.nextSearchOffset = LineDocumentUtils.getLineStartOffset(doc, offset);
         } catch (BadLocationException ex) {
             Logger.getLogger(AbstractTokenList.class.getName()).log(Level.FINE, null, ex);
             this.nextSearchOffset = offset;
diff --git a/ide/spellchecker.bindings.properties/src/org/netbeans/modules/spellchecker/bindings/properties/AbstractTokenList.java b/ide/spellchecker.bindings.properties/src/org/netbeans/modules/spellchecker/bindings/properties/AbstractTokenList.java
index 0dae0149b3de..7a2b7b595a03 100644
--- a/ide/spellchecker.bindings.properties/src/org/netbeans/modules/spellchecker/bindings/properties/AbstractTokenList.java
+++ b/ide/spellchecker.bindings.properties/src/org/netbeans/modules/spellchecker/bindings/properties/AbstractTokenList.java
@@ -25,10 +25,10 @@
 import java.util.logging.Logger;
 import javax.swing.event.ChangeListener;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.SyntaxSupport;
-import org.netbeans.editor.Utilities;
 import org.netbeans.modules.spellchecker.spi.language.TokenList;
 import org.openide.ErrorManager;
 
@@ -55,7 +55,7 @@ public void setStartOffset (int offset) {
         currentStartOffset = (-1);
         this.ignoreBefore = offset;
         try {
-            this.nextSearchOffset = Utilities.getRowStart (doc, offset);
+            this.nextSearchOffset = LineDocumentUtils.getLineStartOffset(doc, offset);
         } catch (BadLocationException ex) {
             Logger.getLogger (AbstractTokenList.class.getName ()).log (Level.FINE, null, ex);
             this.nextSearchOffset = offset;
diff --git a/ide/spellchecker/nbproject/project.xml b/ide/spellchecker/nbproject/project.xml
index 87ffbdd48413..d777f2158dfc 100644
--- a/ide/spellchecker/nbproject/project.xml
+++ b/ide/spellchecker/nbproject/project.xml
@@ -52,6 +52,14 @@
                         1.6.1
                     
                 
+                
+                    org.netbeans.modules.editor.document
+                    
+                    
+                    
+                        1.40
+                    
+                
                 
                     org.netbeans.modules.editor.lib
                     
diff --git a/ide/spellchecker/src/org/netbeans/modules/spellchecker/completion/WordCompletion.java b/ide/spellchecker/src/org/netbeans/modules/spellchecker/completion/WordCompletion.java
index 710175738122..af3c2adbbab0 100644
--- a/ide/spellchecker/src/org/netbeans/modules/spellchecker/completion/WordCompletion.java
+++ b/ide/spellchecker/src/org/netbeans/modules/spellchecker/completion/WordCompletion.java
@@ -21,9 +21,9 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
 import org.netbeans.modules.spellchecker.ComponentPeer;
 import org.netbeans.modules.spellchecker.spi.dictionary.Dictionary;
 import org.netbeans.modules.spellchecker.spi.dictionary.ValidityType;
@@ -71,7 +71,7 @@ protected void query(CompletionResultSet resultSet, Document document, final int
                 document.render(new Runnable() {
                     public void run() {
                         try {
-                            int lineStart = Utilities.getRowStart(bdoc, caretOffset);
+                            int lineStart = LineDocumentUtils.getLineStartOffset(bdoc, caretOffset);
                             
                             l.setStartOffset(lineStart);
                             
diff --git a/ide/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/MethodChooser.java b/ide/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/MethodChooser.java
index 32f8f998ca26..7c6ab6fbe5c5 100644
--- a/ide/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/MethodChooser.java
+++ b/ide/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/MethodChooser.java
@@ -42,6 +42,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.StyleConstants;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.BaseCaret;
@@ -215,8 +216,8 @@ public boolean showUI() {
             maxOffs = Math.max(segments[x].getEndOffset(), maxOffs);
         }
         try {
-            startLine = Utilities.getLineOffset((BaseDocument)doc, minOffs) + 1;
-            endLine = Utilities.getLineOffset((BaseDocument)doc, maxOffs) + 1;
+            startLine = LineDocumentUtils.getLineIndex((BaseDocument)doc, minOffs) + 1;
+            endLine = LineDocumentUtils.getLineIndex((BaseDocument)doc, maxOffs) + 1;
         } catch (BadLocationException e) {
         }
         if (SwingUtilities.isEventDispatchThread()) {
@@ -681,7 +682,7 @@ public void mouseClicked(MouseEvent e) {
                 }
             }
             try {
-                int line = Utilities.getLineOffset((BaseDocument) doc, position) + 1;
+                int line = LineDocumentUtils.getLineIndex((BaseDocument) doc, position) + 1;
                 if (line < startLine || line > endLine) {
                     releaseUI(false);
                     return;
diff --git a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java
index 6d9e78b8a41e..002ee2714e86 100644
--- a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java
+++ b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java
@@ -62,12 +62,12 @@
 import javax.swing.text.Position;
 import javax.swing.text.StyledDocument;
 import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.AttributesUtilities;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
 import org.netbeans.api.editor.settings.FontColorSettings;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
 import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
 import org.netbeans.lib.editor.util.swing.DocumentUtilities;
 import org.netbeans.spi.editor.highlighting.HighlightAttributeValue;
@@ -407,7 +407,7 @@ private synchronized void setComponents(Set newComponents) {
 
     public synchronized void insertUpdate(DocumentEvent e) {
         try {
-            int offset = Utilities.getRowStart(doc, e.getOffset());
+            int offset = LineDocumentUtils.getLineStartOffset(doc, e.getOffset());
 
             Set modifiedLines = new HashSet();
 
@@ -421,7 +421,7 @@ public synchronized void insertUpdate(DocumentEvent e) {
             if (line == null)
                 return ;
 
-            int endOffset = Utilities.getRowEnd(doc, e.getOffset() + e.getLength());
+            int endOffset = LineDocumentUtils.getLineEndOffset(doc, e.getOffset() + e.getLength());
 
             if (endOffset < line.getOffset())
                 return;
@@ -431,7 +431,7 @@ public synchronized void insertUpdate(DocumentEvent e) {
             //make sure the highlights are removed even for multi-line inserts:
             try {
                 int rowStart = e.getOffset();
-                int rowEnd = Utilities.getRowEnd(doc, e.getOffset() + e.getLength());
+                int rowEnd = LineDocumentUtils.getLineEndOffset(doc, e.getOffset() + e.getLength());
 
                 getBag(doc).removeHighlights(rowStart, rowEnd, false);
             } catch (BadLocationException ex) {
@@ -453,7 +453,7 @@ public synchronized void removeUpdate(DocumentEvent e) {
         try {
             Position current = null;
             int index = -1;
-            int startOffset = Utilities.getRowStart(doc, e.getOffset());
+            int startOffset = LineDocumentUtils.getLineStartOffset(doc, e.getOffset());
 
             while (current == null) {
                 index = findPositionGE(startOffset);
@@ -472,7 +472,7 @@ public synchronized void removeUpdate(DocumentEvent e) {
                 return;
             }
 
-            int endOffset = Utilities.getRowEnd(doc, e.getOffset());
+            int endOffset = LineDocumentUtils.getLineEndOffset(doc, e.getOffset());
 
             if (endOffset < current.getOffset())
                 return;
@@ -625,8 +625,8 @@ public void run() {
                         if (start < 0) start = 0;
                         if (end < 0) end = 0;
 
-                        int startLine = Utilities.getRowStart(doc, start);
-                        int endLine = Utilities.getRowEnd(doc, end) + 1;
+                        int startLine = LineDocumentUtils.getLineStartOffset(doc, start);
+                        int endLine = LineDocumentUtils.getLineEndOffset(doc, end) + 1;
 
                         int index = findPositionGE(startLine);
 
@@ -850,9 +850,9 @@ void updateHighlightsOnLine(Position line) throws IOException {
     static void updateHighlightsOnLine(OffsetsBag bag, BaseDocument doc, Position line, List errorDescriptions) throws IOException {
         try {
             int rowStart = line.getOffset();
-            int rowEnd = Utilities.getRowEnd(doc, rowStart);
-            int rowHighlightStart = Utilities.getRowFirstNonWhite(doc, rowStart);
-            int rowHighlightEnd = Utilities.getRowLastNonWhite(doc, rowStart) + 1;
+            int rowEnd = LineDocumentUtils.getLineEndOffset(doc, rowStart);
+            int rowHighlightStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowStart);
+            int rowHighlightEnd = LineDocumentUtils.getLineLastNonWhitespace(doc, rowStart) + 1;
 
             if (rowStart <= rowEnd) {
                 bag.removeHighlights(rowStart, rowEnd, false);
@@ -1200,7 +1200,7 @@ private synchronized int findPositionGE(int offset) {
     private synchronized Position getPosition(int lineNumber, boolean create) throws BadLocationException {
         try {
             while (true) {
-                int lineStart = Utilities.getRowStartFromLineOffset(doc, lineNumber);
+                int lineStart = LineDocumentUtils.getLineStartFromIndex(doc, lineNumber);
                 if (lineStart < 0) {
                     Element lineRoot = doc.getDefaultRootElement();
                     int lineElementCount = lineRoot.getElementCount();
@@ -1294,7 +1294,7 @@ public void run() {
                         return ;
                     }
 
-                    Position pos = getPosition(Utilities.getLineOffset(doc, offset), true);
+                    Position pos = getPosition(LineDocumentUtils.getLineIndex(doc, offset), true);
 
                     List errsForCurrentLine = getErrorsForLine(pos, true);
 
@@ -1324,7 +1324,7 @@ public void run() {
 
     public synchronized List getErrorsGE(int offset) {
         try {
-            int index = findPositionGE(Utilities.getRowStart(doc, offset));
+            int index = findPositionGE(LineDocumentUtils.getLineStartOffset(doc, offset));
             if (index < 0) return Collections.emptyList();
 
             while (index < knownPositions.size()) {
@@ -1384,7 +1384,7 @@ public int lineNumber(final Position offset) {
         doc.render(new Runnable() {
             public void run() {
                 try {
-                    result[0] = Utilities.getLineOffset(doc, offset.getOffset());
+                    result[0] = LineDocumentUtils.getLineIndex(doc, offset.getOffset());
                 } catch (BadLocationException ex) {
                     Exceptions.printStackTrace(ex);
                 }
@@ -1467,7 +1467,7 @@ public void run() {
                             return ;
                         }
                         
-                        int lineNumber = Utilities.getLineOffset((BaseDocument) document, startOffset);
+                        int lineNumber = LineDocumentUtils.getLineIndex((BaseDocument) document, startOffset);
 
                         if (lineNumber < 0) {
                             return;
diff --git a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsControllerImpl.java b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsControllerImpl.java
index 63d26c3bddd8..8e6ef95b5bd7 100644
--- a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsControllerImpl.java
+++ b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsControllerImpl.java
@@ -39,6 +39,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.Position;
 import javax.swing.text.StyledDocument;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 import org.netbeans.spi.editor.hints.ErrorDescription;
@@ -121,7 +122,7 @@ static int[] computeLineSpan(Document doc, int lineNumber) throws BadLocationExc
         int lineEndOffset;
         
         if (doc instanceof BaseDocument) {
-            lineEndOffset = Utilities.getRowEnd((BaseDocument) doc, lineStartOffset);
+            lineEndOffset = LineDocumentUtils.getLineEndOffset((BaseDocument) doc, lineStartOffset);
         } else {
             //XXX: performance:
             String lineText = doc.getText(lineStartOffset, doc.getLength() - lineStartOffset);
diff --git a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java
index e0112d03fc97..f43df4987149 100644
--- a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java
+++ b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java
@@ -76,6 +76,7 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.Position;
 import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
 import org.netbeans.editor.AnnotationDesc;
@@ -625,7 +626,7 @@ boolean invokeDefaultAction(boolean onlyActive) {
         if (doc instanceof BaseDocument) {
             try {
                 Rectangle carretRectangle = comp.modelToView(comp.getCaretPosition());
-                int line = Utilities.getLineOffset((BaseDocument) doc, comp.getCaretPosition());
+                int line = LineDocumentUtils.getLineIndex((BaseDocument) doc, comp.getCaretPosition());
                 FixData fixes;
                 String description;
 
@@ -666,7 +667,7 @@ boolean invokeDefaultAction(boolean onlyActive) {
                     description = annotation.getDescription();
                 }
 
-                Point p = comp.modelToView(Utilities.getRowStartFromLineOffset((BaseDocument) doc, line)).getLocation();
+                Point p = comp.modelToView(LineDocumentUtils.getLineStartFromIndex((BaseDocument) doc, line)).getLocation();
                 p.y += carretRectangle.height;
                 if(comp.getParent() instanceof JViewport) {
                     p.x += ((JViewport)comp.getParent()).getViewPosition().x;
diff --git a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/NextErrorAction.java b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/NextErrorAction.java
index 3064a60815e1..8a5780fdbe3e 100644
--- a/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/NextErrorAction.java
+++ b/ide/spi.editor.hints/src/org/netbeans/modules/editor/hints/NextErrorAction.java
@@ -32,6 +32,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
 import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 
@@ -118,7 +119,7 @@ private List findNextError(JTextComponent comp, int offset) {
     private int findNextUnused(JTextComponent comp, int offset) {
         try {
             BaseDocument doc = Utilities.getDocument(comp);
-            int lineStart = Utilities.getRowStart(doc, offset);
+            int lineStart = LineDocumentUtils.getLineStartOffset(doc, offset);
             // "unused-browseable" in java.editor/.../ColoringManager and csl.api/.../ColoringManager
             HighlightsSequence s = HighlightingManager.getInstance(comp).getBottomHighlights().getHighlights(lineStart, Integer.MAX_VALUE);
             int lastUnusedEndOffset = -1;
diff --git a/ide/spi.editor.hints/test/unit/src/org/netbeans/modules/editor/hints/AnnotationHolderTest.java b/ide/spi.editor.hints/test/unit/src/org/netbeans/modules/editor/hints/AnnotationHolderTest.java
index 3d4345aaf3db..ac77120b3f5e 100644
--- a/ide/spi.editor.hints/test/unit/src/org/netbeans/modules/editor/hints/AnnotationHolderTest.java
+++ b/ide/spi.editor.hints/test/unit/src/org/netbeans/modules/editor/hints/AnnotationHolderTest.java
@@ -28,6 +28,7 @@
 import javax.swing.text.DefaultEditorKit;
 import javax.swing.text.Document;
 import javax.swing.text.Position;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.GuardedDocument;
@@ -51,7 +52,9 @@
 import org.openide.util.lookup.Lookups;
 
 import static org.netbeans.modules.editor.hints.AnnotationHolder.*;
+
 import org.netbeans.spi.editor.hints.Fix;
+
 import static org.netbeans.spi.editor.hints.Severity.*;
 
 /**
@@ -209,17 +212,17 @@ public void testMultilineHighlights() throws Exception {
         BaseDocument bdoc = (BaseDocument) doc;
         
         bag = new OffsetsBag(doc);
-        AnnotationHolder.updateHighlightsOnLine(bag, bdoc, bdoc.createPosition(Utilities.getRowStartFromLineOffset(bdoc, 0)), errors);
+        AnnotationHolder.updateHighlightsOnLine(bag, bdoc, bdoc.createPosition(LineDocumentUtils.getLineStartFromIndex(bdoc, 0)), errors);
         
         assertHighlights("", bag, new int[] {47 - 30, 50 - 30}, new AttributeSet[] {AnnotationHolder.getColoring(ERROR, doc)});
         
         bag = new OffsetsBag(doc);
-        AnnotationHolder.updateHighlightsOnLine(bag, bdoc, bdoc.createPosition(Utilities.getRowStartFromLineOffset(bdoc, 1)), errors);
+        AnnotationHolder.updateHighlightsOnLine(bag, bdoc, bdoc.createPosition(LineDocumentUtils.getLineStartFromIndex(bdoc, 1)), errors);
         
         assertHighlights("", bag, new int[] {53 - 30, 60 - 30}, new AttributeSet[] {AnnotationHolder.getColoring(ERROR, doc)});
         
         bag = new OffsetsBag(doc);
-        AnnotationHolder.updateHighlightsOnLine(bag, bdoc, bdoc.createPosition(Utilities.getRowStartFromLineOffset(bdoc, 2)), errors);
+        AnnotationHolder.updateHighlightsOnLine(bag, bdoc, bdoc.createPosition(LineDocumentUtils.getLineStartFromIndex(bdoc, 2)), errors);
         
         assertHighlights("", bag, new int[] {65 - 30, 72 - 30}, new AttributeSet[] {AnnotationHolder.getColoring(ERROR, doc)});
     }
diff --git a/ide/subversion/src/org/netbeans/modules/subversion/ui/blame/AnnotationBar.java b/ide/subversion/src/org/netbeans/modules/subversion/ui/blame/AnnotationBar.java
index 78b9b0c633fb..6f04b50fddab 100644
--- a/ide/subversion/src/org/netbeans/modules/subversion/ui/blame/AnnotationBar.java
+++ b/ide/subversion/src/org/netbeans/modules/subversion/ui/blame/AnnotationBar.java
@@ -55,6 +55,7 @@
 import java.text.DateFormat;
 import java.text.MessageFormat;
 import java.util.logging.Level;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
 import org.netbeans.api.editor.settings.FontColorNames;
@@ -718,7 +719,7 @@ public void run() {
         int line = -1;
         int offset = carett.getDot();
         try {
-            line = Utilities.getLineOffset(doc, offset);
+            line = LineDocumentUtils.getLineIndex(doc, offset);
         } catch (BadLocationException ex) {
             Subversion.LOG.log(Level.SEVERE, "Can not get line for caret at offset " + offset, ex); // NOI18N
             clearRecentFeedback();
@@ -1096,7 +1097,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 JTextComponent component = editorUI.getComponent();
                 BaseTextUI textUI = (BaseTextUI)component.getUI();
                 int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                line = Utilities.getLineOffset(doc, clickOffset);
+                line = LineDocumentUtils.getLineIndex(doc, clickOffset);
             }catch (BadLocationException ble){
             }
         }
diff --git a/ide/versioning.ui/src/org/netbeans/modules/versioning/ui/diff/DiffSidebar.java b/ide/versioning.ui/src/org/netbeans/modules/versioning/ui/diff/DiffSidebar.java
index a387b6ab34b9..3f58d16e19c6 100644
--- a/ide/versioning.ui/src/org/netbeans/modules/versioning/ui/diff/DiffSidebar.java
+++ b/ide/versioning.ui/src/org/netbeans/modules/versioning/ui/diff/DiffSidebar.java
@@ -76,6 +76,7 @@
 import java.util.Collections;
 import java.util.Set;
 import javax.swing.plaf.TextUI;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.queries.FileEncodingQuery;
 import org.netbeans.modules.versioning.core.api.VCSFileProxy;
 import org.openide.util.Mutex;
@@ -292,7 +293,7 @@ private int getDiffIndex(Difference diff) {
     }
 
     private int computeDocumentOffset(int lineOffset) {
-        int end = Utilities.getRowStartFromLineOffset(document, lineOffset);
+        int end = LineDocumentUtils.getLineStartFromIndex(document, lineOffset);
         if (end == -1) {
             Element lineRoot = document.getParagraphElement(0).getParentElement();
             for (end = lineRoot.getElement(lineOffset - 1).getEndOffset(); end > document.getLength(); end--) {
@@ -304,16 +305,16 @@ private int computeDocumentOffset(int lineOffset) {
     void onRollback(Difference diff) {
         try {
             if (diff.getType() == Difference.ADD) {
-                int start = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart() - 1);
+                int start = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart() - 1);
                 int end = computeDocumentOffset(diff.getSecondEnd());
                 document.remove(start, end - start);
             } else if (diff.getType() == Difference.CHANGE) {
-                int start = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart() - 1);
+                int start = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart() - 1);
                 int end = computeDocumentOffset(diff.getSecondEnd());
                 document.replace(start, end - start, diff.getFirstText(), null);
             } else {
                 int start = computeDocumentOffset(diff.getSecondStart());
-                String newline = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart()) == -1 ? "\n" : "";
+                String newline = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart()) == -1 ? "\n" : "";
                 document.insertString(start, newline + diff.getFirstText(), null);
             }
             LOG.finer("refreshing diff in onRollback");
@@ -335,10 +336,10 @@ public void run () {
                 if (canModify) {
                     int start, end;
                     if (diff.getType() == Difference.DELETE) {
-                        start = end = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart());
+                        start = end = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart());
                     } else {
-                        start = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart() - 1);
-                        end = Utilities.getRowStartFromLineOffset(document, diff.getSecondEnd());
+                        start = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondStart() - 1);
+                        end = LineDocumentUtils.getLineStartFromIndex(document, diff.getSecondEnd());
                     }
                     MarkBlockChain mbc = ((GuardedDocument) document).getGuardedBlockChain();
                     canModify = (mbc.compareBlock(start, end) & MarkBlock.OVERLAP) == 0;
@@ -385,8 +386,8 @@ private Point scrollToDifference(Difference diff) {
         try {
             EditorUI editorUI = Utilities.getEditorUI(textComponent);
             int visibleBorder = editorUI.getLineHeight() * 5;
-            int startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) textComponent.getDocument(), lineStart);
-            int endOffset = Utilities.getRowStartFromLineOffset((BaseDocument) textComponent.getDocument(), lineEnd);
+            int startOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) textComponent.getDocument(), lineStart);
+            int endOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) textComponent.getDocument(), lineEnd);
             Rectangle startRect = textComponent.getUI().modelToView(textComponent, startOffset);
             Rectangle endRect = textComponent.getUI().modelToView(textComponent, endOffset);
             Rectangle visibleRect = new Rectangle(startRect.x - visibleBorder, startRect.y - visibleBorder, 
@@ -518,7 +519,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 if (component != null) {
                     TextUI textUI = component.getUI();
                     int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                    line = Utilities.getLineOffset(document, clickOffset);
+                    line = LineDocumentUtils.getLineIndex(document, clickOffset);
                 }
             }catch (BadLocationException ble){
                 LOG.log(Level.WARNING, "getLineFromMouseEvent", ble); // NOI18N
diff --git a/ide/versioning.util/src/org/netbeans/modules/versioning/annotate/AnnotationBar.java b/ide/versioning.util/src/org/netbeans/modules/versioning/annotate/AnnotationBar.java
index 52b225014107..9bbcc45f31e6 100644
--- a/ide/versioning.util/src/org/netbeans/modules/versioning/annotate/AnnotationBar.java
+++ b/ide/versioning.util/src/org/netbeans/modules/versioning/annotate/AnnotationBar.java
@@ -50,6 +50,7 @@
 import java.io.IOException;
 import java.io.CharConversionException;
 import java.text.DateFormat;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.EditorStyleConstants;
 import org.netbeans.api.editor.settings.FontColorNames;
@@ -416,7 +417,7 @@ public void run() {
         int line = -1;
         int offset = carett.getDot();
         try {
-            line = Utilities.getLineOffset(doc, offset);
+            line = LineDocumentUtils.getLineIndex(doc, offset);
         } catch (BadLocationException ex) {
             ErrorManager err = ErrorManager.getDefault();
             err.annotate(ex, "Can not get line for caret at offset " + offset); // NOI18N
@@ -782,7 +783,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 JTextComponent component = editorUI.getComponent();
                 BaseTextUI textUI = (BaseTextUI)component.getUI();
                 int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                line = Utilities.getLineOffset(doc, clickOffset);
+                line = LineDocumentUtils.getLineIndex(doc, clickOffset);
             } catch (BadLocationException ble) {
                 // there's not such line, return -1
             }
diff --git a/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/AbstractIndenter.java b/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/AbstractIndenter.java
index a6ea39a562eb..d008958d6e67 100644
--- a/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/AbstractIndenter.java
+++ b/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/AbstractIndenter.java
@@ -34,6 +34,7 @@
 import java.util.prefs.Preferences;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.settings.SimpleValueNames;
 import org.netbeans.api.lexer.Language;
 import org.netbeans.api.lexer.Token;
@@ -292,9 +293,9 @@ private void calculateIndentation() throws BadLocationException {
         JoinedTokenSequence joinedTS = JoinedTokenSequence.createFromCodeBlocks(blocks);
 
         // start on the beginning of line:
-        int start = Utilities.getRowStart(doc, startOffset);
+        int start = LineDocumentUtils.getLineStartOffset(doc, startOffset);
         // end after the last line:
-        int end = Utilities.getRowEnd(doc, endOffset)+1;
+        int end = LineDocumentUtils.getLineEndOffset(doc, endOffset)+1;
         if (end > doc.getLength()) {
             end = doc.getLength();
         }
@@ -322,8 +323,8 @@ private void calculateIndentation() throws BadLocationException {
             initialOffset = getFormatStableStart(joinedTS, start, end, rangesToIgnore);
             if (DEBUG_PERFORMANCE) {
                 System.err.println("[IndPer] Locating FormatStableStart took "+(System.currentTimeMillis()-startTime1)+" ms");
-                System.err.println("[IndPer] Current line index is: "+(Utilities.getLineOffset(doc, start)));
-                System.err.println("[IndPer] FormatStableStart line starts at index: "+(Utilities.getLineOffset(doc, initialOffset)));
+                System.err.println("[IndPer] Current line index is: "+(LineDocumentUtils.getLineIndex(doc, start)));
+                System.err.println("[IndPer] FormatStableStart line starts at index: "+(LineDocumentUtils.getLineIndex(doc, initialOffset)));
                 System.err.println("[IndPer] Number of ranges to ignore: "+rangesToIgnore.ranges.size());
             }
             if (DEBUG && !rangesToIgnore.isEmpty()) {
@@ -361,7 +362,7 @@ private int findPreviousOccuranceOfOurLanguage(JoinedTokenSequence ts, int s
         // will try to find our language there:
 
         // find line start and move to previous line if possible:
-        int lineStart = Utilities.getRowStart(getDocument(), start);
+        int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), start);
         if (lineStart > 0) {
             lineStart--;
         }
@@ -371,7 +372,7 @@ private int findPreviousOccuranceOfOurLanguage(JoinedTokenSequence ts, int s
             offset = 0;
         }
         // find beginning of this line
-        lineStart = Utilities.getRowStart(getDocument(), offset);
+        lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), offset);
 
         // use line start as beginning for our language search:
         if (ts.move(lineStart, true)) {
@@ -402,8 +403,8 @@ private void applyIndentation() throws BadLocationException {
         }
 
         // apply line data into concrete indentation:
-        int lineStart = Utilities.getLineOffset(getDocument(), context.startOffset());
-        int lineEnd = Utilities.getLineOffset(getDocument(), context.endOffset());
+        int lineStart = LineDocumentUtils.getLineIndex(getDocument(), context.startOffset());
+        int lineEnd = LineDocumentUtils.getLineIndex(getDocument(), context.endOffset());
         assert formattingContext.getIndentationData() != null;
         List> indentationData = formattingContext.getIndentationData();
 
@@ -677,7 +678,7 @@ private void addLanguageEndLine(List lines) throws BadLocationException {
             return;
         }
         int lineIndex = lastLine.index+1;
-        int offset = Utilities.getRowStartFromLineOffset(getDocument(), lineIndex);
+        int offset = LineDocumentUtils.getLineStartFromIndex(getDocument(), lineIndex);
         if (offset == -1) {
             return;
         }
@@ -821,7 +822,7 @@ public int compare(LineCommandsPair o1, LineCommandsPair o2) {
                 // put all commands on the last line;
                 // that should do the trick
                 if (lastLine == null) {
-                    int offset = Utilities.getRowStartFromLineOffset(getDocument(), pair.line);
+                    int offset = LineDocumentUtils.getLineStartFromIndex(getDocument(), pair.line);
                     if (offset == -1) {
                         // lines does not exist so ignore:
                         break;
@@ -997,16 +998,16 @@ private void recalculateLineIndexes() throws BadLocationException {
     private List calculateLinePairs(List> blocks, int startOffset, int endOffset) throws BadLocationException {
         List lps = new ArrayList();
         LinePair lastOne = null;
-        int startLine = Utilities.getLineOffset(getDocument(), startOffset);
-        int endLine = Utilities.getLineOffset(getDocument(), endOffset);
+        int startLine = LineDocumentUtils.getLineIndex(getDocument(), startOffset);
+        int endLine = LineDocumentUtils.getLineIndex(getDocument(), endOffset);
         for (JoinedTokenSequence.CodeBlock block : blocks) {
             for (JoinedTokenSequence.TokenSequenceWrapper tsw : block.tss) {
                 if (tsw.isVirtual()) {
                     continue;
                 }
                 LinePair lp = new LinePair();
-                lp.startingLine = Utilities.getLineOffset(getDocument(), LexUtilities.getTokenSequenceStartOffset(tsw.getTokenSequence()));
-                lp.endingLine = Utilities.getLineOffset(getDocument(), LexUtilities.getTokenSequenceEndOffset(tsw.getTokenSequence()));
+                lp.startingLine = LineDocumentUtils.getLineIndex(getDocument(), LexUtilities.getTokenSequenceStartOffset(tsw.getTokenSequence()));
+                lp.endingLine = LineDocumentUtils.getLineIndex(getDocument(), LexUtilities.getTokenSequenceEndOffset(tsw.getTokenSequence()));
                 if (lp.startingLine > endLine) {
                     break;
                 }
@@ -1093,16 +1094,16 @@ private void processLanguage(JoinedTokenSequence joinedTS, List li
             for (int line = lp.startingLine; line <= lp.endingLine; line++) {
 
                 // find line starting offset
-                int rowStartOffset = Utilities.getRowStartFromLineOffset(doc, line);
+                int rowStartOffset = LineDocumentUtils.getLineStartFromIndex(doc, line);
                 if (rowStartOffset < overallStartOffset) {
                     rowStartOffset = overallStartOffset;
                 }
 
                 // find first non-white character
-                int firstNonWhite = Utilities.getRowFirstNonWhite(doc, rowStartOffset);
+                int firstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowStartOffset);
 
                 // find line ending offset
-                int rowEndOffset = Utilities.getRowEnd(doc, rowStartOffset);
+                int rowEndOffset = LineDocumentUtils.getLineEndOffset(doc, rowStartOffset);
                 int nextLineStartOffset = rowEndOffset+1;
 
                 // check whether line can be skip completely:
@@ -1228,9 +1229,9 @@ private void processLanguage(JoinedTokenSequence joinedTS, List li
     }
 
     private boolean doesLineStartWithOurLanguage(BaseDocument doc, int lineIndex, JoinedTokenSequence joinedTS) throws BadLocationException {
-        int rowStartOffset = Utilities.getRowStartFromLineOffset(doc, lineIndex);
-        int rowEndOffset = Utilities.getRowEnd(doc, rowStartOffset);
-        int firstNonWhite = Utilities.getRowFirstNonWhite(doc, rowStartOffset);
+        int rowStartOffset = LineDocumentUtils.getLineStartFromIndex(doc, lineIndex);
+        int rowEndOffset = LineDocumentUtils.getLineEndOffset(doc, rowStartOffset);
+        int firstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowStartOffset);
         if (firstNonWhite != -1) {
             // there is something on the line:
             int newRowStartOffset = findLanguageOffset(joinedTS, rowStartOffset, rowEndOffset, true);
@@ -1773,9 +1774,9 @@ private List generateBlockIndentsForForeignLanguage(List indentedLin
     private Line generateBasicLine(int index) throws BadLocationException {
         Line line = new Line();
         line.index = index;
-        line.offset = Utilities.getRowStartFromLineOffset(getDocument(), index);
+        line.offset = LineDocumentUtils.getLineStartFromIndex(getDocument(), index);
         line.existingLineIndent = IndentUtils.lineIndent(getDocument(), line.offset);
-        int nonWS = Utilities.getRowFirstNonWhite(getDocument(), line.offset);
+        int nonWS = LineDocumentUtils.getLineFirstNonWhitespace(getDocument(), line.offset);
         line.emptyLine = nonWS == -1;
         // if (first-non-whitespace-offset - line-start-offset) is different from 
         // existingLineIndent then line starts with tab characters which will need
@@ -1783,7 +1784,7 @@ private Line generateBasicLine(int index) throws BadLocationException {
         // possible tabs get replaced:
         line.tabIndentation = nonWS == -1 || line.existingLineIndent != (nonWS - line.offset);
         line.lineStartOffset = line.offset;
-        line.lineEndOffset = Utilities.getRowEnd(getDocument(), line.offset);
+        line.lineEndOffset = LineDocumentUtils.getLineEndOffset(getDocument(), line.offset);
         line.lineIndent = new ArrayList();
         line.lineIndent.add(new IndentCommand(IndentCommand.Type.NO_CHANGE, line.offset, getIndentationSize()));
         line.preliminaryNextLineIndent = new ArrayList();
@@ -1844,7 +1845,7 @@ private void modifyDocument(List indentedLines, int lineStart, int lineEnd
     }
         
     private void debugIndentation(int lineOffset, List iis, String text, boolean indentable) throws BadLocationException {
-        int index = Utilities.getLineOffset(getDocument(), lineOffset);
+        int index = LineDocumentUtils.getLineIndex(getDocument(), lineOffset);
         char ch = ' ';
         if (indentable) {
             ch = '*';
@@ -1910,8 +1911,8 @@ private void updateOffset(int diff) {
         }
 
         private void recalculateLineIndex(BaseDocument doc) throws BadLocationException {
-            index = Utilities.getLineOffset(doc, offset);
-            int rowStart = Utilities.getRowStart(doc, offset);
+            index = LineDocumentUtils.getLineIndex(doc, offset);
+            int rowStart = LineDocumentUtils.getLineStartOffset(doc, offset);
 
             // Java formatter is fiddling with lines it should not. This is a check
             // that if line start is different then issue a warning. See also
diff --git a/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/MarkupAbstractIndenter.java b/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/MarkupAbstractIndenter.java
index fef8843aec82..6ca6e54a5edc 100644
--- a/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/MarkupAbstractIndenter.java
+++ b/ide/web.indent/src/org/netbeans/modules/web/indent/api/support/MarkupAbstractIndenter.java
@@ -26,6 +26,7 @@
 import java.util.Set;
 import java.util.Stack;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.Language;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenId;
@@ -145,7 +146,7 @@ protected int getFormatStableStart(JoinedTokenSequence ts, int startOffset,
             }
 
             if (isStartTagSymbol(tk) || isStableFormattingStartToken(tk, ts)) {
-                    int firstNonWhite = Utilities.getRowFirstNonWhite(getDocument(), ts.offset());
+                    int firstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(getDocument(), ts.offset());
                     if (firstNonWhite != -1 && firstNonWhite == ts.offset()) {
                         foundOffset = ts.offset();
                         break;
@@ -197,8 +198,8 @@ private void eliminateUnnecessaryTags(JoinedTokenSequence ts, int from, int
                         rangeStart = ts.offset();
                     }
                     if (rangeStart < rangeEnd) {
-                        int startLine = Utilities.getLineOffset(getDocument(), rangeStart);
-                        int endLine = Utilities.getLineOffset(getDocument(), rangeEnd);
+                        int startLine = LineDocumentUtils.getLineIndex(getDocument(), rangeStart);
+                        int endLine = LineDocumentUtils.getLineIndex(getDocument(), rangeEnd);
                         // ignore a range on a single line; they are not worth the effort
                         // and are not properly handled in processEliminatedTags() anyway;
                         // t o d o: perhaps if range covers whole line it could be added
diff --git a/ide/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/EndTagResultItem.java b/ide/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/EndTagResultItem.java
index e954186a2080..222022a384c9 100644
--- a/ide/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/EndTagResultItem.java
+++ b/ide/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/EndTagResultItem.java
@@ -23,6 +23,7 @@
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
@@ -93,8 +94,8 @@ private void reindent(JTextComponent component) {
                 @Override
                 public void run() {
                     try {
-                        int startOffset = Utilities.getRowStart(doc, dotPos);
-                        int endOffset = Utilities.getRowEnd(doc, dotPos);
+                        int startOffset = LineDocumentUtils.getLineStartOffset(doc, dotPos);
+                        int endOffset = LineDocumentUtils.getLineEndOffset(doc, dotPos);
                         indent.reindent(startOffset, endOffset);
                     } catch (BadLocationException ex) {
                         //ignore
diff --git a/ide/xml.text/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java b/ide/xml.text/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java
index 63785e34a6dc..2bd00e855d2b 100644
--- a/ide/xml.text/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java
+++ b/ide/xml.text/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java
@@ -28,6 +28,7 @@
 import java.util.prefs.Preferences;
 import javax.swing.event.DocumentEvent;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.Fold;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.fold.FoldType;
@@ -406,8 +407,8 @@ private void createFolds(FoldHierarchyTransaction fhTran)
     public boolean isOneLiner(int start, int end) {
         try {
             BaseDocument doc = getDocument();
-            return Utilities.getLineOffset(doc, start) ==
-                   Utilities.getLineOffset(doc, end);
+            return LineDocumentUtils.getLineIndex(doc, start) ==
+                   LineDocumentUtils.getLineIndex(doc, end);
         } catch (BadLocationException ex) {
             //Exceptions.printStackTrace(ex);
             return false;
diff --git a/ide/xml.text/src/org/netbeans/modules/xml/text/indent/DTDFormatter.java b/ide/xml.text/src/org/netbeans/modules/xml/text/indent/DTDFormatter.java
index 7050703e9745..7df9984ea9f6 100644
--- a/ide/xml.text/src/org/netbeans/modules/xml/text/indent/DTDFormatter.java
+++ b/ide/xml.text/src/org/netbeans/modules/xml/text/indent/DTDFormatter.java
@@ -18,20 +18,14 @@
  */
 package org.netbeans.modules.xml.text.indent;
 
-import java.io.IOException;
 import javax.swing.text.Document;
 import javax.swing.text.BadLocationException;
-
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.Syntax;
-import org.netbeans.editor.TokenID;
-import org.netbeans.editor.TokenItem;
-import org.netbeans.editor.TokenItem;
 import org.netbeans.editor.ext.AbstractFormatLayer;
 import org.netbeans.editor.ext.FormatTokenPosition;
 import org.netbeans.editor.ext.ExtFormatter;
-import org.netbeans.editor.ext.FormatLayer;
 import org.netbeans.editor.ext.FormatSupport;
-import org.netbeans.editor.ext.ExtFormatSupport;
 import org.netbeans.editor.ext.FormatWriter;
 import org.netbeans.editor.Utilities;
 import org.netbeans.editor.BaseDocument;
@@ -95,7 +89,7 @@ public int indentNewLine (Document doc, int offset) {
                 bdoc.insertString (offset, "\n", null); // NOI18N
                 offset++;
 
-                int fullLine = Utilities.getFirstNonWhiteBwd (bdoc, offset - 1);
+                int fullLine = LineDocumentUtils.getPreviousNonWhitespace (bdoc, offset - 1);
                 int indent = Utilities.getRowIndent (bdoc, fullLine);
                 
 //                if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("+             ::indentNewLine: fullLine = " + fullLine); // NOI18N
diff --git a/ide/xml.text/src/org/netbeans/modules/xml/text/indent/LineBreakHook.java b/ide/xml.text/src/org/netbeans/modules/xml/text/indent/LineBreakHook.java
index 2cba004210e6..183de8ed12f1 100644
--- a/ide/xml.text/src/org/netbeans/modules/xml/text/indent/LineBreakHook.java
+++ b/ide/xml.text/src/org/netbeans/modules/xml/text/indent/LineBreakHook.java
@@ -20,6 +20,7 @@
 
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
 import org.netbeans.api.lexer.Token;
@@ -142,7 +143,7 @@ public void insert(MutableContext context) throws BadLocationException {
 
         int insertPos = context.getCaretOffset();
         int caretPos = context.getComponent().getCaretPosition();
-        int lineStartPos = Utilities.getRowStart(doc, insertPos);
+        int lineStartPos = LineDocumentUtils.getLineStartOffset(doc, insertPos);
 
         TokenHierarchy h = TokenHierarchy.get(doc);
         TokenSequence seq = h.tokenSequence();
@@ -150,10 +151,10 @@ public void insert(MutableContext context) throws BadLocationException {
         seq.move(context.getCaretOffset());
         int openOffset = followsOpeningTag(seq);
         
-        int nonWhiteBefore = Utilities.getFirstNonWhiteBwd(doc, insertPos, lineStartPos);
+        int nonWhiteBefore = LineDocumentUtils.getPreviousNonWhitespace(doc, insertPos, lineStartPos);
 
-        int lineEndPos = Utilities.getRowEnd(doc, caretPos);
-        int nonWhiteAfter = Utilities.getFirstNonWhiteFwd(doc, caretPos, lineEndPos);
+        int lineEndPos = LineDocumentUtils.getLineEndOffset(doc, caretPos);
+        int nonWhiteAfter = LineDocumentUtils.getNextNonWhitespace(doc, caretPos, lineEndPos);
 
         // there is a opening tag preceding on the line && something following the insertion point
         if (nonWhiteBefore != -1 && nonWhiteAfter != -1 && openOffset >= 0) {
@@ -163,7 +164,7 @@ public void insert(MutableContext context) throws BadLocationException {
             // now we need to position the caret at the END of the line immediately 
             // preceding the closing tag. Assuming it's already indented
             if (precedesClosingTag(seq)) {
-                int startClosingLine = Utilities.getRowStart(doc, nonWhiteAfter);
+                int startClosingLine = LineDocumentUtils.getLineStartOffset(doc, nonWhiteAfter);
                 int nextLineStart = Utilities.getRowStart(doc, insertPos, 1);
                 if (nextLineStart >= startClosingLine - 1) {
                     insertBlankBetweenTabs(context, openOffset);
@@ -181,7 +182,7 @@ public void insert(MutableContext context) throws BadLocationException {
         int desiredIndent;
 
         if (openOffset != Integer.MIN_VALUE) {
-            desiredIndent = IndentUtils.lineIndent(doc, Utilities.getRowStart(doc, Math.abs(openOffset)));
+            desiredIndent = IndentUtils.lineIndent(doc, LineDocumentUtils.getLineStartOffset(doc, Math.abs(openOffset)));
             if (openOffset >= 0) {
                 desiredIndent += IndentUtils.indentLevelSize(doc);
             }
diff --git a/ide/xml.text/src/org/netbeans/modules/xml/text/indent/XMLLexerFormatter.java b/ide/xml.text/src/org/netbeans/modules/xml/text/indent/XMLLexerFormatter.java
index 57a05851c931..0489b22e15f9 100644
--- a/ide/xml.text/src/org/netbeans/modules/xml/text/indent/XMLLexerFormatter.java
+++ b/ide/xml.text/src/org/netbeans/modules/xml/text/indent/XMLLexerFormatter.java
@@ -114,7 +114,7 @@ private void changePrettyText(LineDocument doc, TokenIndent tag) throws BadLocat
         if(noNewline || so == 0 || CharSequences.indexOf(temp, "\n") != -1){ // NOI18N
             int i = LineDocumentUtils.getLineFirstNonWhitespace(doc, so);
             if (i == -1) {
-                i = LineDocumentUtils.getLineEnd(doc, so);
+                i = LineDocumentUtils.getLineEndOffset(doc, so);
             }
             int rowStart = LineDocumentUtils.getLineStart(doc, so);
             
@@ -650,7 +650,7 @@ private List getTagsLocked(int startOffset, int endOffset) throws B
 
                     for (int lno = 0; lno < lineCount; lno++) {
                         // indent 1st comment line, as if it was text:
-                        int lineEnd = LineDocumentUtils.getLineEnd(basedoc, currentOffset);
+                        int lineEnd = LineDocumentUtils.getLineEndOffset(basedoc, currentOffset);
 
                         int desiredIndent;
                         if (lno == 0 || lno == lineCount -1) {
diff --git a/ide/xml.text/src/org/netbeans/modules/xml/text/syntax/XMLKit.java b/ide/xml.text/src/org/netbeans/modules/xml/text/syntax/XMLKit.java
index 33cbe75e0efb..01db29346f6b 100644
--- a/ide/xml.text/src/org/netbeans/modules/xml/text/syntax/XMLKit.java
+++ b/ide/xml.text/src/org/netbeans/modules/xml/text/syntax/XMLKit.java
@@ -29,6 +29,7 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.BadLocationException;
 import javax.swing.*;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.lexer.Language;
 import org.netbeans.api.xml.lexer.XMLTokenId;
@@ -41,7 +42,9 @@
 
 import org.netbeans.modules.xml.text.XmlCommentHandler;
 import org.netbeans.modules.xml.text.completion.NodeSelector;
+
 import static org.netbeans.modules.xml.text.syntax.DTDKit.MIME_TYPE;
+
 import org.netbeans.modules.xml.text.syntax.bridge.LegacySyntaxBridge;
 
 
@@ -194,21 +197,21 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
             BaseDocument doc = (BaseDocument)target.getDocument();
             try {
                 if (caret.isSelectionVisible()) {
-                    int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
+                    int startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                     int endPos = target.getSelectionEnd();
                     doc.atomicLock();
                     try {
 
-                        if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
+                        if (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) {
                             endPos--;
                         }
 
                         int pos = startPos;
-                        int lineCnt = Utilities.getRowCount(doc, startPos, endPos);                            
+                        int lineCnt = LineDocumentUtils.getLineCount(doc, startPos, endPos);                            
 
                         for (;lineCnt > 0; lineCnt--) {
                             doc.insertString(pos, commentStartString, null); 
-                            doc.insertString(Utilities.getRowEnd(doc,pos), commentEndString, null);
+                            doc.insertString(LineDocumentUtils.getLineEndOffset(doc,pos), commentEndString, null);
                             pos = Utilities.getRowStart(doc, pos, +1);
                         }
 
@@ -216,9 +219,9 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
                         doc.atomicUnlock();
                     }
                 } else { // selection not visible
-                    doc.insertString(Utilities.getRowStart(doc, target.getSelectionStart()),
+                    doc.insertString(LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart()),
                         commentStartString, null);
-                    doc.insertString(Utilities.getRowEnd(doc, target.getSelectionStart()),
+                    doc.insertString(LineDocumentUtils.getLineEndOffset(doc, target.getSelectionStart()),
                         commentEndString, null);
                 }
             } catch (BadLocationException e) {
@@ -254,29 +257,29 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
             BaseDocument doc = (BaseDocument)target.getDocument();
             try {
                 if (caret.isSelectionVisible()) {
-                    int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
+                    int startPos = LineDocumentUtils.getLineStartOffset(doc, target.getSelectionStart());
                     int endPos = target.getSelectionEnd();
                     doc.atomicLock();
                     try {
 
-                        if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
+                        if (endPos > 0 && LineDocumentUtils.getLineStartOffset(doc, endPos) == endPos) {
                             endPos--;
                         }
 
                         int pos = startPos;
-                        int lineCnt = Utilities.getRowCount(doc, startPos, endPos);
+                        int lineCnt = LineDocumentUtils.getLineCount(doc, startPos, endPos);
                         char[] startChars, endChars;
 
                         for (; lineCnt > 0; lineCnt-- ) {
                             startChars = doc.getChars(pos, 4 );
-                            endChars = doc.getChars(Utilities.getRowEnd(doc,pos)-3, 3 );
+                            endChars = doc.getChars(LineDocumentUtils.getLineEndOffset(doc,pos)-3, 3 );
 
                             if(startChars[0] == commentStart[0] && startChars[1] == commentStart[1] &&
                                 startChars[2] == commentStart[2] && startChars[3] == commentStart[3] &&
                                 endChars[0] == commentEnd[0] && endChars[1] == commentEnd[1] && endChars[2] == commentEnd[2] ){
 
                                 doc.remove(pos,4);
-                                doc.remove(Utilities.getRowEnd(doc,pos)-3,3);
+                                doc.remove(LineDocumentUtils.getLineEndOffset(doc,pos)-3,3);
                             }                                
                             pos = Utilities.getRowStart(doc, pos, +1);
                         }
@@ -286,12 +289,12 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
                     }
                 } else { // selection not visible
                   char[] startChars = doc.getChars(target.getSelectionStart(), 4 );
-                  char[] endChars = doc.getChars(Utilities.getRowEnd(doc,target.getSelectionStart())-3, 3 );
+                  char[] endChars = doc.getChars(LineDocumentUtils.getLineEndOffset(doc,target.getSelectionStart())-3, 3 );
                   if(startChars[0] == commentStart[0] && startChars[1] == commentStart[1] &&
                                 startChars[2] == commentStart[2] && startChars[3] == commentStart[3] &&
                                 endChars[0] == commentEnd[0] && endChars[1] == commentEnd[1] && endChars[2] == commentEnd[2] ){
                         doc.remove(target.getSelectionStart(),4);
-                        doc.remove(Utilities.getRowEnd(doc,target.getSelectionStart())-3,3);
+                        doc.remove(LineDocumentUtils.getLineEndOffset(doc,target.getSelectionStart())-3,3);
                     }
                 }
             } catch (BadLocationException e) {
diff --git a/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/ToggleBreakpointActionProvider.java b/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/ToggleBreakpointActionProvider.java
index 94748fb67be3..44d896249180 100644
--- a/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/ToggleBreakpointActionProvider.java
+++ b/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/ToggleBreakpointActionProvider.java
@@ -45,6 +45,7 @@
 import org.netbeans.spi.debugger.ContextProvider;
 import org.netbeans.api.debugger.jpda.JPDADebugger;
 import org.netbeans.api.debugger.jpda.LineBreakpoint;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.java.source.CancellableTask;
 import org.netbeans.api.java.source.CompilationController;
 import org.netbeans.api.java.source.JavaSource;
@@ -257,10 +258,10 @@ private int checkLineBreakability(String url, final int lineNumber, final JEdito
         if (ec == null) return lineNumber;
         final BaseDocument doc = (BaseDocument)ec.getDocument();
         if (doc == null) return lineNumber;
-        final int rowStartOffset = Utilities.getRowStartFromLineOffset(doc, lineNumber - 1);
+        final int rowStartOffset = LineDocumentUtils.getLineStartFromIndex(doc, lineNumber - 1);
         final int rowEndOffset;
         try {
-            rowEndOffset = Utilities.getRowEnd(doc, rowStartOffset);
+            rowEndOffset = LineDocumentUtils.getLineEndOffset(doc, rowStartOffset);
         } catch (BadLocationException ex) {
             return lineNumber;
         }
@@ -360,7 +361,7 @@ public void run(CompilationController ci) throws Exception {
                     if (execTree == null || !isBreakable(execTreePath)) {
                         if (outerTree != null && isBreakable(outerTreePath)) {
                             long offs = positions.getStartPosition(compUnit, outerTree);
-                            result[0] = Utilities.getLineOffset(doc, (int)offs) + 1;
+                            result[0] = LineDocumentUtils.getLineIndex(doc, (int)offs) + 1;
                         } else {
                             if (outerTree instanceof BlockTree) {
                                 Tree pTree = outerTreePath.getParentPath().getLeaf();
diff --git a/java/gradle.java/test/unit/src/org/netbeans/modules/gradle/java/queries/GradleDependenciesImplementationTest.java b/java/gradle.java/test/unit/src/org/netbeans/modules/gradle/java/queries/GradleDependenciesImplementationTest.java
index 0a7b313bcab0..f8ccc336d08a 100644
--- a/java/gradle.java/test/unit/src/org/netbeans/modules/gradle/java/queries/GradleDependenciesImplementationTest.java
+++ b/java/gradle.java/test/unit/src/org/netbeans/modules/gradle/java/queries/GradleDependenciesImplementationTest.java
@@ -167,7 +167,7 @@ public void testDependencyBlockRange() throws Exception {
         
         int start = loc.getStartOffset();
         int depStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, start);
-        int depEnd = LineDocumentUtils.getLineEnd(doc, start);
+        int depEnd = LineDocumentUtils.getLineEndOffset(doc, start);
         
         String s = doc.getText(depStart, depEnd - depStart);
         assertEquals("dependencies {", s);
@@ -203,7 +203,7 @@ public void testLocationOfBlockDependencyList() throws Exception {
         
         int start = loc.getStartOffset();
         int depStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, start);
-        int depEnd = LineDocumentUtils.getLineEnd(doc, start);
+        int depEnd = LineDocumentUtils.getLineEndOffset(doc, start);
         
         String s = doc.getText(depStart, depEnd - depStart);
         assertEquals("implementation(", s);
diff --git a/java/java.editor.lib/src/org/netbeans/editor/ext/java/JavaFormatter.java b/java/java.editor.lib/src/org/netbeans/editor/ext/java/JavaFormatter.java
index 87c9b0d660e3..0947a40dc983 100644
--- a/java/java.editor.lib/src/org/netbeans/editor/ext/java/JavaFormatter.java
+++ b/java/java.editor.lib/src/org/netbeans/editor/ext/java/JavaFormatter.java
@@ -21,6 +21,7 @@
 
 import javax.swing.text.JTextComponent;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.TokenItem;
 import org.netbeans.editor.TokenItem;
 import org.netbeans.editor.BaseDocument;
@@ -61,7 +62,7 @@ public int[] getReformatBlock(JTextComponent target, String typedText) {
              */
             if ("e".equals(typedText)) { // NOI18N
                 try {
-                    int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
+                    int fnw = LineDocumentUtils.getLineFirstNonWhitespace(doc, dotPos);
                     if (fnw >= 0 && fnw + 4 == dotPos
                         && CharSequenceUtilities.textEquals("else", DocumentUtilities.getText(doc, fnw, 4)) // NOI18N
                     ) {
@@ -72,7 +73,7 @@ public int[] getReformatBlock(JTextComponent target, String typedText) {
 
             } else if (":".equals(typedText)) { // NOI18N
                 try {
-                    int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
+                    int fnw = LineDocumentUtils.getLineFirstNonWhitespace(doc, dotPos);
                     if (fnw >= 0 && fnw + 4 <= doc.getLength()
                         && CharSequenceUtilities.textEquals("case", DocumentUtilities.getText(doc, fnw, 4)) // NOI18N
                     ) {
diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java b/java/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java
index 980d1b81625d..736f8f30c87d 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
-import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimePath;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
 import org.netbeans.api.editor.mimelookup.MimeRegistrations;
@@ -31,11 +31,11 @@
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
-import static org.netbeans.modules.editor.java.JavaKit.JAVA_MIME_TYPE;
 import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor;
 import org.openide.util.NbPreferences;
 
+import static org.netbeans.modules.editor.java.JavaKit.JAVA_MIME_TYPE;
+
 /**
  *
  * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com)
@@ -105,7 +105,7 @@ static int nextCamelCasePositionImpl(Document doc, int offset) throws BadLocatio
         }
 
         // not an identifier - simply return next word offset
-        return Utilities.getNextWord((BaseDocument)doc, offset);
+        return LineDocumentUtils.getNextWordStart((BaseDocument)doc, offset);
     }
 
     static int previousCamelCasePosition(CamelCaseInterceptor.MutableContext context) throws BadLocationException {
@@ -193,7 +193,7 @@ static int previousCamelCasePositionImpl(Document doc, int offset) throws BadLoc
         }
 
         // not an identifier - simply return previous word offset
-        return Utilities.getPreviousWord((BaseDocument)doc, offset);
+        return LineDocumentUtils.getPreviousWordStart((BaseDocument)doc, offset);
     }
 
     public static class JavaCamelCaseInterceptor implements CamelCaseInterceptor {
diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java b/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java
index f76ce1ed9e3b..918b435865f4 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java
@@ -33,6 +33,7 @@
 
 import org.netbeans.api.editor.EditorActionNames;
 import org.netbeans.api.editor.EditorActionRegistration;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.api.editor.fold.FoldUtilities;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
@@ -397,7 +398,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
                     sb.append(':');
                 }
                 try {
-                    sb.append(Utilities.getLineOffset(doc, target.getCaret().getDot()) + 1);
+                    sb.append(LineDocumentUtils.getLineIndex(doc, target.getCaret().getDot()) + 1);
                 } catch (BadLocationException e) {
                 }
                 sb.append(' ');
diff --git a/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java b/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java
index 0682f52f5f6f..748d61344802 100644
--- a/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java
+++ b/java/java.editor/src/org/netbeans/modules/editor/java/TypingCompletion.java
@@ -26,6 +26,7 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.SimpleValueNames;
 import org.netbeans.api.java.lexer.JavaTokenId;
@@ -266,7 +267,7 @@ static int completeQuote(TypedTextInterceptor.MutableContext context) throws Bad
                 || id == JavaTokenId.CHAR_LITERAL
                 || id == JavaTokenId.MULTILINE_STRING_LITERAL);
 
-        int lastNonWhite = org.netbeans.editor.Utilities.getRowLastNonWhite((BaseDocument) context.getDocument(), context.getOffset());
+        int lastNonWhite = LineDocumentUtils.getLineLastNonWhitespace((BaseDocument) context.getDocument(), context.getOffset());
         // eol - true if the caret is at the end of line (ignoring whitespaces)
         boolean eol = lastNonWhite < context.getOffset();
         if (insideString) {
@@ -385,7 +386,7 @@ static boolean isAddRightBrace(BaseDocument doc, int caretOffset) throws BadLoca
         if (tokenBalance(doc, JavaTokenId.LBRACE) <= 0) {
             return false;
         }
-        int caretRowStartOffset = org.netbeans.editor.Utilities.getRowStart(doc, caretOffset);
+        int caretRowStartOffset = LineDocumentUtils.getLineStartOffset(doc, caretOffset);
         TokenSequence ts = javaTokenSequence(doc, caretOffset, true);
         if (ts == null) {
             return false;
@@ -420,7 +421,7 @@ static boolean isAddRightBrace(BaseDocument doc, int caretOffset) throws BadLoca
      * character on the caret row is returned.
      */
     static int getRowOrBlockEnd(BaseDocument doc, int caretOffset, boolean[] insert) throws BadLocationException {
-        int rowEnd = org.netbeans.editor.Utilities.getRowLastNonWhite(doc, caretOffset);
+        int rowEnd = LineDocumentUtils.getLineLastNonWhitespace(doc, caretOffset);
         if (rowEnd == -1 || caretOffset >= rowEnd) {
             return caretOffset;
         }
diff --git a/java/java.editor/test/qa-functional/src/org/netbeans/test/java/editor/completion/CompletionTestCase.java b/java/java.editor/test/qa-functional/src/org/netbeans/test/java/editor/completion/CompletionTestCase.java
index 775de12f42f8..98fd482df6f7 100644
--- a/java/java.editor/test/qa-functional/src/org/netbeans/test/java/editor/completion/CompletionTestCase.java
+++ b/java/java.editor/test/qa-functional/src/org/netbeans/test/java/editor/completion/CompletionTestCase.java
@@ -27,6 +27,7 @@
 import javax.swing.JEditorPane;
 import javax.swing.SwingUtilities;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.test.java.editor.lib.EditorTestCase;
 import org.netbeans.test.java.editor.lib.EditorTestCase.ValueResolver;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
@@ -224,7 +225,7 @@ private void testPerform(PrintWriter out, PrintWriter log,
             throw new IllegalStateException("The testPerform method may be called only inside AWT event dispatch thread.");
         
         BaseDocument doc        = Utilities.getDocument(editor);
-        int          lineOffset = Utilities.getRowStartFromLineOffset(doc, lineIndex -1);
+        int          lineOffset = LineDocumentUtils.getLineStartFromIndex(doc, lineIndex -1);
         
         editor.grabFocus();
         editor.getCaret().setDot(lineOffset);
diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProvider.java b/java/java.hints/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProvider.java
index 8d29604082ab..bed7db4dc8aa 100644
--- a/java/java.hints/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProvider.java
+++ b/java/java.hints/src/org/netbeans/modules/java/hints/infrastructure/ErrorHintsProvider.java
@@ -51,6 +51,7 @@
 import javax.swing.text.StyledDocument;
 import javax.tools.Diagnostic;
 import org.netbeans.api.editor.document.EditorDocumentUtils;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.java.lexer.JavaTokenId;
 import org.netbeans.api.java.source.CompilationInfo;
 import org.netbeans.api.java.source.JavaParserResultTask;
@@ -189,8 +190,8 @@ ErrorDescription processRule(CompilationInfo info, Integer forPosition, Diagnost
 
         if (forPosition != null) {
             try {
-                int posRowStart = org.netbeans.editor.Utilities.getRowStart((NbEditorDocument) doc, forPosition);
-                int errRowStart = org.netbeans.editor.Utilities.getRowStart((NbEditorDocument) doc, range[0].getOffset());
+                int posRowStart = LineDocumentUtils.getLineStartOffset((NbEditorDocument) doc, forPosition);
+                int errRowStart = LineDocumentUtils.getLineStartOffset((NbEditorDocument) doc, range[0].getOffset());
                 if (posRowStart != errRowStart) {
                     return null;
                 }
diff --git a/java/jshell.support/src/org/netbeans/modules/jshell/editor/HistoryCompletionProvider.java b/java/jshell.support/src/org/netbeans/modules/jshell/editor/HistoryCompletionProvider.java
index 7254d77030b6..91898d418418 100644
--- a/java/jshell.support/src/org/netbeans/modules/jshell/editor/HistoryCompletionProvider.java
+++ b/java/jshell.support/src/org/netbeans/modules/jshell/editor/HistoryCompletionProvider.java
@@ -117,7 +117,7 @@ static ShellSession checkInputSection(JTextComponent component) {
         int caret = component.getCaretPosition();
         int lineStart = is.getPartBegin();
         try {
-            int lineEnd = LineDocumentUtils.getLineEnd(ld, caret);
+            int lineEnd = LineDocumentUtils.getLineEndOffset(ld, caret);
             if (caret < lineStart || caret > lineEnd) {
                 return null;
             }
diff --git a/java/jshell.support/src/org/netbeans/modules/jshell/editor/JShellImports.java b/java/jshell.support/src/org/netbeans/modules/jshell/editor/JShellImports.java
index 27847c0e41cc..e1806a42cc5a 100644
--- a/java/jshell.support/src/org/netbeans/modules/jshell/editor/JShellImports.java
+++ b/java/jshell.support/src/org/netbeans/modules/jshell/editor/JShellImports.java
@@ -115,7 +115,7 @@ public void run(ResultIterator resultIterator) throws Exception {
                 // generate the import
                 doc.insertString(o, 
                         "import " + fullyQualifiedClassName + ";\n", null);
-                int eo = LineDocumentUtils.getLineEnd(ld, o);
+                int eo = LineDocumentUtils.getLineEndOffset(ld, o);
                 rf.lock();
                 rf.reformat(o, eo);
             } catch (BadLocationException ex) {
diff --git a/java/jshell.support/src/org/netbeans/modules/jshell/editor/OverrideEditorActions.java b/java/jshell.support/src/org/netbeans/modules/jshell/editor/OverrideEditorActions.java
index 4f726bbf6504..e0325ac1e806 100644
--- a/java/jshell.support/src/org/netbeans/modules/jshell/editor/OverrideEditorActions.java
+++ b/java/jshell.support/src/org/netbeans/modules/jshell/editor/OverrideEditorActions.java
@@ -137,7 +137,7 @@ public void actionPerformed(ActionEvent evt, JTextComponent target) {
                         if (homeKeyColumnOne) { // to first column
                             dot = lineStartPos;
                         } else { // either to line start or text start
-                            int textStartPos = Utilities.getRowFirstNonWhite(doc, lineStartPos);
+                            int textStartPos = LineDocumentUtils.getLineFirstNonWhitespace(doc, lineStartPos);
                             if (textStartPos < 0) { // no text on the line
                                 textStartPos = Utilities.getRowEnd(target, lineStartPos);
                             }
@@ -271,7 +271,7 @@ protected boolean delegates(JTextComponent target) {
                 return true;
             }
             try {
-                int end = LineDocumentUtils.getLineEnd(ld, input.getPartBegin());
+                int end = LineDocumentUtils.getLineEndOffset(ld, input.getPartBegin());
                 return offset > end;
             } catch (BadLocationException ex) {
                 return true;
@@ -308,7 +308,7 @@ protected boolean delegates(JTextComponent target, PositionRegion region, int po
                 return true;
             }
             try {
-                int end = LineDocumentUtils.getLineEnd(ld, region.getStartOffset());
+                int end = LineDocumentUtils.getLineEndOffset(ld, region.getStartOffset());
                 // delegate for all but the first line
                 return pos > end;
             } catch (BadLocationException ex) {
diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrTypedTextInterceptor.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrTypedTextInterceptor.java
index a52b6b938de5..03a2cedf477b 100644
--- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrTypedTextInterceptor.java
+++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrTypedTextInterceptor.java
@@ -120,7 +120,7 @@ private static String textBefore(Context context, int lenght) throws BadLocation
     private static int quotesInLine(Context context, char quote) throws BadLocationException {
         LineDocument doc = (LineDocument) context.getDocument();
         int lineStart = LineDocumentUtils.getLineStart(doc, context.getOffset());
-        int lineEnd = LineDocumentUtils.getLineEnd(doc, context.getOffset());
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, context.getOffset());
         char[] line = doc.getText(lineStart, lineEnd - lineStart).toCharArray();
 
         int quotes = 0;
diff --git a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/refactoring/Refactoring.java b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/refactoring/Refactoring.java
index 027ec05012f4..a40c28bab576 100644
--- a/java/languages.antlr/src/org/netbeans/modules/languages/antlr/refactoring/Refactoring.java
+++ b/java/languages.antlr/src/org/netbeans/modules/languages/antlr/refactoring/Refactoring.java
@@ -160,7 +160,7 @@ public Problem prepare(RefactoringElementsBag refactoringElements) {
                             LineDocument ldoc = (LineDocument) doc;
 
                             int rowStart = LineDocumentUtils.getLineStart(ldoc, or.getStart());
-                            int rowEnd = LineDocumentUtils.getLineEnd(ldoc, or.getEnd());
+                            int rowEnd = LineDocumentUtils.getLineEndOffset(ldoc, or.getEnd());
 
                             bounds = new PositionBounds(
                                     es.createPositionRef(or.getStart(), Position.Bias.Forward),
diff --git a/java/maven.grammar/src/org/netbeans/modules/maven/grammar/effpom/AnnotationBar.java b/java/maven.grammar/src/org/netbeans/modules/maven/grammar/effpom/AnnotationBar.java
index f5436dc8d417..f87b2560c3e6 100644
--- a/java/maven.grammar/src/org/netbeans/modules/maven/grammar/effpom/AnnotationBar.java
+++ b/java/maven.grammar/src/org/netbeans/modules/maven/grammar/effpom/AnnotationBar.java
@@ -36,10 +36,13 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.maven.model.InputLocation;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.fold.FoldHierarchy;
 import org.netbeans.modules.maven.api.ModelUtils;
 import org.netbeans.modules.maven.grammar.effpom.LocationAwareMavenXpp3Writer.Location;
+
 import static org.netbeans.modules.maven.grammar.effpom.Bundle.*;
+
 import org.openide.awt.GraphicsUtils;
 import org.openide.util.NbBundle.Messages;
 
@@ -312,7 +315,7 @@ public void run() {
         int line;
         int offset = caret.getDot();
         try {
-            line = Utilities.getLineOffset(doc, offset);
+            line = LineDocumentUtils.getLineIndex(doc, offset);
         } catch (BadLocationException ex) {
             LOG.log(Level.SEVERE, "Can not get line for caret at offset ", offset); // NOI18N
             return;
@@ -620,7 +623,7 @@ private int getLineFromMouseEvent(MouseEvent e){
                 JTextComponent component = editorUI.getComponent();
                 BaseTextUI textUI = (BaseTextUI)component.getUI();
                 int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
-                line = Utilities.getLineOffset(doc, clickOffset);
+                line = LineDocumentUtils.getLineIndex(doc, clickOffset);
             }catch (BadLocationException ble){
             }
         }
diff --git a/java/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/GoToImplementation.java b/java/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/GoToImplementation.java
index 36556c6b6269..9834e00f1fe0 100644
--- a/java/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/GoToImplementation.java
+++ b/java/maven.grammar/src/org/netbeans/modules/maven/hyperlinks/GoToImplementation.java
@@ -26,6 +26,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
 import org.netbeans.api.editor.EditorActionRegistration;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.project.Project;
 import org.netbeans.api.project.ProjectManager;
 import org.netbeans.editor.AnnotationDesc;
@@ -69,7 +70,7 @@ public void actionPerformed(ActionEvent e, final JTextComponent c) {
                  @Override
                 public void run() {
                     try {
-                        int line = Utilities.getLineOffset((BaseDocument) doc, currentPosition);
+                        int line = LineDocumentUtils.getLineIndex((BaseDocument) doc, currentPosition);
                         AnnotationDesc desc = annotations.getActiveAnnotation(line);
                         if (desc == null) {
                             return;
diff --git a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/hints/HintsTask.java b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/hints/HintsTask.java
index b70f613500df..34859472aea5 100644
--- a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/hints/HintsTask.java
+++ b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/hints/HintsTask.java
@@ -197,8 +197,8 @@ protected boolean isUpToDate(Context context, Document doc, DocumentVersion oldV
 
         @Override
         public List getErrorDescriptionsAt(CompilationInfo info, Context context, Document doc) throws BadLocationException {
-            int rowStart = LineDocumentUtils.getLineStart((BaseDocument) doc, context.getPosition());
-            int rowEnd = LineDocumentUtils.getLineEnd((BaseDocument) doc, context.getPosition());
+            int rowStart = LineDocumentUtils.getLineStartOffset((BaseDocument) doc, context.getPosition());
+            int rowEnd = LineDocumentUtils.getLineEndOffset((BaseDocument) doc, context.getPosition());
 
             return new HintsInvoker(HintsSettings.getSettingsFor(info.getFileObject()), rowStart, rowEnd, context.getCancel()).computeHints(info);
         }
diff --git a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/LineBreakpoint.java b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/LineBreakpoint.java
index 199e74fd5894..15b9a2ace3b9 100644
--- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/LineBreakpoint.java
+++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/LineBreakpoint.java
@@ -116,7 +116,7 @@ public void run(ResultIterator resultIterator) throws Exception {
                                 if (parserResult instanceof PHPParseResult) {
                                     PHPParseResult phpParserResult = (PHPParseResult) parserResult;
                                     int rowStart = LineDocumentUtils.getLineStartFromIndex(baseDocument, myLine.getLineNumber());
-                                    int contentStart = Utilities.getRowFirstNonWhite(baseDocument, rowStart);
+                                    int contentStart = LineDocumentUtils.getLineFirstNonWhitespace(baseDocument, rowStart);
                                     int contentEnd = LineDocumentUtils.getLineLastNonWhitespace(baseDocument, rowStart) + 1;
                                     StatementVisitor statementVisitor = new StatementVisitor(contentStart, contentEnd);
                                     statementVisitor.scan(phpParserResult.getProgram().getStatements());
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java b/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java
index 0562f98d53a3..78a1f2daba6e 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java
@@ -575,17 +575,17 @@ private int getOffset(NamespaceScope namespaceScope, int caretPosition, CheckVis
             if (lastSingleUse != null
                     && lastGroupUse != null) {
                 if (lastSingleUse.getOffset() > lastGroupUse.getOffset()) {
-                    return LineDocumentUtils.getLineEnd(baseDocument, lastSingleUse.getOffset());
+                    return LineDocumentUtils.getLineEndOffset(baseDocument, lastSingleUse.getOffset());
                 }
                 // XXX is this correct?
-                return LineDocumentUtils.getLineEnd(baseDocument, lastGroupUse.getNameRange().getEnd());
+                return LineDocumentUtils.getLineEndOffset(baseDocument, lastGroupUse.getNameRange().getEnd());
             }
             if (lastSingleUse != null) {
-                return LineDocumentUtils.getLineEnd(baseDocument, lastSingleUse.getOffset());
+                return LineDocumentUtils.getLineEndOffset(baseDocument, lastSingleUse.getOffset());
             }
             if (lastGroupUse != null) {
                 // XXX is this correct?
-                return LineDocumentUtils.getLineEnd(baseDocument, lastGroupUse.getNameRange().getEnd());
+                return LineDocumentUtils.getLineEndOffset(baseDocument, lastGroupUse.getNameRange().getEnd());
             }
             // NETBEANS-4978 check whether declare statemens exist
             // e.g. in the following case, insert the code(use statements) after the declare statement
@@ -597,7 +597,7 @@ private int getOffset(NamespaceScope namespaceScope, int caretPosition, CheckVis
             //         $test = new Foo();
             //     }
             // }
-            int offset = LineDocumentUtils.getLineEnd(baseDocument, namespaceScope.getOffset());
+            int offset = LineDocumentUtils.getLineEndOffset(baseDocument, namespaceScope.getOffset());
             if (namespaceScope.isDefaultNamespace()) {
                 // GH-5578: e.g. namespaceScope offset is 0 when phptag is in HTML
                 // 
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportModulePanel.java b/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportModulePanel.java
index a4704edb7794..6956ffa05174 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportModulePanel.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/ImportModulePanel.java
@@ -269,7 +269,7 @@ private void importModule(String importCode, boolean importInPreviousLine, boole
         if (basePosition != -1) {
             EditList edits = new EditList(document);
             try {
-                int rowEnd = importInPreviousLine ? LineDocumentUtils.getLineStart(document, position) : LineDocumentUtils.getLineEnd(document, basePosition);
+                int rowEnd = importInPreviousLine ? LineDocumentUtils.getLineStartOffset(document, position) : LineDocumentUtils.getLineEndOffset(document, basePosition);
                 if (importInPreviousLine) {
                     importCode += "\n"; //NOI18N
                 } else {
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/actions/InsertSemicolonAction.java b/php/php.editor/src/org/netbeans/modules/php/editor/actions/InsertSemicolonAction.java
index 0027ba82ebd2..f975061daf3e 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/actions/InsertSemicolonAction.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/actions/InsertSemicolonAction.java
@@ -74,7 +74,7 @@ public void run() {
                     try {
                         Caret caret = target.getCaret();
                         int caretPosition = caret.getDot();
-                        int eolOffset = LineDocumentUtils.getLineEnd(doc, caretPosition);
+                        int eolOffset = LineDocumentUtils.getLineEndOffset(doc, caretPosition);
                         doc.insertString(eolOffset, SEMICOLON, null);
                         newLineProcessor.processNewLine(eolOffset, caret, indenter);
                     } catch (BadLocationException ex) {
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/codegen/AutoImport.java b/php/php.editor/src/org/netbeans/modules/php/editor/codegen/AutoImport.java
index d573550b988a..e3207bac7a9d 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/codegen/AutoImport.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/codegen/AutoImport.java
@@ -622,12 +622,17 @@ private String getWord(int offset) {
         }
 
         private int getLineStart(int offset) {
-            return LineDocumentUtils.getLineStart(baseDocument, offset);
+            try {
+                return LineDocumentUtils.getLineStartOffset(baseDocument, offset);
+            } catch (BadLocationException ex) {
+                LOGGER.log(Level.WARNING, "Invalid offset: {0}", ex.offsetRequested()); // NOI18N
+            }
+            return offset;
         }
 
         private int getLineEnd(int offset) {
             try {
-                return LineDocumentUtils.getLineEnd(baseDocument, offset);
+                return LineDocumentUtils.getLineEndOffset(baseDocument, offset);
             } catch (BadLocationException ex) {
                 LOGGER.log(Level.WARNING, "Invalid offset: {0}", ex.offsetRequested()); // NOI18N
             }
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java
index 6bbff061c9f6..df5233fcdcd1 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java
@@ -2559,9 +2559,9 @@ private String getPrefix(ParserResult info, int caretOffset, boolean upToOffset,
             if (doc == null) {
                 return null;
             }
-            int lineBegin = LineDocumentUtils.getLineStart(doc, caretOffset);
+            int lineBegin = LineDocumentUtils.getLineStartOffset(doc, caretOffset);
             if (lineBegin != -1) {
-                int lineEnd = LineDocumentUtils.getLineEnd(doc, caretOffset);
+                int lineEnd = LineDocumentUtils.getLineEndOffset(doc, caretOffset);
                 String line = doc.getText(lineBegin, lineEnd - lineBegin);
                 int lineOffset = caretOffset - lineBegin;
                 int start = lineOffset;
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/IndentationCounter.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/IndentationCounter.java
index 18295da01045..70eeb6ca1fbb 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/IndentationCounter.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/IndentationCounter.java
@@ -86,7 +86,7 @@ private Indentation countUnderReadLock(int caretOffset) {
         try {
             boolean insideString = false;
             TokenSequence ts = LexUtilities.getPHPTokenSequence(doc, caretOffset);
-            int caretLineStart = LineDocumentUtils.getLineStart(doc, LineDocumentUtils.getLineStart(doc, caretOffset) - 1);
+            int caretLineStart = LineDocumentUtils.getLineStartOffset(doc, LineDocumentUtils.getLineStartOffset(doc, caretOffset) - 1);
             if (ts != null) {
                 ts.move(caretOffset);
                 ts.moveNext();
@@ -123,7 +123,7 @@ private Indentation countUnderReadLock(int caretOffset) {
                     newIndent = Utilities.getRowIndent(doc, caretLineStart);
                     if (newIndent < 0) {
                         int caretStart = caretOffset - 1;
-                        int caretLineEnd = LineDocumentUtils.getLineEnd(doc, LineDocumentUtils.getLineEnd(doc, caretOffset) - 1);
+                        int caretLineEnd = LineDocumentUtils.getLineEndOffset(doc, LineDocumentUtils.getLineEndOffset(doc, caretOffset) - 1);
                         int curlyOffset = ts.offset() - 1;
                         if (caretLineEnd == caretStart) {
                             newIndent = caretStart - caretLineStart;
@@ -177,7 +177,7 @@ private Indentation countUnderReadLock(int caretOffset) {
                 }
                 if ((ts.token().id() == PHPTokenId.PHP_ENCAPSED_AND_WHITESPACE || ts.token().id() == PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) && caretOffset > ts.offset()) {
 
-                    int stringLineStart = LineDocumentUtils.getLineStart(doc, ts.offset());
+                    int stringLineStart = LineDocumentUtils.getLineStartOffset(doc, ts.offset());
 
                     if (stringLineStart >= caretLineStart) {
                         // string starts on the same line:
@@ -206,7 +206,7 @@ private Indentation countUnderReadLock(int caretOffset) {
                             int casePosition = breakProceededByCase(ts); // is after break in case statement?
                             if (casePosition > -1) {
                                 newIndent = Utilities.getRowIndent(doc, anchor);
-                                if (LineDocumentUtils.getLineStart(doc, casePosition) != caretLineStart) {
+                                if (LineDocumentUtils.getLineStartOffset(doc, casePosition) != caretLineStart) {
                                     // check that case is not on the same line, where enter was pressed
                                     newIndent -= indentSize;
                                 }
@@ -882,7 +882,7 @@ public void run() {
 
         private void modifyUnderWriteLock(Context context) {
             try {
-                context.modifyIndent(LineDocumentUtils.getLineStart((BaseDocument) context.document(), context.caretOffset()), indentation);
+                context.modifyIndent(LineDocumentUtils.getLineStartOffset((BaseDocument) context.document(), context.caretOffset()), indentation);
             } catch (BadLocationException ex) {
                 Exceptions.printStackTrace(ex);
             }
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
index 1fdfe55582e2..f1851b0285b6 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
@@ -1838,7 +1838,7 @@ && countOfNewLines(formatTokens.get(index + 1).getOldText()) > 0) {
                                                             : Integer.valueOf(0);
                                                 }
 
-                                                int lineOffset = LineDocumentUtils.getLineStart(doc, phpOpenTagOffset);
+                                                int lineOffset = LineDocumentUtils.getLineStartOffset(doc, phpOpenTagOffset);
                                                 int firstNonWhiteCharacterOffset = LineDocumentUtils.getNextNonWhitespace(doc, lineOffset);
                                                 if (firstNonWhiteCharacterOffset == phpOpenTagOffset) {
                                                     indentRule = true;
@@ -1948,7 +1948,7 @@ && countOfNewLines(formatTokens.get(index + 1).getOldText()) > 0) {
                                                 int lineNumber = LineDocumentUtils.getLineIndex(doc, offset);
                                                 Integer suggestedIndent = suggestedLineIndents.get(lineNumber);
                                                 if (suggestedIndent != null) {
-                                                    int lineOffset = LineDocumentUtils.getLineStart(doc, offset);
+                                                    int lineOffset = LineDocumentUtils.getLineStartOffset(doc, offset);
                                                     int firstNW = LineDocumentUtils.getNextNonWhitespace(doc, lineOffset);
                                                     if (firstNW == offset) {
                                                         countSpaces = lastPHPIndent == 0 ? htmlIndent : lastPHPIndent + htmlIndent + docOptions.initialIndent;
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java b/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
index c00a2999eb10..2d0f69463789 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/lexer/LexUtilities.java
@@ -327,8 +327,8 @@ public static OffsetRange findBegin(BaseDocument doc, TokenSequence ts = LexUtilities.getPHPTokenSequence(doc, begin);
             if (ts == null) {
@@ -423,7 +423,7 @@ public static int getTokenBalance(BaseDocument doc, char open, char close, int o
      */
     public static boolean isCommentOnlyLine(BaseDocument doc, int offset)
         throws BadLocationException {
-        int begin = Utilities.getRowFirstNonWhite(doc, offset);
+        int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
 
         if (begin == -1) {
             return false; // whitespace only
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedBreakInterceptor.java b/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedBreakInterceptor.java
index 62352172b17f..50b1dd7a5a3b 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedBreakInterceptor.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedBreakInterceptor.java
@@ -30,7 +30,6 @@
 import org.netbeans.api.lexer.TokenSequence;
 import org.netbeans.api.lexer.TokenUtilities;
 import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
 import org.netbeans.lib.editor.util.swing.DocumentUtilities;
 import org.netbeans.modules.csl.spi.GsfUtilities;
 import org.netbeans.modules.php.api.util.FileUtils;
@@ -67,8 +66,8 @@ public void insert(MutableContext context) throws BadLocationException {
         final BaseDocument doc = (BaseDocument) context.getDocument();
         int offset = context.getCaretOffset();
         boolean insertMatching = TypingHooksUtils.isInsertMatchingEnabled();
-        int lineBegin = LineDocumentUtils.getLineStart(doc, offset);
-        int lineEnd = LineDocumentUtils.getLineEnd(doc, offset);
+        int lineBegin = LineDocumentUtils.getLineStartOffset(doc, offset);
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, offset);
         if (lineBegin == offset && lineEnd == offset) {
             // Pressed return on a blank newline - do nothing
             return;
@@ -103,7 +102,7 @@ public void insert(MutableContext context) throws BadLocationException {
             } else {
                 // I'm inserting a newline in the middle of a sentence, such as the scenario in #118656
                 // I should insert the end AFTER the text on the line
-                String restOfLine = doc.getText(offset, LineDocumentUtils.getLineEnd(doc, afterLastNonWhite) - offset);
+                String restOfLine = doc.getText(offset, LineDocumentUtils.getLineEndOffset(doc, afterLastNonWhite) - offset);
                 sb.append(restOfLine);
                 sb.append("\n"); //NOI18N
                 sb.append(createIndentString(doc, offset, indent));
@@ -194,7 +193,7 @@ public void insert(MutableContext context) throws BadLocationException {
             // Pressing newline in the whitespace before a comment
             // should be identical to pressing newline with the caret
             // at the beginning of the comment
-            int begin = Utilities.getRowFirstNonWhite(doc, offset);
+            int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
             if (begin != -1 && offset < begin) {
                 ts.move(begin);
                 if (ts.moveNext()) {
@@ -215,7 +214,7 @@ public void insert(MutableContext context) throws BadLocationException {
             // We should only continue comments if the previous line had a comment
             // (and a comment from the beginning, not a trailing comment)
             boolean previousLineWasComment = false;
-            int rowStart = LineDocumentUtils.getLineStart(doc, offset);
+            int rowStart = LineDocumentUtils.getLineStartOffset(doc, offset);
             if (rowStart > 0) {
                 int prevBegin = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowStart - 1);
                 if (prevBegin != -1) {
@@ -231,7 +230,7 @@ public void insert(MutableContext context) throws BadLocationException {
             if (previousLineWasComment || offset > begin) {
                 if (ts.offset() + token.length() > offset + 1) {
                     // See if the remaining text is just whitespace
-                    String trailing = doc.getText(offset, LineDocumentUtils.getLineEnd(doc, offset) - offset);
+                    String trailing = doc.getText(offset, LineDocumentUtils.getLineEndOffset(doc, offset) - offset);
                     if (trailing.trim().length() != 0 && !trailing.startsWith("//")) { //NOI18N
                         continueComment = true;
                     }
@@ -246,9 +245,9 @@ public void insert(MutableContext context) throws BadLocationException {
                 if (!continueComment) {
                     // See if the next line is a comment; if so we want to continue
                     // comments editing the middle of the comment
-                    int nextLine = LineDocumentUtils.getLineEnd(doc, offset) + 1;
+                    int nextLine = LineDocumentUtils.getLineEndOffset(doc, offset) + 1;
                     if (nextLine < doc.getLength()) {
-                        int nextLineFirst = Utilities.getRowFirstNonWhite(doc, nextLine);
+                        int nextLineFirst = LineDocumentUtils.getLineFirstNonWhitespace(doc, nextLine);
                         if (nextLineFirst != -1) {
                             Token firstToken = LexUtilities.getToken(doc, nextLineFirst);
                             if (firstToken != null && firstToken.id() == PHPTokenId.PHP_LINE_COMMENT) {
@@ -274,7 +273,7 @@ public void insert(MutableContext context) throws BadLocationException {
                 sb.append(commentDelimiter);
                 // Copy existing indentation
                 int afterHash = begin + commentDelimiter.length();
-                String line = doc.getText(afterHash, LineDocumentUtils.getLineEnd(doc, afterHash) - afterHash);
+                String line = doc.getText(afterHash, LineDocumentUtils.getLineEndOffset(doc, afterHash) - afterHash);
                 for (int i = 0; i < line.length(); i++) {
                     char c = line.charAt(i);
                     if (c == ' ' || c == '\t') {
@@ -647,7 +646,7 @@ private static Object[] beforeBreakInComments(
             } else {
                 // I'm inserting a newline in the middle of a sentence, such as the scenario in #118656
                 // I should insert the end AFTER the text on the line
-                String restOfLine = doc.getText(insertOffset, LineDocumentUtils.getLineEnd(doc, afterLastNonWhite) - insertOffset);
+                String restOfLine = doc.getText(insertOffset, LineDocumentUtils.getLineEndOffset(doc, afterLastNonWhite) - insertOffset);
                 sb.append(org.netbeans.modules.editor.indent.api.IndentUtils.createIndentString(doc, indent));
                 if (insertAsterisk) {
                     sb.append(" * "); // NOI18N
@@ -679,8 +678,8 @@ private static Object[] beforeBreakInComments(
                 assert false : "PHP_COMMENT_END without PHP_COMMENT or PHP_COMMENT_START"; //NOI18N
             }
             int indent = GsfUtilities.getLineIndent(doc, ts.offset());
-            int beforeFirstNonWhite = Utilities.getRowFirstNonWhite(doc, insertOffset);
-            int rowStart = LineDocumentUtils.getLineStart(doc, insertOffset);
+            int beforeFirstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, insertOffset);
+            int rowStart = LineDocumentUtils.getLineStartOffset(doc, insertOffset);
             StringBuilder sb = new StringBuilder("\n"); // NOI18N
             int newCaretOffset = 1;
             int newCaretOffset2 = insertOffset;
@@ -790,7 +789,7 @@ static boolean isEndMissing(BaseDocument doc, int offset, boolean skipJunk,
             boolean[] insertEndResult, boolean[] insertRBraceResult, int[] startOffsetResult,
             int[] indentResult, PHPTokenId insertingEnd) throws BadLocationException {
         if (startOffsetResult != null) {
-            startOffsetResult[0] = Utilities.getRowFirstNonWhite(doc, offset);
+            startOffsetResult[0] = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
         }
         TokenSequence ts = LexUtilities.getPHPTokenSequence(doc, offset);
         if (ts == null) {
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java b/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java
index c99621066d5c..7ad9612b5484 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java
@@ -440,7 +440,7 @@ private void reindent(BaseDocument doc, int offset, TokenId id, Caret caret) thr
             }
             Token token = ts.token();
             if ((token.id() == id)) {
-                final int rowFirstNonWhite = Utilities.getRowFirstNonWhite(doc, offset);
+                final int rowFirstNonWhite = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
                 if (id == PHPTokenId.PHP_CURLY_OPEN && ts.offset() == rowFirstNonWhite
                         && ts.movePrevious()) {
                     // The curly is at the first nonwhite char at the line.
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/AddUseImportSuggestion.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/AddUseImportSuggestion.java
index ba22ffaeb74d..f5e033f25661 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/AddUseImportSuggestion.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/AddUseImportSuggestion.java
@@ -307,7 +307,7 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, 0, "\n" + getGeneratedCode(), true, 0); //NOI18N
             edits.apply();
-            UiUtils.open(scope.getFileObject(), LineDocumentUtils.getLineStart(doc, getOffsetRange().getEnd()));
+            UiUtils.open(scope.getFileObject(), LineDocumentUtils.getLineStartOffset(doc, getOffsetRange().getEnd()));
         }
 
         private String getGeneratedCode() {
@@ -316,7 +316,7 @@ private String getGeneratedCode() {
 
         private int getOffset() {
             try {
-                return LineDocumentUtils.getLineEnd(doc, getReferenceElement().getOffset());
+                return LineDocumentUtils.getLineEndOffset(doc, getReferenceElement().getOffset());
             } catch (BadLocationException ex) {
                 Exceptions.printStackTrace(ex);
             }
@@ -380,7 +380,7 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, oldName.toString().length(), getGeneratedCode(), true, 0); //NOI18N
             edits.apply();
-            UiUtils.open(scope.getFileObject(), LineDocumentUtils.getLineStart(doc, templateOffset));
+            UiUtils.open(scope.getFileObject(), LineDocumentUtils.getLineStartOffset(doc, templateOffset));
         }
 
         private String getGeneratedCode() {
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/ArrayDimensionSyntaxSuggestionHint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/ArrayDimensionSyntaxSuggestionHint.java
index e91f6aacc7ac..f60bd92387d4 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/ArrayDimensionSyntaxSuggestionHint.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/ArrayDimensionSyntaxSuggestionHint.java
@@ -128,8 +128,8 @@ public List getHints() {
                             // all
                             int lineIndex = LineDocumentUtils.getLineIndex(document, fixInfo.getOffsetRange().getStart());
                             if (originalLineIndex != lineIndex) {
-                                int lineStart = LineDocumentUtils.getLineStart(document, fixInfo.getOffsetRange().getStart());
-                                int lineEnd = LineDocumentUtils.getLineEnd(document, fixInfo.getOffsetRange().getStart());
+                                int lineStart = LineDocumentUtils.getLineStartOffset(document, fixInfo.getOffsetRange().getStart());
+                                int lineEnd = LineDocumentUtils.getLineEndOffset(document, fixInfo.getOffsetRange().getStart());
                                 addHint(hints, new OffsetRange(lineStart, lineEnd), createAllFixes(fixInfos));
                                 originalLineIndex = lineIndex;
                             }
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/ImplementAbstractMethodsHintError.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/ImplementAbstractMethodsHintError.java
index a945640413f5..6d5a72eafd36 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/ImplementAbstractMethodsHintError.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/ImplementAbstractMethodsHintError.java
@@ -326,12 +326,12 @@ private static int getNewMethodsOffset(TypeScope typeScope, BaseDocument doc, in
         }
         if (offset == -1 && typeScope.getBlockRange() != null) {
             try {
-                int rowStartOfClassEnd = LineDocumentUtils.getLineStart(doc, typeScope.getBlockRange().getEnd());
+                int rowStartOfClassEnd = LineDocumentUtils.getLineStartOffset(doc, typeScope.getBlockRange().getEnd());
                 int rowEndOfPreviousRow = rowStartOfClassEnd - 1;
 
                 // #254173 the previous row may have something to break the code
                 // e.g. "{" for the class declaration, a field accross multiple lines
-                int rowStartOfPreviousRow = LineDocumentUtils.getLineStart(doc, rowEndOfPreviousRow);
+                int rowStartOfPreviousRow = LineDocumentUtils.getLineStartOffset(doc, rowEndOfPreviousRow);
                 int newMethodPossibleOffset = rowStartOfPreviousRow < rowEndOfPreviousRow ? rowStartOfClassEnd : rowStartOfPreviousRow;
 
                 int newMethodLineOffset = LineDocumentUtils.getLineIndex(doc, newMethodPossibleOffset);
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
index 0b9738fe3031..3f0938259e4f 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
@@ -528,8 +528,8 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, 0, "\n" + item.getCustomInsertTemplate(), true, 0); //NOI18N
             edits.apply();
-            templateOffset = LineDocumentUtils.getLineEnd(doc, templateOffset + 1);
-            UiUtils.open(type.getFileObject(), LineDocumentUtils.getLineEnd(doc, templateOffset + 1) - 1);
+            templateOffset = LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1);
+            UiUtils.open(type.getFileObject(), LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1) - 1);
         }
 
         @Override
@@ -569,8 +569,8 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, 0, "\n" + item.getCustomInsertTemplate(), true, 0); //NOI18N
             edits.apply();
-            templateOffset = LineDocumentUtils.getLineEnd(doc, templateOffset + 1);
-            UiUtils.open(type.getFileObject(), LineDocumentUtils.getLineEnd(doc, templateOffset + 1) - 1);
+            templateOffset = LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1);
+            UiUtils.open(type.getFileObject(), LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1) - 1);
         }
 
         @Override
@@ -613,7 +613,7 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, 0, "\n" + templ, true, 0); //NOI18N
             edits.apply();
-            templateOffset = LineDocumentUtils.getLineEnd(doc, templateOffset + 1) - 2;
+            templateOffset = LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1) - 2;
             UiUtils.open(type.getFileObject(), templateOffset);
         }
 
@@ -674,7 +674,7 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, 0, "\n" + templ, true, 0); //NOI18N
             edits.apply();
-            templateOffset = LineDocumentUtils.getLineEnd(doc, templateOffset + 1) - 2;
+            templateOffset = LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1) - 2;
             UiUtils.open(type.getFileObject(), templateOffset);
         }
 
@@ -726,7 +726,7 @@ public void implement() throws Exception {
             EditList edits = new EditList(doc);
             edits.replace(templateOffset, 0, "\n" + templ, true, 0); //NOI18N
             edits.apply();
-            templateOffset = LineDocumentUtils.getLineEnd(doc, templateOffset + 1) - 2;
+            templateOffset = LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1) - 2;
             UiUtils.open(type.getFileObject(), templateOffset);
         }
 
@@ -799,7 +799,7 @@ public void implement() throws Exception {
             edits.replace(templateOffset, 0, "\n" + template, true, 0); // NOI18N
             edits.apply();
             int caretPositionFromEndOftemplate = Type.STRING.equalsIgnoreCase(backingType) ? 2 : 1;
-            templateOffset = LineDocumentUtils.getLineEnd(doc, templateOffset + 1) - caretPositionFromEndOftemplate;
+            templateOffset = LineDocumentUtils.getLineEndOffset(doc, templateOffset + 1) - caretPositionFromEndOftemplate;
             UiUtils.open(type.getFileObject(), templateOffset);
         }
 
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/NestedBlocksHint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/NestedBlocksHint.java
index 60670c57461a..ac10b2c7f888 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/NestedBlocksHint.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/NestedBlocksHint.java
@@ -106,7 +106,7 @@ private Collection getHints() {
         private void createHint(ASTNode block) {
             int lineEnd = block.getEndOffset();
             try {
-                lineEnd = LineDocumentUtils.getLineEnd(baseDocument, block.getStartOffset());
+                lineEnd = LineDocumentUtils.getLineEndOffset(baseDocument, block.getStartOffset());
             } catch (BadLocationException ex) {
                 LOGGER.log(Level.FINE, null, ex);
             }
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR12FilesHint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR12FilesHint.java
index cd2a8956e357..6282a77bdf33 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR12FilesHint.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR12FilesHint.java
@@ -44,12 +44,12 @@ protected CheckVisitor createVisitor(FileObject fileObject, BaseDocument baseDoc
         FilesVisitor filesVisitor = new FilesVisitor(this, fileObject, baseDocument);
         try {
             int lastPosition = baseDocument.getLength();
-            int lineStart = LineDocumentUtils.getLineStart(baseDocument, lastPosition);
+            int lineStart = LineDocumentUtils.getLineStartOffset(baseDocument, lastPosition);
             if (!endsWithSingleLF(baseDocument)) {
                 filesVisitor.createHint(new OffsetRange(lineStart, lastPosition), Bundle.PSR12FilesTerminatedWithSingleLFHint());
             }
             if (!isLF(baseDocument)) {
-                int lineEnd = LineDocumentUtils.getLineEnd(baseDocument, 0);
+                int lineEnd = LineDocumentUtils.getLineEndOffset(baseDocument, 0);
                 filesVisitor.createHint(new OffsetRange(0, lineEnd), Bundle.PSR12FilesLFOnlyHint());
             }
         } catch (BadLocationException ex) {
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/VarDocSuggestion.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/VarDocSuggestion.java
index 899a588789b6..a2ae45575196 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/VarDocSuggestion.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/VarDocSuggestion.java
@@ -181,8 +181,8 @@ private String getTypeTemplate() {
         }
 
         private int getOffset(BaseDocument doc) throws BadLocationException {
-            final int caretOffset = LineDocumentUtils.getLineStart(doc, context.caretOffset);
-            return LineDocumentUtils.getLineEnd(doc, caretOffset - 1);
+            final int caretOffset = LineDocumentUtils.getLineStartOffset(doc, context.caretOffset);
+            return LineDocumentUtils.getLineEndOffset(doc, caretOffset - 1);
         }
 
         private void scheduleShowingCompletion() {
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/VerificationUtils.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/VerificationUtils.java
index fe8b2418a2ca..0a487eea9f78 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/VerificationUtils.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/VerificationUtils.java
@@ -44,8 +44,8 @@ public static OffsetRange createLineBounds(int caretOffset, BaseDocument doc) {
         OffsetRange result = OffsetRange.NONE;
         if (caretOffset != -1) {
             try {
-                int lineBegin = caretOffset >= 0 ? LineDocumentUtils.getLineStart(doc, caretOffset) : -1;
-                int lineEnd = (lineBegin != -1) ? LineDocumentUtils.getLineEnd(doc, caretOffset) : -1;
+                int lineBegin = caretOffset >= 0 ? LineDocumentUtils.getLineStartOffset(doc, caretOffset) : -1;
+                int lineEnd = (lineBegin != -1) ? LineDocumentUtils.getLineEndOffset(doc, caretOffset) : -1;
                 if (lineBegin > -1 && lineEnd != -1 && lineBegin <= lineEnd) {
                     result = new OffsetRange(lineBegin, lineEnd);
                 }
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/WrongParamNameHint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/WrongParamNameHint.java
index f3b3a8a21a00..634758574c1d 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/WrongParamNameHint.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/WrongParamNameHint.java
@@ -158,7 +158,7 @@ private void createHint(PHPDocNode paramVariable, String parameterName) {
         private int getLineEnd(PHPDocNode paramVariable) {
             int result = paramVariable.getEndOffset();
             try {
-                result = LineDocumentUtils.getLineEnd(doc, paramVariable.getStartOffset());
+                result = LineDocumentUtils.getLineEndOffset(doc, paramVariable.getStartOffset());
             } catch (BadLocationException ex) {
                 LOGGER.log(Level.FINE, null, ex);
             }
diff --git a/php/php.latte/src/org/netbeans/modules/php/latte/hints/HintsUtils.java b/php/php.latte/src/org/netbeans/modules/php/latte/hints/HintsUtils.java
index 8bb7d9599076..d7ea598e82b3 100644
--- a/php/php.latte/src/org/netbeans/modules/php/latte/hints/HintsUtils.java
+++ b/php/php.latte/src/org/netbeans/modules/php/latte/hints/HintsUtils.java
@@ -21,6 +21,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 import org.netbeans.modules.csl.api.OffsetRange;
@@ -40,8 +41,8 @@ public static OffsetRange createLineBounds(int caretOffset, BaseDocument doc) {
         OffsetRange result = OffsetRange.NONE;
         if (caretOffset != -1) {
             try {
-                int lineBegin = caretOffset > 0 ? Utilities.getRowStart(doc, caretOffset) : -1;
-                int lineEnd = (lineBegin != -1) ? Utilities.getRowEnd(doc, caretOffset) : -1;
+                int lineBegin = caretOffset > 0 ? LineDocumentUtils.getLineStartOffset(doc, caretOffset) : -1;
+                int lineEnd = (lineBegin != -1) ? LineDocumentUtils.getLineEndOffset(doc, caretOffset) : -1;
                 if (lineBegin > -1 && lineEnd != -1 && lineBegin <= lineEnd) {
                     result = new OffsetRange(lineBegin, lineEnd);
                 }
diff --git a/php/php.latte/src/org/netbeans/modules/php/latte/indent/LatteIndenter.java b/php/php.latte/src/org/netbeans/modules/php/latte/indent/LatteIndenter.java
index 850a4137b90a..07eeb1fd31bc 100644
--- a/php/php.latte/src/org/netbeans/modules/php/latte/indent/LatteIndenter.java
+++ b/php/php.latte/src/org/netbeans/modules/php/latte/indent/LatteIndenter.java
@@ -24,10 +24,10 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenSequence;
-import org.netbeans.editor.Utilities;
 import org.netbeans.modules.editor.indent.spi.Context;
 import org.netbeans.modules.php.latte.LatteSyntax;
 import org.netbeans.modules.php.latte.lexer.LatteMarkupTokenId;
@@ -154,7 +154,7 @@ protected List getLineIndent(IndenterContextData
                 } else if (start == ts.offset()) {
                     if (end < commentEndOffset) {
                         // if comment ends on next line put formatter to IN_COMMENT state
-                        int lineStart = Utilities.getRowStart(getDocument(), ts.offset());
+                        int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), ts.offset());
                         preservedLineIndentation = start - lineStart;
                     }
                 } else if (end == commentEndOffset) {
diff --git a/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedElement.java b/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedElement.java
index bc0003ec6c6a..0679b2172e7e 100644
--- a/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedElement.java
+++ b/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedElement.java
@@ -25,6 +25,7 @@
 import javax.swing.Icon;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Position.Bias;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 import org.netbeans.modules.csl.api.OffsetRange;
@@ -136,16 +137,16 @@ public static WhereUsedElement create(String name, FileObject fo,  OffsetRange r
                 // for for example find subclasses (using a singly dummy FileInfo) I need
                 // to read it here instead
                 String content = bdoc.getText(0, bdoc.getLength());
-                int sta = Utilities.getRowFirstNonWhite(bdoc, start);
+                int sta = LineDocumentUtils.getLineFirstNonWhitespace(bdoc, start);
 
                 if (sta == -1) {
-                    sta = Utilities.getRowStart(bdoc, start);
+                    sta = LineDocumentUtils.getLineStartOffset(bdoc, start);
                 }
 
-                int en = Utilities.getRowLastNonWhite(bdoc, start);
+                int en = LineDocumentUtils.getLineLastNonWhitespace(bdoc, start);
 
                 if (en == -1) {
-                    en = Utilities.getRowEnd(bdoc, start);
+                    en = LineDocumentUtils.getLineEndOffset(bdoc, start);
                 } else {
                     // Last nonwhite - left side of the last char, not inclusive
                     en++;
diff --git a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/actions/ToggleBlockCommentAction.java b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/actions/ToggleBlockCommentAction.java
index c5c1f4eea8e0..84f3c134dfcd 100644
--- a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/actions/ToggleBlockCommentAction.java
+++ b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/actions/ToggleBlockCommentAction.java
@@ -22,6 +22,7 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.TokenSequence;
 import org.netbeans.editor.BaseAction;
 import org.netbeans.editor.BaseDocument;
@@ -77,10 +78,10 @@ public void run() {
                             commentIt.set(false);
                         } else {
                             try {
-                                ts.move(Utilities.getRowStart(doc, caretOffset) + tplMetaData.getCloseDelimiter().length() + 1);
+                                ts.move(LineDocumentUtils.getLineStartOffset(doc, caretOffset) + tplMetaData.getCloseDelimiter().length() + 1);
                                 ts.moveNext();
                                 if (ts.token() != null && ts.token().id() == TplTopTokenId.T_COMMENT
-                                        && Utilities.getRowEnd(doc, caretOffset) == caretOffset) {
+                                        && LineDocumentUtils.getLineEndOffset(doc, caretOffset) == caretOffset) {
                                     commentIt.set(false);
                                 }
                             } catch (BadLocationException ex) {
@@ -158,8 +159,8 @@ private static int[] getPositions(TokenSequence ts, boolean comme
                 positions[0] = caretOffset;
                 positions[1] = target.getSelectionEnd();
             } else {
-                positions[0] = Utilities.getRowStart((BaseDocument) target.getDocument(), caretOffset);
-                positions[1] = Utilities.getRowEnd((BaseDocument) target.getDocument(), caretOffset);
+                positions[0] = LineDocumentUtils.getLineStartOffset((BaseDocument) target.getDocument(), caretOffset);
+                positions[1] = LineDocumentUtils.getLineEndOffset((BaseDocument) target.getDocument(), caretOffset);
             }
         } else {
             while (ts.movePrevious() && ts.token().id() != TplTopTokenId.T_SMARTY_OPEN_DELIMITER) {
diff --git a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/coloring/EmbeddingHighlightsContainer.java b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/coloring/EmbeddingHighlightsContainer.java
index 12c25e0b7a82..454c0398f47e 100644
--- a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/coloring/EmbeddingHighlightsContainer.java
+++ b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/coloring/EmbeddingHighlightsContainer.java
@@ -29,6 +29,7 @@
 import javax.swing.text.Document;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyleConstants;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.api.editor.settings.AttributesUtilities;
 import org.netbeans.api.editor.settings.FontColorSettings;
@@ -180,17 +181,17 @@ private boolean _moveNext() {
                                 } while (eTokenSequence.moveNext());
 
                                 realEndOffset = endOffset > realEndOffset ? endOffset : realEndOffset + 1;
-                                int startLO = Utilities.getLineOffset((BaseDocument) document, startOffset);
-                                int endLO = Utilities.getLineOffset((BaseDocument) document, endOffset);
+                                int startLO = LineDocumentUtils.getLineIndex((BaseDocument) document, startOffset);
+                                int endLO = LineDocumentUtils.getLineIndex((BaseDocument) document, endOffset);
                                 if (startLO != endLO) {
                                     //not just one line block - test boundaries
-                                    if ((Utilities.getFirstNonWhiteBwd((BaseDocument) document, Utilities.getRowEnd((BaseDocument) document, startOffset)) + 1) == startOffset) {
+                                    if ((LineDocumentUtils.getPreviousNonWhitespace((BaseDocument) document, LineDocumentUtils.getLineEndOffset((BaseDocument) document, startOffset)) + 1) == startOffset) {
                                         //just  tag on the first line -> move start to next line
-                                        startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, startLO + 1);
+                                        startOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, startLO + 1);
                                     }
-                                    if (Utilities.getFirstNonWhiteFwd((BaseDocument) document, Utilities.getRowStartFromLineOffset((BaseDocument) document, endLO)) == endOffset) {
+                                    if (LineDocumentUtils.getNextNonWhitespace((BaseDocument) document, LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, endLO)) == endOffset) {
                                         //just  tag on the last line -> move block end to previous line end
-                                        endOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, endLO);
+                                        endOffset = LineDocumentUtils.getLineStartFromIndex((BaseDocument) document, endLO);
                                     }
                                 }
 
diff --git a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/TplCompletionItem.java b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/TplCompletionItem.java
index aaa1966feed0..11976863acb1 100644
--- a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/TplCompletionItem.java
+++ b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/completion/TplCompletionItem.java
@@ -32,6 +32,7 @@
 import java.awt.event.KeyEvent;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;
 import org.netbeans.spi.editor.completion.support.CompletionUtilities;
 import org.openide.util.ImageUtilities;
@@ -168,8 +169,8 @@ private void reindent(JTextComponent component) {
 
                 public void run() {
                     try {
-                        int startOffset = Utilities.getRowStart(doc, dotPos);
-                        int endOffset = Utilities.getRowEnd(doc, dotPos);
+                        int startOffset = LineDocumentUtils.getLineStartOffset(doc, dotPos);
+                        int endOffset = LineDocumentUtils.getLineEndOffset(doc, dotPos);
                         indent.reindent(startOffset, endOffset);
                     } catch (BadLocationException ex) {
                         //ignore
diff --git a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java
index ed98049c297c..6e6c16e930bd 100644
--- a/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java
+++ b/php/php.smarty/src/org/netbeans/modules/php/smarty/editor/indent/TplIndenter.java
@@ -25,11 +25,11 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenId;
 import org.netbeans.api.lexer.TokenSequence;
-import org.netbeans.editor.Utilities;
 import org.netbeans.lib.editor.util.CharSequenceUtilities;
 import org.netbeans.modules.editor.indent.spi.Context;
 import org.netbeans.modules.php.smarty.editor.TplSyntax;
@@ -263,7 +263,7 @@ protected List getLineIndent(IndenterContextData c
                 } else if (start == ts.offset()) {
                     if (end < commentEndOffset) {
                         // if comment ends on next line put formatter to IN_COMMENT state
-                        int lineStart = Utilities.getRowStart(getDocument(), ts.offset());
+                        int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), ts.offset());
                         preservedLineIndentation = start - lineStart;
                     }
                 } else if (end == commentEndOffset) {
diff --git a/php/php.twig/src/org/netbeans/modules/php/twig/editor/actions/ToggleBlockCommentAction.java b/php/php.twig/src/org/netbeans/modules/php/twig/editor/actions/ToggleBlockCommentAction.java
index a2d1ca9c57a5..951376eab1a3 100644
--- a/php/php.twig/src/org/netbeans/modules/php/twig/editor/actions/ToggleBlockCommentAction.java
+++ b/php/php.twig/src/org/netbeans/modules/php/twig/editor/actions/ToggleBlockCommentAction.java
@@ -26,6 +26,7 @@
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.LineDocumentUtils;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenSequence;
 import org.netbeans.editor.BaseAction;
@@ -276,8 +277,8 @@ public void comment(BaseDocument baseDocument) throws BadLocationException {
                 offsetCommentStart = getStart();
                 offsetCommentEnd = getEnd();
             } else {
-                offsetCommentStart = Utilities.getRowStart(baseDocument, getStart());
-                offsetCommentEnd = Utilities.getRowEnd(baseDocument, getEnd());
+                offsetCommentStart = LineDocumentUtils.getLineStartOffset(baseDocument, getStart());
+                offsetCommentEnd = LineDocumentUtils.getLineEndOffset(baseDocument, getEnd());
             }
             baseDocument.insertString(offsetCommentStart, TwigTopLexer.OPEN_COMMENT, null);
             baseDocument.insertString(offsetCommentEnd + TwigTopLexer.OPEN_COMMENT.length(), TwigTopLexer.CLOSE_COMMENT, null);
diff --git a/php/php.twig/src/org/netbeans/modules/php/twig/editor/format/TwigIndenter.java b/php/php.twig/src/org/netbeans/modules/php/twig/editor/format/TwigIndenter.java
index c3b4d977f280..78982f5381ec 100644
--- a/php/php.twig/src/org/netbeans/modules/php/twig/editor/format/TwigIndenter.java
+++ b/php/php.twig/src/org/netbeans/modules/php/twig/editor/format/TwigIndenter.java
@@ -162,7 +162,7 @@ protected List getLineIndent(IndenterContextData
                 } else if (start == ts.offset()) {
                     if (end < commentEndOffset) {
                         // if comment ends on next line put formatter to IN_COMMENT state
-                        int lineStart = LineDocumentUtils.getLineStart(getDocument(), ts.offset());
+                        int lineStart = LineDocumentUtils.getLineStartOffset(getDocument(), ts.offset());
                         preservedLineIndentation = start - lineStart;
                     }
                 } else if (end == commentEndOffset) {
diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedBreakInterceptor.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedBreakInterceptor.java
index 986abf7488f0..2f91859d7071 100644
--- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedBreakInterceptor.java
+++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedBreakInterceptor.java
@@ -98,8 +98,8 @@ public void insert(MutableContext context) throws BadLocationException {
         TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc);
         int offset = context.getCaretOffset();
 
-        int lineBegin = LineDocumentUtils.getLineStart(doc, offset);
-        int lineEnd = LineDocumentUtils.getLineEnd(doc, offset);
+        int lineBegin = LineDocumentUtils.getLineStartOffset(doc, offset);
+        int lineEnd = LineDocumentUtils.getLineEndOffset(doc, offset);
 
         if (lineBegin == offset && lineEnd == offset) {
             // Pressed return on a blank newline - do nothing
@@ -152,7 +152,7 @@ public void insert(MutableContext context) throws BadLocationException {
                     // I'm inserting a newline in the middle of a sentence, such as the scenario in #118656
                     // I should insert the end AFTER the text on the line
                     String restOfLine = doc.getText(offset,
-                            Math.min(end, LineDocumentUtils.getLineEnd(doc, afterLastNonWhite)) - offset);
+                            Math.min(end, LineDocumentUtils.getLineEndOffset(doc, afterLastNonWhite)) - offset);
                     sb.append("\n"); // XXX On Windows, do \r\n?
                     sb.append(IndentUtils.createIndentString(doc, indent + IndentUtils.indentLevelSize(doc)));
                     // right brace must be included into the correct context - issue #219683
@@ -297,7 +297,7 @@ public void insert(MutableContext context) throws BadLocationException {
             // Pressing newline in the whitespace before a comment
             // should be identical to pressing newline with the caret
             // at the beginning of the comment
-            int begin = Utilities.getRowFirstNonWhite(doc, offset);
+            int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
             if (begin != -1 && offset < begin) {
                 ts.move(begin);
                 if (ts.moveNext()) {
@@ -312,8 +312,8 @@ public void insert(MutableContext context) throws BadLocationException {
         if ((id == JsTokenId.BLOCK_COMMENT || id == JsTokenId.DOC_COMMENT)
                 && offset > ts.offset() && offset < ts.offset()+ts.token().length()) {
             // Continue *'s
-            int begin = Utilities.getRowFirstNonWhite(doc, offset);
-            int end = LineDocumentUtils.getLineEnd(doc, offset)+1;
+            int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
+            int end = LineDocumentUtils.getLineEndOffset(doc, offset)+1;
             if (begin == -1) {
                 begin = end;
             }
@@ -346,7 +346,7 @@ public void insert(MutableContext context) throws BadLocationException {
                     // Copy existing indentation inside the block
                     sb.append("*"); //NOI18N
                     int afterStar = isBlockStart ? begin+2 : begin+1;
-                    line = doc.getText(afterStar, LineDocumentUtils.getLineEnd(doc, afterStar)-afterStar);
+                    line = doc.getText(afterStar, LineDocumentUtils.getLineEndOffset(doc, afterStar)-afterStar);
                     for (int i = 0; i < line.length(); i++) {
                         char c = line.charAt(i);
                         if (c == ' ' || c == '\t') { //NOI18N
@@ -380,15 +380,15 @@ public void insert(MutableContext context) throws BadLocationException {
             // or if the next line is a comment!
 
             boolean continueComment = false;
-            int begin = Utilities.getRowFirstNonWhite(doc, offset);
+            int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
 
             // We should only continue comments if the previous line had a comment
             // (and a comment from the beginning, not a trailing comment)
             boolean previousLineWasComment = false;
             boolean nextLineIsComment = false;
-            int rowStart = LineDocumentUtils.getLineStart(doc, offset);
+            int rowStart = LineDocumentUtils.getLineStartOffset(doc, offset);
             if (rowStart > 0) {
-                int prevBegin = Utilities.getRowFirstNonWhite(doc, rowStart - 1);
+                int prevBegin = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowStart - 1);
                 if (prevBegin != -1) {
                     Token firstToken = LexUtilities.getToken(
                             doc, prevBegin, language);
@@ -397,9 +397,9 @@ public void insert(MutableContext context) throws BadLocationException {
                     }
                 }
             }
-            int rowEnd = LineDocumentUtils.getLineEnd(doc, offset);
+            int rowEnd = LineDocumentUtils.getLineEndOffset(doc, offset);
             if (rowEnd < doc.getLength()) {
-                int nextBegin = Utilities.getRowFirstNonWhite(doc, rowEnd + 1);
+                int nextBegin = LineDocumentUtils.getLineFirstNonWhitespace(doc, rowEnd + 1);
                 if (nextBegin != -1) {
                     Token firstToken = LexUtilities.getToken(
                             doc, nextBegin, language);
@@ -416,7 +416,7 @@ public void insert(MutableContext context) throws BadLocationException {
                     || (offset > ts.offset() && offset < ts.offset() + ts.token().length())) {
                 if (ts.offset() + token.length() > offset + 1) {
                     // See if the remaining text is just whitespace
-                    String trailing = doc.getText(offset, LineDocumentUtils.getLineEnd(doc, offset) - offset);
+                    String trailing = doc.getText(offset, LineDocumentUtils.getLineEndOffset(doc, offset) - offset);
                     if (trailing.trim().length() != 0) {
                         continueComment = true;
                     }
@@ -432,9 +432,9 @@ public void insert(MutableContext context) throws BadLocationException {
                 if (!continueComment) {
                     // See if the next line is a comment; if so we want to continue
                     // comments editing the middle of the comment
-                    int nextLine = LineDocumentUtils.getLineEnd(doc, offset) + 1;
+                    int nextLine = LineDocumentUtils.getLineEndOffset(doc, offset) + 1;
                     if (nextLine < doc.getLength()) {
-                        int nextLineFirst = Utilities.getRowFirstNonWhite(doc, nextLine);
+                        int nextLineFirst = LineDocumentUtils.getLineFirstNonWhitespace(doc, nextLine);
                         if (nextLineFirst != -1) {
                             Token firstToken = LexUtilities.getToken(
                                     doc, nextLineFirst, language);
@@ -457,7 +457,7 @@ public void insert(MutableContext context) throws BadLocationException {
                 sb.append("//"); // NOI18N
                 // Copy existing indentation
                 int afterSlash = begin + 2;
-                String line = doc.getText(afterSlash, LineDocumentUtils.getLineEnd(doc, afterSlash) - afterSlash);
+                String line = doc.getText(afterSlash, LineDocumentUtils.getLineEndOffset(doc, afterSlash) - afterSlash);
                 for (int i = 0; i < line.length(); i++) {
                     char c = line.charAt(i);
                     if (c == ' ' || c == '\t') {
@@ -534,7 +534,7 @@ private int getNextLineIndentation(BaseDocument doc, int offset) throws BadLocat
                 }
                 return indent;
             }
-            currentOffset = LineDocumentUtils.getLineStart(doc, currentOffset) - 1;
+            currentOffset = LineDocumentUtils.getLineStartOffset(doc, currentOffset) - 1;
         }
 
         return indent;
@@ -603,7 +603,7 @@ private boolean isAddRightBrace(BaseDocument doc, int caretOffset) throws BadLoc
             return false;
         }
 
-        int caretRowStartOffset = LineDocumentUtils.getLineStart(doc, caretOffset);
+        int caretRowStartOffset = LineDocumentUtils.getLineStartOffset(doc, caretOffset);
         ts = LexUtilities.getPositionedSequence(doc, caretOffset, language);
         if (ts == null) {
             return false;
@@ -728,7 +728,7 @@ private int getUnbalancedCurlyOffset(BaseDocument doc, int offset) throws BadLoc
 
     private int getCurlyIndent(BaseDocument doc, int offset) {
         try {
-            int lineStart = LineDocumentUtils.getLineStart(doc, offset);
+            int lineStart = LineDocumentUtils.getLineStartOffset(doc, offset);
             TokenSequence ts = LexUtilities.getTokenSequence(
                     doc, lineStart, language);
 
@@ -803,7 +803,7 @@ private static boolean hasCommentEnd(TokenSequence language)
             throws BadLocationException {
 
-        int begin = Utilities.getRowFirstNonWhite(doc, offset);
+        int begin = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
 
         if (begin == -1) {
             return false; // whitespace only
@@ -820,8 +820,8 @@ private static boolean isCommentOnlyLine(BaseDocument doc, int offset, Language<
     /** Compute the balance of begin/end tokens on the line */
     private static int getLineBalance(BaseDocument doc, int offset, TokenId up, TokenId down) {
         try {
-            int begin = LineDocumentUtils.getLineStart(doc, offset);
-            int end = LineDocumentUtils.getLineEnd(doc, offset);
+            int begin = LineDocumentUtils.getLineStartOffset(doc, offset);
+            int end = LineDocumentUtils.getLineEndOffset(doc, offset);
 
             TokenSequence ts = LexUtilities.getJsTokenSequence(doc, begin);
             if (ts == null) {
diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedTextInterceptor.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedTextInterceptor.java
index 735cb25550eb..df207b74a17e 100644
--- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedTextInterceptor.java
+++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsTypedTextInterceptor.java
@@ -527,7 +527,7 @@ private boolean isQuoteCompletablePosition(LineDocument doc, int dotPos)
             return true;
         } else {
             // test that we are in front of ) , " or ' ... etc.
-            int eol = LineDocumentUtils.getLineEnd(doc, dotPos);
+            int eol = LineDocumentUtils.getLineEndOffset(doc, dotPos);
 
             if ((dotPos == eol) || (eol == -1)) {
                 return false;
diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/IndentContext.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/IndentContext.java
index ed5cea6c714e..9598fcc6b022 100644
--- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/IndentContext.java
+++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/IndentContext.java
@@ -92,7 +92,7 @@ public IndentContext(Context context, Defaults.Provider provider) {
         int lineEnd = -1;
         if (doc != null) {
             try {
-                lineEnd = LineDocumentUtils.getLineEnd(doc,
+                lineEnd = LineDocumentUtils.getLineEndOffset(doc,
                         context.caretOffset());
             } catch (BadLocationException | IndexOutOfBoundsException ex) {
             }
diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/JsFormatter.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/JsFormatter.java
index 4cc67d995447..db806696d2f3 100644
--- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/JsFormatter.java
+++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/formatter/JsFormatter.java
@@ -1810,7 +1810,7 @@ private int getFormatStableStart(Document doc, Language language,
                 try {
                     int lineTextEnd = LineDocumentUtils.getLineLastNonWhitespace(ld, sequenceBegin);
                     if (lineTextEnd == -1 || sequenceBegin > lineTextEnd) {
-                        return Math.min(doc.getLength(), LineDocumentUtils.getLineEnd(ld, sequenceBegin) + 1);
+                        return Math.min(doc.getLength(), LineDocumentUtils.getLineEndOffset(ld, sequenceBegin) + 1);
                     }
                 } catch (BadLocationException ex) {
                     LOGGER.log(Level.INFO, null, ex);
@@ -2206,7 +2206,7 @@ private void computeIndents(IndentContext context, int initialIndent, int indent
                     context.addIndentation(new IndentContext.Indentation(offset, indent, continued));
                 }
 
-                int endOfLine = LineDocumentUtils.getLineEnd(ld, offset) + 1;
+                int endOfLine = LineDocumentUtils.getLineEndOffset(ld, offset) + 1;
 
                 if (lineBegin != -1) {
                     balance += getTokenBalance(context, ts, lineBegin, endOfLine, true, indentOnly);
@@ -2516,7 +2516,7 @@ private int isEndIndent(IndentContext context, int offset) throws BadLocationExc
                 // Check if there are multiple end markers here... if so increase indent level.
                 // This should really do an iteration... for now just handling the most common
                 // scenario in JavaScript where we have }) in object literals
-                int lineEnd = LineDocumentUtils.getLineEnd(ld, offset);
+                int lineEnd = LineDocumentUtils.getLineEndOffset(ld, offset);
                 int newOffset = offset;
                 while (newOffset < lineEnd && token != null) {
                     newOffset += token.length();
diff --git a/webcommon/javascript2.jade/src/org/netbeans/modules/javascript2/jade/editor/indent/IndentationCounter.java b/webcommon/javascript2.jade/src/org/netbeans/modules/javascript2/jade/editor/indent/IndentationCounter.java
index dd61fb2b88a8..fbcc22d01452 100644
--- a/webcommon/javascript2.jade/src/org/netbeans/modules/javascript2/jade/editor/indent/IndentationCounter.java
+++ b/webcommon/javascript2.jade/src/org/netbeans/modules/javascript2/jade/editor/indent/IndentationCounter.java
@@ -55,7 +55,7 @@ private Indentation countUnderReadLock(int caretOffset) {
         int newIndent = 0;
         try {
             final TokenSequence ts = TokenHierarchy.get(doc).tokenSequence(JadeTokenId.jadeLanguage());
-            final int caretLineStart = LineDocumentUtils.getLineStart(doc, LineDocumentUtils.getLineStart(doc, caretOffset) - 1);
+            final int caretLineStart = LineDocumentUtils.getLineStartOffset(doc, LineDocumentUtils.getLineStartOffset(doc, caretOffset) - 1);
             if (ts != null) {
                 ts.move(caretOffset);
                 ts.moveNext();
@@ -69,7 +69,7 @@ private Indentation countUnderReadLock(int caretOffset) {
                     }
                 }
                 if (ts.token().id() == JadeTokenId.COMMENT || ts.token().id() == JadeTokenId.UNBUFFERED_COMMENT) {
-                    final int firstNonWsIndex = LineDocumentUtils.getLineFirstNonWhitespace(doc, LineDocumentUtils.getLineStart(doc, caretOffset) - 1);
+                    final int firstNonWsIndex = LineDocumentUtils.getLineFirstNonWhitespace(doc, LineDocumentUtils.getLineStartOffset(doc, caretOffset) - 1);
                     ts.move(firstNonWsIndex);
                     ts.moveNext();
                     if (ts.token() != null
@@ -137,8 +137,7 @@ public void run() {
 
         private void modifyUnderWriteLock(Context context) {
             try {
-                context.modifyIndent(
-                        LineDocumentUtils.getLineStart((BaseDocument) context.document(), context.caretOffset()),
+                context.modifyIndent(LineDocumentUtils.getLineStartOffset((BaseDocument) context.document(), context.caretOffset()),
                         indentation);
             } catch (BadLocationException ex) {
                 Exceptions.printStackTrace(ex);