blob: eab74cce6df22c90e39228e1878c79ca03efd3b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*******************************************************************************
* 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) {
}
}
|