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