Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2019-06-10 06:10:39 -0400
committerJuergen Haug2019-06-10 14:41:24 -0400
commite92381148e80ad6e3229a874ff367cf067da93d1 (patch)
treeeb5f619155aac804053030b29a4d0c4efff479e1
parent2f0bd26685540086e59577b80cd3a5aac6711ce9 (diff)
downloadorg.eclipse.etrice-e92381148e80ad6e3229a874ff367cf067da93d1.tar.gz
org.eclipse.etrice-e92381148e80ad6e3229a874ff367cf067da93d1.tar.xz
org.eclipse.etrice-e92381148e80ad6e3229a874ff367cf067da93d1.zip
Bug 548124 - [ui] added editor folding for copyright and importsHEADmaster
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/folding/FoldingRegionProvider.java77
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/hover/BaseHoverDocumentationProvider.java16
-rw-r--r--plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java12
-rw-r--r--plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/ETMapUiModule.java12
-rw-r--r--plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/ETPhysUiModule.java14
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java12
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomEObjectHover.xtend3
8 files changed, 141 insertions, 6 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 b7975ba62..533dee979 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
@@ -27,6 +27,7 @@ Export-Package: org.eclipse.etrice.core.common.ui.autoedit,
org.eclipse.etrice.core.common.ui.contentassist.antlr,
org.eclipse.etrice.core.common.ui.contentassist.antlr.internal,
org.eclipse.etrice.core.common.ui.editor,
+ org.eclipse.etrice.core.common.ui.editor.folding,
org.eclipse.etrice.core.common.ui.editor.model,
org.eclipse.etrice.core.common.ui.highlight,
org.eclipse.etrice.core.common.ui.hover,
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/folding/FoldingRegionProvider.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/folding/FoldingRegionProvider.java
new file mode 100644
index 000000000..e720e41d4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/folding/FoldingRegionProvider.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.editor.folding;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.etrice.core.common.base.Import;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.xtext.resource.ILocationInFileProvider;
+import org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider;
+import org.eclipse.xtext.ui.editor.folding.IFoldingRegionAcceptor;
+import org.eclipse.xtext.ui.editor.folding.IFoldingRegionAcceptorExtension;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.util.ITextRegion;
+
+import com.google.inject.Inject;
+
+public class FoldingRegionProvider extends DefaultFoldingRegionProvider {
+
+ @Inject
+ private ILocationInFileProvider locationInFileProvider;
+
+ @Override
+ protected void computeCommentFolding(IXtextDocument xtextDocument,
+ IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor, ITypedRegion typedRegion,
+ boolean initiallyFolded) throws BadLocationException {
+
+ // auto fold copyright
+ boolean isFolded = initiallyFolded;
+ int offset = typedRegion.getOffset();
+ int length = typedRegion.getLength();
+ if(offset == 0) {
+ String text = xtextDocument.get(offset, length);
+ isFolded |= text.trim().toLowerCase().contains("copyright");
+ }
+
+ super.computeCommentFolding(xtextDocument, foldingRegionAcceptor, typedRegion, isFolded);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void computeObjectFolding(EObject eObject, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor,
+ boolean initiallyFolded) {
+
+ if(eObject instanceof Import) {
+ // fold imports
+ EStructuralFeature importsFeature = eObject.eContainmentFeature();
+ if(importsFeature.isMany()) {
+ List<Import> imports = (List<Import>) eObject.eContainer().eGet(importsFeature);
+ if(imports.size() >= 2 && imports.get(0) == eObject) {
+ // assuming imports syntax is a single block
+ ITextRegion region = imports.stream().map(imp -> locationInFileProvider.getFullTextRegion(imp)).reduce((first, second) -> first.merge(second)).get();
+ ITextRegion significant = locationInFileProvider.getSignificantTextRegion(eObject);
+ ((IFoldingRegionAcceptorExtension<ITextRegion>)foldingRegionAcceptor).accept(region.getOffset(), region.getLength(), true, significant);
+ }
+ }
+ }
+
+ super.computeObjectFolding(eObject, foldingRegionAcceptor, initiallyFolded);
+ }
+
+}
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
index af3c3379f..330986e07 100644
--- 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
@@ -19,15 +19,25 @@ import static org.eclipse.etrice.core.common.documentation.DocumentationMarkup.g
import static org.eclipse.etrice.core.common.documentation.DocumentationMarkup.trimMarkupTag;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.ui.editor.hover.html.DefaultHoverDocumentationProvider;
public class BaseHoverDocumentationProvider extends DefaultHoverDocumentationProvider {
@Override
- public String getDocumentation(EObject object) {
+ public String getDocumentation(EObject object) {
String text = super.getDocumentation(object);
-
- return (text != null) ? processMarkup(text) : null;
+ if (text != null) {
+ // hide copyright header
+ int totalOffset = NodeModelUtils.getNode(object).getTotalOffset();
+ if (totalOffset == 0 && text.trim().toLowerCase().startsWith("copyright")) {
+ return null;
+ } else {
+ return processMarkup(text);
+ }
+ }
+
+ return null;
}
protected String processMarkup(String text) {
diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java
index a8550b5f0..1cd0beba3 100644
--- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java
+++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java
@@ -14,9 +14,13 @@
package org.eclipse.etrice.core.ui;
+import org.eclipse.etrice.core.common.ui.editor.folding.FoldingRegionProvider;
+import org.eclipse.etrice.core.common.ui.hover.BaseHoverDocumentationProvider;
import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.core.ui.linking.ConfigHyperlinkHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.xtext.ui.editor.folding.IFoldingRegionProvider;
+import org.eclipse.xtext.ui.editor.hover.html.IEObjectHoverDocumentationProvider;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper;
/**
@@ -38,4 +42,12 @@ public class ConfigUiModule extends
public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
return ConfigHyperlinkHelper.class;
}
+
+ public Class<? extends IFoldingRegionProvider> bindIFoldingRegionProvider() {
+ return FoldingRegionProvider.class;
+ }
+
+ public Class<? extends IEObjectHoverDocumentationProvider> bindIEObjectHoverDocumentationProvider() {
+ return BaseHoverDocumentationProvider.class;
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/ETMapUiModule.java b/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/ETMapUiModule.java
index 0a9916ff1..676226d87 100644
--- a/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/ETMapUiModule.java
+++ b/plugins/org.eclipse.etrice.core.etmap.ui/src/org/eclipse/etrice/core/etmap/ui/ETMapUiModule.java
@@ -14,9 +14,13 @@
package org.eclipse.etrice.core.etmap.ui;
+import org.eclipse.etrice.core.common.ui.editor.folding.FoldingRegionProvider;
+import org.eclipse.etrice.core.common.ui.hover.BaseHoverDocumentationProvider;
import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.core.common.ui.linking.ImportAwareHyperlinkHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.xtext.ui.editor.folding.IFoldingRegionProvider;
+import org.eclipse.xtext.ui.editor.hover.html.IEObjectHoverDocumentationProvider;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper;
/**
@@ -34,4 +38,12 @@ public class ETMapUiModule extends org.eclipse.etrice.core.etmap.ui.AbstractETMa
public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
return ImportAwareHyperlinkHelper.class;
}
+
+ public Class<? extends IFoldingRegionProvider> bindIFoldingRegionProvider() {
+ return FoldingRegionProvider.class;
+ }
+
+ public Class<? extends IEObjectHoverDocumentationProvider> bindIEObjectHoverDocumentationProvider() {
+ return BaseHoverDocumentationProvider.class;
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/ETPhysUiModule.java b/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/ETPhysUiModule.java
index 900f4a851..c8d9b1a1f 100644
--- a/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/ETPhysUiModule.java
+++ b/plugins/org.eclipse.etrice.core.etphys.ui/src/org/eclipse/etrice/core/etphys/ui/ETPhysUiModule.java
@@ -14,15 +14,20 @@
package org.eclipse.etrice.core.etphys.ui;
+import org.eclipse.etrice.core.common.ui.editor.folding.FoldingRegionProvider;
+import org.eclipse.etrice.core.common.ui.hover.BaseHoverDocumentationProvider;
import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.core.common.ui.linking.ImportAwareHyperlinkHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.xtext.ui.editor.folding.IFoldingRegionProvider;
+import org.eclipse.xtext.ui.editor.hover.html.IEObjectHoverDocumentationProvider;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper;
/**
* Use this class to register components to be used within the IDE.
*/
public class ETPhysUiModule extends org.eclipse.etrice.core.etphys.ui.AbstractETPhysUiModule {
+
public ETPhysUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
@@ -30,8 +35,17 @@ public class ETPhysUiModule extends org.eclipse.etrice.core.etphys.ui.AbstractET
public Class<? extends org.eclipse.xtext.ui.editor.IURIEditorOpener> bindIURIEditorOpener() {
return GlobalNonPlatformURIEditorOpener.class;
}
+
public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
return ImportAwareHyperlinkHelper.class;
}
+ public Class<? extends IFoldingRegionProvider> bindIFoldingRegionProvider() {
+ return FoldingRegionProvider.class;
+ }
+
+ public Class<? extends IEObjectHoverDocumentationProvider> bindIEObjectHoverDocumentationProvider() {
+ return BaseHoverDocumentationProvider.class;
+ }
+
}
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 c7eb390ef..bd67c349d 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
@@ -16,6 +16,7 @@ package org.eclipse.etrice.core.ui;
import org.eclipse.etrice.core.common.ui.autoedit.BaseAutoEditStrategyProvider;
import org.eclipse.etrice.core.common.ui.editor.BaseDoubleClickStrategyProvider;
+import org.eclipse.etrice.core.common.ui.editor.folding.FoldingRegionProvider;
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;
@@ -34,6 +35,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
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.folding.IFoldingRegionProvider;
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;
@@ -59,8 +61,6 @@ 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(RoomHoverProvider.class);
-
- binder.bind(IEObjectHoverDocumentationProvider.class).to(BaseHoverDocumentationProvider.class);
}
@Override
@@ -110,6 +110,14 @@ public class RoomUiModule extends org.eclipse.etrice.core.ui.AbstractRoomUiModul
return BaseDoubleClickStrategyProvider.class;
}
+ public Class<? extends IFoldingRegionProvider> bindIFoldingRegionProvider() {
+ return FoldingRegionProvider.class;
+ }
+
+ public Class<? extends IEObjectHoverDocumentationProvider> bindIEObjectHoverDocumentationProvider() {
+ return BaseHoverDocumentationProvider.class;
+ }
+
@Override
public Class<? extends org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider> bindIssueResolutionProvider() {
return RoomQuickFixProviderXtend.class;
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomEObjectHover.xtend b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomEObjectHover.xtend
index 8043af85f..68570d762 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomEObjectHover.xtend
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomEObjectHover.xtend
@@ -32,11 +32,12 @@ class RoomEObjectHover extends KeywordEObjectTextHover {
RoomGrammarAccess grammar
override protected getXtextElementAt(XtextResource resource, int offset) {
- // lookup expression
+
val parseResult = resource.parseResult
if(parseResult !== null) {
val leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.rootNode, offset)
if(leafNode?.grammarElement instanceof RuleCall) {
+ // lookup model element in DetailCode
if((leafNode.grammarElement as RuleCall).rule == grammar.CC_STRINGRule && leafNode.semanticElement instanceof DetailCode){
val exprFeature = UIExpressionUtil.findAtOffset(leafNode, offset)
if(exprFeature?.data instanceof EObject)

Back to the top