/** * Converts the given string into an array of lines. The lines * don't contain any line delimiter characters. * * @return the string converted into an array of strings. Returns <code> * null</code> if the input string can't be converted in an array of lines. */ public static String[] convertIntoLines(String input) { try { ILineTracker tracker= new DefaultLineTracker(); tracker.set(input); int size= tracker.getNumberOfLines(); String result[]= new String[size]; for (int i= 0; i < size; i++) { IRegion region= tracker.getLineInformation(i); int offset= region.getOffset(); result[i]= input.substring(offset, offset + region.getLength()); } return result; } catch (BadLocationException e) { return null; } }
fLineTracker.set(command.text); int lines= fLineTracker.getNumberOfLines(); int offset= fLineTracker.getLineOffset(i); int endOffset= offset + fLineTracker.getLineLength(i); String line= text.substring(offset, endOffset);
public static String trimIndentation(String source, int tabWidth, int indentWidth, boolean considerFirstLine) { try { ILineTracker tracker= new DefaultLineTracker(); tracker.set(source); int size= tracker.getNumberOfLines(); if (size == 1) return source; String lines[]= new String[size]; for (int i= 0; i < size; i++) { IRegion region= tracker.getLineInformation(i); int offset= region.getOffset(); lines[i]= source.substring(offset, offset + region.getLength()); } Strings.trimIndentation(lines, tabWidth, indentWidth, considerFirstLine); StringBuffer result= new StringBuffer(); int last= size - 1; for (int i= 0; i < size; i++) { result.append(lines[i]); if (i < last) result.append(tracker.getLineDelimiter(i)); } return result.toString(); } catch (BadLocationException e) { Assert.isTrue(false,"Can not happend"); //$NON-NLS-1$ return null; } }
/** * @return the offset from where we have to read on in the Store */ private int calculateBacklogOffset() { int numberOfLines = getTracker().getNumberOfLines(); if(numberOfLines <= backlogLines) { return 0; } int overflow = numberOfLines - backlogLines; try { return getTracker().getLineOffset(overflow); } catch(BadLocationException ble) { return 0; } }
@Override public void set(String text) { if (hasActiveRewriteSession()) { fPendingRequests.clear(); fPendingRequests.add(new Request(text)); return; } fDelegate.set(text); }
this.codeSnippetBuffer.setLength(0); String replacement = formattedSnippet; tracker.set(formattedSnippet); int numberOfLines = tracker.getNumberOfLines(); if (numberOfLines > 1) { int lastLineOffset = -1; if (i>0) this.codeSnippetBuffer.append(linePrefix); try { lastLineOffset = tracker.getLineOffset(i+1); this.codeSnippetBuffer.append(formattedSnippet.substring(tracker.getLineOffset(i), lastLineOffset)); } catch (BadLocationException e) {
@Override public int getNumberOfLines() { try { checkRewriteSession(); } catch (BadLocationException x) { // TODO there is currently no way to communicate that exception back to the document } return fDelegate.getNumberOfLines(); }
@Override public IRegion getLineInformation(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineInformation(line); }
@Override public int getLineOffset(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineOffset(line); }
@Override public String getLineDelimiter(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineDelimiter(line); }
@Override public int getLineLength(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineLength(line); }
@Override public void set(String text) { if (hasActiveRewriteSession()) { fPendingRequests.clear(); fPendingRequests.add(new Request(text)); return; } fDelegate.set(text); }
this.codeSnippetBuffer.setLength(0); String replacement = formattedSnippet; tracker.set(formattedSnippet); int numberOfLines = tracker.getNumberOfLines(); if (numberOfLines > 1) { int lastLineOffset = -1; if (i>0) this.codeSnippetBuffer.append(linePrefix); try { lastLineOffset = tracker.getLineOffset(i+1); this.codeSnippetBuffer.append(formattedSnippet.substring(tracker.getLineOffset(i), lastLineOffset)); } catch (BadLocationException e) {
@Override public int getNumberOfLines() { try { checkRewriteSession(); } catch (BadLocationException x) { // TODO there is currently no way to communicate that exception back to the document } return fDelegate.getNumberOfLines(); }
@Override public IRegion getLineInformation(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineInformation(line); }
@Override public int getLineOffset(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineOffset(line); }
@Override public String getLineDelimiter(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineDelimiter(line); }
@Override public int getLineLength(int line) throws BadLocationException { checkRewriteSession(); return fDelegate.getLineLength(line); }
/** * Converts the given string into an array of lines. The lines * don't contain any line delimiter characters. * * @param input the string * @return the string converted into an array of strings. Returns <code> * null</code> if the input string can't be converted in an array of lines. */ public static String[] convertIntoLines(String input) { try { ILineTracker tracker= new DefaultLineTracker(); tracker.set(input); int size= tracker.getNumberOfLines(); String result[]= new String[size]; for (int i= 0; i < size; i++) { IRegion region= tracker.getLineInformation(i); int offset= region.getOffset(); result[i]= input.substring(offset, offset + region.getLength()); } return result; } catch (BadLocationException e) { return null; } }