/** Check if the supertype of the given agent is a subtype of Agent. * * @param agent the type to test. */ @Check(CheckType.FAST) public void checkSuperType(SarlAgent agent) { checkSuperTypes( agent, SARL_AGENT__EXTENDS, Utils.singletonList(agent.getExtends()), Agent.class, false); }
/** Generate the given object. * * @param agent the agent. * @param context the context. */ protected void _generate(SarlAgent agent, IExtraLanguageGeneratorContext context) { final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(agent); final PyAppendable appendable = createAppendable(jvmType, context); final List<JvmTypeReference> superTypes; if (agent.getExtends() != null) { superTypes = Collections.singletonList(agent.getExtends()); } else { superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Agent.class, agent)); } final String qualifiedName = this.qualifiedNameProvider.getFullyQualifiedName(agent).toString(); if (generateTypeDeclaration( qualifiedName, agent.getName(), agent.isAbstract(), superTypes, getTypeBuilder().getDocumentation(agent), true, agent.getMembers(), appendable, context, (it, context2) -> { generateGuardEvaluators(qualifiedName, it, context2); })) { final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(agent); writeFile(name, appendable, context); } }
/** Format the given SARL agent. * * @param agent the SARL component. * @param document the document. */ protected void _format(SarlAgent agent, IFormattableDocument document) { formatAnnotations(agent, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(agent, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(agent); document.append(regionFor.keyword(this.keywords.getAgentKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(agent.getExtends()); formatBody(agent, document); }
@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 ISarlAgentBuilder agent = scriptBuilder.addSarlAgent(getTypeName()); agent.setExtends(getSuperClass()); agent.setDocumentation(comment); mon.worked(1); createStandardSARLEventTemplates(Messages.NewSarlAgentWizardPage_3, name -> agent.addSarlBehaviorUnit(name), name -> agent.addSarlCapacityUses(name)); mon.worked(2); if (agent.getSarlAgent().getExtends() != null) { createInheritedMembers( Agent.class.getCanonicalName(), agent.getSarlAgent(), true, () -> agent.addSarlConstructor(), name -> agent.addOverrideSarlAction(name), getSuperClass()); } mon.worked(3); scriptBuilder.build(appender); mon.done(); }
appendConstrainedExtends(context, inferredJvmType, Agent.class, SarlAgent.class, source.getExtends());