Search in sources :

Example 16 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class ServiceLocatorTest method testFQN.

@Test
public void testFQN() {
    MarkupLanguage markupLanguage = locator.getMarkupLanguage(MockMarkupLanguage.class.getName());
    assertNotNull(markupLanguage);
    assertEquals(MockMarkupLanguage.class, markupLanguage.getClass());
}
Also used : MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) Test(org.junit.Test)

Example 17 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class ServiceLocatorTest method testLoadClassNotFound.

@Test
public void testLoadClassNotFound() throws MalformedURLException {
    final URL url = new URL("file://example");
    final AtomicBoolean wasThrown = new AtomicBoolean();
    locator = new ServiceLocator(ServiceLocatorTest.class.getClassLoader()) {

        @Override
        protected Class<?> loadClass(ResourceDescriptor resource, String className) throws ClassNotFoundException {
            wasThrown.set(true);
            throw new ClassNotFoundException(className);
        }

        @Override
        protected List<ResourceDescriptor> discoverServiceResources() {
            return Collections.singletonList(new ResourceDescriptor(url));
        }

        @Override
        protected List<String> readServiceClassNames(URL url) {
            return Collections.singletonList("test.TestLanguage");
        }

        @Override
        void logFailure(String className, Exception e) {
        }
    };
    Set<MarkupLanguage> languages = locator.getAllMarkupLanguages();
    assertTrue(wasThrown.get());
    assertNotNull(languages);
    assertTrue(languages.isEmpty());
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) List(java.util.List) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) URL(java.net.URL) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test)

Example 18 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class ServiceLocatorTest method getAllMarkupLanguagesFiltersDuplicates.

@Test
public void getAllMarkupLanguagesFiltersDuplicates() {
    final MarkupLanguage language1 = new TestMarkupLanguage("Language 1");
    final MarkupLanguage language1b = new MarkupLanguage() {

        {
            setName("Language 1");
        }

        @Override
        public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
            throw new IllegalStateException();
        }
    };
    final MarkupLanguage language2 = new TestMarkupLanguage("Language 3");
    final MarkupLanguage language2b = new TestMarkupLanguage("Language 3");
    ServiceLocator locator = new ServiceLocator(ServiceLocatorTest.class.getClassLoader()) {

        @Override
        void loadMarkupLanguages(MarkupLanguageVisitor visitor) {
            visitor.accept(language1);
            visitor.accept(language1b);
            visitor.accept(language2);
            visitor.accept(language2b);
        }
    };
    Set<MarkupLanguage> markupLanguages = locator.getAllMarkupLanguages();
    assertEquals(3, markupLanguages.size());
    assertTrue(markupLanguages.containsAll(ImmutableSet.of(language1, language1b)));
    assertTrue(markupLanguages.contains(language2) || markupLanguages.contains(language2b));
}
Also used : ServiceLocator(org.eclipse.mylyn.wikitext.util.ServiceLocator) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser) Test(org.junit.Test)

Example 19 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class ShowCheatSheetCommand method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    // $NON-NLS-1$
    Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl");
    if (activeFocusControl instanceof Control) {
        Control control = (Control) activeFocusControl;
        MarkupLanguage markupLanguage = (MarkupLanguage) control.getData(MarkupLanguage.class.getName());
        ISourceViewer viewer = (ISourceViewer) control.getData(ISourceViewer.class.getName());
        if (markupLanguage != null && viewer != null) {
            ToolBarManager toolBarManager = new ToolBarManager();
            toolBarManager.add(new ContextHelpAction());
            final InformationPresenter informationPresenter = InformationPresenterUtil.getHtmlInformationPresenter(viewer, new InformationPresenterUtil.SizeConstraint(50, 200, true, true), toolBarManager, computeCheatSheet(markupLanguage));
            // show information asynchronously since on Eclipse 3.4 it will disappear otherwise
            Display.getCurrent().asyncExec(new Runnable() {

                public void run() {
                    informationPresenter.showInformation();
                }
            });
        }
    }
    return null;
}
Also used : InformationPresenterUtil(org.eclipse.mylyn.internal.wikitext.ui.util.InformationPresenterUtil) Control(org.eclipse.swt.widgets.Control) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) InformationPresenter(org.eclipse.jface.text.information.InformationPresenter) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ContextHelpAction(org.eclipse.mylyn.internal.wikitext.ui.editor.actions.ContextHelpAction)

Example 20 with MarkupLanguage

use of org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage in project mylyn.docs by eclipse.

the class MarkupLanguageProviderTest method getMarkupLanguagesNullName.

@Test
public void getMarkupLanguagesNullName() {
    MarkupLanguageProvider provider = new MarkupLanguageProvider() {

        @Override
        protected Set<MarkupLanguage> loadMarkupLanguages() {
            MockMarkupLanguage language = new MockMarkupLanguage();
            language.setName(null);
            return ImmutableSet.<MarkupLanguage>of(language);
        }
    };
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provided languages must have a name");
    provider.getMarkupLanguages();
}
Also used : MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MockMarkupLanguage(org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) MarkupLanguageProvider(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageProvider) Test(org.junit.Test)

Aggregations

MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)60 Test (org.junit.Test)18 AbstractMarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)15 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)8 File (java.io.File)7 BuildException (org.apache.tools.ant.BuildException)7 CoreException (org.eclipse.core.runtime.CoreException)7 MockMarkupLanguage (org.eclipse.mylyn.internal.wikitext.MockMarkupLanguage)7 StringWriter (java.io.StringWriter)6 HashMap (java.util.HashMap)5 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)5 FileSet (org.apache.tools.ant.types.FileSet)5 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)5 Point (org.eclipse.swt.graphics.Point)5 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)4 TreeMap (java.util.TreeMap)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3