Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8f28887cd0522e96d3d9b08b406fc5680d7d8eba (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
94
95
96
97
98
/*******************************************************************************
 * 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.dctools.ast.internal

import com.google.inject.Singleton
import com.google.inject.Inject
import org.eclipse.jface.viewers.ILabelProvider
import org.eclipse.etrice.core.room.util.RoomHelpers
import org.eclipse.emf.ecore.EObject
import org.eclipse.jface.viewers.StyledString
import org.eclipse.swt.graphics.Image
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal
import org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher
import org.eclipse.jface.text.contentassist.ICompletionProposal
import org.eclipse.swt.graphics.Point
import org.eclipse.etrice.core.room.Operation
import org.eclipse.etrice.core.room.Message
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.Port

@Singleton
class DCProposalConfig {

	@Inject
	protected ILabelProvider labelProvider

	@Inject
	protected RoomHelpers roomHelpers
	
	@Inject
	protected PrefixMatcher prefixMatcher
	
	def ICompletionProposal doCreateProposal(String prefix, String proposal, EObject object, int globalOffset) {
		new ConfigurableCompletionProposal(proposal, globalOffset - prefix.length, prefix.length, proposal.length, object.image, object.displayString, null, null) => [
			matcher = prefixMatcher
			autoInsertable = false
			// TODO adjust length to existing text
			replaceContextLength = proposal.length
		]
	}

	def Pair<String, Point> getPostfixReplacement(EObject object) {
		val brackets = switch object {
			Operation,
			Message:
				#['(', ')']
			
			Attribute case object.size>0,
			Port case object.multiplicity>0:
				#['[', ']']
		}
		
		if (brackets===null) {
			return "" -> null
		}
		
		val replacement = switch object {
			Operation:
				object.arguments.map[name].join(', ')
			
			Message case object.data !== null:
				object.data.refType.type.name
			
			Attribute, // fall through
			InterfaceItem:
				'0'
			
			default:
				''
		}

		replacement.wrap(brackets.head, brackets.last)
	}
	
	private def Pair<String, Point> wrap(String text, String left, String right) {
		val selection = if (!text.empty) new Point(1, text.length)
		left + text + right -> selection
	}
	
	private def StyledString getDisplayString(EObject object) {
		
	}	

	private def Image getImage(EObject object) {
		
	}	
}

Back to the top