Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -185,24 +185,24 @@ 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
{
sectionStart = firstLineStartOffset;
}

// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,8 +160,8 @@ private Collection<LineSetAnnotation> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.getLineStart2(doc, target.getSelectionStart());
TokenHierarchy th = TokenHierarchy.create(target.getText(), JspTokenId.language());
List<TokenSequence> ets = th.embeddedTokenSequences(startPos, false);
if (!ets.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.getLineStart2(doc, ts.offset()));
final Position to = doc.createPosition(LineDocumentUtils.getLineEnd(doc, ts.offset()));

SwingUtilities.invokeLater(new Runnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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.spi.editor.completion.support.AsyncCompletionTask;
import org.netbeans.spi.editor.completion.support.CompletionUtilities;
import org.netbeans.swing.plaf.LFCustoms;
Expand Down Expand Up @@ -248,8 +249,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.getLineStart2(doc, dotPos);
int endOffset = LineDocumentUtils.getLineEnd(doc, dotPos);
indent.reindent(startOffset, endOffset);
} catch (BadLocationException ex) {
//ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected List<IndentCommand> getLineIndent(IndenterContextData<ELTokenId> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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;
Expand Down Expand Up @@ -152,7 +153,7 @@ protected int getPreservedLineInitialIndentation(JoinedTokenSequence<JspTokenId>
} while (ts.movePrevious());
int indent = 0;
if (found) {
int lineStart = Utilities.getRowStart(getDocument(), ts.offset());
int lineStart = LineDocumentUtils.getLineStart2(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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.getLineStart2(doc, step.getOffset() + 1);
int rowEnd = LineDocumentUtils.getLineEnd(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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.getLineStart2(doc, step.getOffset() + 1);
int rowEnd = LineDocumentUtils.getLineEnd(doc, step.getOffset() + 1);
String fullResult = doc.getText(new int[]{rowStart, rowEnd});
String result = fullResult.trim();
int removed_whitespaces = fullResult.length() - result.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -198,8 +199,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.getLineStart2(doc, newPossition);
if (debug) {
Thread.sleep(3000); // to be visible ;-)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.getLineStart2(doc, newPossition);
if (debug) {
Thread.sleep(3000); // to be visible ;-)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.getLineStart2(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.getLineStart2(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading