/** Check if the supertype of the given behavior is a subtype of Behavior. * * @param behavior the type to test. */ @Check(CheckType.FAST) public void checkSuperType(SarlBehavior behavior) { checkSuperTypes( behavior, SARL_BEHAVIOR__EXTENDS, Utils.singletonList(behavior.getExtends()), Behavior.class, false); }
/** Check the modifiers for the SARL behaviors. * * @param behavior the behavior. */ @Check protected void checkModifiers(SarlBehavior behavior) { this.behaviorModifierValidator.checkModifiers(behavior, MessageFormat.format(Messages.SARLValidator_9, behavior.getName())); }
/** Replies the resource to which the SarlBehavior is attached. */ @Pure public Resource eResource() { return getSarlBehavior().eResource(); }
/** Generate the given object. * * @param behavior the behavior. * @param context the context. */ protected void _generate(SarlBehavior behavior, IExtraLanguageGeneratorContext context) { final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(behavior); final PyAppendable appendable = createAppendable(jvmType, context); final List<JvmTypeReference> superTypes; if (behavior.getExtends() != null) { superTypes = Collections.singletonList(behavior.getExtends()); } else { superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Behavior.class, behavior)); } final String qualifiedName = this.qualifiedNameProvider.getFullyQualifiedName(behavior).toString(); if (generateTypeDeclaration( qualifiedName, behavior.getName(), behavior.isAbstract(), superTypes, getTypeBuilder().getDocumentation(behavior), true, behavior.getMembers(), appendable, context, (it, context2) -> { generateGuardEvaluators(qualifiedName, it, context2); })) { final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(behavior); writeFile(name, appendable, context); } }
if (Strings.isNullOrEmpty(source.getName())) { return; final boolean isAbstract = source.isAbstract() || Utils.hasAbstractMember(source); inferredJvmType.setAbstract(isAbstract); inferredJvmType.setStrictFloatingPoint(false); inferredJvmType.setFinal(!isAbstract && source.isFinal()); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Behavior.class, SarlBehavior.class, source.getExtends());
/** Create a SarlRequiredCapacity. * @param name the types referenced by the SarlRequiredCapacity. */ public void addSarlRequiredCapacity(String... name) { if (name != null && name.length > 0) { SarlRequiredCapacity member = SarlFactory.eINSTANCE.createSarlRequiredCapacity(); this.sarlBehavior.getMembers().add(member); member.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendMember()); Collection<JvmParameterizedTypeReference> thecollection = member.getCapacities(); for (final String aname : name) { if (!Strings.isEmpty(aname)) { thecollection.add(newTypeRef(this.sarlBehavior, aname)); } } } }
isAbstract = ((SarlAgent) declarator).isAbstract(); } else if (declarator instanceof SarlBehavior) { isAbstract = ((SarlBehavior) declarator).isAbstract(); } else if (declarator instanceof SarlSkill) { isAbstract = ((SarlSkill) declarator).isAbstract();
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { this.sarlBehavior.getModifiers().add(modifier); } }
/** Check the container for the SARL behaviors. * * @param behavior the behavior. */ @Check public void checkContainerType(SarlBehavior behavior) { final XtendTypeDeclaration declaringType = behavior.getDeclaringType(); if (declaringType != null) { final String name = canonicalName(declaringType); assert name != null; error(MessageFormat.format(Messages.SARLValidator_29, name), behavior, null, INVALID_NESTED_DEFINITION); } }
/** Change the documentation of the element. * * <p>The documentation will be displayed just before the element. * * @param doc the documentation. */ public void setDocumentation(String doc) { if (Strings.isEmpty(doc)) { getSarlBehavior().eAdapters().removeIf(new Predicate<Adapter>() { public boolean test(Adapter adapter) { return adapter.isAdapterForType(DocumentationAdapter.class); } }); } else { DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter( getSarlBehavior(), DocumentationAdapter.class); if (adapter == null) { adapter = new DocumentationAdapter(); getSarlBehavior().eAdapters().add(adapter); } adapter.setDocumentation(doc); } }
/** Create a SarlCapacityUses. * @param name the types referenced by the SarlCapacityUses. */ public void addSarlCapacityUses(String... name) { if (name != null && name.length > 0) { SarlCapacityUses member = SarlFactory.eINSTANCE.createSarlCapacityUses(); this.sarlBehavior.getMembers().add(member); member.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendMember()); Collection<JvmParameterizedTypeReference> thecollection = member.getCapacities(); for (final String aname : name) { if (!Strings.isEmpty(aname)) { thecollection.add(newTypeRef(this.sarlBehavior, aname)); } } } }
/** Format the given SARL behavior. * * @param behavior the SARL component. * @param document the document. */ protected void _format(SarlBehavior behavior, IFormattableDocument document) { formatAnnotations(behavior, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(behavior, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(behavior); document.append(regionFor.keyword(this.keywords.getBehaviorKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(behavior.getExtends()); formatBody(behavior, document); }
/** Replies the resource to which the SarlBehavior is attached. */ @Pure public Resource eResource() { return getSarlBehavior().eResource(); }
@Override protected void generateTypeContent(ISourceAppender appender, IJvmTypeProvider typeProvider, String comment, IProgressMonitor monitor) throws Exception { final SubMonitor mon = SubMonitor.convert(monitor, 4); final ScriptSourceAppender scriptBuilder = this.codeBuilderFactory.buildScript( getPackageFragment().getElementName(), typeProvider); final ISarlBehaviorBuilder behavior = scriptBuilder.addSarlBehavior(getTypeName()); behavior.setExtends(getSuperClass()); behavior.setDocumentation(comment); mon.worked(1); createStandardSARLEventTemplates(Messages.NewSarlBehaviorWizardPage_4, name -> behavior.addSarlBehaviorUnit(name), name -> behavior.addSarlCapacityUses(name)); mon.worked(2); if (behavior.getSarlBehavior().getExtends() != null) { createInheritedMembers( Behavior.class.getCanonicalName(), behavior.getSarlBehavior(), true, () -> behavior.addSarlConstructor(), name -> behavior.addOverrideSarlAction(name), getSuperClass()); } mon.worked(3); scriptBuilder.build(appender); mon.done(); }