Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import org.eclipse.jface.text.IDocument;

public class Main {
    public static Object[] getLine(IDocument document, int offset) {
        String text = document.get();
        if (offset > text.length()) {
            throw new IndexOutOfBoundsException();
        }
        int start = offset, end = offset;
        while (start > 0 && text.charAt(start) != '\n') {
            start--;
        }
        while (end < text.length() && text.charAt(end) != '\n') {
            end++;
        }
        try {
            return new Object[] { text.substring(start > 0 ? start + 1 : 0, end), start > 0 ? start + 1 : 0 };
        } catch (StringIndexOutOfBoundsException e) {
            String msg = "exception from getLine(" + offset + "). start=" + start + "; end=" + end + "; text="
                    + text;
            throw new RuntimeException(msg, e);
        }
    }
}