/** Append the SARL specification version as an annotation to the given container. * * <p>The added annotation may be used by any underground platform for determining what is * the version of the SARL specification that was used for generating the container. * * @param context the current generation context. * @param source the source object. * @param target the inferred JVM object. */ protected void appendSARLSpecificationVersion(GenerationContext context, XtendTypeDeclaration source, JvmDeclaredType target) { addAnnotationSafe(target, SarlSpecification.class, SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING); }
final GenerationContext context = openContext(source, inferredJvmType, Arrays.asList( SarlField.class, SarlConstructor.class)); try { setVisibility(inferredJvmType, source); inferredJvmType.setStatic(false); inferredJvmType.setAbstract(false); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Event.class, SarlEvent.class, source.getExtends()); appendAOPMembers( inferredJvmType, source, appendDefaultConstructors(source, inferredJvmType); appendComparisonFunctions(context, source, inferredJvmType); appendToStringFunctions(context, source, inferredJvmType); appendCloneFunctionIfCloneable(context, source, inferredJvmType); appendSerialNumberIfSerializable(context, source, inferredJvmType); appendSARLSpecificationVersion(context, source, inferredJvmType); appendSARLElementType(source, inferredJvmType);
final GenerationContext context = openContext(source, inferredJvmType, Collections.singleton(SarlAction.class)); try { setVisibility(inferredJvmType, source); inferredJvmType.setStatic(false); inferredJvmType.setStrictFloatingPoint(false); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Capacity.class, SarlCapacity.class, source.getExtends()); appendAOPMembers( inferredJvmType, source, appendFunctionalInterfaceAnnotation(inferredJvmType); appendSARLSpecificationVersion(context, source, inferredJvmType); appendSARLElementType(source, inferredJvmType); closeContext(context); appendCapacityContextAwareWrapper(source, inferredJvmType);
final GenerationContext context = openContext(source, inferredJvmType, Arrays.asList( SarlField.class, SarlConstructor.class, SarlAction.class)); try { setVisibility(inferredJvmType, source); appendSyntheticDefaultValuedParameterMethods( source, inferredJvmType, appendComparisonFunctions(context, source, inferredJvmType); appendCloneFunctionIfCloneable(context, source, inferredJvmType); appendDefaultConstructors(source, inferredJvmType); appendSerialNumberIfSerializable(context, source, inferredJvmType); appendSARLSpecificationVersion(context, source, inferredJvmType); appendSARLElementType(source, inferredJvmType); } finally { closeContext(context);
"checkstyle:npathcomplexity", "checkstyle:booleanexpressioncomplexity"}) protected void transform(final XtendFunction source, final JvmGenericType container, boolean allowDispatch) { final GenerationContext context = getContext(container); container.getMembers().add(operation); operation.setSimpleName(sourceName); setVisibility(operation, source); operation.setStrictFloatingPoint(source.isStrictFloatingPoint()); operation.setStatic(source.isStatic()); copyAndFixTypeParameters(source.getTypeParameters(), operation); translateSarlFormalParameters( context, operation, container, isVarArgs, final JvmTypeReference selectedReturnType = inferFunctionReturnType(source, operation, inheritedOperation); operation.setReturnType(selectedReturnType); setBody(operation, source.getExpression()); translateAnnotationsTo(source.getAnnotations(), operation); && this.annotationFinder.findAnnotation(operation, Override.class) == null && this.typeReferences.findDeclaredType(Override.class, source) != null) { addAnnotationSafe(operation, Override.class); isEarlyExit = this.earlyExitComputer.isEarlyExitOperation(action); if (isEarlyExit) {
staticConstructor.setStatic(true); staticConstructor.setReturnType(this._typeReferenceBuilder.typeRef(Void.TYPE)); setBody(staticConstructor, source.getExpression()); copyAndCleanDocumentationTo(source, staticConstructor); return; final GenerationContext context = getContext(container); this.associator.associatePrimary(source, constructor); constructor.setSimpleName(constructorName); setVisibility(constructor, source); constructor.setVarArgs(isVarArgs); translateSarlFormalParameters( context, constructor, container, isVarArgs, copyAndFixTypeParameters(source.getTypeParameters(), constructor); for (final JvmTypeReference exception : source.getExceptions()) { constructor.getExceptions().add(this.typeBuilder.cloneWithProxies(exception)); translateAnnotationsTo(source.getAnnotations(), constructor); setBody(constructor, source.getExpression()); copyAndCleanDocumentationTo(source, constructor); copyAndCleanDocumentationTo(source, constructor2); constructor2.setSimpleName(container.getSimpleName());
final GenerationContext context = getContext(container); if (context == null) { return; addAnnotationSafe(field, Extension.class); field.getAnnotations().add(annotationClassRef(ImportedCapacityFeature.class, Collections.singletonList(capacityType))); appendGeneratedAnnotation(field, getContext(container)); container.getMembers().add(operation); operation.setVisibility(JvmVisibility.PRIVATE); operation.setReturnType(cloneWithTypeParametersAndProxies(capacityType, operation)); operation.setSimpleName(methodName); setBody(operation, it -> { it.append("if (this.").append(fieldName).append(" == null || this."); //$NON-NLS-1$ //$NON-NLS-2$ it.append(fieldName).append(".get() == null) {"); //$NON-NLS-1$ }); appendGeneratedAnnotation(operation, context); if (context.getGeneratorConfig2().isGeneratePureAnnotation()) { addAnnotationSafe(operation, Pure.class);
final GenerationContext context = getContext(container); if (source.getName() != null && !Strings.isNullOrEmpty(source.getName().getSimpleName()) && context != null) { final XExpression guard = source.getGuard(); bodyOperation.getParameters().add(jvmParam); setBody(bodyOperation, source.getExpression()); translateAnnotationsTo(source.getAnnotations(), bodyOperation); if (context.getGeneratorConfig2().isGeneratePureAnnotation() && !this.services.getExpressionHelper().hasSideEffects(source.getExpression())) { addAnnotationSafe(bodyOperation, Pure.class); guardOperation.getParameters().add(jvmParam); setBody(guardOperation, guard); appendGeneratedAnnotation(guardOperation, context); if (context.getGeneratorConfig2().isGeneratePureAnnotation()) { addAnnotationSafe(guardOperation, Pure.class); context.incrementSerial(bodyMethodName.hashCode()); } else { logInternalError(Messages.SARLJvmModelInferrer_10);
translateParameter(owner, param); final JvmFormalParameter lastParam = owner.getParameters().get(owner.getParameters().size() - 1); final String namePostPart = inferredParam.getDefaultValueAnnotationValue(); final String name = this.sarlSignatureProvider.createFieldNameForDefaultValueID(namePostPart); final JvmTypeReference fieldType = skipTypeParameters(paramType, actionContainer); final JvmField field = this.typeBuilder.toField(defaultValue, name, fieldType, it -> { SARLJvmModelInferrer.this.typeBuilder.setDocumentation(it, this.readAndWriteTracking.markInitialized(field, null); addAnnotationSafe(lastParam, DefaultValue.class, namePostPart); appendGeneratedAnnotation(field, context, rawCode); addAnnotationSafe(owner, DefaultValueSource.class);
if (!isAppendToStringFunctionsEnable(context)) { return; param.setParameterType(SARLJvmModelInferrer.this._typeReferenceBuilder.typeRef(ToStringBuilder.class)); it2.getParameters().add(param); setBody(it2, it3 -> { it3.append("super.toString(builder);"); //$NON-NLS-1$ for (final JvmField attr : declaredInstanceFields) { }); if (op != null) { appendGeneratedAnnotation(op, context); if (context.getGeneratorConfig2().isGeneratePureAnnotation()) { addAnnotationSafe(op, Pure.class);
if (!isAppendCloneFunctionsEnable(context)) { return; target.getMembers().add(operation); operation.setVisibility(JvmVisibility.PUBLIC); addAnnotationSafe(operation, Override.class); if (context.getGeneratorConfig2().isGeneratePureAnnotation()) { addAnnotationSafe(operation, Pure.class); setBody(operation, it -> { it.append("try {"); //$NON-NLS-1$ it.increaseIndentation().newLine(); it.append("}"); //$NON-NLS-1$ }); appendGeneratedAnnotation(operation, context);
final GenerationContext context = getContext(container); if (context != null) { final Collection<Pair<SarlBehaviorUnit, Collection<Procedure1<? super ITreeAppendable>>>> allEvaluators appendGeneratedAnnotation(operation, context); addAnnotationSafe(operation, PerceptGuardEvaluator.class); container.getMembers().add(operation); setBody(operation, it -> { it.append("assert "); //$NON-NLS-1$ it.append(this.grammarKeywordAccess.getOccurrenceKeyword());
setBody(op, it -> { it.append(redefinedOperation.getSimpleName()); addAnnotationSafe(op, DefaultValueUse.class, originalSignature); appendGeneratedAnnotation(op, context);
return null; addAnnotationSafe(result, Override.class); if (generatePureAnnotation) { addAnnotationSafe(result, Pure.class); setBody(result, it -> { final TypeReferences refs = SARLJvmModelInferrer.this.typeReferences; it.append("int result = super.").append(HASHCODE_FUNCTION_NAME); //$NON-NLS-1$ boolean firstAttr = true; for (final JvmField field : jvmFields) { if (isEqualityTestValidField(field.getType())) { if (firstAttr) { firstAttr = false;
return null; addAnnotationSafe(result, Override.class); if (generatePureAnnotation) { addAnnotationSafe(result, Pure.class); this.associator.associate(sarlElement, param); result.getParameters().add(param); setBody(result, new Procedures.Procedure1<ITreeAppendable>() { @SuppressWarnings("synthetic-access") @Override
/** Generate the extended types for the given SARL statement. * * @param context the context of the generation. * @param owner the JVM element to change. * @param defaultJvmType the default JVM type. * @param defaultSarlType the default SARL type. * @param supertype the supertype. */ protected void appendConstrainedExtends( GenerationContext context, JvmGenericType owner, Class<?> defaultJvmType, Class<? extends XtendTypeDeclaration> defaultSarlType, JvmParameterizedTypeReference supertype) { final List<? extends JvmParameterizedTypeReference> supertypes; if (supertype == null) { supertypes = Collections.emptyList(); } else { supertypes = Collections.singletonList(supertype); } appendConstrainedExtends(context, owner, defaultJvmType, defaultSarlType, supertypes); }
/** Append the clone function only if the type is a subtype of {@link Cloneable}. * * <p>The clone function replies a value of the current type, not {@code Object}. * * @param context the current generation context. * @param source the source object. * @param target the inferred JVM object. * @since 0.6 * @see #appendCloneFunction(GenerationContext, XtendTypeDeclaration, JvmGenericType) */ protected void appendCloneFunctionIfCloneable(GenerationContext context, XtendTypeDeclaration source, JvmGenericType target) { if (!target.isInterface() && this.inheritanceHelper.isSubTypeOf(target, Cloneable.class, null)) { appendCloneFunction(context, source, target); } }
final GenerationContext context = openContext(source, inferredJvmType, Arrays.asList( SarlField.class, SarlConstructor.class, SarlAction.class, SarlBehaviorUnit.class, SarlCapacityUses.class, SarlRequiredCapacity.class)); setVisibility(inferredJvmType, source); final boolean isAbstract = source.isAbstract() || Utils.hasAbstractMember(source); inferredJvmType.setAbstract(isAbstract); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Agent.class, SarlAgent.class, source.getExtends()); appendAOPMembers( inferredJvmType, source, appendComparisonFunctions(context, source, inferredJvmType); appendCloneFunctionIfCloneable(context, source, inferredJvmType); appendDefaultConstructors(source, inferredJvmType); appendSerialNumberIfSerializable(context, source, inferredJvmType); appendSARLSpecificationVersion(context, source, inferredJvmType); appendSARLElementType(source, inferredJvmType); closeContext(context);
/** Append the SARL element type as an annotation to the given container. * * <p>The added annotation may be used by any underground platform for determining what is * the type of the SARL element without invoking the costly "instanceof" operations. * * @param source the source object. * @param target the inferred JVM object. */ protected void appendSARLElementType(XtendTypeDeclaration source, JvmDeclaredType target) { addAnnotationSafe(target, SarlElementType.class, source.eClass().getClassifierID()); }
final GenerationContext context = openContext(source, inferredJvmType, Arrays.asList( SarlField.class, SarlConstructor.class, SarlAction.class, SarlBehaviorUnit.class, SarlCapacityUses.class, SarlRequiredCapacity.class)); setVisibility(inferredJvmType, source); inferredJvmType.setStatic(false); final boolean isAbstract = source.isAbstract() || Utils.hasAbstractMember(source); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Skill.class, SarlSkill.class, source.getExtends()); appendConstrainedImplements(context, inferredJvmType, Capacity.class, SarlCapacity.class, source.getImplements()); appendAOPMembers( inferredJvmType, source, appendComparisonFunctions(context, source, inferredJvmType); appendCloneFunctionIfCloneable(context, source, inferredJvmType); appendDefaultConstructors(source, inferredJvmType); appendSerialNumberIfSerializable(context, source, inferredJvmType); appendSARLSpecificationVersion(context, source, inferredJvmType); appendSARLElementType(source, inferredJvmType);