/** Add the super type. * @param superType the qualified name of the super type. */ public void addExtends(String superType) { if (!Strings.isEmpty(superType) && !Capacity.class.getName().equals(superType)) { JvmParameterizedTypeReference superTypeRef = newTypeRef(this.sarlCapacity, superType); JvmTypeReference baseTypeRef = findType(this.sarlCapacity, Capacity.class.getCanonicalName()); if (isSubTypeOf(this.sarlCapacity, superTypeRef, baseTypeRef)) { this.sarlCapacity.getExtends().add(superTypeRef); return; } } }
/** Check if a capacity has a feature defined inside. * * @param capacity the capacity to test. */ @Check(CheckType.FAST) public void checkCapacityFeatures(SarlCapacity capacity) { if (capacity.getMembers().isEmpty()) { if (!isIgnored(DISCOURAGED_CAPACITY_DEFINITION)) { addIssue(Messages.SARLValidator_77, capacity, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, DISCOURAGED_CAPACITY_DEFINITION, capacity.getName(), "aFunction"); //$NON-NLS-1$ } } }
/** Replies the resource to which the SarlCapacity is attached. */ @Pure public Resource eResource() { return getSarlCapacity().eResource(); }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlCapacity == null) { this.sarlCapacity = SarlFactory.eINSTANCE.createSarlCapacity(); script.getXtendTypes().add(this.sarlCapacity); this.sarlCapacity.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlCapacity.setName(name); } } }
/** Generate the given object. * * @param capacity the capacity. * @param context the context. */ protected void _generate(SarlCapacity capacity, IExtraLanguageGeneratorContext context) { final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(capacity); final PyAppendable appendable = createAppendable(jvmType, context); final List<? extends JvmTypeReference> superTypes; if (!capacity.getExtends().isEmpty()) { superTypes = capacity.getExtends(); } else { superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Capacity.class, capacity)); } if (generateTypeDeclaration( this.qualifiedNameProvider.getFullyQualifiedName(capacity).toString(), capacity.getName(), true, superTypes, getTypeBuilder().getDocumentation(capacity), true, capacity.getMembers(), appendable, context, null)) { final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(capacity); writeFile(name, appendable, context); } }
if (Strings.isNullOrEmpty(source.getName())) { return; translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Capacity.class, SarlCapacity.class, source.getExtends());
public void checkDefaultSkillAnnotation(SarlCapacity capacity) { final String annotationId = DefaultSkill.class.getName(); final XAnnotation annotation = IterableExtensions.findFirst(capacity.getAnnotations(), it -> { return Strings.equal(annotationId, it.getAnnotationType().getIdentifier()); }); error(MessageFormat.format( Messages.SARLValidator_71, capacity.getName(), type.getSimpleName()), expr, null,
/** Check the modifiers for the SARL capacities. * * @param capacity the capacity. */ @Check protected void checkModifiers(SarlCapacity capacity) { this.capacityModifierValidator.checkModifiers(capacity, MessageFormat.format(Messages.SARLValidator_9, capacity.getName())); }
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { this.sarlCapacity.getModifiers().add(modifier); } }
/** Check the container for the SARL capacities. * * @param capacity the capacity. */ @Check public void checkContainerType(SarlCapacity capacity) { final XtendTypeDeclaration declaringType = capacity.getDeclaringType(); if (declaringType != null) { final String name = canonicalName(declaringType); assert name != null; error(MessageFormat.format(Messages.SARLValidator_30, name), capacity, 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)) { getSarlCapacity().eAdapters().removeIf(new Predicate<Adapter>() { public boolean test(Adapter adapter) { return adapter.isAdapterForType(DocumentationAdapter.class); } }); } else { DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter( getSarlCapacity(), DocumentationAdapter.class); if (adapter == null) { adapter = new DocumentationAdapter(); getSarlCapacity().eAdapters().add(adapter); } adapter.setDocumentation(doc); } }
/** Check if the supertype of the given capacity is a subtype of Capacity. * * @param capacity the type to test. */ @Check(CheckType.FAST) public void checkSuperTypes(SarlCapacity capacity) { checkSuperTypes( capacity, SARL_CAPACITY__EXTENDS, capacity.getExtends(), Capacity.class, false); }
/** Replies the resource to which the SarlCapacity is attached. */ @Pure public Resource eResource() { return getSarlCapacity().eResource(); }
/** Format the given SARL capacity. * * @param capacity the SARL component. * @param document the document. */ protected void _format(SarlCapacity capacity, IFormattableDocument document) { formatAnnotations(capacity, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(capacity, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(capacity); document.append(regionFor.keyword(this.keywords.getCapacityKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); formatCommaSeparatedList(capacity.getExtends(), document); formatBody(capacity, document); }