Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2018-10-12 04:12:07 -0400
committerHenrik Rentz-Reichert2018-10-12 04:12:07 -0400
commitd6b0c775dc01c38c119c6ec70c40b3ebea1bb499 (patch)
tree0dd34cff97a4471415aab114414efda94a97444f
parentc44e6a3effc01dd7552a0576375511c9ed511a40 (diff)
downloadorg.eclipse.etrice-d6b0c775dc01c38c119c6ec70c40b3ebea1bb499.tar.gz
org.eclipse.etrice-d6b0c775dc01c38c119c6ec70c40b3ebea1bb499.tar.xz
org.eclipse.etrice-d6b0c775dc01c38c119c6ec70c40b3ebea1bb499.zip
removed usage of DCTools again
rolled back to previous implementation Change-Id: I218c8ad4adaec940ca0e2340cef5074a07b7dae6
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend93
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/RoomSemanticHighlightingCalculator.java71
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomHoverProvider.xtend17
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/linking/RoomHyperlinkHelper.java24
5 files changed, 62 insertions, 146 deletions
diff --git a/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF
index 39a59ca6b..d593980bb 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF
@@ -24,8 +24,7 @@ Require-Bundle: org.eclipse.etrice.core.fsm.ui;bundle-version="2.0.0",
org.eclipse.help,
com.google.inject,
org.eclipse.etrice.expressions.ui,
- org.eclipse.etrice.ui.behavior.fsm;bundle-version="2.0.0",
- org.eclipse.etrice.dctools;bundle-version="2.0.0"
+ org.eclipse.etrice.ui.behavior.fsm;bundle-version="2.0.0"
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.etrice.core.ui,
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend
deleted file mode 100644
index eab74cce6..000000000
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core.ui.highlight
-
-import org.eclipse.etrice.core.room.Attribute
-import org.eclipse.etrice.core.room.InterfaceItem
-import org.eclipse.etrice.core.room.MessageData
-import org.eclipse.etrice.core.room.Operation
-import org.eclipse.etrice.core.room.VarDecl
-import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstIdentifierNode
-import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstNode
-import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstOtherNode
-import org.eclipse.etrice.dctools.fsm.ast.util.IDCAstNodeVisitor
-import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor
-import org.eclipse.xtext.nodemodel.INode
-import org.eclipse.etrice.dctools.ast.DCUtil
-import org.eclipse.etrice.dctools.fsm.ast.nodes.DCAstOperationCallNode
-import org.eclipse.etrice.core.room.Message
-
-class HighlightingAstVisitor implements IDCAstNodeVisitor {
-
- IHighlightedPositionAcceptor acceptor
- int baseOffset
-
- static def highlight(INode node, IHighlightedPositionAcceptor acceptor, DCUtil util) {
- val ast = util.parseAndLink(node)
- val offset = util.getDelimiterAdjustedOffset(node)
- val visitor = new HighlightingAstVisitor(acceptor, offset)
- ast.visit(visitor)
- }
-
- private new(IHighlightedPositionAcceptor acceptor, int baseOffset) {
- this.acceptor = acceptor
- this.baseOffset = baseOffset
- }
-
- override boolean visitBegin(DCAstNode node) {
- var int begin
- var int length
- val highlightId = switch node {
- DCAstOtherNode: {
- begin = node.token.begin
- length = node.token.length
- switch node.token.token.kind {
- case COMMENT: RoomHighlightingConfiguration.COMMENT_ID
- case STRING: RoomHighlightingConfiguration.STRING_ID
- case NUMBER: RoomHighlightingConfiguration.NUMBER_ID
- case KEYWORD: RoomHighlightingConfiguration.KEYWORD_ID
- default: null
- }
- }
- DCAstIdentifierNode: {
- begin = node.token.begin
- length = node.token.length
- switch DCUtil.getLinkedObject(node) {
- Attribute,
- MessageData,
- VarDecl: RoomHighlightingConfiguration.HL_EXPR_ATTRIBUTE_ID
- InterfaceItem: RoomHighlightingConfiguration.HL_EXPR_INTERFACE_ITEM_ID
- Operation: RoomHighlightingConfiguration.HL_EXPR_OPERATION_ID
- default: null
- }
- }
- DCAstOperationCallNode: {
- begin = node.idNode.token.begin
- length = node.idNode.token.length
- switch node.linkedObject {
- Message: RoomHighlightingConfiguration.HL_EXPR_OPERATION_ID
- default: null
- }
- }
- }
- if (highlightId !== null) {
- acceptor.addPosition(baseOffset + begin, length, highlightId)
- }
- return true
- }
-
- override void visitEnd(DCAstNode node) {
- }
-}
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 c238b7547..1b7fd2f88 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
@@ -17,18 +17,25 @@ package org.eclipse.etrice.core.ui.highlight;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.common.ui.highlight.BaseSemanticHighlighter;
import org.eclipse.etrice.core.converter.RoomValueConverterService;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.services.RoomGrammarAccess;
-import org.eclipse.etrice.dctools.ast.DCUtil;
-import org.eclipse.etrice.dctools.fsm.ast.DCLanguage;
-import org.eclipse.etrice.ui.behavior.fsm.Activator;
-import org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences.PreferenceConstants;
-import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.etrice.core.ui.util.UIExpressionUtil;
+import org.eclipse.etrice.core.ui.util.UIExpressionUtil.ExpressionCache;
+import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider;
+import org.eclipse.etrice.expressions.ui.highlight.ExpressionRuleFactory;
+import org.eclipse.etrice.expressions.ui.highlight.TargetLanguageRuleFactory;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.Token;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.util.CancelIndicator;
+import com.google.common.collect.Iterables;
import com.google.inject.Inject;
/**
@@ -36,24 +43,19 @@ import com.google.inject.Inject;
*
*/
public class RoomSemanticHighlightingCalculator extends BaseSemanticHighlighter {
+
+ @Inject
+ RoomGrammarAccess grammar;
- @Inject RoomGrammarAccess grammar;
- @Inject RoomValueConverterService converterService;
- @Inject DCUtil detailCodeUtil;
- DCLanguage language = null;
-
- public RoomSemanticHighlightingCalculator() {
- }
+ @Inject
+ RoomValueConverterService converterService;
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
if (resource == null || resource.getParseResult() == null)
return;
-
- if (language==null) {
- setLanguage();
- }
+ ExpressionCache expressionCache = new ExpressionCache();
INode root = resource.getParseResult().getRootNode();
for (INode node : root.getAsTreeIterable()) {
if(cancelIndicator.isCanceled())
@@ -68,22 +70,39 @@ public class RoomSemanticHighlightingCalculator extends BaseSemanticHighlighter
acceptor.addPosition(node.getOffset(), node.getLength(), RoomHighlightingConfiguration.HL_ANNOTATION_ID);
}
else if(ruleCall.getRule() == grammar.getCC_STRINGRule()) {
- HighlightingAstVisitor.highlight(node, acceptor, detailCodeUtil);
+ detailCodeHighlight(node, acceptor, expressionCache);
}
}
}
}
-
- private void setLanguage() {
- IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
- String lang = preferenceStore.getString(PreferenceConstants.EDITOR_LANGUAGE);
- if (lang.equals(PreferenceConstants.JAVA_LANGUAGE)) {
- language = DCLanguage.JAVA_LANGUAGE;
+
+ protected void detailCodeHighlight(INode node, IHighlightedPositionAcceptor acceptor, ExpressionCache cache) {
+ final String text = converterService.getCC_StringConverter().stripDelim(node.getText());
+ final int offset = node.getOffset() + converterService.getCC_StringConverter().getDelim().length();
+
+ DetailCode dc = null;
+ if(node.getParent().getSemanticElement() instanceof DetailCode) {
+ dc = (DetailCode) node.getParent().getSemanticElement();
}
- else {
- language = DCLanguage.CPP_LANGUAGE;
+ IDetailExpressionProvider exprProvider = UIExpressionUtil.getExpressionProvider(dc, null, cache);
+ XtextHighlightStyles styles = new XtextHighlightStyles();
+ RuleBasedScanner scanner = new RuleBasedScanner();
+ scanner.setRules(Iterables.toArray(Iterables.concat(
+ TargetLanguageRuleFactory.getGeneralLiteralRules(styles),
+ ExpressionRuleFactory.getInitialExpressionRules(exprProvider, styles),
+ TargetLanguageRuleFactory.getGeneralKeywordRules(styles))
+ , IRule.class));
+ scanner.setRange(new Document(text), 0, text.length());
+
+ IToken lastToken = null;
+ while(lastToken != Token.EOF) {
+ lastToken = scanner.nextToken();
+ if(lastToken != null && lastToken.getData() != null) {
+ acceptor.addPosition(offset + scanner.getTokenOffset(), scanner.getTokenLength(), (String) lastToken.getData());
+ }
}
- detailCodeUtil.setLanguage(language);
+
}
+
}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomHoverProvider.xtend b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomHoverProvider.xtend
index 69c5d5fcd..428b519fc 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomHoverProvider.xtend
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/hover/RoomHoverProvider.xtend
@@ -15,10 +15,11 @@
package org.eclipse.etrice.core.ui.hover
import com.google.inject.Inject
+import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.common.ui.hover.KeywordEObjectTextHover
import org.eclipse.etrice.core.fsm.fSM.DetailCode
import org.eclipse.etrice.core.services.RoomGrammarAccess
-import org.eclipse.etrice.dctools.ast.DCUtil
+import org.eclipse.etrice.core.ui.util.UIExpressionUtil
import org.eclipse.jface.text.Region
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
@@ -27,8 +28,8 @@ import org.eclipse.xtext.util.Tuples
class RoomHoverProvider extends KeywordEObjectTextHover {
- @Inject RoomGrammarAccess grammar
- @Inject DCUtil util
+ @Inject
+ RoomGrammarAccess grammar
override protected getXtextElementAt(XtextResource resource, int offset) {
// lookup expression
@@ -37,13 +38,9 @@ class RoomHoverProvider extends KeywordEObjectTextHover {
val leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.rootNode, offset)
if(leafNode?.grammarElement instanceof RuleCall) {
if((leafNode.grammarElement as RuleCall).rule == grammar.CC_STRINGRule && leafNode.semanticElement instanceof DetailCode){
-// println("RoomHoverProvider at offset " + offset + " " + leafNode.offset + " " + leafNode.text.substring(offset - leafNode.offset))
- val result = util.findAtOffset(leafNode, offset)
- if (result!==null) {
-// val begin = result.begin
-// println("RoomHoverProvider hit " + (leafNode.offset + result.begin) +" " + result.length + " " + leafNode.text.substring(begin, begin + result.length))
- return Tuples.create(result.object, new Region(leafNode.offset + result.begin, result.length))
- }
+ val exprFeature = UIExpressionUtil.findAtOffset(leafNode, offset)
+ if(exprFeature?.data instanceof EObject)
+ return Tuples.create(exprFeature.data as EObject, new Region(offset, exprFeature.id.length))
}
}
}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/linking/RoomHyperlinkHelper.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/linking/RoomHyperlinkHelper.java
index fde66a3c8..3639f06fe 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/linking/RoomHyperlinkHelper.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/linking/RoomHyperlinkHelper.java
@@ -23,8 +23,8 @@ import org.eclipse.etrice.core.room.ActorRef;
import org.eclipse.etrice.core.room.RefSegment;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.services.RoomGrammarAccess;
-import org.eclipse.etrice.dctools.ast.DCUtil;
-import org.eclipse.etrice.dctools.ast.DCUtil.FindResult;
+import org.eclipse.etrice.core.ui.util.UIExpressionUtil;
+import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider.ExpressionFeature;
import org.eclipse.jface.text.Region;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.RuleCall;
@@ -44,7 +44,6 @@ public class RoomHyperlinkHelper extends ImportAwareHyperlinkHelper {
@Inject private RoomGrammarAccess grammar;
@Inject private RoomHelpers roomHelpers;
- @Inject private DCUtil util;
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
@@ -70,16 +69,12 @@ public class RoomHyperlinkHelper extends ImportAwareHyperlinkHelper {
}
}
- if (leaf.getGrammarElement() instanceof RuleCall) {
- if (((RuleCall) leaf.getGrammarElement()).getRule() == grammar.getCC_STRINGRule()
- && leaf.getSemanticElement() instanceof DetailCode) {
- // System.out.println("RoomHyperlinkHelper at offset " + offset + " " + leaf.getOffset() + " " + leaf.getText().substring(offset - leaf.getOffset()));
- FindResult result = util.findAtOffset(leaf, offset);
- if (result != null) {
- // int begin = result.getBegin();
- // System.out.println("RoomHyperlinkHelper hit " + (leaf.getOffset() + result.getBegin()) +" " + result.getLength() + " " + leaf.getText().substring(begin, begin + result.getLength()));
- Region region = new Region(leaf.getOffset() + result.getBegin(), result.getLength());
- createHyperlinksTo(resource, region, result.getObject(), acceptor);
+ if(leaf.getGrammarElement() instanceof RuleCall) {
+ if(((RuleCall) leaf.getGrammarElement()).getRule() == grammar.getCC_STRINGRule() && leaf.getSemanticElement() instanceof DetailCode) {
+ ExpressionFeature exprFeature = UIExpressionUtil.findAtOffset(leaf, offset);
+ if(exprFeature != null && exprFeature.getData() instanceof EObject) {
+ Region region = new Region(leaf.getOffset(), leaf.getLength());
+ createHyperlinksTo(resource, region, (EObject) exprFeature.getData(), acceptor);
}
}
}
@@ -92,13 +87,12 @@ public class RoomHyperlinkHelper extends ImportAwareHyperlinkHelper {
ActorContainerClass lastAcContainer = roomHelpers.getParentContainer(aim);
ActorRef lastRef = null;
for (RefSegment ref : aim.getPath().getRefs()) {
- for (ActorRef r : lastAcContainer.getActorRefs()) {
+ for (ActorRef r : lastAcContainer.getActorRefs())
if (r.getName().equals(ref.getRef())) {
lastRef = r;
lastAcContainer = lastRef.getType();
break;
}
- }
}
return lastRef;

Back to the top