Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.DefaultLineTracker


    if (tabWidth < 0 || indentWidth <= 0 || code == null || indentUnitsToRemove < 0 || newIndentString == null || lineDelim == null) {
      throw new IllegalArgumentException();
    }
   
    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++) {
        IRegion region= tracker.getLineInformation(i);
        int start= region.getOffset();
        int end= start + region.getLength();
        String line= code.substring(start, end);
       
        if (i == 0) {  // no indent for first line (contained in the formatted string)
View Full Code Here


      throw new IllegalArgumentException();
    }
   
    ArrayList result= new ArrayList();
    try {
      ILineTracker tracker= new DefaultLineTracker();
      tracker.set(source);
      int nLines= tracker.getNumberOfLines();
      if (nLines == 1)
        return (ReplaceEdit[])result.toArray(new ReplaceEdit[result.size()]);
      for (int i= 1; i < nLines; i++) {
        IRegion region= tracker.getLineInformation(i);
        int offset= region.getOffset();
        String line= source.substring(offset, offset + region.getLength());
        int length= indexOfIndent(line, indentUnitsToRemove, tabWidth, indentWidth);
        if (length >= 0) {
          result.add(new ReplaceEdit(offset, length, newIndentString));
View Full Code Here

   * @return the preprocessed code snippet
   */
  private String preprocessCodeSnippet(String snippet) {
    // strip content prefix
    StringBuffer buffer= new StringBuffer();
    ILineTracker tracker= new DefaultLineTracker();
    String contentPrefix= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX.trim();
   
    buffer.setLength(0);
    buffer.append(snippet);
    tracker.set(snippet);
    for (int line= tracker.getNumberOfLines() - 1; line > 0; line--) {
      int lineOffset;
      try {
        lineOffset= tracker.getLineOffset(line);
      } catch (BadLocationException e) {
        // Can not happen
        CommentFormatterUtil.log(e);
        return snippet;
      }
View Full Code Here

   * @return the postprocessed code snippet
   */
  private String postprocessCodeSnippet(String snippet, String indentation) {
    // patch content prefix
    StringBuffer buffer= new StringBuffer();
    ILineTracker tracker= new DefaultLineTracker();
    String patch= indentation + MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;

    // remove trailing spaces
    int i= snippet.length();
    while (i > 0 && ' ' == snippet.charAt(i-1))
      i--;
    snippet= snippet.substring(0, i);
   
    buffer.setLength(0);
    String lineDelimiter= getDelimiter();
    if (lineDelimiter != null && snippet.indexOf(lineDelimiter) != 0)
      buffer.append(lineDelimiter);
    buffer.append(convertJava2Html(snippet));
    if (lineDelimiter != null && snippet.lastIndexOf(lineDelimiter) != snippet.length() - lineDelimiter.length())
      buffer.append(lineDelimiter);
    tracker.set(buffer.toString());
   
    for (int line= tracker.getNumberOfLines() - 1; line > 0; line--)
      try {
        buffer.insert(tracker.getLineOffset(line), patch);
      } catch (BadLocationException e) {
        // Can not happen
        CommentFormatterUtil.log(e);
        return snippet;
      }
View Full Code Here

   
    fTabSize= DefaultCodeFormatterOptions.SPACE == this.preferences.tab_char ? this.preferences.indentation_size : this.preferences.tab_size;

    this.scribe = formatter.scribe;

    final ILineTracker tracker= new DefaultLineTracker();

    IRegion range= null;
    CommentLine line= null;

    tracker.set(getText(0, getLength()));
    final int lines= tracker.getNumberOfLines();

    fSingleLine= lines == 1;

    try {

      for (int index= 0; index < lines; index++) {

        range= tracker.getLineInformation(index);
        line= createLine();
        line.append(new CommentRange(range.getOffset(), range.getLength()));

        fLines.add(line);
      }
View Full Code Here

   *  region lies outside the source.
   */
  public String[] convertIntoLines(int offset, int length, boolean lastNewLineCreateEmptyLine) {
    try {
      String text= fDocument.get(offset, length);
      ILineTracker tracker= new DefaultLineTracker();
      tracker.set(text);
      int size= tracker.getNumberOfLines();
      int lastLine= size - 1;
      List result= new ArrayList(size);
      for (int i= 0; i < size; i++) {
        IRegion region= tracker.getLineInformation(i);
        String line= getContent(offset + region.getOffset(), region.getLength());
        if (i < lastLine || !"".equals(line) || lastNewLineCreateEmptyLine) //$NON-NLS-1$
          result.add(line);
      }
      return (String[]) result.toArray(new String[result.size()]);
View Full Code Here

   * @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) {
View Full Code Here

  protected void installTabsToSpacesConverter() {
    SourceViewerConfiguration config= getSourceViewerConfiguration();
    if (config != null && fSourceViewer instanceof ITextViewerExtension7) {
      int tabWidth= config.getTabWidth(fSourceViewer);
      TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
      tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
      tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
      ((ITextViewerExtension7)fSourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
      updateIndentPrefixes();
    }
  }
View Full Code Here

        }
    }

    private void configureTabConverter() {
        if (tabConverter != null) {
            tabConverter.setLineTracker(new DefaultLineTracker());
        }
    }
View Full Code Here

            public void documentChanged(DocumentEvent event) {
                changed = true;
            }
        });
        setTextStore(new StringTextStore());
        setLineTracker(new DefaultLineTracker());
        completeInitialization();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.DefaultLineTracker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.