Here you can find the source of adjustForLineComment(JTextComponent editor, int iStart)
public static int adjustForLineComment(JTextComponent editor, int iStart) throws BadLocationException
//package com.java2s; //License from project: Apache License import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.Element; import javax.swing.text.JTextComponent; public class Main { public static int adjustForLineComment(JTextComponent editor, int iStart) throws BadLocationException { Document doc = editor.getDocument(); Element root = doc.getDefaultRootElement(); Element line = root.getElement(root.getElementIndex(iStart)); int iLineOffset = line.getStartOffset(); int iLength = iStart - iLineOffset; if (iLength <= 0) { return iStart; }/* ww w. j a va 2 s. co m*/ String strLine = doc.getText(iLineOffset, iLength); if (strLine.contains("//")) { return iLineOffset; } return iStart; } }