Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend')
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend91
1 files changed, 91 insertions, 0 deletions
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
new file mode 100644
index 000000000..f20a4621d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/highlight/HighlightingAstVisitor.xtend
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 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) {
+ }
+}

Back to the top