/** Check if the supertype of the given event is a subtype of Event. * * @param event the type to test. */ @Check(CheckType.FAST) public void checkSuperType(SarlEvent event) { checkSuperTypes( event, SARL_EVENT__EXTENDS, Utils.singletonList(event.getExtends()), Event.class, false); }
/** Check if the modifiers for the SARL events. * * @param event the event. */ @Check protected void checkModifiers(SarlEvent event) { this.eventModifierValidator.checkModifiers(event, MessageFormat.format(Messages.SARLValidator_9, event.getName())); }
/** Replies the resource to which the SarlEvent is attached. */ @Pure public Resource eResource() { return getSarlEvent().eResource(); }
/** Generate the given object. * * @param event the event. * @param context the context. */ protected void _generate(SarlEvent event, IExtraLanguageGeneratorContext context) { final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(event); final PyAppendable appendable = createAppendable(jvmType, context); final List<JvmTypeReference> superTypes; if (event.getExtends() != null) { superTypes = Collections.singletonList(event.getExtends()); } else { superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Event.class, event)); } if (generateTypeDeclaration( this.qualifiedNameProvider.getFullyQualifiedName(event).toString(), event.getName(), event.isAbstract(), superTypes, getTypeBuilder().getDocumentation(event), true, event.getMembers(), appendable, context, null)) { final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(event); writeFile(name, appendable, context); } }
if (Strings.isNullOrEmpty(source.getName())) { return; inferredJvmType.setStrictFloatingPoint(false); if (!inferredJvmType.isAbstract()) { inferredJvmType.setFinal(source.isFinal()); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); appendConstrainedExtends(context, inferredJvmType, Event.class, SarlEvent.class, source.getExtends());
/** Create an expression but does not change the container. * * @param expression the textual representation of the expression. * @return the expression. */ @Pure protected XExpression fromString(String expression) { if (!Strings.isEmpty(expression)) { ResourceSet resourceSet = this.context.eResource().getResourceSet(); URI uri = computeUnusedUri(resourceSet); Resource resource = getResourceFactory().createResource(uri); resourceSet.getResources().add(resource); try (StringInputStream is = new StringInputStream(generateExpressionCode(expression))) { resource.load(is, null); SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0); SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0); SarlField member = (SarlField) topElement.getMembers().get(0); return member.getInitialValue(); } catch (Throwable exception) { throw new RuntimeException(exception); } finally { resourceSet.getResources().remove(resource); } } throw new IllegalArgumentException("not a valid expression"); }
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { this.sarlEvent.getModifiers().add(modifier); } }
/** Check if the modifiers for the SARL events. * * @param event the event. */ @Check public void checkContainerType(SarlEvent event) { final XtendTypeDeclaration declaringType = event.getDeclaringType(); if (declaringType != null) { final String name = canonicalName(declaringType); assert name != null; error(MessageFormat.format(Messages.SARLValidator_32, name), event, 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)) { getSarlEvent().eAdapters().removeIf(new Predicate<Adapter>() { public boolean test(Adapter adapter) { return adapter.isAdapterForType(DocumentationAdapter.class); } }); } else { DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter( getSarlEvent(), DocumentationAdapter.class); if (adapter == null) { adapter = new DocumentationAdapter(); getSarlEvent().eAdapters().add(adapter); } adapter.setDocumentation(doc); } }
static JvmParameterizedTypeReference parseType(Notifier context, String typeName, AbstractBuilder caller) { ResourceSet resourceSet = toResource(context).getResourceSet(); URI uri = caller.computeUnusedUri(resourceSet); Resource resource = caller.getResourceFactory().createResource(uri); resourceSet.getResources().add(resource); try (StringInputStream is = new StringInputStream(generateTypenameCode(typeName))) { resource.load(is, null); SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0); SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0); SarlField member = (SarlField) topElement.getMembers().get(0); JvmTypeReference reference = member.getType(); if (reference instanceof JvmParameterizedTypeReference) { final JvmParameterizedTypeReference pref = (JvmParameterizedTypeReference) reference; if (!pref.getArguments().isEmpty()) { EcoreUtil2.resolveAll(resource); return pref; } } } catch (Exception exception) { throw new TypeNotPresentException(typeName, exception); } finally { resourceSet.getResources().remove(resource); } throw new TypeNotPresentException(typeName, null); }
/** Format the given SARL event. * * @param event the SARL component. * @param document the document. */ protected void _format(SarlEvent event, IFormattableDocument document) { formatAnnotations(event, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(event, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(event); document.append(regionFor.keyword(this.keywords.getEventKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(event.getExtends()); formatBody(event, document); }
/** Replies the resource to which the SarlEvent is attached. */ @Pure public Resource eResource() { return getSarlEvent().eResource(); }
@SuppressWarnings("all") @Override protected void generateTypeContent(ISourceAppender appender, IJvmTypeProvider typeProvider, String comment, IProgressMonitor monitor) throws Exception { final SubMonitor mon = SubMonitor.convert(monitor, 3); final ScriptSourceAppender scriptBuilder = this.codeBuilderFactory.buildScript( getPackageFragment().getElementName(), typeProvider); final ISarlEventBuilder event = scriptBuilder.addSarlEvent(getTypeName()); event.setExtends(getSuperClass()); event.setDocumentation(comment); mon.worked(1); if (event.getSarlEvent().getExtends() != null) { createInheritedMembers( Event.class.getCanonicalName(), event.getSarlEvent(), false, () -> event.addSarlConstructor(), null, getSuperClass()); } mon.worked(2); scriptBuilder.build(appender); mon.done(); }