use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method replaceAllRegex.
private void replaceAllRegex(String findString, String replaceString, boolean forwardSearch) throws BadLocationException {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
int index = forwardSearch ? 0 : fDocument.getLength();
while (index != -1) {
if (findReplaceDocumentAdapter.find(index, findString, forwardSearch, true, false, true) == null)
break;
IRegion region = findReplaceDocumentAdapter.replace(replaceString, true);
index = forwardSearch ? region.getOffset() + region.getLength() : region.getOffset() - 1;
}
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.
the class ProjectionViewer method getFindReplaceDocumentAdapter.
@Override
protected FindReplaceDocumentAdapter getFindReplaceDocumentAdapter() {
if (fFindReplaceDocumentAdapter == null) {
IDocument document = isProjectionMode() ? getDocument() : getVisibleDocument();
fFindReplaceDocumentAdapter = new FindReplaceDocumentAdapter(document);
}
return fFindReplaceDocumentAdapter;
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project webtools.sourceediting by eclipse.
the class BasicStructuredDocument method search.
/**
* @deprecated in superclass in 3.0 - use a FindReplaceDocumentAdapter
* directly
* @see IDocument#search
*/
public int search(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException {
// (dmw) I added this warning, to know if still being used. I'm not
// sure it
// works as expected any longer.
// but the warning should be removed, once know.
// $NON-NLS-1$
Logger.log(Logger.INFO, "WARNING: using unsupported deprecated method 'search'");
int offset = -1;
IRegion match = new FindReplaceDocumentAdapter(this).find(startPosition, findString, forwardSearch, caseSensitive, wholeWord, false);
if (match != null) {
offset = match.getOffset();
}
return offset;
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project mdw-designer by CenturyLinkCloud.
the class JavaProcessConsole method findAndSelect.
public int findAndSelect(int widgetOffset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord) {
if (getViewer().getTextWidget() == null)
return -1;
try {
int fromOffset = 0;
if (widgetOffset == -1) {
fromOffset = -1;
} else {
fromOffset = getViewer().getTextWidget().getCaretOffset();
if (getViewer().getTextWidget().getSelectionCount() > 0)
fromOffset++;
if (fromOffset >= getViewer().getDocument().getLength() && fromOffset > 0)
fromOffset--;
}
IRegion matchRegion = new FindReplaceDocumentAdapter(getViewer().getDocument()).find(fromOffset, findString, searchForward, caseSensitive, wholeWord, false);
if (matchRegion != null) {
int widgetPos = matchRegion.getOffset();
int length = matchRegion.getLength();
getViewer().getTextWidget().setSelectionRange(widgetPos, length);
getViewer().setSelection(getViewer().getSelection(), true);
return getViewer().widgetOffset2ModelOffset(widgetPos);
}
} catch (BadLocationException ex) {
PluginMessages.log(ex);
}
return -1;
}
use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project titan.EclipsePlug-ins by eclipse.
the class TITANTemplateContext method evaluate.
@Override
public TemplateBuffer evaluate(final Template template) throws BadLocationException, TemplateException {
if (!canEvaluate(template)) {
return null;
}
TemplateTranslator translator = new TemplateTranslator();
TemplateBuffer buffer = translator.translate(template);
getContextType().resolve(buffer, this);
if (isReadOnly()) {
// if it is read only we should not modify it
return buffer;
}
// calculate base indentation prefix
IDocument document = getDocument();
String prefixString = "";
String delimeter = null;
try {
IRegion lineRegion = document.getLineInformationOfOffset(getCompletionOffset());
int firstCharLocation = FirstCharAction.firstVisibleCharLocation(document, lineRegion);
if (firstCharLocation != -1) {
prefixString = document.get(lineRegion.getOffset(), firstCharLocation - lineRegion.getOffset());
}
delimeter = document.getLineDelimiter(document.getLineOfOffset(getCompletionOffset()));
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
TemplateVariable[] variables = buffer.getVariables();
// apply the base indentation prefix to every line but the first
IDocument temporalDocument = new Document(buffer.getString());
MultiTextEdit edit = new MultiTextEdit(0, temporalDocument.getLength());
List<RangeMarker> positions = variablesToPositions(variables);
for (int i = temporalDocument.getNumberOfLines() - 1; i >= 0; i--) {
edit.addChild(new InsertEdit(temporalDocument.getLineOffset(i), prefixString));
}
edit.addChildren(positions.toArray(new TextEdit[positions.size()]));
// replace line delimeters with the ones at the insertion
String delimeterZero = temporalDocument.getLineDelimiter(0);
if (delimeter != null && delimeterZero != null && !delimeter.equals(delimeterZero)) {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(temporalDocument);
int startOffset = 0;
IRegion region = adapter.find(startOffset, delimeterZero, true, false, false, false);
while (region != null) {
edit.addChild(new ReplaceEdit(region.getOffset(), region.getLength(), delimeter));
startOffset = region.getOffset() + region.getLength();
region = adapter.find(startOffset, delimeterZero, true, false, false, false);
}
}
edit.apply(temporalDocument, TextEdit.UPDATE_REGIONS);
positionsToVariables(positions, variables);
buffer.setContent(temporalDocument.get(), variables);
return buffer;
}
Aggregations