/** Check if implemented interfaces of a skill are redundant. * * @param skill the skill. */ @Check public void checkRedundantImplementedInterfaces(SarlSkill skill) { checkRedundantInterfaces( skill, SARL_SKILL__IMPLEMENTS, skill.getImplements(), Utils.singletonList(skill.getExtends())); }
/** Check the modifiers for the SARL skills. * * @param skill the skill. */ @Check protected void checkModifiers(SarlSkill skill) { this.skillModifierValidator.checkModifiers(skill, MessageFormat.format(Messages.SARLValidator_9, skill.getName())); }
/** Replies the resource to which the SarlSkill is attached. */ @Pure public Resource eResource() { return getSarlSkill().eResource(); }
/** Generate the given object. * * @param skill the skill. * @param context the context. */ protected void _generate(SarlSkill skill, IExtraLanguageGeneratorContext context) { final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(skill); final PyAppendable appendable = createAppendable(jvmType, context); List<JvmTypeReference> superTypes = getSuperTypes(skill.getExtends(), skill.getImplements()); if (superTypes.isEmpty()) { superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Skill.class, skill)); } final String qualifiedName = this.qualifiedNameProvider.getFullyQualifiedName(skill).toString(); if (generateTypeDeclaration( qualifiedName, skill.getName(), skill.isAbstract(), superTypes, getTypeBuilder().getDocumentation(skill), true, skill.getMembers(), appendable, context, (it, context2) -> { generateGuardEvaluators(qualifiedName, it, context2); })) { final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(skill); 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, Skill.class, SarlSkill.class, source.getExtends()); appendConstrainedImplements(context, inferredJvmType, Capacity.class, SarlCapacity.class, source.getImplements());
/** 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.sarlSkill.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.sarlSkill, aname)); } } } }
/** Add an implemented type. * @param type the qualified name of the implemented type. */ public void addImplements(String type) { if (!Strings.isEmpty(type)) { this.sarlSkill.getImplements().add(newTypeRef(this.sarlSkill, type)); } }
isAbstract = ((SarlBehavior) declarator).isAbstract(); } else if (declarator instanceof SarlSkill) { isAbstract = ((SarlSkill) declarator).isAbstract(); } else { return;
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { this.sarlSkill.getModifiers().add(modifier); } }
/** Check the container for the SARL skills. * * @param skill the skill. */ @Check public void checkContainerType(SarlSkill skill) { final XtendTypeDeclaration declaringType = skill.getDeclaringType(); if (declaringType != null) { final String name = canonicalName(declaringType); assert name != null; error(MessageFormat.format(Messages.SARLValidator_31, name), skill, 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)) { getSarlSkill().eAdapters().removeIf(new Predicate<Adapter>() { public boolean test(Adapter adapter) { return adapter.isAdapterForType(DocumentationAdapter.class); } }); } else { DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter( getSarlSkill(), DocumentationAdapter.class); if (adapter == null) { adapter = new DocumentationAdapter(); getSarlSkill().eAdapters().add(adapter); } adapter.setDocumentation(doc); } }
/** 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.sarlSkill.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.sarlSkill, aname)); } } } }
/** Check if the supertype of the given skill is a subtype of Skill. * * @param skill the type to test. */ @Check(CheckType.FAST) public void checkSuperType(SarlSkill skill) { final int nbSuperTypes = checkSuperTypes( skill, SARL_SKILL__EXTENDS, Utils.singletonList(skill.getExtends()), Skill.class, false); checkImplementedTypes( skill, SARL_SKILL__IMPLEMENTS, skill.getImplements(), Capacity.class, nbSuperTypes > 0 ? 0 : 1, true); }
/** Replies the resource to which the SarlSkill is attached. */ @Pure public Resource eResource() { return getSarlSkill().eResource(); }
/** Format the given SARL skill. * * @param skill the SARL component. * @param document the document. */ protected void _format(SarlSkill skill, IFormattableDocument document) { formatAnnotations(skill, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(skill, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(skill); document.append(regionFor.keyword(this.keywords.getSkillKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(skill.getExtends()); document.surround(regionFor.keyword(this.keywords.getImplementsKeyword()), ONE_SPACE); formatCommaSeparatedList(skill.getImplements(), document); formatBody(skill, document); }