Search in sources :

Example 31 with FindReplaceDocumentAdapter

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;
    }
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion)

Example 32 with FindReplaceDocumentAdapter

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;
}
Also used : IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter)

Example 33 with FindReplaceDocumentAdapter

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;
}
Also used : IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter)

Example 34 with FindReplaceDocumentAdapter

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;
}
Also used : Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 35 with FindReplaceDocumentAdapter

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;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) RangeMarker(org.eclipse.text.edits.RangeMarker) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter)

Aggregations

FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)35 IRegion (org.eclipse.jface.text.IRegion)24 Test (org.junit.Test)20 BadLocationException (org.eclipse.jface.text.BadLocationException)18 Region (org.eclipse.jface.text.Region)12 IDocument (org.eclipse.jface.text.IDocument)7 Document (org.eclipse.jface.text.Document)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 Position (org.eclipse.jface.text.Position)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)2 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 Ignore (org.junit.Ignore)2 SQLDocument (com.cubrid.common.ui.query.editor.SQLDocument)1 SQLPartitionScanner (com.cubrid.common.ui.query.editor.SQLPartitionScanner)1 SQLTextViewer (com.cubrid.common.ui.query.editor.SQLTextViewer)1 SQLViewerConfiguration (com.cubrid.common.ui.query.editor.SQLViewerConfiguration)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1