/** Check the top elements within a script are not duplicated. * * @param script the SARL script */ @Check public void checkTopElementsAreUnique(SarlScript script) { final Multimap<String, XtendTypeDeclaration> name2type = HashMultimap.create(); for (final XtendTypeDeclaration declaration : script.getXtendTypes()) { final String name = declaration.getName(); if (!Strings.isEmpty(name)) { name2type.put(name, declaration); } } for (final String name: name2type.keySet()) { final Collection<XtendTypeDeclaration> types = name2type.get(name); if (types.size() > 1) { for (final XtendTypeDeclaration type: types) { error( MessageFormat.format(Messages.SARLValidator_93, name), type, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, DUPLICATE_TYPE_NAME); } } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlBehavior == null) { this.sarlBehavior = SarlFactory.eINSTANCE.createSarlBehavior(); script.getXtendTypes().add(this.sarlBehavior); this.sarlBehavior.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlBehavior.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlSpace == null) { this.sarlSpace = SarlFactory.eINSTANCE.createSarlSpace(); script.getXtendTypes().add(this.sarlSpace); this.sarlSpace.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlSpace.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlSkill == null) { this.sarlSkill = SarlFactory.eINSTANCE.createSarlSkill(); script.getXtendTypes().add(this.sarlSkill); this.sarlSkill.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlSkill.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlArtifact == null) { this.sarlArtifact = SarlFactory.eINSTANCE.createSarlArtifact(); script.getXtendTypes().add(this.sarlArtifact); this.sarlArtifact.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlArtifact.setName(name); } } }
/** 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); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlEvent == null) { this.sarlEvent = SarlFactory.eINSTANCE.createSarlEvent(); script.getXtendTypes().add(this.sarlEvent); this.sarlEvent.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlEvent.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlAgent == null) { this.sarlAgent = SarlFactory.eINSTANCE.createSarlAgent(); script.getXtendTypes().add(this.sarlAgent); this.sarlAgent.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlAgent.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlInterface == null) { this.container = script; this.sarlInterface = SarlFactory.eINSTANCE.createSarlInterface(); script.getXtendTypes().add(this.sarlInterface); this.sarlInterface.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlInterface.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlEnumeration == null) { this.container = script; this.sarlEnumeration = SarlFactory.eINSTANCE.createSarlEnumeration(); script.getXtendTypes().add(this.sarlEnumeration); this.sarlEnumeration.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlEnumeration.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlClass == null) { this.container = script; this.sarlClass = SarlFactory.eINSTANCE.createSarlClass(); script.getXtendTypes().add(this.sarlClass); this.sarlClass.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlClass.setName(name); } } }
/** Initialize the Ecore element when inside a script. */ public void eInit(SarlScript script, String name, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlAnnotationType == null) { this.container = script; this.sarlAnnotationType = SarlFactory.eINSTANCE.createSarlAnnotationType(); script.getXtendTypes().add(this.sarlAnnotationType); this.sarlAnnotationType.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration()); if (!Strings.isEmpty(name)) { this.sarlAnnotationType.setName(name); } } }
/** Generate the given script. * * @param script the script. * @param context the context. */ protected void _generate(SarlScript script, IExtraLanguageGeneratorContext context) { if (script != null) { for (final XtendTypeDeclaration content : script.getXtendTypes()) { if (context.getCancelIndicator().isCanceled()) { return; } try { generate(content, context); } finally { context.clearData(); } } } }
/** 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"); }
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); }