Search in sources :

Example 11 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.platform.text by eclipse.

the class ProjectionViewer method setVisibleDocument.

@Override
protected void setVisibleDocument(IDocument document) {
    if (!isProjectionMode()) {
        super.setVisibleDocument(document);
        return;
    }
    // In projection mode we don't want to throw away the find/replace document adapter
    FindReplaceDocumentAdapter adapter = fFindReplaceDocumentAdapter;
    super.setVisibleDocument(document);
    fFindReplaceDocumentAdapter = adapter;
}
Also used : FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter)

Example 12 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project linuxtools by eclipse.

the class GNUFormat method findChangeLogEntry.

private int findChangeLogEntry(IDocument changelogDoc, String entry) {
    FindReplaceDocumentAdapter findDocumentAptd = new FindReplaceDocumentAdapter(changelogDoc);
    IRegion region = null;
    try {
        region = findDocumentAptd.find(0, entry, true, false, /*whole world */
        false, true);
    } catch (BadLocationException e) {
        ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        return -1;
    }
    if (region != null) {
        // make a new entry.
        return region.getOffset() > 0 ? -1 : 0;
    } else
        return -1;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 13 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project eclipse.jdt.ls by eclipse.

the class HoverHandlerTest method testHoverThrowable.

@Test
public void testHoverThrowable() throws Exception {
    String uriString = ClassFileUtil.getURI(project, "java.lang.Exception");
    IClassFile classFile = JDTUtils.resolveClassFile(uriString);
    String contents = JavaLanguageServerPlugin.getContentProviderManager().getSource(classFile, monitor);
    IDocument document = new Document(contents);
    IRegion region = new FindReplaceDocumentAdapter(document).find(0, "Throwable", true, false, false, false);
    int offset = region.getOffset();
    int line = document.getLineOfOffset(offset);
    int character = offset - document.getLineOffset(line);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uriString);
    Position position = new Position(line, character);
    TextDocumentPositionParams params = new TextDocumentPositionParams(textDocument, position);
    Hover hover = handler.hover(params, monitor);
    assertNotNull(hover);
    assertTrue("Unexpected hover ", !hover.getContents().isEmpty());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IClassFile(org.eclipse.jdt.core.IClassFile) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) MarkedString(org.eclipse.lsp4j.MarkedString) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 14 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction method updateEditorSelection.

/**
 * @param editorPart
 * @param selection
 */
public static boolean updateEditorSelection(IEditorPart editorPart, Object selection, IService service) {
    ITextEditor[] textEditors = OpenMappingUtils.getTextEditors(editorPart);
    if (textEditors.length == 0) {
        return false;
    }
    textEditors[0].selectAndReveal(0, 0);
    FindReplaceDocumentAdapter findAdapter = null;
    ITextEditor textEditor = null;
    for (int i = 0; i < textEditors.length && findAdapter == null; i++) {
        textEditor = textEditors[i];
        findAdapter = OpenMappingUtils.createFindDocAdapter(textEditor);
    }
    if (findAdapter == null) {
        return false;
    }
    IJavaProject proj = ProjectUtils.findJavaProject(editorPart);
    IRegion selectRegion = OpenMappingUtils.findSelectRegion(proj, findAdapter, selection, service);
    if (selectRegion != null) {
        if (editorPart instanceof MultiPageEditorPart) {
            ((MultiPageEditorPart) editorPart).setActiveEditor(textEditor);
        }
        textEditor.selectAndReveal(selectRegion.getOffset(), selectRegion.getLength());
        return true;
    }
    return false;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IJavaProject(org.eclipse.jdt.core.IJavaProject) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion)

Example 15 with FindReplaceDocumentAdapter

use of org.eclipse.jface.text.FindReplaceDocumentAdapter in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction method updateEditorSelection.

/**
 * @param editorPart
 * @param compositeProperty
 * @param parentProperty
 */
public static boolean updateEditorSelection(IEditorPart editorPart, IProperty compositeProperty, IProperty parentProperty, IService service) {
    ITextEditor[] textEditors = OpenMappingUtils.getTextEditors(editorPart);
    if (textEditors.length == 0) {
        return false;
    }
    textEditors[0].selectAndReveal(0, 0);
    FindReplaceDocumentAdapter findAdapter = null;
    ITextEditor textEditor = null;
    for (int i = 0; i < textEditors.length && findAdapter == null; i++) {
        textEditor = textEditors[i];
        findAdapter = OpenMappingUtils.createFindDocAdapter(textEditor);
    }
    if (findAdapter == null) {
        return false;
    }
    IJavaProject proj = ProjectUtils.findJavaProject(editorPart);
    IRegion parentRegion = OpenMappingUtils.findSelectRegion(proj, findAdapter, parentProperty, service);
    if (parentRegion == null) {
        return false;
    }
    int startOffset = parentRegion.getOffset() + parentRegion.getLength();
    IRegion propRegion = null;
    try {
        final String hbmPropertyPattern = OpenMappingUtils.generateHbmPropertyPattern(compositeProperty, service);
        propRegion = findAdapter.find(startOffset, hbmPropertyPattern, true, true, false, true);
        IPersistentClass rootClass = parentProperty.getPersistentClass();
        if (propRegion == null && parentProperty.isComposite() && (parentProperty.equals(rootClass.getIdentifierProperty()) || !rootClass.hasIdentifierProperty())) {
            // try to use key-property
            // $NON-NLS-1$ //$NON-NLS-2$
            String pattern = hbmPropertyPattern.replaceFirst("<property", "<key-property");
            propRegion = findAdapter.find(startOffset, pattern, true, true, false, true);
            if (propRegion == null) {
                // try to use key-many-to-one
                // $NON-NLS-1$ //$NON-NLS-2$
                pattern = hbmPropertyPattern.replaceFirst("<many-to-one", "<key-many-to-one");
                propRegion = findAdapter.find(startOffset, pattern, true, true, false, true);
            }
        }
    } catch (BadLocationException e) {
        HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenMappingAction_selection_not_found, e);
    }
    if (propRegion == null && parentProperty.isComposite()) {
        String[] componentPatterns = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
        OpenMappingUtils.createPattern("embeddable", "class", parentProperty.getValue().getComponentClassName()), OpenMappingUtils.createPattern("embeddable", "class", // $NON-NLS-1$//$NON-NLS-2$
        OpenMappingUtils.getShortClassName(parentProperty.getValue().getComponentClassName())) };
        IRegion componentRegion = null;
        for (int i = 0; i < componentPatterns.length && componentRegion == null; i++) {
            try {
                componentRegion = findAdapter.find(0, componentPatterns[i], true, true, false, true);
            } catch (BadLocationException e) {
            // ignore
            }
        }
        if (componentRegion != null) {
            try {
                propRegion = findAdapter.find(parentRegion.getOffset() + parentRegion.getLength(), OpenMappingUtils.generateOrmEmbeddablePropertyPattern(compositeProperty), true, true, false, true);
            } catch (BadLocationException e) {
            // ignore
            }
        }
    }
    if (propRegion == null) {
        return false;
    }
    int length = compositeProperty.getName().length();
    int offset = propRegion.getOffset() + propRegion.getLength() - length - 1;
    propRegion = new Region(offset, length);
    if (editorPart instanceof MultiPageEditorPart) {
        ((MultiPageEditorPart) editorPart).setActiveEditor(textEditor);
    }
    textEditor.selectAndReveal(propRegion.getOffset(), propRegion.getLength());
    return true;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IJavaProject(org.eclipse.jdt.core.IJavaProject) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) BadLocationException(org.eclipse.jface.text.BadLocationException)

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