blob: 0a33cde85b250a782aa3756a6492093ddd8db02d [file] [log] [blame]
/**
*
* 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 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:
* 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
}
}