1 11 package org.eclipse.jdt.internal.corext.refactoring.nls; 12 13 import org.eclipse.jface.text.BadLocationException; 14 import org.eclipse.jface.text.IDocument; 15 import org.eclipse.jface.text.IRegion; 16 17 import org.eclipse.jdt.internal.ui.JavaPlugin; 18 19 22 public class SimpleLineReader { 23 24 private IDocument fInput; 25 private int fCurrLine; 26 27 public SimpleLineReader(IDocument input) { 28 fInput = input; 29 fCurrLine= 0; 30 } 31 32 public String readLine() { 33 int nLines= fInput.getNumberOfLines(); 34 if (fCurrLine >= nLines) { 35 return null; 36 } 37 38 try { 39 IRegion region= fInput.getLineInformation(fCurrLine++); 40 String content= fInput.get(region.getOffset(), region.getLength()); 41 42 int start= region.getOffset(); 43 44 boolean continuesOnNext= content.endsWith("\\") && !isCommentOrWhiteSpace(content); 46 while (continuesOnNext && fCurrLine < nLines) { 47 region= fInput.getLineInformation(fCurrLine++); 48 content= fInput.get(region.getOffset(), region.getLength()); 49 continuesOnNext= content.endsWith("\\") && !isCommentOrWhiteSpace(content); } 51 int end; 52 if (fCurrLine < nLines) { 53 end= fInput.getLineOffset(fCurrLine); } else { 55 end= fInput.getLength(); 56 if (end == start) { 57 return null; } 59 } 60 return fInput.get(start, end - start); 61 } catch (BadLocationException e) { 62 JavaPlugin.log(e); 64 } 65 return null; 66 } 67 68 public static boolean isCommentOrWhiteSpace(String line) { 69 line = line.trim(); 70 return (line.length() == 0) || line.charAt(0) == '!' || line.charAt(0) == '#'; 71 } 72 } 73 | Popular Tags |