当前位置: 首页>>代码示例>>Java>>正文


Java DefaultLineTracker类代码示例

本文整理汇总了Java中org.eclipse.jface.text.DefaultLineTracker的典型用法代码示例。如果您正苦于以下问题:Java DefaultLineTracker类的具体用法?Java DefaultLineTracker怎么用?Java DefaultLineTracker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultLineTracker类属于org.eclipse.jface.text包,在下文中一共展示了DefaultLineTracker类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changeLineDelimiter

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
private static String changeLineDelimiter(String code, String lineDelim) {
	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++) {
			if (i != 0) {
				buf.append(lineDelim);
			}
			IRegion region = tracker.getLineInformation(i);
			String line= code.substring(region.getOffset(), region.getOffset() + region.getLength());
			buf.append(line);
		}
		return buf.toString();
	} catch (BadLocationException e) {
		// can not happen
		return code;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:CodeTemplateContext.java

示例2: installTabsToSpacesConverter

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
@Override
protected void installTabsToSpacesConverter() {
	ISourceViewer sourceViewer = getSourceViewer();
	SourceViewerConfiguration config = getSourceViewerConfiguration();
	if (config != null && sourceViewer instanceof ITextViewerExtension7) {
		int tabWidth = config.getTabWidth(sourceViewer);
		TabsToSpacesConverter tabToSpacesConverter = new TabsToSpacesConverter();
		tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
		IDocumentProvider provider = getDocumentProvider();
		if (provider instanceof ICompilationUnitDocumentProvider) {
			ICompilationUnitDocumentProvider cup = (ICompilationUnitDocumentProvider) provider;
			tabToSpacesConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
		} else
			tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
		((ITextViewerExtension7) sourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
		updateIndentPrefixes();
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:19,代码来源:TypeScriptEditor.java

示例3: changeLineDelimiter

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
private static String changeLineDelimiter(String code, String lineDelim) {
  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++) {
      if (i != 0) {
        buf.append(lineDelim);
      }
      IRegion region = tracker.getLineInformation(i);
      String line = code.substring(region.getOffset(), region.getOffset() + region.getLength());
      buf.append(line);
    }
    return buf.toString();
  } catch (BadLocationException e) {
    // can not happen
    return code;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:CodeTemplateContext.java

示例4: convertIntoLines

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
/**
 * 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;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:Strings.java

示例5: trimIndentation

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
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;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:Strings.java

示例6: convertIntoLines

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
/**
 * 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;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:Strings.java

示例7: installTabsToSpacesConverter

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
@Override
protected void installTabsToSpacesConverter() {
	ISourceViewer sourceViewer= getSourceViewer();
	SourceViewerConfiguration config= getSourceViewerConfiguration();
	if (config != null && sourceViewer instanceof ITextViewerExtension7) {
		int tabWidth= config.getTabWidth(sourceViewer);
		TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
		tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
		IDocumentProvider provider= getDocumentProvider();
		if (provider instanceof ICompilationUnitDocumentProvider) {
			ICompilationUnitDocumentProvider cup= (ICompilationUnitDocumentProvider) provider;
			tabToSpacesConverter.setLineTracker(cup.createLineTracker(getEditorInput()));
		} else
			tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
		((ITextViewerExtension7)sourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
		updateIndentPrefixes();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:CompilationUnitEditor.java

示例8: changeIndent

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
/**
 * Change the indent of a, possible multiple line, code string. The given number of indent units
 * is removed, and a new indent string is added.
 * <p>
 * The first line of the code will not be changed (It is considered to have no indent as it
 * might start in the middle of a line).
 * </p>
 *
 * @param code the code to change the indent of
 * @param indentUnitsToRemove the number of indent units to remove from each line (except the
 *            first) of the given code
 * @param tabWidth the size of one tab in space equivalents
 * @param indentWidth the width of one indentation unit in space equivalents
 * @param newIndentString the new indent string to be added to all lines (except the first)
 * @param lineDelim the new line delimiter to be used. The returned code will contain only this
 *            line delimiter.
 * @return the newly indent code, containing only the given line delimiters.
 * @exception IllegalArgumentException if:
 *                <ul>
 *                <li>the given <code>indentWidth</code> is lower or equals to zero</li>
 *                <li>the given <code>tabWidth</code> is lower than zero</li>
 *                <li>the given <code>code</code> is null</li>
 *                <li>the given <code>indentUnitsToRemove</code> is lower than zero</li>
 *                <li>the given <code>newIndentString</code> is null</li>
 *                <li>the given <code>lineDelim</code> is null</li>
 *                </ul>
 */
public static String changeIndent(String code, int indentUnitsToRemove, int tabWidth, int indentWidth,
		String newIndentString, String lineDelim) {
	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)
				buf.append(line);
			} else {
				// no new line after last line
				buf.append(lineDelim);
				buf.append(newIndentString);
				buf.append(trimIndent(line, indentUnitsToRemove, tabWidth, indentWidth));
			}
		}
		return buf.toString();
	} catch (BadLocationException e) {
		// can not happen
		return code;
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:67,代码来源:Indent.java

示例9: getChangeIndentEdits

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
/**
 * Returns the text edits retrieved after changing the indentation of a, possible multi-line,
 * code string.
 * <p>
 * The given number of indent units is removed, and a new indent string is added.
 * </p>
 * <p>
 * The first line of the code will not be changed (It is considered to have no indent as it
 * might start in the middle of a line).
 * </p>
 *
 * @param source The code to change the indent of
 * @param indentUnitsToRemove the number of indent units to remove from each line (except the
 *            first) of the given code
 * @param tabWidth the size of one tab in space equivalents
 * @param indentWidth the width of one indentation unit in space equivalents
 * @param newIndentString the new indent string to be added to all lines (except the first)
 * @return returns the resulting text edits
 * @exception IllegalArgumentException if:
 *                <ul>
 *                <li>the given <code>indentWidth</code> is lower or equals to zero</li>
 *                <li>the given <code>tabWidth</code> is lower than zero</li>
 *                <li>the given <code>source</code> is null</li>
 *                <li>the given <code>indentUnitsToRemove</code> is lower than zero</li>
 *                <li>the given <code>newIndentString</code> is null</li>
 *                </ul>
 */
public static ReplaceEdit[] getChangeIndentEdits(String source, int indentUnitsToRemove, int tabWidth,
		int indentWidth, String newIndentString) {
	if (tabWidth < 0 || indentWidth <= 0 || source == null || indentUnitsToRemove < 0 || newIndentString == null) {
		throw new IllegalArgumentException();
	}

	ArrayList<ReplaceEdit> result = new ArrayList<ReplaceEdit>();
	try {
		ILineTracker tracker = new DefaultLineTracker();
		tracker.set(source);
		int nLines = tracker.getNumberOfLines();
		if (nLines == 1) {
			return 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));
			} else {
				length = measureIndentUnits(line, tabWidth, indentWidth);
				result.add(new ReplaceEdit(offset, length, "")); //$NON-NLS-1$
			}
		}
	} catch (BadLocationException cannotHappen) {}
	return result.toArray(new ReplaceEdit[result.size()]);
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:57,代码来源:Indent.java

示例10: LogDocument

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
public LogDocument(LogFile file, String encoding) throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, PartInitException {
	super();
	if (file.getEncoding() == null)
		file.setEncoding(encoding);
	this.file = file;
	this.encoding = file.getEncoding();
	this.charset = Charset.forName(file.getEncoding());
	IPreferenceStore store = LogViewerPlugin.getDefault().getPreferenceStore();
	store.addPropertyChangeListener(new PropertyChangeListener());
	backlogLines = store.getInt(ILogViewerConstants.PREF_BACKLOG);
	setTextStore(new GapTextStore(50, 300, 1f));
	setLineTracker(new DefaultLineTracker());
	completeInitialization();
	reader = new BackgroundReader(file.getFileType(),file.getFileName(),charset,this);
}
 
开发者ID:anb0s,项目名称:LogViewer,代码行数:16,代码来源:LogDocument.java

示例11: trimIndentation

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
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;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:Strings.java

示例12: changeIndent

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
/**
 * Change the indent of a, possible multiple line, code string. The given number of indent units is removed,
 * and a new indent string is added.
 * <p>The first line of the code will not be changed (It is considered to have no indent as it might start in
 * the middle of a line).</p>
 *
 * @param code the code to change the indent of
 * @param indentUnitsToRemove the number of indent units to remove from each line (except the first) of the given code
 * @param tabWidth the size of one tab in space equivalents
 * @param indentWidth the width of one indentation unit in space equivalents
 * @param newIndentString the new indent string to be added to all lines (except the first)
 * @param lineDelim the new line delimiter to be used. The returned code will contain only this line delimiter.
 * @return the newly indent code, containing only the given line delimiters.
 * @exception IllegalArgumentException if:
 * <ul>
 * <li>the given <code>indentWidth</code> is lower than zero</li>
 * <li>the given <code>tabWidth</code> is lower than zero</li>
 * <li>the given <code>code</code> is null</li>
 * <li>the given <code>indentUnitsToRemove</code> is lower than zero</li>
 * <li>the given <code>newIndentString</code> is null</li>
 * <li>the given <code>lineDelim</code> is null</li>
 * </ul>
 */
public static String changeIndent(String code, int indentUnitsToRemove, int tabWidth, int indentWidth, String newIndentString, String lineDelim) {
	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)
				buf.append(line);
			} else { // no new line after last line
				buf.append(lineDelim);
				buf.append(newIndentString);
				if(indentWidth != 0) {
					buf.append(trimIndent(line, indentUnitsToRemove, tabWidth, indentWidth));
				} else {
					buf.append(line);
				}
			}
		}
		return buf.toString();
	} catch (BadLocationException e) {
		// can not happen
		return code;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:63,代码来源:IndentManipulation.java

示例13: getChangeIndentEdits

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
/**
 * Returns the text edits retrieved after changing the indentation of a, possible multi-line, code string.
 *
 * <p>The given number of indent units is removed, and a new indent string is added.</p>
 * <p>The first line of the code will not be changed (It is considered to have no indent as it might start in
 * the middle of a line).</p>
 *
 * @param source The code to change the indent of
 * @param indentUnitsToRemove the number of indent units to remove from each line (except the first) of the given code
 * @param tabWidth the size of one tab in space equivalents
 * @param indentWidth the width of one indentation unit in space equivalents
 * @param newIndentString the new indent string to be added to all lines (except the first)
 * @return returns the resulting text edits
 * @exception IllegalArgumentException if:
 * <ul>
 * <li>the given <code>indentWidth</code> is lower than zero</li>
 * <li>the given <code>tabWidth</code> is lower than zero</li>
 * <li>the given <code>source</code> is null</li>
 * <li>the given <code>indentUnitsToRemove</code> is lower than zero</li>
 * <li>the given <code>newIndentString</code> is null</li>
 * </ul>
 */
public static ReplaceEdit[] getChangeIndentEdits(String source, int indentUnitsToRemove, int tabWidth, int indentWidth, String newIndentString) {
	if (tabWidth < 0 || indentWidth < 0 || source == null || indentUnitsToRemove < 0 || newIndentString == null) {
		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));
			} else {
				length= measureIndentUnits(line, tabWidth, indentWidth);
				result.add(new ReplaceEdit(offset, length, "")); //$NON-NLS-1$
			}
		}
	} catch (BadLocationException cannotHappen) {
		// can not happen
	}
	return (ReplaceEdit[])result.toArray(new ReplaceEdit[result.size()]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:52,代码来源:IndentManipulation.java

示例14: createLineTracker

import org.eclipse.jface.text.DefaultLineTracker; //导入依赖的package包/类
public ILineTracker createLineTracker(Object element) {
	return new DefaultLineTracker();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:CompilationUnitDocumentProvider.java


注:本文中的org.eclipse.jface.text.DefaultLineTracker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。