@Override protected boolean isSelectableElement(SarlAgent element) { return element != null && !Strings.isNullOrEmpty(element.getName()); }
@Override protected URI getResourceURIForValidEObject(Object object) { if (object instanceof SarlAgent) { final SarlAgent agent = (SarlAgent) object; return agent.eResource().getURI(); } return null; }
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { this.sarlAgent.getModifiers().add(modifier); } }
/** 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); } }
if (Strings.isNullOrEmpty(source.getName())) { return; inferredJvmType.setStrictFloatingPoint(false); setVisibility(inferredJvmType, source); final boolean isAbstract = source.isAbstract() || Utils.hasAbstractMember(source); inferredJvmType.setAbstract(isAbstract); inferredJvmType.setFinal(!isAbstract && source.isFinal()); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Agent.class, SarlAgent.class, source.getExtends());
/** 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); }
/** 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.sarlAgent.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.sarlAgent, aname)); } } } }
isAbstract = ((XtendClass) declarator).isAbstract(); } else if (declarator instanceof SarlAgent) { isAbstract = ((SarlAgent) declarator).isAbstract(); } else if (declarator instanceof SarlBehavior) { isAbstract = ((SarlBehavior) declarator).isAbstract();
/** Check the container for the SARL agents. * * @param agent the agent. */ @Check public void checkContainerType(SarlAgent agent) { final XtendTypeDeclaration declaringType = agent.getDeclaringType(); if (declaringType != null) { final String name = canonicalName(declaringType); assert name != null; error(MessageFormat.format(Messages.SARLValidator_28, name), agent, 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)) { getSarlAgent().eAdapters().removeIf(new Predicate<Adapter>() { public boolean test(Adapter adapter) { return adapter.isAdapterForType(DocumentationAdapter.class); } }); } else { DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter( getSarlAgent(), DocumentationAdapter.class); if (adapter == null) { adapter = new DocumentationAdapter(); getSarlAgent().eAdapters().add(adapter); } adapter.setDocumentation(doc); } }
/** 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); }
/** 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.sarlAgent.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.sarlAgent, aname)); } } } }
@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(); }
/** Check the modifiers for the SARL agents. * * @param agent the agent. */ @Check protected void checkModifiers(SarlAgent agent) { this.agentModifierValidator.checkModifiers(agent, MessageFormat.format(Messages.SARLValidator_9, agent.getName())); }
/** Replies the resource to which the SarlAgent is attached. */ @Pure public Resource eResource() { return getSarlAgent().eResource(); }
/** Replies the resource to which the SarlAgent is attached. */ @Pure public Resource eResource() { return getSarlAgent().eResource(); }