Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 10708c01ed5e6592cede389c16897331cb95f3e6 (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
/*******************************************************************************
 * 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:
 * 		Juergen Haug (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.core.common.formatting2

import com.google.inject.Inject
import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.common.base.Annotation
import org.eclipse.etrice.core.common.base.AnnotationType
import org.eclipse.etrice.core.common.base.Documentation
import org.eclipse.etrice.core.common.base.Import
import org.eclipse.etrice.core.common.services.BaseGrammarAccess
import org.eclipse.xtext.formatting2.AbstractFormatter2
import org.eclipse.xtext.formatting2.IFormattableDocument

class BaseFormatter extends AbstractFormatter2 {
	
	@Inject extension BaseGrammarAccess
	
	/**
	 *  recursive keyword formatting
	 */
	protected def void formatAllByKeywords(EObject it, extension IFormattableDocument document) {		
		allRegionsFor.keywordPairs('{', '}').forEach[
			key.prepend[oneSpace]
			interior[indent]
			value.prepend[newLine]
		]
		allRegionsFor.keywordPairs('(', ')').forEach[interior[noSpace]]
		allRegionsFor.keyword('(').prepend[noSpace lowPriority]
		
		allRegionsFor.keywords(',').forEach[append[oneSpace]]
		allRegionsFor.keywords('.').forEach[surround[noSpace]]
		
		allRegionsFor.keywords(':').forEach[prepend[noSpace] append[oneSpace]]
		
		// TIME
		allRegionsFor.keywords(getTIMEAccess.getSKeyword_0_1, getTIMEAccess.msKeyword_1_1, getTIMEAccess.usKeyword_2_1, getTIMEAccess.nsKeyword_3_1).forEach[
			if(previousHiddenRegion.length > 1) prepend[oneSpace] else prepend[noSpace]
			append[oneSpace lowPriority]
		]
	}
	
	def dispatch void format(Documentation it, extension IFormattableDocument document) {
		// TODO
	}
	
	def dispatch void format(Import it, extension IFormattableDocument document) {
		regionFor.keywords(importAccess.importKeyword_0, importAccess.modelKeyword_1_1).forEach[append[oneSpace]]
		regionFor.keyword(importAccess.fromKeyword_1_0_1).surround[oneSpace]
	}
	
	def dispatch void format(AnnotationType it, extension IFormattableDocument document) {
		regionFor.keyword(annotationTypeAccess.annotationTypeKeyword_0).append[oneSpace]
		regionFor.keyword(annotationTypeAccess.targetKeyword_4).prepend[newLine]
		attributes.forEach[prepend[newLine]]
	}
	
	def dispatch void format(Annotation it, extension IFormattableDocument document) {
		regionFor.keyword(annotationAccess.commercialAtKeyword_0).append[noSpace]
		attributes.forEach[prepend[newLine]]
	}
	
}
		

Back to the top