Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2019-07-17 08:47:34 +0000
committerJuergen Haug2019-07-17 08:49:30 +0000
commit26dcf9bc71d62d27eaa1ee940b76b3ae61a3f50a (patch)
tree163ce5959ec2d3c549e6fb925adf3957ff8856fe
parenta80dc281a8ed60ede81911e927e0c05973881de9 (diff)
downloadorg.eclipse.etrice-26dcf9bc71d62d27eaa1ee940b76b3ae61a3f50a.tar.gz
org.eclipse.etrice-26dcf9bc71d62d27eaa1ee940b76b3ae61a3f50a.tar.xz
org.eclipse.etrice-26dcf9bc71d62d27eaa1ee940b76b3ae61a3f50a.zip
Bug 549333 - [ui] Improve highlight of annotations and comments
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseHighlightingConfig.java24
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java34
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java4
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java3
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomHighlightingConfiguration.java14
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomSemanticHighlightingCalculator.java14
6 files changed, 62 insertions, 31 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseHighlightingConfig.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseHighlightingConfig.java
index b1a54f630..e569bc306 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseHighlightingConfig.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseHighlightingConfig.java
@@ -13,6 +13,7 @@
package org.eclipse.etrice.core.common.ui.highlight;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
@@ -20,13 +21,30 @@ import org.eclipse.xtext.ui.editor.utils.TextStyle;
public class BaseHighlightingConfig extends DefaultHighlightingConfiguration {
+ /** Annotations */
+ public static final String HL_ANNOTATION_ID = "hl_annotation";
+ /** Smart strings */
public static final String HL_CCSTRING = "ccstring";
+ /** Comments that are treated as documentation */
+ public static final String HL_DOCUMENTATION = "documentation";
@Override
public void configure(IHighlightingConfigurationAcceptor acceptor) {
super.configure(acceptor);
+ acceptor.acceptDefaultHighlighting(HL_ANNOTATION_ID, "Annotation", typeAnnotationBlock());
acceptor.acceptDefaultHighlighting(HL_CCSTRING, "CCString", detailCodeStringStyle());
+ acceptor.acceptDefaultHighlighting(HL_DOCUMENTATION, "Documentation", documentationStyle());
+ }
+
+ // method for calculating an actual text styles
+ public TextStyle typeAnnotationBlock() {
+ TextStyle textStyle = new TextStyle();
+ // textStyle.setBackgroundColor(new RGB(155, 55, 255));
+ textStyle.setColor(new RGB(160, 0, 0));
+ textStyle.setStyle(SWT.BOLD);
+ // textStyle.setFontData(defaultCommentFont);
+ return textStyle;
}
public TextStyle detailCodeStringStyle() {
@@ -34,4 +52,10 @@ public class BaseHighlightingConfig extends DefaultHighlightingConfiguration {
textStyle.setBackgroundColor(new RGB(220, 220, 220));
return textStyle;
}
+
+ public TextStyle documentationStyle() {
+ TextStyle textStyle = commentTextStyle().copy();
+ textStyle.setColor(new RGB(62, 87, 118));
+ return textStyle;
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java
index af6d684d2..2441af88d 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java
@@ -14,6 +14,10 @@
package org.eclipse.etrice.core.common.ui.highlight;
+import static org.eclipse.etrice.core.common.ui.highlight.BaseHighlightingConfig.HL_ANNOTATION_ID;
+import static org.eclipse.etrice.core.common.ui.highlight.BaseHighlightingConfig.HL_DOCUMENTATION;
+import static org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration.NUMBER_ID;
+
import java.util.List;
import org.eclipse.emf.ecore.EObject;
@@ -23,9 +27,11 @@ import org.eclipse.etrice.core.common.converter.CCStringIndentation;
import org.eclipse.etrice.core.common.services.BaseGrammarAccess;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.RuleCall;
+import org.eclipse.xtext.documentation.IEObjectDocumentationProviderExtension;
import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.nodemodel.INode;
+import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
import org.eclipse.xtext.util.CancelIndicator;
@@ -35,11 +41,9 @@ import com.google.inject.Inject;
public class BaseSemanticHighlighter implements ISemanticHighlightingCalculator {
- @Inject
- BaseGrammarAccess grammar;
-
- @Inject
- BaseConverterService converterService;
+ @Inject BaseGrammarAccess grammar;
+ @Inject BaseConverterService converterService;
+ @Inject(optional = true) IEObjectDocumentationProviderExtension docuProvider;
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
@@ -56,14 +60,26 @@ public class BaseSemanticHighlighter implements ISemanticHighlightingCalculator
}
protected void provideHighlightingFor(INode node, XtextResource resource, IHighlightedPositionAcceptor acceptor) {
- EObject obj = node.getGrammarElement();
- if (obj instanceof RuleCall) {
- AbstractRule rule = ((RuleCall) obj).getRule();
+ EObject grammarElement = node.getGrammarElement();
+ if (grammarElement instanceof RuleCall) {
+ AbstractRule rule = ((RuleCall) grammarElement).getRule();
if(rule == grammar.getCC_STRINGRule()) {
ccStringHighlight(node, acceptor, converterService.getCC_StringConverter());
}
else if(rule == grammar.getNumberLiteralRule()) {
- acceptor.addPosition(node.getOffset(), node.getLength() , DefaultHighlightingConfiguration.NUMBER_ID);
+ acceptor.addPosition(node.getOffset(), node.getLength() , NUMBER_ID);
+ }
+ } else {
+ if(grammarElement == grammar.getAnnotationAccess().getTypeAnnotationTypeCrossReference_1_0()
+ || grammarElement == grammar.getAnnotationAccess().getCommercialAtKeyword_0()) {
+ // highlight annotation @FQN
+ acceptor.addPosition(node.getOffset(), node.getLength(), HL_ANNOTATION_ID);
+ }
+ else if(docuProvider != null && grammarElement == grammar.getML_COMMENTRule()) {
+ // highlight comments that are treated as comments
+ EObject semanticObj = NodeModelUtils.findActualSemanticObjectFor(node);
+ if(semanticObj != null && docuProvider.getDocumentationNodes(semanticObj).contains(node))
+ acceptor.addPosition(node.getOffset(), node.getLength() , HL_DOCUMENTATION);
}
}
}
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java
index 5a1838102..a8bf34bd3 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java
@@ -84,6 +84,8 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
@Check
public void checkAnnotationAttributeMandatory(Annotation a) {
+ if(a.getType().eIsProxy()) return;
+
for (AnnotationAttribute att : a.getType().getAttributes()) {
if (!att.isOptional()) {
boolean isDefined = false;
@@ -106,6 +108,8 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
@Check
public void checkAnnotationAttributeType(Annotation a) {
+ if(a.getType().eIsProxy()) return;
+
HashSet<String> names = new HashSet<String>();
for (KeyValue kv : a.getAttributes()) {
int idx = a.getAttributes().indexOf(kv);
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 bd67c349d..d5ac6fe15 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
@@ -32,6 +32,8 @@ 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.IEObjectDocumentationProviderExtension;
+import org.eclipse.xtext.documentation.impl.MultiLineCommentDocumentationProvider;
import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategyProvider;
import org.eclipse.xtext.ui.editor.doubleClicking.DoubleClickStrategyProvider;
@@ -61,6 +63,7 @@ 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(IEObjectDocumentationProviderExtension.class).to(MultiLineCommentDocumentationProvider.class);
}
@Override
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomHighlightingConfiguration.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomHighlightingConfiguration.java
index a50aa3fee..fd600037f 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomHighlightingConfiguration.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomHighlightingConfiguration.java
@@ -17,8 +17,6 @@ package org.eclipse.etrice.core.ui.highlight;
import org.eclipse.etrice.core.common.ui.highlight.BaseHighlightingConfig;
import org.eclipse.etrice.expressions.ui.highlight.AbstractHighlightStyles;
import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
import org.eclipse.xtext.ui.editor.utils.TextStyle;
@@ -29,7 +27,6 @@ import org.eclipse.xtext.ui.editor.utils.TextStyle;
public class RoomHighlightingConfiguration extends BaseHighlightingConfig {
// provide an id string for the highlighting calculator
- public static final String HL_ANNOTATION_ID = "hl_annotation";
public static final String HL_EXPR_SPECIAL_FEATURE_ID = "hl_expr_specialfeature";
public static final String HL_EXPR_OPERATION_ID = "hl_expr_operation";
public static final String HL_EXPR_ATTRIBUTE_ID = "hl_expr_attribute";
@@ -48,7 +45,6 @@ public class RoomHighlightingConfiguration extends BaseHighlightingConfig {
// that will appear in the preference page and the initial text style
public void configure(IHighlightingConfigurationAcceptor acceptor) {
super.configure(acceptor);
- acceptor.acceptDefaultHighlighting(HL_ANNOTATION_ID, "Annotation", typeAnnotationBlock());
acceptor.acceptDefaultHighlighting(HL_EXPR_SPECIAL_FEATURE_ID, "Expression Special Feature", expressionSpecialFeature());
acceptor.acceptDefaultHighlighting(HL_EXPR_OPERATION_ID, "Expression Operation", expressionOperation());
acceptor.acceptDefaultHighlighting(HL_EXPR_ATTRIBUTE_ID, "Expression Attribute", expressionAttribute());
@@ -59,16 +55,6 @@ public class RoomHighlightingConfiguration extends BaseHighlightingConfig {
acceptor.acceptDefaultHighlighting(HL_EXTERNAL_TYPE_ID, "Expression External Type", externalType());
acceptor.acceptDefaultHighlighting(HL_DEPRECATED_ID, "Deprecated", deprecated());
}
-
- // method for calculating an actual text styles
- public TextStyle typeAnnotationBlock() {
- TextStyle textStyle = new TextStyle();
- // textStyle.setBackgroundColor(new RGB(155, 55, 255));
- textStyle.setColor(new RGB(160, 0, 0));
- textStyle.setStyle(SWT.BOLD);
- // textStyle.setFontData(defaultCommentFont);
- return textStyle;
- }
public TextStyle expressionSpecialFeature() {
TextStyle textStyle = new TextStyle();
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomSemanticHighlightingCalculator.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomSemanticHighlightingCalculator.java
index b3a885c4d..26616d7cd 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomSemanticHighlightingCalculator.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomSemanticHighlightingCalculator.java
@@ -83,20 +83,18 @@ public class RoomSemanticHighlightingCalculator extends BaseSemanticHighlighter
super.provideHighlightingFor(node, resource, acceptor);
- EObject obj = node.getGrammarElement();
- if (obj instanceof RuleCall) {
- RuleCall ruleCall = (RuleCall) obj;
- if(ruleCall.getRule() == grammar.getAnnotationRule()){
- acceptor.addPosition(node.getOffset(), node.getLength(), HL_ANNOTATION_ID);
- }
- else if(ruleCall.getRule() == grammar.getCC_STRINGRule()) {
+ EObject grammarElement = node.getGrammarElement();
+ if (grammarElement instanceof RuleCall) {
+ RuleCall ruleCall = (RuleCall) grammarElement;
+
+ if(ruleCall.getRule() == grammar.getCC_STRINGRule()) {
detailCodeHighlight(node, acceptor, expressionCache);
}
else if(ruleCall.getRule() == grammar.getIDRule() || ruleCall.getRule() == grammar.getFQNRule()) {
highlightDeprecated(node, acceptor);
}
}
- else if(obj instanceof CrossReference) {
+ else if(grammarElement instanceof CrossReference) {
highlightDeprecated(node, acceptor);
}
}

Back to the top