diff options
8 files changed, 166 insertions, 41 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF index e193bc06a..b7975ba62 100644 --- a/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF @@ -26,7 +26,6 @@ Export-Package: org.eclipse.etrice.core.common.ui.autoedit, org.eclipse.etrice.core.common.ui.contentassist, org.eclipse.etrice.core.common.ui.contentassist.antlr, org.eclipse.etrice.core.common.ui.contentassist.antlr.internal, - org.eclipse.etrice.core.common.ui.documentation, org.eclipse.etrice.core.common.ui.editor, org.eclipse.etrice.core.common.ui.editor.model, org.eclipse.etrice.core.common.ui.highlight, diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/documentation/CommentDocumentationProvider.xtend b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/documentation/CommentDocumentationProvider.xtend deleted file mode 100644 index 21f78c628..000000000 --- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/documentation/CommentDocumentationProvider.xtend +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 protos software gmbh (http://www.protos.de). - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * CONTRIBUTORS: - * Juergen Haug (initial contribution) - * - *******************************************************************************/ - -package org.eclipse.etrice.core.common.ui.documentation - -import org.eclipse.emf.ecore.EObject -import org.eclipse.xtext.documentation.impl.MultiLineCommentDocumentationProvider -import org.eclipse.xtext.util.Strings - -class CommentDocumentationProvider extends MultiLineCommentDocumentationProvider { - - override getDocumentation(EObject o) { - val text = super.getDocumentation(o) - if (Strings.isEmpty(text)) { - return text - } - - text.replace('\r\n', '<br>').replace('\n', '<br>') - } - -} diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/hover/BaseHoverDocumentationProvider.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/hover/BaseHoverDocumentationProvider.java new file mode 100644 index 000000000..8bc349c61 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/hover/BaseHoverDocumentationProvider.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.common.ui.hover; + +import static org.eclipse.etrice.core.common.documentation.DocumentationMarkup.MARKUP_ASCIIDOC; +import static org.eclipse.etrice.core.common.documentation.DocumentationMarkup.getMarkupType; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.ui.editor.hover.html.DefaultHoverDocumentationProvider; + +public class BaseHoverDocumentationProvider extends DefaultHoverDocumentationProvider { + + @Override + public String getDocumentation(EObject object) { + String text = super.getDocumentation(object); + + return (text != null) ? processMarkup(text) : null; + } + + protected String processMarkup(String text) { + String markup = getMarkupType(text); + String normText = text.replace("\r\n", "\n"); + + // return eclipse hover output html + if(MARKUP_ASCIIDOC.equals(markup)) { + // # asciidoctor markup + // simulate asciidoctor line break behavior + // 1. asciidoc new paragraph + // 2. asciidoc new line + return normText + .replaceAll("\\n\\n", "<br><br>") + .replaceAll(" \\+\\n", "<br>"); + } + else { + // # html markup + return normText; + } + } +} diff --git a/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF index fa63d005d..bcf63a905 100644 --- a/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF @@ -33,6 +33,7 @@ Export-Package: org.eclipse.etrice.core.common, org.eclipse.etrice.core.common.basetest.impl, org.eclipse.etrice.core.common.basetest.util, org.eclipse.etrice.core.common.converter, + org.eclipse.etrice.core.common.documentation, org.eclipse.etrice.core.common.formatting2, org.eclipse.etrice.core.common.generator, org.eclipse.etrice.core.common.naming, diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/documentation/DocumentationMarkup.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/documentation/DocumentationMarkup.java new file mode 100644 index 000000000..22f958267 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/documentation/DocumentationMarkup.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2010 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.common.documentation; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DocumentationMarkup { + + public static final String MARKUP_ASCIIDOC = "asciidoc"; + public static final String MARKUP_HTML = "html"; + + private static final Pattern MARKUP_PATTERN = Pattern.compile("\\A\\s*\\<\\!\\-\\-\\s*(\\w+)\\s*\\-\\-\\>\\s*"); + + /** + * Determine the markup style of the documentation string. Default is html. + * The tag must appear on the first line and must be commented using html, e.g. + * <code><!-- html --></code> or <code><!-- asciidoc --></code> + * + * @param text not null + */ + public static String getMarkupType(String text) { + Matcher markupMatcher = MARKUP_PATTERN.matcher(text); + + String markup = (markupMatcher.find()) ? markupMatcher.group(1) : null; + if (markup != null && markup.matches("adoc|asciidoc|asciidoctor")) { + return MARKUP_ASCIIDOC; + } + + return MARKUP_HTML; + } + + /** + * Remove markup tag if present. Also removes surrounding whitespace. + * + * @param text not null + */ + public static String trimMarkupTag(String text) { + Matcher markupMatcher = MARKUP_PATTERN.matcher(text); + return markupMatcher.replaceFirst(""); + } + +} diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java index a9dad807f..d6a8333e4 100644 --- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java +++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java @@ -15,9 +15,9 @@ package org.eclipse.etrice.core.ui; import org.eclipse.etrice.core.common.ui.autoedit.BaseAutoEditStrategyProvider; -import org.eclipse.etrice.core.common.ui.documentation.CommentDocumentationProvider; import org.eclipse.etrice.core.common.ui.editor.BaseDoubleClickStrategyProvider; import org.eclipse.etrice.core.common.ui.editor.model.BaseTokenTypeToPartitionMapper; +import org.eclipse.etrice.core.common.ui.hover.BaseHoverDocumentationProvider; import org.eclipse.etrice.core.common.ui.hover.IKeywordHoverContentProvider; import org.eclipse.etrice.core.common.ui.hover.KeywordHoverProvider; import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener; @@ -31,12 +31,12 @@ import org.eclipse.etrice.core.ui.quickfix.RoomQuickFixProviderXtend; import org.eclipse.etrice.doc.KeywordHoverContentProvider; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; -import org.eclipse.xtext.documentation.IEObjectDocumentationProvider; import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator; import org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategyProvider; import org.eclipse.xtext.ui.editor.doubleClicking.DoubleClickStrategyProvider; import org.eclipse.xtext.ui.editor.hover.IEObjectHover; import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider; +import org.eclipse.xtext.ui.editor.hover.html.IEObjectHoverDocumentationProvider; import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper; import org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper; import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration; @@ -58,7 +58,9 @@ public class RoomUiModule extends org.eclipse.etrice.core.ui.AbstractRoomUiModul // keyword hover stuff binder.bind(IKeywordHoverContentProvider.class).to(KeywordHoverContentProvider.class); - binder.bind(IEObjectHoverProvider.class).to(KeywordHoverProvider.class); + binder.bind(IEObjectHoverProvider.class).to(KeywordHoverProvider.class); + + binder.bind(IEObjectHoverDocumentationProvider.class).to(BaseHoverDocumentationProvider.class); } @Override @@ -108,10 +110,6 @@ public class RoomUiModule extends org.eclipse.etrice.core.ui.AbstractRoomUiModul return BaseDoubleClickStrategyProvider.class; } - public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProvider() { - return CommentDocumentationProvider.class; - } - @Override public Class<? extends org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider> bindIssueResolutionProvider() { return RoomQuickFixProviderXtend.class; diff --git a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/AsciiDocGen.xtend b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/AsciiDocGen.xtend index 748704dc4..a714c83c7 100644 --- a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/AsciiDocGen.xtend +++ b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/gen/AsciiDocGen.xtend @@ -40,12 +40,14 @@ import org.eclipse.etrice.generator.base.io.IGeneratorFileIO import org.eclipse.etrice.generator.fsm.base.CodegenHelpers import org.eclipse.xtext.documentation.IEObjectDocumentationProvider +import static org.eclipse.etrice.core.common.documentation.DocumentationMarkup.* + @Singleton class AsciiDocGen { @Inject extension RoomHelpers @Inject extension CodegenHelpers - @Inject extension IEObjectDocumentationProvider + @Inject IEObjectDocumentationProvider eObjDocuProvider def doGenerate(Root root, IGeneratorFileIO fileIO, boolean includeImages) { val packages = root.models.groupBy[name].entrySet.map[new RoomPackage(key, value)].sortBy[name] @@ -489,6 +491,23 @@ class AsciiDocGen { } builder.toString } + + def private String documentation(EObject obj) { + val raw = eObjDocuProvider.getDocumentation(obj) + if(raw === null) + return null; + + switch getMarkupType(raw) { + case MARKUP_HTML: ''' + ++++ + <div class="paragraph"><p>«trimMarkupTag(raw)»</p></div> + ++++ + ''' + default: { + trimMarkupTag(raw) + } + } + } private static class RoomPackage { diff --git a/tests/org.eclipse.etrice.core.common.tests/src/org/eclipse/etrice/core/common/tests/DocumentationMarkupTest.xtend b/tests/org.eclipse.etrice.core.common.tests/src/org/eclipse/etrice/core/common/tests/DocumentationMarkupTest.xtend new file mode 100644 index 000000000..a533a9294 --- /dev/null +++ b/tests/org.eclipse.etrice.core.common.tests/src/org/eclipse/etrice/core/common/tests/DocumentationMarkupTest.xtend @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.common.tests + +import org.eclipse.etrice.core.common.documentation.DocumentationMarkup +import org.junit.Test + +import static org.junit.Assert.* + +class DocumentationMarkupTest extends DocumentationMarkup { + + @Test + def void getMarkupTypeTest() { + assertEquals('html', getMarkupType('text')) + assertEquals('html', getMarkupType('<!--html-->')) + assertEquals('html', getMarkupType('<!-- html -->')) + assertEquals('html', getMarkupType('<!-- html -->\\n')) + assertEquals('html', getMarkupType(' <!-- html -->\\r\\n')) + assertEquals('asciidoc', getMarkupType('<!-- asciidoc -->')) + } + +}
\ No newline at end of file |