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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations