use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.
the class FileRefHyperlinkDetectorTest method testNoHyperlinkInDocument.
@Test
public void testNoHyperlinkInDocument() throws CoreException {
ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(project, fileRefPatterns);
ITextViewer mockTextViewer = mock(ITextViewer.class);
when(mockTextViewer.getDocument()).thenReturn(new Document("Some contents without hyperlink in it."));
IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(7, 15), false);
assertThat(detectHyperlinks, is(nullValue()));
}
use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.
the class MarkupSourceViewerConfiguration method createCustomHyperlinkDetectors.
@Override
protected List<IHyperlinkDetector> createCustomHyperlinkDetectors(ISourceViewer sourceViewer) {
List<IHyperlinkDetector> detectors = new ArrayList<>();
if (markupHyperlinkDetector == null) {
markupHyperlinkDetector = new MarkupHyperlinkDetector();
markupHyperlinkDetector.setMarkupLanguage(markupLanguage);
markupHyperlinkDetector.setFile(file);
}
if (fileRefHyperlinkDetector == null && file != null) {
Map<String, List<String>> hyperlinkDectectorFileRefRegexes = WikiTextUiPlugin.getDefault().getHyperlinkDectectorFileRefRegexes();
List<String> fileRefHyperlinkRegexes = hyperlinkDectectorFileRefRegexes.getOrDefault(markupLanguage.getName(), ImmutableList.of());
fileRefHyperlinkDetector = new FileRefHyperlinkDetector(file.getParent(), fileRefHyperlinkRegexes);
}
detectors.add(markupHyperlinkDetector);
detectors.add(fileRefHyperlinkDetector);
detectors.add(markupHyperlinkDetector);
detectors.addAll(super.createCustomHyperlinkDetectors(sourceViewer));
return detectors;
}
use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.
the class FileRefHyperlinkDetectorTest method testFileDoesNotExist.
@Test
public void testFileDoesNotExist() throws CoreException {
ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(project, fileRefPatterns);
ITextViewer mockTextViewer = mock(ITextViewer.class);
when(mockTextViewer.getDocument()).thenReturn(new Document("image::file-that-does-not-exist.png[]"));
IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(7, 15), false);
assertThat(detectHyperlinks, is(nullValue()));
}
use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.
the class FileRefHyperlinkDetectorTest method testFindFileRefAndOpenHyperlink.
@Test
public void testFindFileRefAndOpenHyperlink() throws CoreException {
String asciidocFileName = "simon-scholz.adoc";
IFile file = project.getFile(asciidocFileName);
file.create(new ByteArrayInputStream("== Writing tests is kinda documentation".getBytes()), true, new NullProgressMonitor());
ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(file.getParent(), fileRefPatterns);
ITextViewer mockTextViewer = mock(ITextViewer.class);
when(mockTextViewer.getDocument()).thenReturn(new Document("include::" + asciidocFileName + "[]"));
IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(9, 17), false);
assertThat(detectHyperlinks.length, is(1));
IHyperlink hyperlink = detectHyperlinks[0];
hyperlink.open();
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
IFile editorFile = ((IFileEditorInput) editorInput).getFile();
assertThat(file, equalTo(editorFile));
}
}
use of org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector in project mylyn.docs by eclipse.
the class FileRefHyperlinkDetectorTest method testDeeperNestedFolderStructure.
@Test
public void testDeeperNestedFolderStructure() throws CoreException {
IFolder folder = project.getFolder("AsciiDoctor Tutorial");
if (!folder.exists()) {
folder.create(IResource.NONE, true, new NullProgressMonitor());
}
IFolder nestedResourcesFolder = folder.getFolder("resources");
if (!nestedResourcesFolder.exists()) {
nestedResourcesFolder.create(IResource.NONE, true, new NullProgressMonitor());
}
IFile fileInNestedFolder = nestedResourcesFolder.getFile("nested-document.adoc");
if (!fileInNestedFolder.exists()) {
fileInNestedFolder.create(new ByteArrayInputStream("include::../../article.adoc[]".getBytes()), true, new NullProgressMonitor());
}
IFile articleFile = project.getFile("article.adoc");
if (!articleFile.exists()) {
articleFile.create(new ByteArrayInputStream("== Overview".getBytes()), true, new NullProgressMonitor());
}
ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(fileInNestedFolder.getParent(), fileRefPatterns);
ITextViewer mockTextViewer = mock(ITextViewer.class);
when(mockTextViewer.getDocument()).thenReturn(new Document("include::../../article.adoc[]"));
IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(9, 17), false);
assertThat(detectHyperlinks.length, is(1));
IHyperlink hyperlink = detectHyperlinks[0];
hyperlink.open();
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
IFile editorFile = ((IFileEditorInput) editorInput).getFile();
assertThat(articleFile, equalTo(editorFile));
}
}
Aggregations