本文整理汇总了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;
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
}
示例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()]);
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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()]);
}
示例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