Search in sources :

Example 31 with MarkupLanguage

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

the class WikiTextSourceEditor method updateOutlineNow.

private void updateOutlineNow() {
    if (!outlineDirty) {
        return;
    }
    if (getSourceViewer().getTextWidget().isDisposed()) {
        return;
    }
    // we maintain the outline even if the outline page is not in use, which allows us to use the outline for
    // content assist and other things
    MarkupLanguage markupLanguage = getMarkupLanguage();
    if (markupLanguage == null) {
        return;
    }
    final MarkupLanguage language = markupLanguage.clone();
    final String content = document.get();
    final int contentGeneration;
    synchronized (WikiTextSourceEditor.this) {
        contentGeneration = documentGeneration;
        initializeOutlineParser();
    }
    outlineParser.setMarkupLanguage(language);
    OutlineItem rootItem = outlineParser.parse(content);
    updateOutline(contentGeneration, rootItem);
}
Also used : AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) Point(org.eclipse.swt.graphics.Point) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 32 with MarkupLanguage

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

the class WikiTextExtensionPointReader method instantiateMarkupLanguage.

private MarkupLanguage instantiateMarkupLanguage(String name, Class<? extends MarkupLanguage> languageClass) {
    try {
        MarkupLanguage language = languageClass.newInstance();
        language.setName(name);
        language.setExtendsLanguage(languageExtensionByLanguage.get(name));
        configureFileExtensions(language);
        return language;
    } catch (Exception e) {
        log(IStatus.ERROR, // $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        Messages.getString("WikiTextExtensionPointReader.2"), // $NON-NLS-1$
        name, languageClass.getName(), e.getMessage()), e);
    }
    return null;
}
Also used : MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) CoreException(org.eclipse.core.runtime.CoreException)

Example 33 with MarkupLanguage

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

the class WikiTextExtensionPointReader method initializeMarkupLanguages.

private void initializeMarkupLanguages() {
    synchronized (this) {
        if (this.languageByName == null) {
            SortedMap<String, Class<? extends MarkupLanguage>> markupLanguageByName = new TreeMap<>();
            Map<String, Class<? extends MarkupLanguage>> languageByFileExtension = new HashMap<>();
            Map<String, String> languageExtensionByLanguage = new HashMap<>();
            Map<Class<? extends MarkupLanguage>, String> languageNameByLanguage = new HashMap<>();
            IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getExtensionPointNamespace(), EXTENSION_MARKUP_LANGUAGE);
            if (extensionPoint != null) {
                IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
                for (IConfigurationElement element : configurationElements) {
                    // $NON-NLS-1$
                    String name = element.getAttribute("name");
                    if (name == null || name.length() == 0) {
                        log(IStatus.ERROR, MessageFormat.format(EXTENSION_MARKUP_LANGUAGE + // $NON-NLS-1$
                        Messages.getString("WikiTextExtensionPointReader.10"), element.getDeclaringExtension().getContributor().getName()));
                        continue;
                    }
                    // $NON-NLS-1$
                    String extendsLanguage = element.getAttribute("extends");
                    Object markupLanguage;
                    try {
                        // $NON-NLS-1$
                        markupLanguage = element.createExecutableExtension("class");
                    } catch (CoreException e) {
                        getLog().log(e.getStatus());
                        continue;
                    }
                    if (!(markupLanguage instanceof MarkupLanguage)) {
                        log(IStatus.ERROR, // $NON-NLS-1$
                        MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("WikiTextExtensionPointReader.13"), markupLanguage.getClass().getName()));
                        continue;
                    }
                    MarkupLanguage d = (MarkupLanguage) markupLanguage;
                    {
                        Class<? extends MarkupLanguage> previous = markupLanguageByName.put(name, d.getClass());
                        if (previous != null) {
                            log(IStatus.ERROR, MessageFormat.format(EXTENSION_MARKUP_LANGUAGE + // $NON-NLS-1$
                            Messages.getString("WikiTextExtensionPointReader.14"), name, element.getDeclaringExtension().getContributor().getName(), name));
                            markupLanguageByName.put(name, previous);
                            continue;
                        } else {
                            languageNameByLanguage.put(d.getClass(), name);
                        }
                    }
                    if (extendsLanguage != null) {
                        languageExtensionByLanguage.put(name, extendsLanguage);
                    }
                    // $NON-NLS-1$
                    String fileExtensions = element.getAttribute("fileExtensions");
                    if (fileExtensions != null) {
                        // $NON-NLS-1$
                        String[] parts = fileExtensions.split("\\s*,\\s*");
                        for (String part : parts) {
                            if (part.length() != 0) {
                                part = part.toLowerCase();
                                Class<? extends MarkupLanguage> previous = languageByFileExtension.put(part, d.getClass());
                                if (previous != null) {
                                    log(IStatus.ERROR, MessageFormat.format(EXTENSION_MARKUP_LANGUAGE + // $NON-NLS-1$
                                    Messages.getString("WikiTextExtensionPointReader.17"), part, element.getDeclaringExtension().getContributor().getName(), part));
                                    languageByFileExtension.put(part, previous);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            this.languageByFileExtension = languageByFileExtension;
            this.languageByName = markupLanguageByName;
            this.languageExtensionByLanguage = languageExtensionByLanguage;
            this.languageNameByLanguage = languageNameByLanguage;
        }
    }
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Example 34 with MarkupLanguage

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

the class WikiTextExtensionPointReader method initializeValidationRules.

private void initializeValidationRules() {
    initializeMarkupLanguages();
    synchronized (this) {
        if (validationRulesByLanguageName == null) {
            Map<String, ValidationRules> validationRulesByLanguageName = new HashMap<>();
            IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getExtensionPointNamespace(), EXTENSION_VALIDATION_RULES);
            if (extensionPoint != null) {
                IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
                for (IConfigurationElement element : configurationElements) {
                    try {
                        // $NON-NLS-1$
                        String markupLanguage = element.getAttribute("markupLanguage");
                        if (markupLanguage == null || markupLanguage.length() == 0) {
                            // $NON-NLS-1$
                            throw new Exception(Messages.getString("WikiTextExtensionPointReader.4"));
                        }
                        if (!languageByName.containsKey(markupLanguage)) {
                            throw new Exception(MessageFormat.format(Messages.getString("WikiTextExtensionPointReader.5"), // $NON-NLS-1$
                            languageByName));
                        }
                        Object extension;
                        try {
                            // $NON-NLS-1$
                            extension = element.createExecutableExtension("class");
                        } catch (CoreException e) {
                            getLog().log(e.getStatus());
                            continue;
                        }
                        if (!(extension instanceof ValidationRule)) {
                            throw new Exception(MessageFormat.format(Messages.getString("WikiTextExtensionPointReader.7"), // $NON-NLS-1$
                            extension.getClass().getName()));
                        }
                        ValidationRules rules = validationRulesByLanguageName.get(markupLanguage);
                        if (rules == null) {
                            rules = new ValidationRules();
                            validationRulesByLanguageName.put(markupLanguage, rules);
                        }
                        rules.addValidationRule((ValidationRule) extension);
                    } catch (Exception e) {
                        log(IStatus.ERROR, // $NON-NLS-1$
                        MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("WikiTextExtensionPointReader.8"), element.getDeclaringExtension().getContributor().getName(), EXTENSION_VALIDATION_RULES, e.getMessage()), e);
                    }
                }
            }
            // now that we have the basic validation rules, check for language extensions and connect the hierarchy
            // first ensure that all language names have templates defined
            Set<String> languageNames = getMarkupLanguageNames();
            for (String languageName : languageNames) {
                ValidationRules rules = validationRulesByLanguageName.get(languageName);
                if (rules == null) {
                    rules = new ValidationRules();
                    validationRulesByLanguageName.put(languageName, rules);
                }
            }
            // next connect the hierarchy
            for (String languageName : languageNames) {
                MarkupLanguage markupLanguage = getMarkupLanguage(languageName);
                if (markupLanguage != null && markupLanguage.getExtendsLanguage() != null) {
                    ValidationRules languageRules = validationRulesByLanguageName.get(languageName);
                    ValidationRules parentLanguageRules = validationRulesByLanguageName.get(markupLanguage.getExtendsLanguage());
                    languageRules.setParent(parentLanguageRules);
                }
            }
            this.validationRulesByLanguageName = validationRulesByLanguageName;
        }
    }
}
Also used : HashMap(java.util.HashMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) ValidationRule(org.eclipse.mylyn.wikitext.validation.ValidationRule) ValidationRules(org.eclipse.mylyn.wikitext.validation.ValidationRules) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Example 35 with MarkupLanguage

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

the class MarkupTask method createMarkupLanguage.

/**
 * Create a {@link MarkupLanguage markup language parser} for the {@link #getMarkupLanguage() specified markup
 * language}.
 *
 * @return the markup language
 * @throws BuildException
 *             if the markup language is not specified or if it is unknown.
 */
protected MarkupLanguage createMarkupLanguage() throws BuildException {
    if (markupLanguage == null) {
        // $NON-NLS-1$
        throw new BuildException(Messages.getString("MarkupTask.0"));
    }
    try {
        MarkupLanguage language = ServiceLocator.getInstance(getClass().getClassLoader()).getMarkupLanguage(markupLanguage);
        if (internalLinkPattern != null) {
            // $NON-NLS-1$
            checkAbstractMarkupLanguage(language, "internalLinkPattern");
            ((AbstractMarkupLanguage) language).setInternalLinkPattern(internalLinkPattern);
        }
        if (markupLanguageConfiguration != null) {
            language.configure(markupLanguageConfiguration);
        }
        return language;
    } catch (IllegalArgumentException e) {
        throw new BuildException(e.getMessage(), e);
    }
}
Also used : BuildException(org.apache.tools.ant.BuildException) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)

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