Skip to main content
summaryrefslogtreecommitdiffstats
blob: b34207b2a5e04a4a7c16233ecd8686446842e5d9 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
 *                                                                            
 * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
 *                                                                            
 * 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:   
 * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation 
 * 
 * 
 *  This copyright notice shows up in the generated Java code
 *
 */
 
 package org.eclipse.osbp.utils.annotation

import java.util.ArrayList
import javax.inject.Inject
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.common.types.JvmAnnotationReference
import org.eclipse.xtext.common.types.JvmDeclaredType
import org.eclipse.xtext.common.types.JvmEnumerationLiteral
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.common.types.JvmStringAnnotationValue
import org.eclipse.xtext.common.types.JvmTypeReference
import org.eclipse.xtext.common.types.TypesFactory
import org.eclipse.xtext.common.types.util.TypeReferences
import java.util.List
import org.eclipse.xtext.common.types.JvmGenericType

class CommonUtils {
		@Inject
		private TypesFactory typesFactory
	
		def void addStringValuesToAnnotation(JvmAnnotationReference annotationRef, ArrayList<String> annotationStringList){
			var JvmStringAnnotationValue value = typesFactory.createJvmStringAnnotationValue
			for (annotationString : annotationStringList){
				value.values += annotationString
			}
	//		annotationRef.values += value
			annotationRef.explicitValues += value
		}

	/**
     * Creates a string annotation value and adds it to the given annotation reference
     */
	def dispatch addAnnAttr(JvmAnnotationReference annRef, EObject context, String name, String stringValue) {
		val String[] stringValues = #[stringValue]
		return addAnnAttrArr(annRef, context, name, stringValues)
	}

		
	/**
     * Creates a string annotation value and adds it to the given annotation reference
     */
	def addAnnAttrArr(JvmAnnotationReference annRef, EObject context, String name, String[] stringValues) {

		// create the parameter
		val value = typesFactory.createJvmStringAnnotationValue
		annRef.explicitValues += value

		// create the operation
		val JvmOperation op = typesFactory.createJvmOperation
		op.setSimpleName(name)
		value.setOperation(op)
		for (stringValue: stringValues){
			value.values += stringValue
		}

		return value
	}


	/**
     * Creates a boolean annotation value and adds it to the given annotation reference
     */
	def dispatch addAnnAttr(JvmAnnotationReference annRef, EObject context, String name, boolean booleanValue) {
		// create the parameter
		val value = typesFactory.createJvmBooleanAnnotationValue
		annRef.explicitValues += value

		// create the operation
		val JvmOperation op = typesFactory.createJvmOperation
		op.setSimpleName(name)
		value.setOperation(op)
		value.values += booleanValue
		return value
	}


	/**
     * Creates a string annotation value and adds it to the given annotation reference
     */
	def dispatch addAnnAttr(JvmAnnotationReference annRef, EObject context, String name, JvmTypeReference typeValue) {
		// create the parameter
		val value = typesFactory.createJvmTypeAnnotationValue
		annRef.explicitValues += value

		// create the operation
		val JvmOperation op = typesFactory.createJvmOperation
		op.setSimpleName(name)
		value.setOperation(op)
		value.values += typeValue
		return value
	}

	/**
	 * Creates an enum annotation value and adds it to the given annotation reference
	 */
	def dispatch addAnnAttr(JvmAnnotationReference annRef, EObject context/*, TypeReferences references */, String name, Enum<?>... enums) {

		// create the parameter
		val value = typesFactory.createJvmEnumAnnotationValue
		annRef.explicitValues += value

		// create the enum type
//		val declaredType = references.findDeclaredType(enums.get(0).declaringClass, context) as JvmDeclaredType
		for (Enum<?> enumxx : enums) {

			// create the operation
			val JvmOperation op = typesFactory.createJvmOperation
			op.setSimpleName(name)
//			op.setDeclaringType(declaredType)
			value.setOperation(op)

			// create the literal
			val JvmEnumerationLiteral literal = typesFactory.createJvmEnumerationLiteral
//			literal.setDeclaringType(declaredType)
			literal.setSimpleName(enumxx.name)
			value.values += literal
		}

		return value
	}
		
}

Back to the top