Search in sources :

Example 6 with ILineTracker

use of org.eclipse.jface.text.ILineTracker in project flux by eclipse.

the class CodeTemplateContext method changeLineDelimiter.

private static String changeLineDelimiter(String code, String lineDelim) {
    try {
        ILineTracker tracker = new DefaultLineTracker();
        tracker.set(code);
        int nLines = tracker.getNumberOfLines();
        if (nLines == 1) {
            return code;
        }
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < nLines; i++) {
            if (i != 0) {
                buf.append(lineDelim);
            }
            IRegion region = tracker.getLineInformation(i);
            String line = code.substring(region.getOffset(), region.getOffset() + region.getLength());
            buf.append(line);
        }
        return buf.toString();
    } catch (BadLocationException e) {
        // can not happen
        return code;
    }
}
Also used : DefaultLineTracker(org.eclipse.jface.text.DefaultLineTracker) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) ILineTracker(org.eclipse.jface.text.ILineTracker)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)6 DefaultLineTracker (org.eclipse.jface.text.DefaultLineTracker)6 ILineTracker (org.eclipse.jface.text.ILineTracker)6 IRegion (org.eclipse.jface.text.IRegion)6 StyledString (org.eclipse.jface.viewers.StyledString)4