| [comment encoding = UTF-8 /] |
| [module generateOclCommon('http://www.eclipse.org/ocl/3.1.0/Pivot','http://www.eclipse.org/emf/2002/Ecore')/] |
| |
| [query public getMoniker(elem : Element) : String = |
| invoke('org.eclipse.ocl.examples.build.acceleo.NameQueries', 'getMoniker(org.eclipse.ocl.examples.pivot.Element)', Sequence{elem}) /] |
| |
| [query public getRootPackage(elem : Package) : Package = |
| if elem.nestingPackage->notEmpty() then elem.nestingPackage.getRootPackage() else elem endif/] |
| |
| [query public getSignature(elem : NamedElement) : String = |
| let parent : EObject = elem.eContainer() in |
| if not parent.oclIsUndefined() then parent.oclAsType(NamedElement).getSignature() + '::' + elem.name |
| else elem.name endif/] |
| |
| [query public getSignature(elem : Operation) : String = |
| let parent : EObject = elem.eContainer() in |
| if not parent.oclIsUndefined() then parent.oclAsType(NamedElement).getSignature() + '::' + elem.name |
| else elem.name endif + '()'/] |
| |
| [query public getPrefixedSymbolName(elem : EObject, prefix : String) : String = |
| invoke('org.eclipse.ocl.examples.build.acceleo.NameQueries', 'getPrefixedSymbolName(java.lang.String, java.lang.Object)', Sequence{prefix, elem}) /] |
| |
| [query public getSymbolName(elem : EObject) : String = |
| invoke('org.eclipse.ocl.examples.build.acceleo.NameQueries', 'getSymbolName(java.lang.Object)', Sequence{elem}) /] |
| |
| [query public isEcoreConstraint(operation : Operation) : Boolean = |
| operation.ownedParameter->select(p : Parameter |
| | (p.name = 'diagnostics') and (p.type.name = 'EDiagnosticChain'))->notEmpty() |
| /] |
| |
| [template public defineConstants(pkg : Package)] |
| [let allComments : OrderedSet(Comment) = pkg.eAllContents(Comment)->asSet()->sortedBy(_body)] |
| [for (pComment : Comment | allComments)] |
| private static Comment [pComment.getPrefixedSymbolName('co_'+pComment.partialName())/] = createComment("[pComment.javaString()/]"); |
| [/for] |
| [/let] |
| |
| [let allPrecedences : OrderedSet(Precedence) = pkg.eAllContents(Precedence)->asSet()->sortedBy(getMoniker())] |
| [for (precedence : Precedence | allPrecedences)] |
| private static Precedence [precedence.getPrefixedSymbolName('prec_'+precedence.partialName())/] = createPrecedence("[precedence.name/]", AssociativityKind.[precedence.associativity.toString().toUpper()/]); |
| [/for] |
| [/let] |
| |
| [let allEnumerationLiterals : OrderedSet(EnumerationLiteral) = pkg.eAllContents(EnumerationLiteral)->asSet()->sortedBy(getMoniker())] |
| [for (enumerationLiteral : EnumerationLiteral | allEnumerationLiterals)] |
| private static EnumerationLiteral [enumerationLiteral.getPrefixedSymbolName('el_'+enumerationLiteral.partialName())/] = createEnumerationLiteral("[enumerationLiteral.name/]"); |
| [/for] |
| [/let] |
| |
| [let allTypes : OrderedSet(Type) = pkg.eAllContents(Type)->asSet()->sortedBy(getMoniker())] |
| [for (type : Type | allTypes)] |
| private static [type.eClass().name/] [type.getPrefixedSymbolName('t_'+type.partialName())/] = create[type.eClass().name/]("[type.name/]"); |
| [/for] |
| [/let] |
| |
| [let allParameters : OrderedSet(Parameter) = pkg.eAllContents(Parameter)->asSet()->sortedBy(getMoniker())] |
| [for (parameter : Parameter | allParameters)] |
| private static Parameter [parameter.getPrefixedSymbolName('pa_'+partialName())/] = createParameter("[parameter.name/]", [parameter.type.getSymbolName()/]); |
| [/for] |
| [/let] |
| |
| [let allIterations : OrderedSet(Iteration) = pkg.eAllContents(Iteration)->asSet()->sortedBy(getMoniker())] |
| [for (iteration : Iteration | allIterations)] |
| private static Iteration [iteration.getPrefixedSymbolName('it_'+iteration.partialName())/] = createIteration("[iteration.name/]", [iteration.type.getSymbolName()/], [if (iteration.implementationClass->notEmpty())]"[iteration.implementationClass/]", [iteration.implementationClass/].INSTANCE[else]null, null[/if], [iteration.ownedParameter->first().getSymbolName()/][for (iterator : Parameter | iteration.ownedIterator)], [iterator.getSymbolName()/][/for]); |
| [/for] |
| [/let] |
| |
| [let allOperations : OrderedSet(Operation) = pkg.eAllContents(Operation)->asSet()->sortedBy(getMoniker())] |
| [for (operation : Operation | allOperations->reject(oclIsKindOf(Iteration))->select(not isEcoreConstraint()))] |
| private static Operation [operation.getPrefixedSymbolName('op_'+operation.partialName())/] = createOperation("[operation.name/]", [operation.type.getSymbolName()/], [if (operation.implementationClass->notEmpty())]"[operation.implementationClass/]", [operation.implementationClass/].INSTANCE[else]null, null[/if][for (parameter : Parameter | operation.ownedParameter)], [parameter.getSymbolName()/][/for]); |
| [/for] |
| [/let] |
| |
| [let allProperties : OrderedSet(Property) = pkg.eAllContents(Property)->asSet()->sortedBy(getMoniker())] |
| [for (property : Property | allProperties)] |
| private static Property [property.getPrefixedSymbolName('pr_'+property.partialName())/] = createProperty("[property.name/]", [property.type.getSymbolName()/], [if (property.implementationClass->notEmpty())]"[property.implementationClass/]", [property.implementationClass/].INSTANCE[else]null, null[/if]); |
| [/for] |
| [/let] |
| |
| [let allTemplateParameters : OrderedSet(TemplateParameter) = pkg.eAllContents(TemplateParameter)->asSet()->sortedBy(getMoniker())] |
| [for (templateParameter : TemplateParameter | allTemplateParameters)] |
| private static TypeTemplateParameter [templateParameter.getPrefixedSymbolName('tp_'+templateParameter.partialName())/] = createTypeTemplateParameter([templateParameter.ownedParameteredElement.getSymbolName()/]); |
| [/for] |
| [/let] |
| |
| [let allTemplateSignatures : OrderedSet(TemplateSignature) = pkg.eAllContents(TemplateSignature)->asSet()->sortedBy(getMoniker())] |
| [for (templateSignature : TemplateSignature | allTemplateSignatures)] |
| private static TemplateSignature [templateSignature.getPrefixedSymbolName('ts_'+templateSignature.partialName())/] = createTemplateSignature([templateSignature.template.getSymbolName()/][for (templateParameter : TemplateParameter | templateSignature.ownedParameter)], [templateParameter.getSymbolName()/][/for]); |
| [/for] |
| [/let] |
| |
| [let allPackages : OrderedSet(Package) = pkg.eAllContents(Package)->asSet()->sortedBy(getMoniker())] |
| [for (pkg : Package | allPackages)] |
| private static [pkg.eClass().name/] [pkg.getPrefixedSymbolName('pk_'+pkg.partialName())/] = create[pkg.eClass().name/]("[pkg.name/]", [if pkg.nsPrefix <> null]"[pkg.nsPrefix/]"[else]null[/if], [if pkg.nsURI <> null]"[pkg.nsURI/]"[else]null[/if]); |
| [/for] |
| [/let] |
| |
| [let allTemplateParameterSubstitutions : OrderedSet(TemplateParameterSubstitution) = pkg.eAllContents(TemplateParameterSubstitution)->asSet()->sortedBy(getMoniker())] |
| [for (templateParameterSubstitution : TemplateParameterSubstitution | allTemplateParameterSubstitutions)] |
| private static TemplateParameterSubstitution [templateParameterSubstitution.getPrefixedSymbolName('tps_'+templateParameterSubstitution.partialName())/] = createTemplateParameterSubstitution([templateParameterSubstitution.formal.getSymbolName()/], [templateParameterSubstitution.actual.getSymbolName()/]); |
| [/for] |
| [/let] |
| |
| [let allTemplateBindings : OrderedSet(TemplateBinding) = pkg.eAllContents(TemplateBinding)->asSet()->sortedBy(getMoniker())] |
| [for (templateBinding : TemplateBinding | allTemplateBindings)] |
| private static TemplateBinding [templateBinding.getPrefixedSymbolName('tb_'+templateBinding.partialName())/] = createTemplateBinding([templateBinding.signature.getSymbolName()/][for (templateParameterSubstitution : TemplateParameterSubstitution | templateBinding.parameterSubstitution)], [templateParameterSubstitution.getSymbolName()/][/for]); |
| [/for] |
| [/let] |
| [/template] |
| |
| [template public emitAccumulator(parameter : Parameter)] |
| [if (parameter.ownedComment->notEmpty())] |
| [parameter.emitComments()/] |
| [/if][parameter.eContainer().getSymbolName()/].getOwnedAccumulators().add([parameter.getSymbolName()/]);[/template] |
| |
| [template public emitComments(namedElement : NamedElement)] |
| [for (pComment : Comment | namedElement.ownedComment)] |
| [namedElement.getSymbolName()/].getOwnedComments().add([pComment.getSymbolName()/]);[/for][/template] |
| |
| [template public emitIterator(parameter : Parameter)] |
| [if (parameter.ownedComment->notEmpty())] |
| [parameter.emitComments()/] |
| [/if][/template] |
| |
| [template public emitMultiplicityElement(multiplicityElement : TypedMultiplicityElement)] |
| [if (multiplicityElement.lower <> 1)] |
| [multiplicityElement.getSymbolName()/].setLower(BigInteger.valueOf([multiplicityElement.lower/])); |
| [/if][if (multiplicityElement.upper <> 1)] |
| [multiplicityElement.getSymbolName()/].setUpper(BigInteger.valueOf([multiplicityElement.upper/])); |
| [/if][if (multiplicityElement.isOrdered)] |
| [multiplicityElement.getSymbolName()/].setIsOrdered(true); |
| [/if][if (not multiplicityElement.isUnique)] |
| [multiplicityElement.getSymbolName()/].setIsUnique(false); |
| [/if][/template] |
| |
| [template public emitOperation(iteration : Iteration)] |
| [emitMultiplicityElement(iteration)/][for (parameter : Parameter | iteration.ownedIterator)] |
| [emitIterator(parameter)/][/for][for (parameter : Parameter | iteration.ownedAccumulator)] |
| [emitAccumulator(parameter)/][/for][for (parameter : Parameter | iteration.ownedParameter)] |
| [emitParameter(parameter)/][/for][if (iteration.precedence->notEmpty())] |
| [iteration.getSymbolName()/].setPrecedence([iteration.precedence.getSymbolName()/]); |
| [/if][if (iteration.ownedComment->notEmpty())] |
| [iteration.emitComments()/] |
| [/if][iteration.eContainer().getSymbolName()/].getOwnedOperations().add([iteration.getSymbolName()/]); |
| [/template] |
| |
| [template public emitOperation(operation : Operation)] |
| [emitMultiplicityElement(operation)/][if (operation.isStatic)] |
| [operation.getSymbolName()/].setIsStatic(true); |
| [/if][if (operation.precedence->notEmpty())] |
| [operation.getSymbolName()/].setPrecedence([operation.precedence.getSymbolName()/]); |
| [/if][if (operation.ownedComment->notEmpty())] |
| [operation.emitComments()/] |
| [/if][operation.eContainer().getSymbolName()/].getOwnedOperations().add([operation.getSymbolName()/]); |
| [/template] |
| |
| [template public emitPackage(pkg : Package)] |
| // |
| // [pkg.getSignature()/] |
| // |
| [for (ownedType : Type | pkg.ownedType->sortedBy(getMoniker()))] |
| [emitType(ownedType)/] |
| [/for] |
| [for (nestedPackage : Package | pkg.nestedPackage->sortedBy(name))] |
| [emitPackage(nestedPackage)/] |
| [/for] |
| [if (pkg.ownedComment->notEmpty())] |
| [pkg.emitComments()/] |
| [/if] |
| [pkg.eContainer().getSymbolName()/].getNestedPackages().add([pkg.getSymbolName()/]); |
| [/template] |
| |
| [template public emitParameter(parameter : Parameter)] |
| [emitMultiplicityElement(parameter)/][if (parameter.ownedComment->notEmpty())] |
| [parameter.emitComments()/][/if][/template] |
| |
| [template public emitPrecedence(precedence : Precedence)] |
| [if (precedence.ownedComment->notEmpty())] |
| [precedence.emitComments()/] |
| [/if] |
| ownedPrecedences.add([precedence.getSymbolName()/]); |
| [/template] |
| |
| [template public emitProperty(property : Property)] |
| [emitMultiplicityElement(property)/][if (property.isComposite)] |
| [property.getSymbolName()/].setIsComposite(true); |
| [/if][if (property.isDerived)] |
| [property.getSymbolName()/].setIsDerived(true); |
| [/if][if (property.isID)] |
| [property.getSymbolName()/].setIsID(true); |
| [/if][if (property.implicit)] |
| [property.getSymbolName()/].setImplicit(true); |
| [/if][if (property.isReadOnly)] |
| [property.getSymbolName()/].setIsReadOnly(true); |
| [/if][if (property.isResolveProxies)] |
| [property.getSymbolName()/].setIsResolveProxies(true); |
| [/if][if (property.isStatic)] |
| [property.getSymbolName()/].setIsStatic(true); |
| [/if][if (property.isTransient)] |
| [property.getSymbolName()/].setIsTransient(true); |
| [/if][if (property.isUnsettable)] |
| [property.getSymbolName()/].setIsUnsettable(true); |
| [/if][if (property.isVolatile)] |
| [property.getSymbolName()/].setIsVolatile(true); |
| [/if][if (property.opposite->notEmpty())] |
| [property.getSymbolName()/].setOpposite([property.opposite.getSymbolName()/]); |
| [/if][if (property.ownedComment->notEmpty())] |
| [property.emitComments()/] |
| [/if][property.eContainer().getSymbolName()/].getOwnedAttributes().add([property.getSymbolName()/]); |
| [/template] |
| |
| [template public emitType(type : Type)] |
| [/template] |
| |
| [template public emitType(type : Class)] |
| // |
| // [type.getSignature()/] |
| // |
| [if (type.oclIsKindOf(ClassifierType))] |
| [type.getSymbolName()/].setInstanceType([type.oclAsType(ClassifierType).instanceType.getSymbolName()/]); |
| [/if] |
| [if (type.oclIsKindOf(CollectionType))] |
| [type.getSymbolName()/].setElementType([type.oclAsType(CollectionType).elementType.getSymbolName()/]); |
| [/if] |
| [if (type.oclIsKindOf(LambdaType))] |
| [let lambdaType : LambdaType = type.oclAsType(LambdaType)] |
| [type.getSymbolName()/].setContextType([lambdaType.contextType.getSymbolName()/]); |
| [for (parameterType : Type| lambdaType.parameterType)] |
| [type.getSymbolName()/].getParameterTypes().add([parameterType.getSymbolName()/]); |
| [/for] |
| [type.getSymbolName()/].setResultType([lambdaType.resultType.getSymbolName()/]); |
| [/let][/if] |
| [if (type.unspecializedElement->notEmpty())] |
| [type.getSymbolName()/].setUnspecializedElement([type.unspecializedElement.getSymbolName()/]); |
| [/if] |
| [if (type.templateBinding->notEmpty())] |
| [for (templateBinding : TemplateBinding | type.templateBinding)] |
| [type.getSymbolName()/].getTemplateBindings().add([templateBinding.getSymbolName()/]); |
| [/for] |
| [/if] |
| [let superClasses : OrderedSet(Type) = type.superClass->select(_package.getRootPackage() = type._package.getRootPackage())] |
| [if (superClasses->notEmpty())] |
| [for (superClass : Type | superClasses)] |
| [type.getSymbolName()/].getSuperClasses().add([superClass.getSymbolName()/]); |
| [/for] |
| [elseif (not type.oclIsKindOf(AnyType))] |
| [type.getSymbolName()/].getSuperClasses().add(standardLibrary.getOclElementType()); |
| [/if] |
| [/let] |
| [for (property : Property | type.ownedAttribute->sortedBy(name))] |
| // |
| // [property.getSignature()/] |
| // |
| [emitProperty(property)/] |
| [/for] |
| [for (operation : Operation | type.ownedOperation->sortedBy(name)->select(not isEcoreConstraint()))] |
| // |
| // [operation.getSignature()/] |
| // |
| [emitOperation(operation)/] |
| [/for] |
| [if (type.ownedComment->notEmpty())] |
| [type.emitComments()/] |
| [/if] |
| [type.eContainer().getSymbolName()/].getOwnedTypes().add([type.getSymbolName()/]); |
| [/template] |
| |
| [template public emitType(type : Enumeration)] |
| // |
| // [type.getSignature()/] |
| // |
| [for (superClass : Type | type.superClass)] |
| [if (type._package.getRootPackage() = superClass._package.getRootPackage())] |
| [type.getSymbolName()/].getSuperClasses().add([superClass.getSymbolName()/]);[/if] |
| [/for] |
| { |
| [for (literal : EnumerationLiteral | type.ownedLiteral)] |
| [type.getSymbolName()/].getOwnedLiterals().add([literal.getSymbolName()/]); |
| [/for] |
| } |
| [if (type.ownedComment->notEmpty())] |
| [type.emitComments()/] |
| [/if] |
| [type.eContainer().getSymbolName()/].getOwnedTypes().add([type.getSymbolName()/]); |
| [/template] |
| |
| [template public partialName(element : Comment)] |
| [element._body.substring(1, 12.min(element._body.size())).javaName() /] |
| [/template] |
| |
| [template public partialName(element : LambdaType)] |
| [element.name.javaName() + '_' + element.contextType.partialName()/] |
| [/template] |
| |
| [template public partialName(element : OclAny)] |
| ['xyzzy'+element.eClass().name /] |
| [/template] |
| |
| [template public partialName(element : Operation)] |
| [element.owningType.partialName()+'_'+element.name.javaName() /] |
| [/template] |
| |
| [template public partialName(element : Package)] |
| [element.name.javaName() /] |
| [/template] |
| |
| [template public partialName(element : Parameter)] |
| [element.eContainer().partialName()+'_'+element.name.javaName()/] |
| [/template] |
| |
| [template public partialName(element : Precedence)] |
| [element.name.javaName() /] |
| [/template] |
| |
| [template public partialName(element : Property)] |
| [element.owningType.partialName()+'_'+element.name.javaName() /] |
| [/template] |
| |
| [template public partialName(element : TemplateBinding)] |
| [element.boundElement.partialName() /] |
| [/template] |
| |
| [template public partialName(element : TemplateParameter)] |
| [if element.signature.template <> null] |
| [element.signature.template.partialName()/][else] |
| ['['+element.signature.partialName()+']'/][/if] |
| [/template] |
| |
| [template public partialName(element : TemplateParameterSubstitution)] |
| [element.templateBinding.boundElement.partialName() /] |
| [/template] |
| |
| [template public partialName(element : TemplateSignature)] |
| [element.template.partialName() /] |
| [/template] |
| |
| [template public partialName(element : Type)] |
| [if element.templateParameter <> null] |
| [element.templateParameter.simpleName()+'_'+element.name.javaName()/][elseif element.templateBinding->notEmpty()] |
| [element.templateBinding.parameterSubstitution->iterate(tps; acc : String = element.name.javaName() | acc +'_'+tps.actual.simpleName())/][else] |
| [element.name.javaName()/][/if] |
| [/template] |
| |
| [template public simpleName(element : OclAny)] |
| ['xyzzy'+element.eClass().name /] |
| [/template] |
| |
| [template public simpleName(element : Operation)] |
| [element.owningType.simpleName()+'_'+element.name.javaName() /] |
| [/template] |
| |
| [template public simpleName(element : TemplateParameter)] |
| [if element.signature.template <> null] |
| [element.signature.template.simpleName()/][else] |
| ['['+element.signature.simpleName()+']'/][/if] |
| [/template] |
| |
| [template public simpleName(element : TemplateParameterSubstitution)] |
| [element.templateBinding.boundElement.simpleName() /] |
| [/template] |
| |
| [template public simpleName(element : Type)] |
| [if element.templateParameter <> null] |
| [element.templateParameter.simpleName()+'_'+element.name.javaName()/][else] |
| [element.name.javaName()/][/if] |
| [/template] |
| |
| [query public javaName(string : String) : String = |
| invoke('org.eclipse.ocl.examples.codegen.common.NameQueries', 'rawEncodeName(java.lang.String)', Sequence{string}) /] |
| |
| [query public javaString(aComment : Comment) : String = |
| invoke('org.eclipse.xtext.util.Strings', 'convertToJavaString(java.lang.String)', Sequence{aComment._body}) /] |