1 11 12 package org.eclipse.jdt.internal.core.dom.rewrite; 13 14 import org.eclipse.jdt.core.dom.CompilationUnit; 15 import org.eclipse.jface.text.BadLocationException; 16 import org.eclipse.jface.text.IDocument; 17 18 21 public abstract class LineInformation { 22 23 public static LineInformation create(final IDocument doc) { 24 return new LineInformation() { 25 public int getLineOfOffset(int offset) { 26 try { 27 return doc.getLineOfOffset(offset); 28 } catch (BadLocationException e) { 29 return -1; 30 } 31 } 32 33 public int getLineOffset(int line) { 34 try { 35 return doc.getLineOffset(line); 36 } catch (BadLocationException e) { 37 return -1; 38 } 39 } 40 }; 41 } 42 43 public static LineInformation create(final CompilationUnit astRoot) { 44 return new LineInformation() { 45 public int getLineOfOffset(int offset) { 46 return astRoot.getLineNumber(offset) - 1; 47 } 48 public int getLineOffset(int line) { 49 return astRoot.getPosition(line + 1, 0); 50 } 51 }; 52 } 53 54 55 56 public abstract int getLineOfOffset(int offset); 57 public abstract int getLineOffset(int line); 58 59 } 60 | Popular Tags |